From 473ead26f8caaad86b60aee6ee4dde962611f7c0 Mon Sep 17 00:00:00 2001 From: nolash Date: Tue, 30 Mar 2021 12:09:30 +0200 Subject: [PATCH] Add declarator to tasker registry instantiation --- apps/cic-eth/cic_eth/registry.py | 18 ++++++++++++++++++ .../cic-eth/cic_eth/runnable/daemons/tasker.py | 13 +++++++------ apps/cic-eth/cic_eth/runnable/view.py | 18 ++++-------------- 3 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 apps/cic-eth/cic_eth/registry.py diff --git a/apps/cic-eth/cic_eth/registry.py b/apps/cic-eth/cic_eth/registry.py new file mode 100644 index 00000000..5687f8fc --- /dev/null +++ b/apps/cic-eth/cic_eth/registry.py @@ -0,0 +1,18 @@ +# external imports +from cic_eth_registry import CICRegistry +from cic_eth_registry.lookup.declarator import AddressDeclaratorLookup + + +def connect_declarator(rpc, chain_spec, trusted_addresses): + registry = CICRegistry(chain_spec, rpc) + declarator_address = registry.by_name('AddressDeclarator') + lookup = AddressDeclaratorLookup(declarator_address, trusted_addresses) + CICRegistry.add_lookup(lookup) + + +def connect(rpc, chain_spec, registry_address): + CICRegistry.address = registry_address + registry = CICRegistry(chain_spec, rpc) + registry_address = registry.by_name('ContractRegistry') + + return registry diff --git a/apps/cic-eth/cic_eth/runnable/daemons/tasker.py b/apps/cic-eth/cic_eth/runnable/daemons/tasker.py index 2c679524..e75a7820 100644 --- a/apps/cic-eth/cic_eth/runnable/daemons/tasker.py +++ b/apps/cic-eth/cic_eth/runnable/daemons/tasker.py @@ -16,8 +16,6 @@ from chainlib.eth.connection import EthUnixSignerConnection from chainlib.chain import ChainSpec # local imports -from cic_eth_registry import CICRegistry - from cic_eth.eth import erc20 from cic_eth.eth import tx from cic_eth.eth import account @@ -33,6 +31,10 @@ from cic_eth.db.models.base import SessionBase from cic_eth.db.models.otx import Otx from cic_eth.db import dsn_from_config from cic_eth.ext import tx +from cic_eth.registry import ( + connect as connect_registry, + connect_declarator, + ) logging.basicConfig(level=logging.WARNING) logg = logging.getLogger() @@ -121,8 +123,6 @@ RPCConnection.register_location(config.get('SIGNER_SOCKET_PATH'), chain_spec, 's Otx.tracing = config.true('TASKS_TRACE_QUEUE_STATUS') -CICRegistry.address = config.get('CIC_REGISTRY_ADDRESS') - def main(): argv = ['worker'] @@ -145,8 +145,8 @@ def main(): # Callback.ssl_ca_file = config.get('SSL_CA_FILE') rpc = RPCConnection.connect(chain_spec, 'default') - registry = CICRegistry(chain_spec, rpc) - registry_address = registry.by_name('ContractRegistry') + + connect_registry(rpc, chain_spec, config.get('CIC_REGISTRY_ADDRESS')) trusted_addresses_src = config.get('CIC_TRUST_ADDRESS') if trusted_addresses_src == None: @@ -155,6 +155,7 @@ def main(): trusted_addresses = trusted_addresses_src.split(',') for address in trusted_addresses: logg.info('using trusted address {}'.format(address)) + connect_declarator(rpc, chain_spec, trusted_addresses) current_app.worker_main(argv) diff --git a/apps/cic-eth/cic_eth/runnable/view.py b/apps/cic-eth/cic_eth/runnable/view.py index 66e08a01..50adce37 100644 --- a/apps/cic-eth/cic_eth/runnable/view.py +++ b/apps/cic-eth/cic_eth/runnable/view.py @@ -14,8 +14,6 @@ import datetime # external imports import confini import celery -from cic_eth_registry import CICRegistry -from cic_eth_registry.lookup.declarator import AddressDeclaratorLookup from chainlib.chain import ChainSpec from chainlib.eth.connection import EthHTTPConnection from hexathon import add_0x @@ -27,6 +25,7 @@ from cic_eth.db.enum import ( status_str, LockEnum, ) +from cic_eth.registry import connect as connect_registry logging.basicConfig(level=logging.WARNING) logg = logging.getLogger() @@ -147,28 +146,19 @@ def render_lock(o, **kwargs): return s -def connect_registry(registry_address, chain_spec, rpc): - CICRegistry.address = registry_address - registry = CICRegistry(chain_spec, rpc) - declarator_address = registry.by_name('AddressDeclarator') - lookup = AddressDeclaratorLookup(declarator_address, trusted_addresses) - registry.add_lookup(lookup) - return registry - - # TODO: move each command to submodule def main(): txs = [] renderer = render_tx if len(config.get('_QUERY')) > 66: - registry = connect_registry(registry_address, chain_spec, rpc) + registry = connect_registry(rpc, chain_spec, registry_address) admin_api.tx(chain_spec, tx_raw=config.get('_QUERY'), registry=registry, renderer=renderer) elif len(config.get('_QUERY')) > 42: - registry = connect_registry(registry_address, chain_spec, rpc) + registry = connect_registry(rpc, chain_spec, registry_address) admin_api.tx(chain_spec, tx_hash=config.get('_QUERY'), registry=registry, renderer=renderer) elif len(config.get('_QUERY')) == 42: - registry = connect_registry(registry_address, chain_spec, rpc) + registry = connect_registry(rpc, chain_spec, registry_address) txs = admin_api.account(chain_spec, config.get('_QUERY'), include_recipient=False, renderer=render_account) renderer = render_account elif len(config.get('_QUERY')) >= 4 and config.get('_QUERY')[:4] == 'lock':