示例#1
0
def sign_send_wait(algod_client: algod.AlgodClient, account: Account, txn):
    """Sign a transaction, submit it, and wait for its confirmation."""
    signed_txn = sign(account, txn)
    tx_id = signed_txn.transaction.get_txid()
    algod_client.send_transactions([signed_txn])
    wait_for_confirmation(algod_client, tx_id)
    return algod_client.pending_transaction_info(tx_id)
示例#2
0
def wait_for_confirmation(client: algod.AlgodClient,
                          transaction_id: str,
                          timeout: int = 100) -> Dict[str, str or int]:
    """
    Check for when the transaction is confirmed by the network. Once confirmed, return
    the transaction information.

    :param client -> ``algod.AlgodClient``: an algorand client object.
    :param transaction_id -> ``str``: id for the transaction.
    """
    start_round = client.status()["last-round"] + 1
    current_round = start_round

    while current_round < start_round + timeout:
        try:
            pending_txn = client.pending_transaction_info(transaction_id)
        except Exception:
            return
        if pending_txn.get("confirmed-round", 0) > 0:
            return pending_txn
        elif pending_txn["pool-error"]:
            raise Exception('pool error: {}'.format(pending_txn["pool-error"]))
        client.status_after_block(current_round)
        current_round += 1
    raise Exception(
        'pending tx not found in timeout rounds, timeout value = : {}'.format(
            timeout))
示例#3
0
def wait_for_confirmation(client: algod.AlgodClient, txid: str):
    """
    Utility function to wait until the transaction is confirmed before
    proceeding.
    """
    last_round = client.status().get("last-round")
    txinfo = client.pending_transaction_info(txid)

    while not txinfo.get("confirmed-round", -1) > 0:
        print(f"Waiting for transaction {txid} confirmation.")
        last_round += 1
        client.status_after_block(last_round)
        txinfo = client.pending_transaction_info(txid)

    print(
        f"Transaction {txid} confirmed in round {txinfo.get('confirmed-round')}."
    )
    return txinfo