Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,33 @@ export async function waitForConfirmation(

/* eslint-disable no-await-in-loop */
while (currentRound < startRound + waitRounds) {
const pendingInfo = await client.pendingTransactionInformation(txid).do();
let poolError = false;
try {
const pendingInfo = await client.pendingTransactionInformation(txid).do();

if (pendingInfo['confirmed-round']) {
// Got the completed Transaction
return pendingInfo;
}
if (pendingInfo['confirmed-round']) {
// Got the completed Transaction
return pendingInfo;
}

if (pendingInfo['pool-error']) {
// If there was a pool error, then the transaction has been rejected!
throw new Error(`Transaction Rejected: ${pendingInfo['pool-error']}`);
if (pendingInfo['pool-error']) {
// If there was a pool error, then the transaction has been rejected
poolError = true;
throw new Error(`Transaction Rejected: ${pendingInfo['pool-error']}`);
}
} catch (err) {
// Ignore errors from PendingTransactionInformation, since it may return 404 if the algod
// instance is behind a load balancer and the request goes to a different algod than the
// one we submitted the transaction to
if (poolError) {
// Rethrow error only if it's because the transaction was rejected
throw err;
}
}

await client.statusAfterBlock(currentRound).do();
currentRound += 1;
}
/* eslint-enable no-await-in-loop */
throw new Error(`Transaction not confirmed after ${waitRounds} rounds!`);
throw new Error(`Transaction not confirmed after ${waitRounds} rounds`);
}