From 8da4c48b9aaefd01042a321bdc5289a70cf304c9 Mon Sep 17 00:00:00 2001 From: obiwan Date: Sun, 13 Mar 2022 12:53:47 -0400 Subject: [PATCH] feat(connection.ts): implement getTransactions implement getTransactions which retrieves multiple transaction responses in a single RPC call --- web3.js/src/connection.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/web3.js/src/connection.ts b/web3.js/src/connection.ts index b17d9206ad0fd8..30e6dc4cbf3985 100644 --- a/web3.js/src/connection.ts +++ b/web3.js/src/connection.ts @@ -3304,6 +3304,34 @@ export class Connection { return res; } + /** + * Fetch transaction details for a batch of confirmed transactions. + * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}. + */ + async getTransactions( + signatures: TransactionSignature[], + commitment?: Finality, + ): Promise<(TransactionResponse | null)[]> { + const batch = signatures.map(signature => { + const args = this._buildArgsAtLeastConfirmed([signature], commitment); + return { + methodName: 'getTransaction', + args, + }; + }); + + const unsafeRes = await this._rpcBatchRequest(batch); + const res = unsafeRes.map((unsafeRes: any) => { + const res = create(unsafeRes, GetTransactionRpcResult); + if ('error' in res) { + throw new Error('failed to get transactions: ' + res.error.message); + } + return res.result; + }); + + return res; + } + /** * Fetch a list of Transactions and transaction statuses from the cluster * for a confirmed block.