diff --git a/eth_possim/contracts.py b/eth_possim/contracts.py index a3dcd2a..25d0a78 100644 --- a/eth_possim/contracts.py +++ b/eth_possim/contracts.py @@ -6,10 +6,25 @@ import re import time from typing import List, Tuple +from web3.types import TxReceipt, HexStr logger = logging.getLogger(__name__) +def wait_for_transaction_receipt(signed_txn_hash: HexStr) -> TxReceipt: + for _ in range(1, 10): + try: + tx_receipt = w3.eth.wait_for_transaction_receipt(signed_txn_hash) + return tx_receipt + except ValueError as exc: + if exc.args[0]["message"] == "transaction indexing is in progress": + logger.info( + "Failed to get transaction receipt due to indexing, will retry" + ) + time.sleep(5) + continue + else: + raise def deploy_compiled_contract( cfg: dict, @@ -54,12 +69,9 @@ def deploy_compiled_contract( private_key=cfg["el"]["funder"]["private_key"], ) w3.eth.send_raw_transaction(signed_txn.rawTransaction) - tx_receipt = w3.eth.wait_for_transaction_receipt(signed_txn.hash) - - logger.info( - f"Contract from '{foundry_json_path}' was published at address '{tx_receipt['contractAddress']}' [block: {tx_receipt['blockNumber']}]" - ) + tx_receipt = wait_for_transaction_receipt(signed_txn.hash) + logger.info(f"Contract from '{foundry_json_path}' was published at address '{tx_receipt['contractAddress']}' [block: {tx_receipt['blockNumber']}]") return tx_receipt["contractAddress"] @@ -105,21 +117,10 @@ def deploy_contract_onchain( private_key=cfg["el"]["funder"]["private_key"], ) w3.eth.send_raw_transaction(signed_txn.rawTransaction) - for _ in range(1, 10): - try: - tx_receipt = w3.eth.wait_for_transaction_receipt(signed_txn.hash) - except ValueError as exc: - if exc.args[0]["message"] == "transaction indexing is in progress": - logger.info( - "Failed to get transaction receipt due to indexing, will retry" - ) - time.sleep(5) - continue - else: - raise + tx_receipt = wait_for_transaction_receipt(signed_txn.hash) - logger.info( - f"Contract from '{path}' was published at address '{tx_receipt['contractAddress']}' [block: {tx_receipt['blockNumber']}]" - ) + logger.info( + f"Contract from '{path}' was published at address '{tx_receipt['contractAddress']}' [block: {tx_receipt['blockNumber']}]" + ) - return tx_receipt["contractAddress"] + return tx_receipt["contractAddress"]