def _get_pending_transaction_by_hash(self, transaction_hash): for transaction in self._pending_transactions: if transaction['hash'] == transaction_hash: return transaction raise TransactionNotFound( "No transaction found for transaction hash: {0}".format(transaction_hash) )
def _get_transaction_by_hash(self, transaction_hash): for block in itertools.chain([self.block], reversed(self.blocks)): for transaction_index, transaction in enumerate( reversed(block['transactions'])): if transaction['hash'] == transaction_hash: return transaction, block, transaction_index else: raise TransactionNotFound( "No transaction found for hash: {0}".format(transaction_hash))
def get_transaction_receipt(self, transaction_hash): try: receipt = self.receipts[transaction_hash] except KeyError: raise TransactionNotFound( "No transaction found for hash: {0}".format(transaction_hash)) _, block, transaction_index = self._get_transaction_by_hash( transaction_hash) return serialize_receipt( receipt, block, transaction_index, is_pending=(block['number'] == self.block['number']), )
def _get_transaction_by_hash(chain, transaction_hash): head_block = chain.get_block() for index, transaction in enumerate(head_block.transactions): if transaction.hash == transaction_hash: return head_block, transaction, index for block_number in range(head_block.number - 1, -1, -1): # TODO: the chain should be able to look these up directly by hash... block = chain.get_canonical_block_by_number(block_number) for index, transaction in enumerate(block.transactions): if transaction.hash == transaction_hash: return block, transaction, index else: raise TransactionNotFound( "No transaction found for transaction hash: {0}".format( encode_hex(transaction_hash)))
def _get_transaction_by_hash(evm, transaction_hash, mined=True): # first check unmined transactions for index, candidate in enumerate(evm.block.get_transaction_hashes()): if candidate == transaction_hash: transaction = evm.block.transaction_list[index] return evm.block, transaction, index # then check work backwards through the blocks looking for mined transactions. for block in reversed(evm.blocks[:-1]): for index, candidate in enumerate(block.get_transaction_hashes()): if candidate == transaction_hash: transaction = block.transaction_list[index] return block, transaction, index else: raise TransactionNotFound( "No transaction found for transaction hash {0}".format( encode_hex(transaction_hash), ))
def _get_transaction_by_hash(evm, transaction_hash): for index, candidate in enumerate(evm.block.transactions): if transaction_hash == candidate.hash: return ( evm.block, candidate, index, True, ) for block_number in range(evm.chain.head.number, -1, -1): block = _get_block_by_number(evm, block_number) for index, transaction in enumerate(block.transactions): if transaction.hash == transaction_hash: return block, transaction, index, False else: raise TransactionNotFound("Transaction with hash {0} not found".format( transaction_hash, ))