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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

support v0 txs for receipt fetching #718

Merged
merged 1 commit into from Nov 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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