Implement wait tool on settings module

This commit is contained in:
lash 2022-05-12 18:20:52 +00:00
parent 6ad0edd8a8
commit e03c5b8035
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 35 additions and 24 deletions

View File

@ -112,7 +112,7 @@ logg.debug('settings loaded:\n{}'.format(settings))
def get_block(settings): def get_block(settings):
hsh = settings.get('HASH') hsh = settings.get('HASH')[0]
r = None r = None
if hsh == None: if hsh == None:
r = get_block_number( r = get_block_number(

View File

@ -103,7 +103,6 @@ settings = process_settings_local(settings, config)
logg.debug('settings loaded:\n{}'.format(settings)) logg.debug('settings loaded:\n{}'.format(settings))
def get_transaction(conn, chain_spec, tx_hash, id_generator): def get_transaction(conn, chain_spec, tx_hash, id_generator):
o = transaction(tx_hash, id_generator=id_generator) o = transaction(tx_hash, id_generator=id_generator)
tx_src = conn.do(o) tx_src = conn.do(o)
@ -150,10 +149,11 @@ def get_address(conn, address, id_generator, height):
def main(): def main():
r = None r = None
if settings.get('HASH') != None: if settings.get('HASH') != None:
hsh = settings.get('HASH')[0]
r = get_transaction( r = get_transaction(
settings.get('CONN'), settings.get('CONN'),
settings.get('CHAIN_SPEC'), settings.get('CHAIN_SPEC'),
settings.get('HASH'), hsh,
settings.get('RPC_ID_GENERATOR'), settings.get('RPC_ID_GENERATOR'),
) )
if not config.true('_RAW'): if not config.true('_RAW'):

View File

@ -64,9 +64,15 @@ config_dir = os.path.join(script_dir, '..', 'data', 'config')
def process_config_local(config, arg, args, flags): def process_config_local(config, arg, args, flags):
config.add(args.ignore, '_IGNORE', False) config.add(args.ignore, '_IGNORE', False)
config.add(args.ignore_all, '_IGNORE_ALL', False) config.add(args.ignore_all, '_IGNORE_ALL', False)
config.add(args.hashes, '_HASHES', False) config.add(args.hashes, '_HASH', False)
return config return config
def process_settings_local(settings, config):
settings.set('HASH', config.get('_HASH'))
return settings
arg_flags = ArgFlag() arg_flags = ArgFlag()
arg = Arg(arg_flags) arg = Arg(arg_flags)
flags = arg_flags.STD_READ flags = arg_flags.STD_READ
@ -98,29 +104,30 @@ def main():
for hsh in config.get('_IGNORE'): for hsh in config.get('_IGNORE'):
hashes_ignore.append(add_0x(hex_uniform(strip_0x(hsh)))) 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: try:
hsh = add_0x(hex_uniform(strip_0x(config.get('_HASHES')[0])))
hashes_ready = [hsh] hashes_ready = [hsh]
except ValueError: except ValueError:
logg.debug('hash argument not a hash, will try it as a file name') 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: for hsh in f:
logg.debug('hshs {}'.format(hsh)) hashes_ready.append(hsh)
hashes_ready.append(add_0x(hex_uniform(strip_0x(hsh.rstrip()))))
f.close() f.close()
else: else:
for hsh in config.get('_HASHES'): for hsh in settings.get('HASH'):
logg.debug('hsh {}'.format(hsh)) if hsh in hashes_ready:
hashes_ready.append(add_0x(hex_uniform(strip_0x(hsh)))) logg.debug('skipping duplicate hash {}'.format(hsh))
continue
hashes_ready.append(hsh)
for hsh in hashes_ready: for hsh in hashes_ready:
logg.debug('processing transaction hash {}'.format(hsh)) logg.info('processing transaction hash {}'.format(hsh))
try: try:
r = settings.get('CONN').wait(hsh) r = settings.get('CONN').wait(hsh)
except RevertEthException: except RevertEthException:
if config.get('_IGNORE_ALL') or hsh in hashes_ignore: 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 continue
sys.stderr.write('revert in transaction hash {}\n'.format(hsh)) sys.stderr.write('revert in transaction hash {}\n'.format(hsh))
sys.exit(1) sys.exit(1)
@ -128,5 +135,3 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -111,19 +111,25 @@ def process_settings_data(settings, config):
def process_settings_hash(settings, config): def process_settings_hash(settings, config):
hsh = None hshs = None
try: try:
hsh = config.get('_HASH') hshs = config.get('_HASH')
except KeyError: except KeyError:
return settings return settings
hsh = strip_0x(hsh) if isinstance(hshs, str):
l = len(hsh) hshs = [hshs]
if l != 64:
raise ValueError('invalid hash length {} for {}'.format(l, hsh))
hsh = add_0x(hsh) r = []
settings.set('HASH', hsh) 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 return settings