contract-registry

Ethereum Smart Contract key-value registry
Log | Files | Refs

commit cfeb143564df71100ae06ef3d9fed9ecf463aaab
parent 0fb5f18671d3b830d9e8df049c1a3a0d1670bec6
Author: nolash <dev@holbrook.no>
Date:   Mon, 12 Apr 2021 16:01:51 +0200

Make gas price, nonce settable, optional send

Diffstat:
Mpython/eth_contract_registry/runnable/deploy.py | 57++++++++++++++++++++++++++++++++++++++++-----------------
Mpython/eth_contract_registry/runnable/set.py | 53++++++++++++++++++++++++++++++++++++++---------------
Mpython/gmon.out | 0
Mpython/requirements.txt | 4++--
Mpython/setup.cfg | 2+-
5 files changed, 81 insertions(+), 35 deletions(-)

diff --git a/python/eth_contract_registry/runnable/deploy.py b/python/eth_contract_registry/runnable/deploy.py @@ -17,8 +17,14 @@ from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer from crypto_dev_signer.keystore.dict import DictKeystore from crypto_dev_signer.eth.helper import EthTxExecutor from chainlib.chain import ChainSpec -from chainlib.eth.nonce import RPCNonceOracle -from chainlib.eth.gas import RPCGasOracle +from chainlib.eth.nonce import ( + RPCNonceOracle, + OverrideNonceOracle, + ) +from chainlib.eth.gas import ( + RPCGasOracle, + OverrideGasOracle, + ) from chainlib.eth.connection import EthHTTPConnection from chainlib.eth.tx import receipt @@ -39,6 +45,9 @@ argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:et argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing') argparser.add_argument('-v', action='store_true', help='Be verbose') argparser.add_argument('-vv', action='store_true', help='Be more verbose') +argparser.add_argument('-d', action='store_true', help='Dump RPC calls to terminal and do not send') +argparser.add_argument('--gas-price', type=int, dest='gas_price', help='Override gas price') +argparser.add_argument('--nonce', type=int, help='Override transaction nonce') argparser.add_argument('--identifier', type=str, action='append', default=[], help='Add contract identifier') argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration') args = argparser.parse_args() @@ -70,8 +79,20 @@ signer = EIP155Signer(keystore) chain_spec = ChainSpec.from_chain_str(args.i) rpc = EthHTTPConnection(args.p) -nonce_oracle = RPCNonceOracle(signer_address, rpc) -gas_oracle = RPCGasOracle(rpc, code_callback=Registry.gas) +nonce_oracle = None +if args.nonce != None: + nonce_oracle = OverrideNonceOracle(signer_address, args.nonce) +else: + nonce_oracle = RPCNonceOracle(signer_address, rpc) + +gas_oracle = None +if args.gas_price !=None: + gas_oracle = OverrideGasOracle(price=args.gas_price, conn=rpc, code_callback=Registry.gas) +else: + gas_oracle = RPCGasOracle(rpc, code_callback=Registry.gas) + +dummy = args.d + identifiers = args.identifier if 'ContractRegistry' not in identifiers: identifiers = ['ContractRegistry'] + identifiers @@ -80,20 +101,22 @@ logg.debug('adding identifiers {}'.format(identifiers)) def main(): c = Registry(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle) (tx_hash_hex, o) = c.constructor(signer_address, identifiers) - rpc.do(o) - if block_last: - r = rpc.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: + if dummy: print(tx_hash_hex) - - sys.exit(0) + print(o) + else: + rpc.do(o) + if block_last: + r = rpc.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) if __name__ == '__main__': diff --git a/python/eth_contract_registry/runnable/set.py b/python/eth_contract_registry/runnable/set.py @@ -12,13 +12,19 @@ import json import argparse import logging -# third-party imports +# external imports from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer from crypto_dev_signer.keystore.dict import DictKeystore from crypto_dev_signer.eth.helper import EthTxExecutor from chainlib.chain import ChainSpec -from chainlib.eth.nonce import RPCNonceOracle -from chainlib.eth.gas import RPCGasOracle +from chainlib.eth.nonce import ( + RPCNonceOracle, + OverrideNonceOracle, + ) +from chainlib.eth.gas import ( + RPCGasOracle, + OverrideGasOracle, + ) from chainlib.eth.connection import EthHTTPConnection from chainlib.eth.tx import receipt from chainlib.eth.constant import ZERO_CONTENT @@ -41,6 +47,9 @@ argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum ke argparser.add_argument('-r', '--registry', dest='r', type=str, help='Contract registry address') argparser.add_argument('-v', action='store_true', help='Be verbose') argparser.add_argument('-vv', action='store_true', help='Be more verbose') +argparser.add_argument('-d', action='store_true', help='Dump RPC calls to terminal and do not send') +argparser.add_argument('--gas-price', type=int, dest='gas_price', help='Override gas price') +argparser.add_argument('--nonce', type=int, help='Override transaction nonce') argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration') argparser.add_argument('identifier', type=str, help='Contract registry identifier') argparser.add_argument('address', type=str, help='Address to set for identifier') @@ -73,12 +82,22 @@ signer = EIP155Signer(keystore) chain_spec = ChainSpec.from_chain_str(args.i) rpc = EthHTTPConnection(args.p) -nonce_oracle = RPCNonceOracle(signer_address, rpc) -gas_oracle = RPCGasOracle(rpc, code_callback=Registry.gas) +nonce_oracle = None +if args.nonce != None: + nonce_oracle = OverrideNonceOracle(signer_address, args.nonce) +else: + nonce_oracle = RPCNonceOracle(signer_address, rpc) + +gas_oracle = None +if args.gas_price !=None: + gas_oracle = OverrideGasOracle(price=args.gas_price, conn=rpc, code_callback=Registry.gas) +else: + gas_oracle = RPCGasOracle(rpc, code_callback=Registry.gas) + +dummy = args.d + registry_address = args.r if registry_address == None: - registry_address = args.a -if registry_address == None: raise ValueError('Registry address must be set') identifier = args.identifier address = args.address @@ -87,14 +106,18 @@ address = args.address def main(): c = Registry(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle) (tx_hash_hex, o) = c.set(registry_address, signer_address, identifier, address, chain_spec, ZERO_CONTENT) - rpc.do(o) - if block_last: - r = rpc.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) - - print(tx_hash_hex) + if dummy: + print(tx_hash_hex) + print(o) + else: + rpc.do(o) + if block_last: + r = rpc.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) + + print(tx_hash_hex) if __name__ == '__main__': diff --git a/python/gmon.out b/python/gmon.out Binary files differ. diff --git a/python/requirements.txt b/python/requirements.txt @@ -1,3 +1,3 @@ confini~=0.3.6rc3 -crypto-dev-signer~=0.4.14a17 -chainlib~=0.0.2a1 +crypto-dev-signer~=0.4.14b1 +chainlib~=0.0.2a8 diff --git a/python/setup.cfg b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = eth-contract-registry -version = 0.5.4a8 +version = 0.5.4a9 description = Ethereum Smart Contract key-value registry author = Louis Holbrook author_email = dev@holbrook.no