commit e135112436055f8d30e50f23d7eab9c516b6359e
parent 224af29ad99e5a112c1c672f2ae052f0b91a0901
Author: lash <dev@holbrook.no>
Date: Sat, 11 Feb 2023 06:29:38 +0000
Refactor cli commands to use updated chainlib
Diffstat:
5 files changed, 223 insertions(+), 136 deletions(-)
diff --git a/python/eth_contract_registry/runnable/deploy.py b/python/eth_contract_registry/runnable/deploy.py
@@ -1,74 +0,0 @@
-"""Deploys contract registry
-
-.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
-.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
-
-"""
-
-# standard imports
-import sys
-import os
-import json
-import argparse
-import logging
-
-# external imports
-import chainlib.eth.cli
-from chainlib.chain import ChainSpec
-from chainlib.eth.connection import EthHTTPConnection
-from chainlib.eth.tx import receipt
-
-# local imports
-from eth_contract_registry.registry import ContractRegistry
-
-logging.basicConfig(level=logging.WARNING)
-logg = logging.getLogger()
-
-arg_flags = chainlib.eth.cli.argflag_std_write
-argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
-argparser.add_argument('--identifier', type=str, action='append', default=[], help='Add contract identifier')
-args = argparser.parse_args()
-
-extra_args = {
- 'identifier': None,
- }
-config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=ContractRegistry.gas())
-
-wallet = chainlib.eth.cli.Wallet()
-wallet.from_config(config)
-
-rpc = chainlib.eth.cli.Rpc(wallet=wallet)
-conn = rpc.connect_by_config(config)
-
-chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
-
-
-def main():
- signer = rpc.get_signer()
- signer_address = rpc.get_sender_address()
-
- gas_oracle = rpc.get_gas_oracle()
- nonce_oracle = rpc.get_nonce_oracle()
-
- c = ContractRegistry(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
- (tx_hash_hex, o) = c.constructor(signer_address, config.get('_IDENTIFIER'))
-
- if config.get('_RPC_SEND'):
- conn.do(o)
- if config.get('_WAIT'):
- r = conn.wait(tx_hash_hex)
- if r['status'] == 0:
- sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
- sys.exit(1)
- # TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
- address = r['contractAddress']
-
- print(address)
- else:
- print(tx_hash_hex)
- else:
- print(o)
-
-
-if __name__ == '__main__':
- main()
diff --git a/python/eth_contract_registry/runnable/list.py b/python/eth_contract_registry/runnable/list.py
@@ -8,8 +8,6 @@
# standard imports
import sys
import os
-import json
-import argparse
import logging
# external imports
@@ -23,6 +21,19 @@ from hexathon import (
add_0x,
strip_0x,
)
+from chainlib.eth.cli.arg import (
+ Arg,
+ ArgFlag,
+ process_args,
+ )
+from chainlib.eth.cli.config import (
+ Config,
+ process_config,
+ )
+from chainlib.eth.cli.log import process_log
+from chainlib.eth.settings import process_settings
+from chainlib.settings import ChainSettings
+
# local imports
from eth_contract_registry.registry import ContractRegistry
@@ -30,23 +41,51 @@ from eth_contract_registry.registry import ContractRegistry
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
-arg_flags = chainlib.eth.cli.argflag_std_read | chainlib.eth.cli.Flag.EXEC
-argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
-argparser.add_argument('identifier', type=str, nargs='?', help='Token symbol to return address for')
+
+def process_config_local(config, arg, args, flags):
+ config.add(config.get('_POSARG'), '_IDENTIFIER')
+ return config
+
+
+arg_flags = ArgFlag()
+arg = Arg(arg_flags)
+flags = arg_flags.STD_READ | arg_flags.EXEC
+
+argparser = chainlib.eth.cli.ArgumentParser()
+argparser = process_args(argparser, arg, flags)
+argparser.add_argument('identifier', type=str, help='Contract identifier to look up')
args = argparser.parse_args()
-extra_args = {
- 'identifier': None,
- }
-config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=ContractRegistry.gas())
+logg = process_log(args, logg)
+
+config = Config()
+config = process_config(config, arg, args, flags, positional_name='identifier')
+config = process_config_local(config, arg, args, flags)
+logg.debug('config loaded:\n{}'.format(config))
+
+settings = ChainSettings()
+settings = process_settings(settings, config)
+logg.debug('settings loaded:\n{}'.format(settings))
-wallet = chainlib.eth.cli.Wallet()
-wallet.from_config(config)
-rpc = chainlib.eth.cli.Rpc(wallet=wallet)
-conn = rpc.connect_by_config(config)
-chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
+#arg_flags = chainlib.eth.cli.argflag_std_read | chainlib.eth.cli.Flag.EXEC
+#argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
+#argparser.add_argument('identifier', type=str, nargs='?', help='Token symbol to return address for')
+#args = argparser.parse_args()
+#
+#extra_args = {
+# 'identifier': None,
+# }
+#config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=ContractRegistry.gas())
+#
+#wallet = chainlib.eth.cli.Wallet()
+#wallet.from_config(config)
+#
+#rpc = chainlib.eth.cli.Rpc(wallet=wallet)
+#conn = rpc.connect_by_config(config)
+#
+#chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
def out_element(e, w=sys.stdout):
@@ -77,7 +116,9 @@ def ls(ifc, conn, registry_address, w=sys.stdout):
def main():
- c = ContractRegistry(chain_spec)
+ c = ContractRegistry(
+ settings.get('CHAIN_SPEC')
+ )
identifier = config.get('_IDENTIFIER')
@@ -86,9 +127,20 @@ def main():
raise ValueError('invalid checksum address for contract')
if identifier != None:
- element(c, conn, registry_address, identifier, w=sys.stdout)
+ element(
+ c,
+ settings.get('CONN'),
+ settings.get('EXEC'),
+ config.get('_IDENTIFIER'),
+ w=sys.stdout,
+ )
else:
- ls(c, conn, registry_address, w=sys.stdout)
+ ls(
+ c,
+ settings.get('CONN'),
+ settings.get('EXEC'),
+ w=sys.stdout,
+ )
if __name__ == '__main__':
diff --git a/python/eth_contract_registry/runnable/publish.py b/python/eth_contract_registry/runnable/publish.py
@@ -0,0 +1,100 @@
+"""Deploys contract registry
+
+.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
+.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
+
+"""
+
+# standard imports
+import sys
+import os
+import logging
+
+# external imports
+import chainlib.eth.cli
+from chainlib.chain import ChainSpec
+from chainlib.eth.connection import EthHTTPConnection
+from chainlib.eth.tx import receipt
+from chainlib.eth.cli.arg import (
+ Arg,
+ ArgFlag,
+ process_args,
+ )
+from chainlib.eth.cli.config import (
+ Config,
+ process_config,
+ )
+from chainlib.eth.cli.log import process_log
+from chainlib.eth.settings import process_settings
+from chainlib.settings import ChainSettings
+from chainlib.eth.constant import ZERO_CONTENT
+
+# local imports
+from eth_contract_registry.registry import ContractRegistry
+
+logging.basicConfig(level=logging.WARNING)
+logg = logging.getLogger()
+
+
+def process_config_local(config, arg, args, flags):
+ identifiers = args.identifier
+ if len(identifiers) == 0:
+ raise ValueError('at least one identifier must be defined')
+ config.add(identifiers, '_IDENTIFIER')
+ return config
+
+
+arg_flags = ArgFlag()
+arg = Arg(arg_flags)
+flags = arg_flags.STD_WRITE
+
+argparser = chainlib.eth.cli.ArgumentParser()
+argparser = process_args(argparser, arg, flags)
+argparser.add_argument('--identifier', type=str, action='append', help='SHA256 of description metadata of contract deployer')
+args = argparser.parse_args()
+
+logg = process_log(args, logg)
+
+config = Config()
+config = process_config(config, arg, args, flags)
+config = process_config_local(config, arg, args, flags)
+logg.debug('config loaded:\n{}'.format(config))
+
+settings = ChainSettings()
+settings = process_settings(settings, config)
+logg.debug('settings loaded:\n{}'.format(settings))
+
+
+def main():
+ conn = settings.get('CONN')
+ c = ContractRegistry(
+ settings.get('CHAIN_SPEC'),
+ signer=settings.get('SIGNER'),
+ gas_oracle=settings.get('FEE_ORACLE'),
+ nonce_oracle=settings.get('NONCE_ORACLE'),
+ )
+
+ (tx_hash_hex, o) = c.constructor(
+ settings.get('SENDER_ADDRESS'),
+ identifier_strings=config.get('_IDENTIFIER'),
+ )
+
+ if settings.get('RPC_SEND'):
+ conn.do(o)
+ if config.true('_WAIT'):
+ r = conn.wait(tx_hash_hex)
+ if r['status'] == 0:
+ sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
+ sys.exit(1)
+ # TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
+ address = r['contractAddress']
+
+ print(address)
+ else:
+ print(tx_hash_hex)
+ else:
+ print(o)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/python/eth_contract_registry/runnable/set.py b/python/eth_contract_registry/runnable/set.py
@@ -8,8 +8,6 @@
# standard imports
import sys
import os
-import json
-import argparse
import logging
# external imports
@@ -23,6 +21,18 @@ from hexathon import (
add_0x,
strip_0x,
)
+from chainlib.eth.cli.arg import (
+ Arg,
+ ArgFlag,
+ process_args,
+ )
+from chainlib.eth.cli.config import (
+ Config,
+ process_config,
+ )
+from chainlib.eth.cli.log import process_log
+from chainlib.eth.settings import process_settings
+from chainlib.settings import ChainSettings
# local imports
from eth_contract_registry.registry import ContractRegistry
@@ -30,57 +40,57 @@ from eth_contract_registry.registry import ContractRegistry
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
-arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC
-argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
-argparser.add_argument('--chain-hash', type=str, dest='chain_hash', default=ZERO_CONTENT, help='Chain config hash to use for entry')
-argparser.add_argument('--identifier', required=True, type=str, help='Contract identifier to set')
-argparser.add_positional('address', type=str, help='Contract address to set for identifier')
-args = argparser.parse_args()
-extra_args = {
- 'chain_hash': None,
- 'identifier': None,
- 'address': None,
- }
-config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=ContractRegistry.gas())
+def process_config_local(config, arg, args, flags):
+ hsh = strip_0x(args.chain_hash)
+ if len(hsh) != 64:
+ raise ValueError('chain hash must be 32 bytes')
+ config.add(hsh, '_CHAIN_HASH')
+ config.add(config.get('_POSARG'), '_IDENTIFIER')
+ return config
-wallet = chainlib.eth.cli.Wallet()
-wallet.from_config(config)
-rpc = chainlib.eth.cli.Rpc(wallet=wallet)
-conn = rpc.connect_by_config(config)
+arg_flags = ArgFlag()
+arg = Arg(arg_flags)
+flags = arg_flags.STD_WRITE | arg_flags.EXEC | arg_flags.WALLET
-chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
-
-
-def main():
- signer = rpc.get_signer()
- signer_address = rpc.get_sender_address()
-
- gas_oracle = rpc.get_gas_oracle()
- nonce_oracle = rpc.get_nonce_oracle()
-
- c = ContractRegistry(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
+argparser = chainlib.eth.cli.ArgumentParser()
+argparser = process_args(argparser, arg, flags)
+argparser.add_argument('--chain-hash', type=str, default=ZERO_CONTENT, help='Chain config hash to use for entry')
+argparser.add_argument('identifier', type=str, help='Contract identifier to set')
+args = argparser.parse_args()
- subject_address = to_checksum_address(config.get('_ADDRESS'))
- if not config.true('_UNSAFE') and strip_0x(subject_address) != strip_0x(config.get('_ADDRESS')):
- raise ValueError('invalid checksum address for subject_address')
+logg = process_log(args, logg)
- registry_address = to_checksum_address(config.get('_EXEC_ADDRESS'))
- if not config.true('_UNSAFE') and strip_0x(registry_address) != strip_0x(config.get('_EXEC_ADDRESS')):
- raise ValueError('invalid checksum address for contract')
+config = Config()
+config = process_config(config, arg, args, flags, positional_name='identifier')
+config = process_config_local(config, arg, args, flags)
+logg.debug('config loaded:\n{}'.format(config))
- chain_config_hash = config.get('_CHAIN_HASH')
- chain_config_hash_bytes = bytes.fromhex(strip_0x(chain_config_hash))
- if len(chain_config_hash_bytes) != 32:
- raise ValueError('chain config hash must be 32 bytes')
- chain_config_hash = add_0x(chain_config_hash)
+settings = ChainSettings()
+settings = process_settings(settings, config)
+logg.debug('settings loaded:\n{}'.format(settings))
- (tx_hash_hex, o) = c.set(registry_address, signer_address, config.get('_IDENTIFIER'), subject_address)
- if config.get('_RPC_SEND'):
+def main():
+ conn = settings.get('CONN')
+ c = ContractRegistry(
+ settings.get('CHAIN_SPEC'),
+ signer=settings.get('SIGNER'),
+ gas_oracle=settings.get('FEE_ORACLE'),
+ nonce_oracle=settings.get('NONCE_ORACLE'),
+ )
+
+ (tx_hash_hex, o) = c.set(
+ settings.get('EXEC'),
+ settings.get('SENDER_ADDRESS'),
+ config.get('_IDENTIFIER'),
+ settings.get('RECIPIENT'),
+ )
+
+ if settings.get('RPC_SEND'):
conn.do(o)
- if config.get('_WAIT'):
+ if config.true('_WAIT'):
r = conn.wait(tx_hash_hex)
if r['status'] == 0:
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
diff --git a/python/setup.cfg b/python/setup.cfg
@@ -34,7 +34,6 @@ packages =
[options.entry_points]
console_scripts =
- eth-contract-registry-deploy = eth_contract_registry.runnable.deploy:main
+ eth-contract-registry-publish = eth_contract_registry.runnable.publish:main
eth-contract-registry-set = eth_contract_registry.runnable.set:main
- #eth-contract-registry-seal = eth_contract_registry.runnable.seal:main
eth-contract-registry-list = eth_contract_registry.runnable.list:main