Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pending transaction 404 #98

Merged
merged 4 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions docs/code/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ the estimated rate.

#### Defined in

[src/transaction.ts:389](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction.ts#L389)
[src/transaction.ts:397](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction.ts#L397)

___

Expand Down Expand Up @@ -225,7 +225,7 @@ Allows for control of fees on a `Transaction` or `SuggestedParams` object

#### Defined in

[src/transaction.ts:412](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction.ts#L412)
[src/transaction.ts:420](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction.ts#L420)

___

Expand Down Expand Up @@ -1153,7 +1153,7 @@ The array of transactions with signers

#### Defined in

[src/transaction.ts:444](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction.ts#L444)
[src/transaction.ts:452](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction.ts#L452)

___

Expand Down Expand Up @@ -1452,7 +1452,7 @@ The suggested transaction parameters

#### Defined in

[src/transaction.ts:435](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction.ts#L435)
[src/transaction.ts:443](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transaction.ts#L443)

___

Expand Down
10 changes: 10 additions & 0 deletions src/transaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ describe('transaction', () => {
algod,
)
})

test('Transaction wait for confirmation http error', async () => {
const { algod } = localnet.context
const txn = await getTestTransaction()
try {
await algokit.waitForConfirmation(txn.txID(), 5, algod)
} catch (e: unknown) {
expect((e as Error).message).toEqual(`Transaction ${txn.txID()} not confirmed after 5 rounds`)
}
})
})

describe('transaction node encoder', () => {
Expand Down
32 changes: 20 additions & 12 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,20 +356,28 @@ export const waitForConfirmation = async function (
const startRound = BigInt(status.lastRound) + 1n
let currentRound = startRound
while (currentRound < startRound + BigInt(maxRoundsToWait)) {
const pendingInfo = modelsv2.PendingTransactionResponse.from_obj_for_encoding(
await algod.pendingTransactionInformation(transactionId).do(),
)
if (pendingInfo !== undefined) {
const confirmedRound = pendingInfo.confirmedRound
if (confirmedRound && confirmedRound > 0) {
return pendingInfo
} else {
const poolError = pendingInfo.poolError
if (poolError != null && poolError.length > 0) {
// If there was a pool error, then the transaction has been rejected!
throw new Error(`Transaction ${transactionId} was rejected; pool error: ${poolError}`)
try {
const pendingInfo = modelsv2.PendingTransactionResponse.from_obj_for_encoding(
await algod.pendingTransactionInformation(transactionId).do(),
)
if (pendingInfo !== undefined) {
const confirmedRound = pendingInfo.confirmedRound
if (confirmedRound && confirmedRound > 0) {
return pendingInfo
} else {
const poolError = pendingInfo.poolError
if (poolError != null && poolError.length > 0) {
// If there was a pool error, then the transaction has been rejected!
throw new Error(`Transaction ${transactionId} was rejected; pool error: ${poolError}`)
}
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: unknown) {
if ((e as Error).name === 'URLTokenBaseHTTPError') {
currentRound++
continue
}
}

await algod.statusAfterBlock(toNumber(currentRound)).do()
Expand Down
Loading