From 1d4b0512ad65b4d2903bd7d022e562cda158a592 Mon Sep 17 00:00:00 2001 From: William Luke Date: Tue, 1 Mar 2022 13:48:58 +0300 Subject: [PATCH] fix(ext): allow loading chain_spec from config --- cic/cmd/ext.py | 8 ++++---- cic/ext/eth/start.py | 32 ++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/cic/cmd/ext.py b/cic/cmd/ext.py index d015a0e..78b0c11 100644 --- a/cic/cmd/ext.py +++ b/cic/cmd/ext.py @@ -10,7 +10,7 @@ from cic.contract.network import Network def process_args(argparser): argparser.add_argument( - "--registry", required=True, type=str, help="contract registry address" + "--registry", type=str, help="contract registry address" ) argparser.add_argument( "-d", "--directory", type=str, dest="directory", default=".", help="directory" @@ -28,11 +28,11 @@ def execute(config, eargs): cn = Network(eargs.directory, targets=eargs.target) cn.load() - chain_spec = ChainSpec.from_chain_str(eargs.i) + chain_spec = ChainSpec.from_chain_str(eargs.i or config.get("CHAIN_SPEC")) m = importlib.import_module(f"cic.ext.{eargs.target}.start") m.extension_start( cn, - registry_address=eargs.registry, + registry_address=eargs.registry or config.get("CIC_REGISTRY_ADDRESS"), chain_spec=chain_spec, rpc_provider=config.get("RPC_PROVIDER"), - ) + ) # TODO add key account address diff --git a/cic/ext/eth/start.py b/cic/ext/eth/start.py index 1482c74..7f6e6ce 100644 --- a/cic/ext/eth/start.py +++ b/cic/ext/eth/start.py @@ -1,6 +1,6 @@ # external imports -from cic_eth_registry import CICRegistry from chainlib.eth.connection import RPCConnection +from cic_eth_registry import CICRegistry def extension_start(network, *args, **kwargs): @@ -9,22 +9,26 @@ def extension_start(network, *args, **kwargs): :param network: Network object to read and write settings from :type network: cic.network.Network """ - CICRegistry.address = kwargs['registry_address'] - key_account_address = kwargs['key_account_address'] or '' + CICRegistry.address = kwargs.get("registry_address") + key_account_address = kwargs.get("key_account_address") + RPCConnection.register_location( + kwargs.get("rpc_provider"), kwargs.get("chain_spec") + ) + conn = RPCConnection.connect(kwargs.get("chain_spec")) - RPCConnection.register_location(kwargs['rpc_provider'], kwargs['chain_spec']) - conn = RPCConnection.connect(kwargs['chain_spec']) + registry = CICRegistry(kwargs.get("chain_spec"), conn) - registry = CICRegistry(kwargs['chain_spec'], conn) + address_declarator = registry.by_name("AddressDeclarator") + network.resource_set( + "eth", "address_declarator", address_declarator, key_account=key_account_address + ) - address_declarator = registry.by_name('AddressDeclarator') - network.resource_set('eth', 'address_declarator', address_declarator, key_account=key_account_address) + token_index = registry.by_name("TokenRegistry") + network.resource_set( + "eth", "token_index", token_index, key_account=key_account_address + ) - token_index = registry.by_name('TokenRegistry') - network.resource_set('eth', 'token_index', token_index, key_account=key_account_address) + network.resource_set("eth", "token", None, key_account=key_account_address) - network.resource_set('eth', 'token', None, key_account=key_account_address) - - - network.set('eth', kwargs['chain_spec']) + network.set("eth", kwargs["chain_spec"]) network.save()