eth-erc20

ERC20 interface and example giftable token contract
Log | Files | Refs | LICENSE

commit 86e3bfbcc1b8a726bb2432a215e60953573e66cc
parent b11cbcd5af908b51a739c51ed52e5bcf20df7846
Author: nolash <dev@holbrook.no>
Date:   Tue, 13 Apr 2021 08:16:32 +0200

Add settable gas price, nonce, optional send

Diffstat:
Mpython/giftable_erc20_token/runnable/deploy.py | 54+++++++++++++++++++++++++++++++++++++++---------------
Mpython/giftable_erc20_token/runnable/gift.py | 54++++++++++++++++++++++++++++++++++++++----------------
Mpython/giftable_erc20_token/runnable/minter.py | 52++++++++++++++++++++++++++++++++++++++--------------
Mpython/requirements.txt | 4++--
Mpython/setup.cfg | 2+-
5 files changed, 118 insertions(+), 48 deletions(-)

diff --git a/python/giftable_erc20_token/runnable/deploy.py b/python/giftable_erc20_token/runnable/deploy.py @@ -20,8 +20,14 @@ from enum import Enum 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 @@ -45,6 +51,9 @@ argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFI argparser.add_argument('--name', default='Giftable Token', type=str, help='Token name') argparser.add_argument('--symbol', default='GFT', type=str, help='Token symbol') argparser.add_argument('--decimals', default=18, type=int, help='Token decimals') +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('-v', action='store_true', help='Be verbose') argparser.add_argument('-vv', action='store_true', help='Be more verbose') args = argparser.parse_args() @@ -76,8 +85,19 @@ 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=GiftableToken.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=GiftableToken.gas) +else: + gas_oracle = RPCGasOracle(rpc, code_callback=GiftableToken.gas) + +dummy = args.d token_name = args.name token_symbol = args.symbol @@ -87,18 +107,22 @@ token_decimals = args.decimals def main(): c = GiftableToken(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle) (tx_hash_hex, o) = c.constructor(signer_address, token_name, token_symbol, token_decimals) - 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) + 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/giftable_erc20_token/runnable/gift.py b/python/giftable_erc20_token/runnable/gift.py @@ -20,8 +20,14 @@ from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer from crypto_dev_signer.keystore.dict import DictKeystore from chainlib.eth.tx import receipt 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 # local imports @@ -43,6 +49,9 @@ argparser.add_argument('-a', '--token-address', required='True', dest='a', type= 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') argparser.add_argument('--recipient', type=str, help='Recipient account address. If not set, tokens will be gifted to the keystore account') argparser.add_argument('value', type=int, help='Value of tokens to mint and gift') @@ -75,8 +84,19 @@ 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=GiftableToken.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=GiftableToken.gas) +else: + gas_oracle = RPCGasOracle(rpc, code_callback=GiftableToken.gas) + +dummy = args.d token_address = args.a recipient_address = args.recipient @@ -88,18 +108,20 @@ token_value = args.value def main(): c = GiftableToken(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle) (tx_hash_hex, o) = c.mint_to(token_address, signer_address, recipient_address, token_value) - rpc.do(o) - if block_last: - r = rpc.wait(tx_hash_hex) - if r['status'] == 0: - sys.stderr.write('EVM revert. Wish I had more to tell you') - sys.exit(1) - - logg.info('mint to {} tx {}'.format(recipient_address, tx_hash_hex)) - - print(tx_hash_hex) - - sys.exit(0) + 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. Wish I had more to tell you') + sys.exit(1) + + logg.info('mint to {} tx {}'.format(recipient_address, tx_hash_hex)) + + print(tx_hash_hex) if __name__ == '__main__': diff --git a/python/giftable_erc20_token/runnable/minter.py b/python/giftable_erc20_token/runnable/minter.py @@ -19,8 +19,14 @@ import time from chainlib.eth.connection import EthHTTPConnection from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer from crypto_dev_signer.keystore.dict import DictKeystore -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.chain import ChainSpec from chainlib.eth.tx import receipt @@ -42,6 +48,9 @@ argparser.add_argument('-a', '--token-address', required='True', dest='a', type= 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') argparser.add_argument('minter_address', type=str, help='Minter address to add') args = argparser.parse_args() @@ -73,8 +82,19 @@ 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=GiftableToken.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=GiftableToken.gas) +else: + gas_oracle = RPCGasOracle(rpc, code_callback=GiftableToken.gas) + +dummy = args.d token_address = args.a minter_address = args.minter_address @@ -83,16 +103,20 @@ minter_address = args.minter_address def main(): c = GiftableToken(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle) (tx_hash_hex, o) = c.add_minter(token_address, signer_address, minter_address) - rpc.do(o) - if block_last: - r = rpc.wait(tx_hash_hex) - if r['status'] == 0: - sys.stderr.write('EVM revert. Wish I had more to tell you') - sys.exit(1) - - logg.info('add minter {} to {} tx {}'.format(minter_address, token_address, tx_hash_hex)) - - 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. Wish I had more to tell you') + sys.exit(1) + + logg.info('add minter {} to {} tx {}'.format(minter_address, token_address, tx_hash_hex)) + + print(tx_hash_hex) if __name__ == '__main__': 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 = giftable-erc20-token -version = 0.0.8a7 +version = 0.0.8a8 description = Simple ERC20 contract with deployment script that lets any address mint and gift itself tokens. author = Louis Holbrook author_email = dev@holbrook.no