def wait_for_confirmation(client, txid, timeout=5):
    """
    Utility function to wait until the transaction is
    confirmed before proceeding.
    """
    current = start = client.status()['last-round'] + 1;
    while current < start + timeout:
        try:
            pending_txn = client.pending_transaction_info(txid)
        except:
            raise Exception(f'Failed to get pending tx info with id {txid}')
        if pending_txn.get('confirmed-round', 0) > 0:
            return pending_txn
        elif pending_txn['pool-error']:
            raise Exception(f'Pool error: {pending_txn["pool-error"]}')
        client.status_after_block(current)
        current += 1
    raise Exception(f'Pending tx not found in timeout rounds, timeout value = : {timeout}')