From 18cb09035470c2dec36e81bc51127e38ecfa2c87 Mon Sep 17 00:00:00 2001 From: lash Date: Mon, 24 Jan 2022 01:06:59 +0000 Subject: [PATCH] Add block start entry for address --- eth_monitor/store/file.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/eth_monitor/store/file.py b/eth_monitor/store/file.py index 8eed8ed..8952b04 100644 --- a/eth_monitor/store/file.py +++ b/eth_monitor/store/file.py @@ -28,8 +28,27 @@ class FileStore: if self.address_rules != None: for a in tx.outputs + tx.inputs: if self.address_rules.apply_rules_addresses(a, a, tx.hash): - a = bytes.fromhex(strip_0x(a)) + a_hex = strip_0x(a).upper() + a = bytes.fromhex(a_hex) self.address_dir.add_dir(tx_hash_dirnormal, a, b'') + dirpath = self.address_dir.to_filepath(a_hex) + fp = os.path.join(dirpath, '.start') + num = tx.block.number + num_compare = 0 + try: + f = open(fp, 'rb') + r = f.read(8) + f.close() + num_compare = int.from_bytes(r, 'big') + except FileNotFoundError: + pass + + if num_compare == 0 or num < num_compare: + logg.debug('recoding new start block {} for {}'.format(num, a)) + num_bytes = num.to_bytes(8, 'big') + f = open(fp, 'wb') + f.write(num_bytes) + f.close() if include_data: src = json.dumps(tx.src()).encode('utf-8')