def raise_transaction_not_found_with_index(params: Tuple[BlockIdentifier, int]) -> NoReturn: block_identifier = params[0] transaction_index = to_integer_if_hex(params[1]) raise TransactionNotFound( f"Transaction index: {transaction_index} " f"on block id: {block_identifier} not found." )
def raise_transaction_not_found(params: Tuple[_Hash32]) -> NoReturn: try: transaction_hash = params[0] message = f"Transaction with hash: {transaction_hash!r} not found." except IndexError: message = "Unknown transaction hash" raise TransactionNotFound(message)
def getTransactionReceipt(self, transaction_hash: _Hash32) -> TxReceipt: result = self.web3.manager.request_blocking( RPC.eth_getTransactionReceipt, [transaction_hash], ) if result is None: raise TransactionNotFound(f"Transaction with hash: {transaction_hash} not found.") return result
def getTransaction(self, transaction_hash): result = self.web3.manager.request_blocking( "eth_getTransactionByHash", [transaction_hash], ) if result is None: raise TransactionNotFound(f"Transaction with hash: {transaction_hash} not found.") return result
def newAccount(self, accountPassword): result = self.web3.manager.request_blocking( "personal_newAccount", [accountPassword], ) if result is None: raise TransactionNotFound(f"Failed to create account.") return result
def wait(self, timeout=60, interval=2) -> dict: end_time = time.time() + timeout * 1_000 while time.time() < end_time: try: return self._web3.eth.getTransactionReceipt(self.tran_hash) except TransactionNotFound: time.sleep(interval) raise TransactionNotFound("timeout and can not find the transaction")
def wait_receipt(web3, tx, retries=30, timeout=5): for _ in range(0, retries): try: receipt = get_receipt(web3, tx) except TransactionNotFound: receipt = None if receipt is not None: return receipt sleep(timeout) # pragma: no cover raise TransactionNotFound(f"Transaction with hash: {tx} not found.")
def raise_transaction_not_found_with_index( params: Tuple[BlockIdentifier, int]) -> NoReturn: try: block_identifier = params[0] transaction_index = to_integer_if_hex(params[1]) message = (f"Transaction index: {transaction_index} " f"on block id: {block_identifier!r} not found.") except IndexError: message = "Unknown transaction index or block identifier" raise TransactionNotFound(message)
def wait_for_receipt_by_blocks(web3, tx, timeout=4, blocks_to_wait=50): previous_block = web3.eth.blockNumber current_block = previous_block while current_block <= previous_block + blocks_to_wait: try: receipt = get_receipt(web3, tx) except TransactionNotFound: receipt = None if receipt is not None: return receipt current_block = web3.eth.blockNumber sleep(timeout) raise TransactionNotFound(f"Transaction with hash: {tx} not found.")
def getTransactionByBlock(self, block_identifier, transaction_index): """ `eth_getTransactionByBlockHashAndIndex` `eth_getTransactionByBlockNumberAndIndex` """ method = select_method_for_block_identifier( block_identifier, if_predefined='eth_getTransactionByBlockNumberAndIndex', if_hash='eth_getTransactionByBlockHashAndIndex', if_number='eth_getTransactionByBlockNumberAndIndex', ) result = self.web3.manager.request_blocking( method, [block_identifier, transaction_index], ) if result is None: raise TransactionNotFound( f"Transaction index: {transaction_index} " f"on block id: {block_identifier} not found.") return result
def raise_transaction_not_found(params: Tuple[_Hash32]) -> NoReturn: transaction_hash = params[0] raise TransactionNotFound( f"Transaction with hash: {transaction_hash} not found.")