Skip to content

Commit

Permalink
support v0 txs for receipt fetching (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmoi committed Nov 13, 2022
1 parent 6b21f01 commit 9a68b8e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -119,6 +119,9 @@ dist/
# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# Idea editors
.idea

# Temporary folders
tmp/
temp/
Expand Down
18 changes: 16 additions & 2 deletions packages/solana-contrib/src/transaction/PendingTransaction.ts
Expand Up @@ -26,6 +26,10 @@ export interface TransactionWaitOptions
* Whether or not to use websockets for awaiting confirmation. Defaults to `false`.
*/
readonly useWebsocket?: boolean;
/**
* Max supported transaction version. Pass `undefined` to only support `legacy` transactions.
*/
readonly maxSupportedTransactionVersion?: number;
}

/**
Expand Down Expand Up @@ -54,6 +58,7 @@ export class PendingTransaction {
*/
async wait({
commitment = "confirmed",
maxSupportedTransactionVersion = 0,
useWebsocket = true,
...retryOpts
}: TransactionWaitOptions = {}): Promise<TransactionReceipt> {
Expand All @@ -62,9 +67,16 @@ export class PendingTransaction {
}
if (useWebsocket) {
await this.confirm({ commitment, ...retryOpts });
return await this.pollForReceipt({ commitment });
return await this.pollForReceipt({
commitment,
maxSupportedTransactionVersion,
});
}
return await this.pollForReceipt({ commitment, ...retryOpts });
return await this.pollForReceipt({
commitment,
maxSupportedTransactionVersion,
...retryOpts,
});
}

/**
Expand All @@ -73,6 +85,7 @@ export class PendingTransaction {
*/
async pollForReceipt({
commitment = "confirmed",
maxSupportedTransactionVersion = 0,
...retryOpts
}: Omit<
TransactionWaitOptions,
Expand All @@ -82,6 +95,7 @@ export class PendingTransaction {
async (retry) => {
const result = await this.connection.getTransaction(this.signature, {
commitment,
maxSupportedTransactionVersion,
});
if (!result) {
retry(new Error("Error fetching transaction"));
Expand Down
Expand Up @@ -2,6 +2,7 @@ import type {
Cluster,
TransactionResponse,
TransactionSignature,
VersionedTransactionResponse,
} from "@solana/web3.js";
import { default as invariant } from "tiny-invariant";

Expand Down Expand Up @@ -57,7 +58,7 @@ export class TransactionReceipt {
/**
* Raw response from web3.js
*/
readonly response: TransactionResponse
readonly response: TransactionResponse | VersionedTransactionResponse
) {}

/**
Expand Down

0 comments on commit 9a68b8e

Please sign in to comment.