From 556366a93384bba51aa617d54bcf50f4473b790a Mon Sep 17 00:00:00 2001 From: William Luke Date: Tue, 1 Mar 2022 16:36:58 +0300 Subject: [PATCH] feat(wizard): add ability to select wallet address --- README.md | 3 +++ cic/contract/contract.py | 21 +++++++++++++++++---- cic/ext/eth/__init__.py | 2 +- cic/ext/eth/rpc.py | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7b17e22..1e22c02 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,9 @@ below are limited to the context of the EVM. poetry run cic -h ``` +```bash + poetry run cic wizard ./somewhere -c ./config/dev-docker +``` ### Tests ``` diff --git a/cic/contract/contract.py b/cic/contract/contract.py index 28fe3c9..5062b55 100644 --- a/cic/contract/contract.py +++ b/cic/contract/contract.py @@ -109,19 +109,32 @@ def generate_contract( CIC_REGISTRY_ADDRESS: {config.get("CIC_REGISTRY_ADDRESS")} CHAIN_SPEC: {config.get("CHAIN_SPEC")} RPC_PROVIDER: {config.get("RPC_PROVIDER")} - AUTH_KEY: {config.get("AUTH_KEY")} """ ) for target in targets: + # TODO Clean this up + modname = f"cic.ext.{target}" + cmd_mod = importlib.import_module(modname) + signer_hint = config.get("WALLET_KEY_FILE") + keys = cmd_mod.list_keys(config, signer_hint) + for idx, key in enumerate(keys): + print(f"{idx} - {key} ") + selecting_key = True + while selecting_key: + idx = int(input("Select key: ")) + if keys[idx] is not None: + key_account_address = keys[idx] + selecting_key = False + else: + print("Invalid key, try again") + m = importlib.import_module(f"cic.ext.{target}.start") m.extension_start( network, registry_address=config.get("CIC_REGISTRY_ADDRESS"), chain_spec=ChainSpec.from_chain_str(config.get("CHAIN_SPEC")), rpc_provider=config.get("RPC_PROVIDER"), - key_account_address=config.get( - "AUTH_KEY" - ), # TODO this should come from the wallet keystore + key_account_address=key_account_address ) network.load() diff --git a/cic/ext/eth/__init__.py b/cic/ext/eth/__init__.py index edcd875..61ae93b 100644 --- a/cic/ext/eth/__init__.py +++ b/cic/ext/eth/__init__.py @@ -18,7 +18,7 @@ from giftable_erc20_token import GiftableToken from hexathon import add_0x, strip_0x # local imports -from cic.ext.eth.rpc import parse_adapter +from cic.ext.eth.rpc import parse_adapter, list_keys from cic.extension import Extension diff --git a/cic/ext/eth/rpc.py b/cic/ext/eth/rpc.py index 19b4ca5..783915b 100644 --- a/cic/ext/eth/rpc.py +++ b/cic/ext/eth/rpc.py @@ -52,3 +52,17 @@ def parse_adapter(config, signer_hint): rpc.connect_by_config(config) return (rpc.conn, signer) + +# TODO Find a better place for this +def list_keys(config, signer_hint): + keystore = None + if signer_hint is None: + logg.info("signer hint missing") + return None + st = os.stat(signer_hint) + if stat.S_ISDIR(st.st_mode): + logg.debug("signer hint is directory") + keystore = EthKeystoreDirectory() + keystore.process_dir(signer_hint, default_password=config.get('WALLET_PASSPHRASE', '')) + + return keystore.list() \ No newline at end of file