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

support v0 txs for receipt fetching #718

Merged
merged 1 commit into from
Nov 13, 2022
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -119,6 +119,9 @@ dist/
# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# Idea editors
.idea

# Temporary folders
tmp/
temp/
18 changes: 16 additions & 2 deletions packages/solana-contrib/src/transaction/PendingTransaction.ts
Original file line number Diff line number Diff line change
@@ -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;
}

/**
@@ -54,6 +58,7 @@ export class PendingTransaction {
*/
async wait({
commitment = "confirmed",
maxSupportedTransactionVersion = 0,
useWebsocket = true,
...retryOpts
}: TransactionWaitOptions = {}): Promise<TransactionReceipt> {
@@ -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,
});
}

/**
@@ -73,6 +85,7 @@ export class PendingTransaction {
*/
async pollForReceipt({
commitment = "confirmed",
maxSupportedTransactionVersion = 0,
...retryOpts
}: Omit<
TransactionWaitOptions,
@@ -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"));
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import type {
Cluster,
TransactionResponse,
TransactionSignature,
VersionedTransactionResponse,
} from "@solana/web3.js";
import { default as invariant } from "tiny-invariant";

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

/**