From 2fe205b1e85dfecfe7292e4268f46356641c4947 Mon Sep 17 00:00:00 2001 From: nolash Date: Mon, 8 Mar 2021 15:51:45 +0100 Subject: [PATCH] Provide web3 constructor to tracker rpc client --- apps/cic-eth/cic_eth/runnable/daemons/tracker.py | 15 +++++++++++++++ apps/contract-migration/scripts/verify.py | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/cic-eth/cic_eth/runnable/daemons/tracker.py b/apps/cic-eth/cic_eth/runnable/daemons/tracker.py index f2dfdc58..d6005770 100644 --- a/apps/cic-eth/cic_eth/runnable/daemons/tracker.py +++ b/apps/cic-eth/cic_eth/runnable/daemons/tracker.py @@ -68,6 +68,21 @@ cic_base.config.log(config) dsn = dsn_from_config(config) SessionBase.connect(dsn, pool_size=1, debug=config.true('DATABASE_DEBUG')) +re_websocket = re.compile('^wss?://') +re_http = re.compile('^https?://') +blockchain_provider = config.get('ETH_PROVIDER') +if re.match(re_websocket, blockchain_provider) != None: + blockchain_provider = web3.Web3.WebsocketProvider(blockchain_provider) +elif re.match(re_http, blockchain_provider) != None: + blockchain_provider = web3.Web3.HTTPProvider(blockchain_provider) +else: + raise ValueError('unknown provider url {}'.format(blockchain_provider)) + +def web3_constructor(): + w3 = web3.Web3(blockchain_provider) + return (blockchain_provider, w3) +RpcClient.set_constructor(web3_constructor) + def main(): # parse chain spec object diff --git a/apps/contract-migration/scripts/verify.py b/apps/contract-migration/scripts/verify.py index 3eb47311..ebcb9fef 100644 --- a/apps/contract-migration/scripts/verify.py +++ b/apps/contract-migration/scripts/verify.py @@ -68,6 +68,7 @@ if args.v == True: logging.getLogger().setLevel(logging.INFO) elif args.vv == True: logging.getLogger().setLevel(logging.DEBUG) +verbose = args.vv or args.v config_dir = os.path.join(args.c) os.makedirs(config_dir, 0o777, True) @@ -313,7 +314,8 @@ def main(): r = l.split(',') try: address = to_checksum(r[0]) - #sys.stdout.write('loading balance {} {}'.format(i, address).ljust(200) + "\r") + if not verbose: + sys.stdout.write('loading balance {} {}'.format(i, address).ljust(200) + "\r") logg.debug('loading balance {} {}'.format(i, address).ljust(200)) except ValueError: break @@ -328,6 +330,7 @@ def main(): verifier = Verifier(conn, api, gas_oracle, chain_spec, account_index_address, sarafu_token_address, user_dir, exit_on_error) user_new_dir = os.path.join(user_dir, 'new') + i = 0 for x in os.walk(user_new_dir): for y in x[2]: if y[len(y)-5:] != '.json': @@ -343,6 +346,8 @@ def main(): f.close() u = Person.deserialize(o) + if not verbose: + sys.stdout.write('processing {} {}'.format(i, u.identities['evm']).ljust(200) + "\r") logg.debug('data {}'.format(u.identities['evm'])) subchain_str = '{}:{}'.format(chain_spec.common_name(), chain_spec.network_id()) @@ -357,6 +362,7 @@ def main(): logg.debug('checking {} -> {} = {}'.format(old_address, new_address, balance)) verifier.verify(new_address, balance) + i += 1 print(verifier)