Skip to content

Commit

Permalink
feat: implement getTransactions (#23633)
Browse files Browse the repository at this point in the history
implement getTransactions which retrieves multiple transaction responses in a single RPC call

Co-authored-by: obiwan <[email protected]>
  • Loading branch information
gebob19 and obiwan authored Apr 25, 2022
1 parent 895f76a commit 0b93de9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions web3.js/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3404,6 +3404,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.
Expand Down

0 comments on commit 0b93de9

Please sign in to comment.