From 9a68b8ecafb97faf6877d39ff6ff4e9585c01d69 Mon Sep 17 00:00:00 2001 From: ilmoi Date: Mon, 14 Nov 2022 00:28:23 +0200 Subject: [PATCH] support v0 txs for receipt fetching (#718) --- .gitignore | 3 +++ .../src/transaction/PendingTransaction.ts | 18 ++++++++++++++++-- .../src/transaction/TransactionReceipt.ts | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index d697a874c..882394627 100644 --- a/.gitignore +++ b/.gitignore @@ -119,6 +119,9 @@ dist/ # Stores VSCode versions used for testing VSCode extensions .vscode-test +# Idea editors +.idea + # Temporary folders tmp/ temp/ diff --git a/packages/solana-contrib/src/transaction/PendingTransaction.ts b/packages/solana-contrib/src/transaction/PendingTransaction.ts index 0c988c569..6dbabdbb2 100644 --- a/packages/solana-contrib/src/transaction/PendingTransaction.ts +++ b/packages/solana-contrib/src/transaction/PendingTransaction.ts @@ -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 { @@ -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")); diff --git a/packages/solana-contrib/src/transaction/TransactionReceipt.ts b/packages/solana-contrib/src/transaction/TransactionReceipt.ts index e7f35d5f7..f74576f74 100644 --- a/packages/solana-contrib/src/transaction/TransactionReceipt.ts +++ b/packages/solana-contrib/src/transaction/TransactionReceipt.ts @@ -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 ) {} /**