Untitled
unknown
plain_text
3 years ago
1.2 kB
14
Indexable
export async function waitForConfirmation(algodclient, txId, timeout) {
if (algodclient == null || txId == null || timeout < 0) {
throw new Error('Bad arguments.');
}
const status = await algodclient.status().do();
if (typeof status === 'undefined')
throw new Error('Unable to get node status');
const startround = status['last-round'] + 1;
let currentround = startround;
/* eslint-disable no-await-in-loop */
while (currentround < startround + timeout) {
const pending = await algodclient
.pendingTransactionInformation(txId)
.do();
if (pending !== undefined) {
if ( pending['confirmed-round'] !== null && pending['confirmed-round'] > 0)
return pending;
if ( pending['pool-error'] != null && pending['pool-error'].length > 0)
throw new Error( `Transaction Rejected pool error${pending['pool-error']}`);
}
await algodclient.statusAfterBlock(currentround).do();
currentround += 1;
}
/* eslint-enable no-await-in-loop */
throw new Error(`Transaction not confirmed after ${timeout} rounds!`);
}Editor is loading...