示例#1
0
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)
示例#2
0
 def getTransaction(self, transaction_hash: _Hash32) -> TxData:
     result = self.web3.manager.request_blocking(
         RPC.eth_getTransactionByHash,
         [transaction_hash],
     )
     if result is None:
         raise TransactionNotFound(f"Transaction with hash: {transaction_hash} not found.")
     return result
示例#3
0
文件: eth.py 项目: ajrgrubbs/web3.py
 def getTransactionReceipt(self, transaction_hash: Hash32) -> TxReceipt:
     result = self.web3.manager.request_blocking(
         "eth_getTransactionReceipt",
         [transaction_hash],
     )
     if result is None:
         raise TransactionNotFound(f"Transaction with hash: {transaction_hash} not found.")
     return result
示例#4
0
 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
示例#5
0
    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")
示例#6
0
 def getTransaction(self, transaction_hash):
     result = self.web3.manager.request_blocking(
         "hpb_getTransactionByHash",
         [transaction_hash],
     )
     if result is None:
         raise TransactionNotFound(
             f"Transaction with hash: {transaction_hash} not found.")
     return result
示例#7
0
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.")
示例#8
0
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)
示例#9
0
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.")
示例#10
0
 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
示例#11
0
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.")
示例#12
0
def raise_transaction_not_found(params: Tuple[_Hash32]) -> NoReturn:
    transaction_hash = params[0]
    raise TransactionNotFound(
        f"Transaction with hash: {transaction_hash} not found.")