accounts-index

Accounts index evm contract tooling with permissioned writes
Log | Files | Refs

commit 2a9a82f5b2ab174202f8a0bcf06cefe3bf7cdf59
parent ed9f15995bf9dca30af670ad432d8bb12b556bbd
Author: Louis Holbrook <accounts-gitlab@holbrook.no>
Date:   Mon, 12 Apr 2021 14:25:22 +0000

Lash/chainlib

Diffstat:
Mpython/eth_accounts_index/runnable/add.py | 49+++++++++++++++++++++++++++++++++++++------------
Mpython/eth_accounts_index/runnable/deploy.py | 56+++++++++++++++++++++++++++++++++++++++-----------------
Apython/eth_accounts_index/runnable/list.py | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpython/eth_accounts_index/runnable/writer.py | 49+++++++++++++++++++++++++++++++++++++------------
Mpython/setup.cfg | 2+-
5 files changed, 213 insertions(+), 42 deletions(-)

diff --git a/python/eth_accounts_index/runnable/add.py b/python/eth_accounts_index/runnable/add.py @@ -16,8 +16,14 @@ import sys from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer from crypto_dev_signer.keystore.dict import DictKeystore 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('-y', '--key-file', dest='y', type=str, help='Ethereum ke argparser.add_argument('-a', '--contract-address', dest='a', required=True, type=str, help='Contract address to account index to edit') 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('address', type=str, help='Address to add') 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=AccountRegistry.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=AccountRegistry.gas) +else: + gas_oracle = RPCGasOracle(rpc, code_callback=AccountRegistry.gas) + +dummy = args.d contract_address = args.a account = args.address @@ -81,14 +102,18 @@ def main(): if __name__ == '__main__': c = AccountRegistry(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle) (tx_hash_hex, o) = c.add(contract_address, signer_address, account) - rpc.do(o) - r = rpc.wait(tx_hash_hex) - if block_last: - 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) + r = rpc.wait(tx_hash_hex) + if block_last: + 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/eth_accounts_index/runnable/deploy.py b/python/eth_accounts_index/runnable/deploy.py @@ -16,8 +16,14 @@ import logging from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer from crypto_dev_signer.keystore.dict import DictKeystore 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 @@ -38,6 +44,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('--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() @@ -68,27 +77,40 @@ 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=AccountRegistry.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=AccountRegistry.gas) +else: + gas_oracle = RPCGasOracle(rpc, code_callback=AccountRegistry.gas) + +dummy = args.d def main(): c = AccountRegistry(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle) (tx_hash_hex, o) = c.constructor(signer_address) - 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_accounts_index/runnable/list.py b/python/eth_accounts_index/runnable/list.py @@ -0,0 +1,99 @@ +"""Query account index state + +.. moduleauthor:: Louis Holbrook <dev@holbrook.no> +.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 + +""" + +# standard imports +import sys +import os +import json +import argparse +import logging + +# third-party 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.connection import EthHTTPConnection +from chainlib.eth.tx import receipt +from chainlib.eth.constant import ZERO_CONTENT +from chainlib.error import JSONRPCException + +# local imports +from eth_accounts_index import AccountRegistry + +logging.basicConfig(level=logging.WARNING) +logg = logging.getLogger() + +script_dir = os.path.dirname(__file__) +data_dir = os.path.join(script_dir, '..', 'data') + +default_format = 'terminal' + +argparser = argparse.ArgumentParser() +argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='RPC provider url (http only)') +argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:ethereum:1', help='Chain specification string') +argparser.add_argument('-a', '--contract-address', dest='a', required=True, type=str, help='Contract address') +argparser.add_argument('-f', '--format', dest='f', type=str, default=default_format, help='Output format [human, brief]') +argparser.add_argument('-v', action='store_true', help='Be verbose') +argparser.add_argument('-vv', action='store_true', help='Be more verbose') +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('address', type=str, nargs='?', help='Address to check registration for') +args = argparser.parse_args() + +if args.vv: + logg.setLevel(logging.DEBUG) +elif args.v: + logg.setLevel(logging.INFO) + +chain_spec = ChainSpec.from_chain_str(args.i) + +rpc = EthHTTPConnection(args.p) +account_registry_address = args.a +address = args.address +fmt = args.f + + +def out_element(e, fmt=default_format, w=sys.stdout): + logg.debug('format {}'.format(fmt)) + if fmt == 'brief': + w.write(str(e[1]) + '\n') + else: + w.write('{} {}\n'.format(e[0], e[1])) + + +def element(ifc, address, fmt=default_format, w=sys.stdout): + o = ifc.have(account_registry_address, address) + r = rpc.do(o) + have = ifc.parse_have(r) + out_element((address, have), fmt, w) + + +def ls(ifc, fmt=default_format, w=sys.stdout): + i = 1 + while True: + o = ifc.account(account_registry_address, i) + try: + r = rpc.do(o) + account = ifc.parse_account(r) + out_element((i, account), fmt, w) + i += 1 + except JSONRPCException as e: + break + + +def main(): + c = AccountRegistry(chain_spec) + if address != None: + element(c, address, fmt=fmt, w=sys.stdout) + else: + ls(c, fmt=fmt, w=sys.stdout) + + +if __name__ == '__main__': + main() diff --git a/python/eth_accounts_index/runnable/writer.py b/python/eth_accounts_index/runnable/writer.py @@ -16,8 +16,14 @@ import sys from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer from crypto_dev_signer.keystore.dict import DictKeystore 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 @@ -40,6 +46,9 @@ argparser.add_argument('-a', '--contract-address', dest='a', required=True, type argparser.add_argument('--delete', action='store_true', help='Delete 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('address', type=str, help='Subject address') args = argparser.parse_args() @@ -71,8 +80,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=AccountRegistry.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=AccountRegistry.gas) +else: + gas_oracle = RPCGasOracle(rpc, code_callback=AccountRegistry.gas) + +dummy = args.d + contract_address = args.a address = args.address delete = False @@ -88,14 +109,18 @@ def main(): (tx_hash_hex, o) = c.delete_writer(contract_address, signer_address, address) else: (tx_hash_hex, o) = c.add_writer(contract_address, signer_address, address) - rpc.do(o) - r = rpc.wait(tx_hash_hex) - if block_last: - 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) + r = rpc.wait(tx_hash_hex) + if block_last: + 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/setup.cfg b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = eth-accounts-index -version = 0.0.11a7 +version = 0.0.11a8 description = Accounts index evm contract tooling with permissioned writes author = Louis Holbrook author_email = dev@holbrook.no