Add settable gas price, nonce, optional send

This commit is contained in:
nolash 2021-04-13 08:16:32 +02:00
parent b11cbcd5af
commit 86e3bfbcc1
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 114 additions and 44 deletions

View File

@ -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,6 +107,10 @@ 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)
if dummy:
print(tx_hash_hex)
print(o)
else:
rpc.do(o)
if block_last:
r = rpc.wait(tx_hash_hex)

View File

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

View File

@ -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,6 +103,10 @@ 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)
if dummy:
print(tx_hash_hex)
print(o)
else:
rpc.do(o)
if block_last:
r = rpc.wait(tx_hash_hex)

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