mirror of
git://holbrook.no/eth-contract-registry
synced 2024-12-22 20:27:32 +01:00
Refactor cli commands to use updated chainlib
This commit is contained in:
parent
224af29ad9
commit
e135112436
@ -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()
|
|
@ -8,8 +8,6 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import json
|
|
||||||
import argparse
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
@ -23,6 +21,19 @@ from hexathon import (
|
|||||||
add_0x,
|
add_0x,
|
||||||
strip_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
|
# local imports
|
||||||
from eth_contract_registry.registry import ContractRegistry
|
from eth_contract_registry.registry import ContractRegistry
|
||||||
@ -30,23 +41,51 @@ from eth_contract_registry.registry import ContractRegistry
|
|||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
arg_flags = chainlib.eth.cli.argflag_std_read | chainlib.eth.cli.Flag.EXEC
|
|
||||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
def process_config_local(config, arg, args, flags):
|
||||||
argparser.add_argument('identifier', type=str, nargs='?', help='Token symbol to return address for')
|
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()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
extra_args = {
|
logg = process_log(args, logg)
|
||||||
'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()
|
config = Config()
|
||||||
wallet.from_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))
|
||||||
|
|
||||||
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
|
settings = ChainSettings()
|
||||||
conn = rpc.connect_by_config(config)
|
settings = process_settings(settings, config)
|
||||||
|
logg.debug('settings loaded:\n{}'.format(settings))
|
||||||
|
|
||||||
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):
|
def out_element(e, w=sys.stdout):
|
||||||
@ -77,7 +116,9 @@ def ls(ifc, conn, registry_address, w=sys.stdout):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
c = ContractRegistry(chain_spec)
|
c = ContractRegistry(
|
||||||
|
settings.get('CHAIN_SPEC')
|
||||||
|
)
|
||||||
|
|
||||||
identifier = config.get('_IDENTIFIER')
|
identifier = config.get('_IDENTIFIER')
|
||||||
|
|
||||||
@ -86,9 +127,20 @@ def main():
|
|||||||
raise ValueError('invalid checksum address for contract')
|
raise ValueError('invalid checksum address for contract')
|
||||||
|
|
||||||
if identifier != None:
|
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:
|
else:
|
||||||
ls(c, conn, registry_address, w=sys.stdout)
|
ls(
|
||||||
|
c,
|
||||||
|
settings.get('CONN'),
|
||||||
|
settings.get('EXEC'),
|
||||||
|
w=sys.stdout,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
100
python/eth_contract_registry/runnable/publish.py
Normal file
100
python/eth_contract_registry/runnable/publish.py
Normal file
@ -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()
|
@ -8,8 +8,6 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import json
|
|
||||||
import argparse
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
@ -23,6 +21,18 @@ from hexathon import (
|
|||||||
add_0x,
|
add_0x,
|
||||||
strip_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
|
# local imports
|
||||||
from eth_contract_registry.registry import ContractRegistry
|
from eth_contract_registry.registry import ContractRegistry
|
||||||
@ -30,57 +40,57 @@ from eth_contract_registry.registry import ContractRegistry
|
|||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC
|
|
||||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
def process_config_local(config, arg, args, flags):
|
||||||
argparser.add_argument('--chain-hash', type=str, dest='chain_hash', default=ZERO_CONTENT, help='Chain config hash to use for entry')
|
hsh = strip_0x(args.chain_hash)
|
||||||
argparser.add_argument('--identifier', required=True, type=str, help='Contract identifier to set')
|
if len(hsh) != 64:
|
||||||
argparser.add_positional('address', type=str, help='Contract address to set for identifier')
|
raise ValueError('chain hash must be 32 bytes')
|
||||||
|
config.add(hsh, '_CHAIN_HASH')
|
||||||
|
config.add(config.get('_POSARG'), '_IDENTIFIER')
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
arg_flags = ArgFlag()
|
||||||
|
arg = Arg(arg_flags)
|
||||||
|
flags = arg_flags.STD_WRITE | arg_flags.EXEC | arg_flags.WALLET
|
||||||
|
|
||||||
|
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()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
extra_args = {
|
logg = process_log(args, logg)
|
||||||
'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())
|
|
||||||
|
|
||||||
wallet = chainlib.eth.cli.Wallet()
|
config = Config()
|
||||||
wallet.from_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))
|
||||||
|
|
||||||
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
|
settings = ChainSettings()
|
||||||
conn = rpc.connect_by_config(config)
|
settings = process_settings(settings, config)
|
||||||
|
logg.debug('settings loaded:\n{}'.format(settings))
|
||||||
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
signer = rpc.get_signer()
|
conn = settings.get('CONN')
|
||||||
signer_address = rpc.get_sender_address()
|
c = ContractRegistry(
|
||||||
|
settings.get('CHAIN_SPEC'),
|
||||||
|
signer=settings.get('SIGNER'),
|
||||||
|
gas_oracle=settings.get('FEE_ORACLE'),
|
||||||
|
nonce_oracle=settings.get('NONCE_ORACLE'),
|
||||||
|
)
|
||||||
|
|
||||||
gas_oracle = rpc.get_gas_oracle()
|
(tx_hash_hex, o) = c.set(
|
||||||
nonce_oracle = rpc.get_nonce_oracle()
|
settings.get('EXEC'),
|
||||||
|
settings.get('SENDER_ADDRESS'),
|
||||||
|
config.get('_IDENTIFIER'),
|
||||||
|
settings.get('RECIPIENT'),
|
||||||
|
)
|
||||||
|
|
||||||
c = ContractRegistry(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
|
if settings.get('RPC_SEND'):
|
||||||
|
|
||||||
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')
|
|
||||||
|
|
||||||
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')
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
(tx_hash_hex, o) = c.set(registry_address, signer_address, config.get('_IDENTIFIER'), subject_address)
|
|
||||||
|
|
||||||
if config.get('_RPC_SEND'):
|
|
||||||
conn.do(o)
|
conn.do(o)
|
||||||
if config.get('_WAIT'):
|
if config.true('_WAIT'):
|
||||||
r = conn.wait(tx_hash_hex)
|
r = conn.wait(tx_hash_hex)
|
||||||
if r['status'] == 0:
|
if r['status'] == 0:
|
||||||
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
|
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
|
||||||
|
@ -34,7 +34,6 @@ packages =
|
|||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts =
|
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-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
|
eth-contract-registry-list = eth_contract_registry.runnable.list:main
|
||||||
|
Loading…
Reference in New Issue
Block a user