chainlib-eth

Ethereum implementation of the chainlib interface
Log | Files | Refs | README | LICENSE

commit e03c5b803534430a4cfaac59552395bbd69fc7c1
parent 6ad0edd8a866b7c9797c87ed68e5abde5fa52931
Author: lash <dev@holbrook.no>
Date:   Thu, 12 May 2022 18:20:52 +0000

Implement wait tool on settings module

Diffstat:
Mchainlib/eth/runnable/block.py | 2+-
Mchainlib/eth/runnable/get.py | 4++--
Mchainlib/eth/runnable/wait.py | 31++++++++++++++++++-------------
Mchainlib/eth/settings.py | 22++++++++++++++--------
4 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/chainlib/eth/runnable/block.py b/chainlib/eth/runnable/block.py @@ -112,7 +112,7 @@ logg.debug('settings loaded:\n{}'.format(settings)) def get_block(settings): - hsh = settings.get('HASH') + hsh = settings.get('HASH')[0] r = None if hsh == None: r = get_block_number( diff --git a/chainlib/eth/runnable/get.py b/chainlib/eth/runnable/get.py @@ -103,7 +103,6 @@ settings = process_settings_local(settings, config) logg.debug('settings loaded:\n{}'.format(settings)) - def get_transaction(conn, chain_spec, tx_hash, id_generator): o = transaction(tx_hash, id_generator=id_generator) tx_src = conn.do(o) @@ -150,10 +149,11 @@ def get_address(conn, address, id_generator, height): def main(): r = None if settings.get('HASH') != None: + hsh = settings.get('HASH')[0] r = get_transaction( settings.get('CONN'), settings.get('CHAIN_SPEC'), - settings.get('HASH'), + hsh, settings.get('RPC_ID_GENERATOR'), ) if not config.true('_RAW'): diff --git a/chainlib/eth/runnable/wait.py b/chainlib/eth/runnable/wait.py @@ -64,9 +64,15 @@ config_dir = os.path.join(script_dir, '..', 'data', 'config') def process_config_local(config, arg, args, flags): config.add(args.ignore, '_IGNORE', False) config.add(args.ignore_all, '_IGNORE_ALL', False) - config.add(args.hashes, '_HASHES', False) + config.add(args.hashes, '_HASH', False) return config + +def process_settings_local(settings, config): + settings.set('HASH', config.get('_HASH')) + return settings + + arg_flags = ArgFlag() arg = Arg(arg_flags) flags = arg_flags.STD_READ @@ -98,29 +104,30 @@ def main(): for hsh in config.get('_IGNORE'): hashes_ignore.append(add_0x(hex_uniform(strip_0x(hsh)))) - if len(config.get('_HASHES')) == 1: + if len(settings.get('HASH')) == 1: + hsh = settings.get('HASH')[0] try: - hsh = add_0x(hex_uniform(strip_0x(config.get('_HASHES')[0]))) hashes_ready = [hsh] except ValueError: logg.debug('hash argument not a hash, will try it as a file name') - f = open(config.get('_HASHES')[0]) + f = open(hsh) for hsh in f: - logg.debug('hshs {}'.format(hsh)) - hashes_ready.append(add_0x(hex_uniform(strip_0x(hsh.rstrip())))) + hashes_ready.append(hsh) f.close() else: - for hsh in config.get('_HASHES'): - logg.debug('hsh {}'.format(hsh)) - hashes_ready.append(add_0x(hex_uniform(strip_0x(hsh)))) + for hsh in settings.get('HASH'): + if hsh in hashes_ready: + logg.debug('skipping duplicate hash {}'.format(hsh)) + continue + hashes_ready.append(hsh) for hsh in hashes_ready: - logg.debug('processing transaction hash {}'.format(hsh)) + logg.info('processing transaction hash {}'.format(hsh)) try: r = settings.get('CONN').wait(hsh) except RevertEthException: if config.get('_IGNORE_ALL') or hsh in hashes_ignore: - logg.info('ignoring revert in transaction hash {}'.format(hsh)) + logg.debug('ignoring revert in transaction hash {}'.format(hsh)) continue sys.stderr.write('revert in transaction hash {}\n'.format(hsh)) sys.exit(1) @@ -128,5 +135,3 @@ def main(): if __name__ == '__main__': main() - - diff --git a/chainlib/eth/settings.py b/chainlib/eth/settings.py @@ -111,19 +111,25 @@ def process_settings_data(settings, config): def process_settings_hash(settings, config): - hsh = None + hshs = None try: - hsh = config.get('_HASH') + hshs = config.get('_HASH') except KeyError: return settings - hsh = strip_0x(hsh) - l = len(hsh) - if l != 64: - raise ValueError('invalid hash length {} for {}'.format(l, hsh)) + if isinstance(hshs, str): + hshs = [hshs] - hsh = add_0x(hsh) - settings.set('HASH', hsh) + r = [] + for hsh in hshs: + hsh = strip_0x(hsh) + l = len(hsh) + if l != 64: + raise ValueError('invalid hash length {} for {}'.format(l, hsh)) + hsh = add_0x(hsh) + r.append(hsh) + + settings.set('HASH', r) return settings