Skip to content

Commit 9dd99e9

Browse files
authored
Fix wait for confirmation function (#480)
* Fix wait for confirmation function * Respond to feedback
1 parent 5f44fc5 commit 9dd99e9

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/wait.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,33 @@ export async function waitForConfirmation(
2626

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

31-
if (pendingInfo['confirmed-round']) {
32-
// Got the completed Transaction
33-
return pendingInfo;
34-
}
33+
if (pendingInfo['confirmed-round']) {
34+
// Got the completed Transaction
35+
return pendingInfo;
36+
}
3537

36-
if (pendingInfo['pool-error']) {
37-
// If there was a pool error, then the transaction has been rejected!
38-
throw new Error(`Transaction Rejected: ${pendingInfo['pool-error']}`);
38+
if (pendingInfo['pool-error']) {
39+
// If there was a pool error, then the transaction has been rejected
40+
poolError = true;
41+
throw new Error(`Transaction Rejected: ${pendingInfo['pool-error']}`);
42+
}
43+
} catch (err) {
44+
// Ignore errors from PendingTransactionInformation, since it may return 404 if the algod
45+
// instance is behind a load balancer and the request goes to a different algod than the
46+
// one we submitted the transaction to
47+
if (poolError) {
48+
// Rethrow error only if it's because the transaction was rejected
49+
throw err;
50+
}
3951
}
4052

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

0 commit comments

Comments
 (0)