From b107e18a0c22b7e90abb1cbdb44343a80627f27c Mon Sep 17 00:00:00 2001 From: Daniel Dimitrov Date: Tue, 22 Jun 2021 16:25:08 +0200 Subject: [PATCH 1/3] Update web3 to v5.20 --- dev-requirements.txt | 25 ++++++++++++++++++++----- setup.cfg | 2 +- src/deploy_tools/cli.py | 4 ++-- src/deploy_tools/transact.py | 10 +++++----- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 53aa04f..8711023 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -4,12 +4,17 @@ # # pip-compile --output-file=dev-requirements.txt dev-requirements.in setup.py # +aiohttp==3.7.4.post0 + # via web3 appdirs==1.4.3 # via # black # virtualenv +async-timeout==3.0.1 + # via aiohttp attrs==19.3.0 # via + # aiohttp # black # jsonschema # pytest @@ -28,7 +33,9 @@ certifi==2019.11.28 cfgv==3.1.0 # via pre-commit chardet==3.0.4 - # via requests + # via + # aiohttp + # requests click==7.1.1 # via # black @@ -117,8 +124,10 @@ hexbytes==0.2.0 identify==1.4.13 # via pre-commit idna==2.9 - # via requests -ipfshttpclient==0.4.12 + # via + # requests + # yarl +ipfshttpclient==0.7.0 # via web3 json-rpc==1.13.0 # via eth-tester-rpc @@ -134,6 +143,10 @@ more-itertools==8.2.0 # via pytest multiaddr==0.0.9 # via ipfshttpclient +multidict==5.1.0 + # via + # aiohttp + # yarl mypy-extensions==0.4.3 # via # mypy @@ -214,7 +227,6 @@ setuptools-scm==3.5.0 # via -r dev-requirements.in six==1.14.0 # via - # ipfshttpclient # jsonschema # multiaddr # packaging @@ -242,6 +254,7 @@ typed-ast==1.4.1 # mypy typing-extensions==3.7.4.1 # via + # aiohttp # mypy # trie urllib3==1.25.8 @@ -254,7 +267,7 @@ virtualenv==20.0.13 # tox wcwidth==0.1.9 # via pytest -web3==5.9.0 +web3==5.20.0 # via contract-deploy-tools (setup.py) websockets==8.1 # via web3 @@ -262,6 +275,8 @@ werkzeug==1.0.1 # via eth-tester-rpc wheel==0.34.2 # via -r dev-requirements.in +yarl==1.6.3 + # via aiohttp # The following packages are considered to be unsafe in a requirements file: # pip diff --git a/setup.cfg b/setup.cfg index 2426d50..616c2df 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,7 +33,7 @@ packages=find: install_requires = py-solc - web3>=5.4.0,<6.0.0 + web3>=5.13.0,<6.0.0 eth-tester[py-evm] eth-utils eth-keyfile diff --git a/src/deploy_tools/cli.py b/src/deploy_tools/cli.py index d747c25..07d1846 100644 --- a/src/deploy_tools/cli.py +++ b/src/deploy_tools/cli.py @@ -585,11 +585,11 @@ def get_nonce(*, web3: Web3, nonce: int, private_key: bytes): if nonce is not None: return nonce elif private_key is not None: - return web3.eth.getTransactionCount( + return web3.eth.get_transaction_count( Account.from_key(private_key).address, block_identifier="pending" ) else: - return web3.eth.getTransactionCount( + return web3.eth.get_transaction_count( web3.eth.accounts[0], block_identifier="pending" ) diff --git a/src/deploy_tools/transact.py b/src/deploy_tools/transact.py index 7339d39..c99cb10 100644 --- a/src/deploy_tools/transact.py +++ b/src/deploy_tools/transact.py @@ -40,7 +40,7 @@ def send_transaction(*, web3: Web3, transaction_options: TxParams, private_key=N transaction = fill_nonce(web3, transaction_options) transaction = fill_transaction_defaults(web3, transaction) signed_transaction = account.sign_transaction(transaction) - tx_hash = web3.eth.sendRawTransaction(signed_transaction.rawTransaction) + tx_hash = web3.eth.send_raw_transaction(signed_transaction.rawTransaction) else: _set_from_address(web3, transaction_options) @@ -86,7 +86,7 @@ def send_function_call_transaction( transaction_options=transaction_options, private_key=private_key, ) - tx_hash = web3.eth.sendRawTransaction(signed_transaction.rawTransaction) + tx_hash = web3.eth.send_raw_transaction(signed_transaction.rawTransaction) else: _set_from_address(web3, transaction_options) @@ -122,7 +122,7 @@ def wait_for_successful_transaction_receipts( failed_tx_hashs = set() for tx_hash in tx_hashs: - receipt = web3.eth.waitForTransactionReceipt(tx_hash, timeout=timeout) + receipt = web3.eth.wait_for_transaction_receipt(tx_hash, timeout=timeout) status = receipt.get("status", None) if status == 0: failed_tx_hashs.add(tx_hash) @@ -143,7 +143,7 @@ def wait_for_successful_transaction_receipt( """See if transaction went through (Solidity code did not throw). :return: Transaction receipt """ - receipt = web3.eth.waitForTransactionReceipt(txid, timeout=timeout) + receipt = web3.eth.wait_for_transaction_receipt(txid, timeout=timeout) status = receipt.get("status", None) if status == 0: raise TransactionFailed @@ -189,7 +189,7 @@ def build_transaction_options(*, gas, gas_price, nonce, value=None): def fill_nonce(web3, transaction_options): if "from" in transaction_options and "nonce" not in transaction_options: - transaction_options["nonce"] = web3.eth.getTransactionCount( + transaction_options["nonce"] = web3.eth.get_transaction_count( transaction_options["from"], block_identifier="pending" ) return transaction_options From 2acbe489d8039d96f8b5f1bd1c59f107d876b37a Mon Sep 17 00:00:00 2001 From: Daniel Dimitrov Date: Tue, 22 Jun 2021 16:26:03 +0200 Subject: [PATCH 2/3] Get revert reason for failed transaction We try to get the more information for failed transaction and output it instead of just throwing a TransactionFailed exception --- src/deploy_tools/transact.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/deploy_tools/transact.py b/src/deploy_tools/transact.py index c99cb10..8b9f189 100644 --- a/src/deploy_tools/transact.py +++ b/src/deploy_tools/transact.py @@ -5,7 +5,7 @@ from web3._utils.transactions import fill_transaction_defaults from web3.eth import Account from web3.types import TxParams, TxReceipt - +from web3.exceptions import ContractLogicError class TransactionsFailed(Exception): def __init__(self, failed_tx_hashs): @@ -146,7 +146,24 @@ def wait_for_successful_transaction_receipt( receipt = web3.eth.wait_for_transaction_receipt(txid, timeout=timeout) status = receipt.get("status", None) if status == 0: - raise TransactionFailed + try: + tx = web3.eth.get_transaction(txid) + result = web3.eth.call({ + "from": tx["from"], + "to": tx.to, + "gasPrice": tx.gasPrice, + "gas": tx.gas, + "value": tx.value, + "data": tx.input, + "nonce": tx.nonce + }, tx.blockNumber) + + return result + except ContractLogicError: + raise ContractLogicError + except: + raise TransactionFailed + elif status == 1: return receipt else: From d53fe789d8af41ec6e159200f1be8f7d59ae4f08 Mon Sep 17 00:00:00 2001 From: Daniel Dimitrov Date: Tue, 22 Jun 2021 16:59:08 +0200 Subject: [PATCH 3/3] Make flake8 and blake happy --- src/deploy_tools/transact.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/deploy_tools/transact.py b/src/deploy_tools/transact.py index 8b9f189..5da8671 100644 --- a/src/deploy_tools/transact.py +++ b/src/deploy_tools/transact.py @@ -7,6 +7,7 @@ from web3.types import TxParams, TxReceipt from web3.exceptions import ContractLogicError + class TransactionsFailed(Exception): def __init__(self, failed_tx_hashs): self.failed_tx_hashs = failed_tx_hashs @@ -148,20 +149,23 @@ def wait_for_successful_transaction_receipt( if status == 0: try: tx = web3.eth.get_transaction(txid) - result = web3.eth.call({ - "from": tx["from"], - "to": tx.to, - "gasPrice": tx.gasPrice, - "gas": tx.gas, - "value": tx.value, - "data": tx.input, - "nonce": tx.nonce - }, tx.blockNumber) + result = web3.eth.call( + { + "from": tx["from"], + "to": tx.to, + "gasPrice": tx.gasPrice, + "gas": tx.gas, + "value": tx.value, + "data": tx.input, + "nonce": tx.nonce, + }, + tx.blockNumber, + ) return result except ContractLogicError: raise ContractLogicError - except: + except Exception: raise TransactionFailed elif status == 1: