Make gas price, nonce settable, optional send

This commit is contained in:
nolash 2021-04-12 16:01:51 +02:00
parent 0fb5f18671
commit cfeb143564
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 79 additions and 33 deletions

View File

@ -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 = 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,6 +101,10 @@ 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)
if dummy:
print(tx_hash_hex)
print(o)
else:
rpc.do(o)
if block_last:
r = rpc.wait(tx_hash_hex)
@ -93,8 +118,6 @@ def main():
else:
print(tx_hash_hex)
sys.exit(0)
if __name__ == '__main__':
main()

View File

@ -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,11 +82,21 @@ signer = EIP155Signer(keystore)
chain_spec = ChainSpec.from_chain_str(args.i)
rpc = EthHTTPConnection(args.p)
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
@ -87,6 +106,10 @@ 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)
if dummy:
print(tx_hash_hex)
print(o)
else:
rpc.do(o)
if block_last:
r = rpc.wait(tx_hash_hex)

Binary file not shown.

View File

@ -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

View File

@ -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