From b51872c2ad88473edc56a2bf8c505069b22efcfc Mon Sep 17 00:00:00 2001 From: nolash Date: Sun, 10 Jan 2021 18:28:12 +0100 Subject: [PATCH] Add eth adapter enhancement from crypto-dev-signer --- .../giftable_erc20_token/runnable/deploy.py | 33 +++---------------- python/giftable_erc20_token/runnable/gift.py | 30 ++--------------- python/setup.cfg | 2 +- 3 files changed, 8 insertions(+), 57 deletions(-) diff --git a/python/giftable_erc20_token/runnable/deploy.py b/python/giftable_erc20_token/runnable/deploy.py index 8b399b3..5462b8e 100644 --- a/python/giftable_erc20_token/runnable/deploy.py +++ b/python/giftable_erc20_token/runnable/deploy.py @@ -20,7 +20,7 @@ from enum import Enum import web3 from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer from crypto_dev_signer.keystore import DictKeystore -from crypto_dev_signer.helper import TxExecutor +from crypto_dev_signer.eth.helper import EthTxExecutor logging.basicConfig(level=logging.WARNING) logg = logging.getLogger() @@ -68,36 +68,15 @@ signer = EIP155Signer(keystore) chain_pair = args.i.split(':') chain_id = int(chain_pair[1]) - -def gas_helper(signer_address, code, inputs): - return 8000000 - -def gas_price_helper(): - return 20000000000 - -def translateTx(tx): - return { - 'from': tx['from'], - 'chainId': tx['chainId'], - 'gas': tx['feeUnits'], - 'gasPrice': tx['feePrice'], - 'nonce': tx['nonce'], - } - -nonce = w3.eth.getTransactionCount(signer_address, 'pending') - -helper = TxExecutor( +helper = EthTxExecutor( + w3, signer_address, signer, - w3.eth.sendRawTransaction, - w3.eth.getTransactionReceipt, - nonce, chain_id, - fee_helper=gas_helper, - fee_price_helper=gas_price_helper, block=args.ww, ) + def main(): f = open(os.path.join(args.abi_dir, 'GiftableToken.json'), 'r') @@ -111,7 +90,6 @@ def main(): c = w3.eth.contract(abi=abi, bytecode=bytecode) (tx_hash, rcpt) = helper.sign_and_send( [ - translateTx, c.constructor(args.n, args.s, args.d).buildTransaction ], force_wait=True, @@ -131,7 +109,6 @@ def main(): continue (tx_hash, rcpt) = helper.sign_and_send( [ - translateTx, c.functions.addMinter(a).buildTransaction, ], ) @@ -141,7 +118,6 @@ def main(): tx = c.functions.mint(mint_total) (tx_hash, rcpt) = helper.sign_and_send( [ - translateTx, c.functions.mint(mint_total).buildTransaction, ], force_wait=True, @@ -150,7 +126,6 @@ def main(): for a in args.account: (tx_hash, rcpt) = helper.sign_and_send( [ - translateTx, c.functions.transfer(a, args.amount).buildTransaction, ], ) diff --git a/python/giftable_erc20_token/runnable/gift.py b/python/giftable_erc20_token/runnable/gift.py index 276094b..55b453c 100644 --- a/python/giftable_erc20_token/runnable/gift.py +++ b/python/giftable_erc20_token/runnable/gift.py @@ -20,7 +20,7 @@ import web3 from eth_keys import keys from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer from crypto_dev_signer.keystore import DictKeystore -from crypto_dev_signer.helper import TxExecutor +from crypto_dev_signer.eth.helper import EthTxExecutor logging.basicConfig(level=logging.WARNING) logg = logging.getLogger() @@ -64,37 +64,15 @@ signer = EIP155Signer(keystore) chain_pair = args.i.split(':') chain_id = int(chain_pair[1]) -def gas_helper(signer_address, code, inputs): - return 8000000 - -def gas_price_helper(): - return 20000000000 - -def translateTx(tx): - return { - 'from': tx['from'], - 'chainId': tx['chainId'], - 'gas': tx['feeUnits'], - 'gasPrice': tx['feePrice'], - 'nonce': tx['nonce'], - } - -nonce = w3.eth.getTransactionCount(signer_address, 'pending') - -helper = TxExecutor( +helper = EthTxExecutor( + w3, signer_address, signer, - w3.eth.sendRawTransaction, - w3.eth.getTransactionReceipt, - nonce, chain_id, - fee_helper=gas_helper, - fee_price_helper=gas_price_helper, block=args.ww, ) - def main(): f = open(os.path.join(args.abi_dir, 'GiftableToken.json'), 'r') @@ -115,7 +93,6 @@ def main(): (tx_hash, rcpt) = helper.sign_and_send( [ - translateTx, c.functions.mint(args.amount).buildTransaction, ], ) @@ -124,7 +101,6 @@ def main(): (tx_hash, rcpt) = helper.sign_and_send( [ - translateTx, c.functions.transfer(recipient, args.amount).buildTransaction, ], ) diff --git a/python/setup.cfg b/python/setup.cfg index feee52d..c9d5365 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = giftable-erc20-token -version = 0.0.7a1 +version = 0.0.7a2 description = Simple ERC20 contract with deployment script that lets any address mint and gift itself tokens. author = Louis Holbrook author_email = dev@holbrook.no