From c971c61dfb0936502fb5a13a017b2b70efc648b5 Mon Sep 17 00:00:00 2001 From: Steven Luscher Date: Thu, 21 Jul 2022 21:02:05 -0700 Subject: [PATCH] feat: add `maxSupportedTransactionVersion` option to `getBlock` and `getTransaction` (#26726) --- web3.js/src/connection.ts | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/web3.js/src/connection.ts b/web3.js/src/connection.ts index 36d4b8b743..7bc37a6fdc 100644 --- a/web3.js/src/connection.ts +++ b/web3.js/src/connection.ts @@ -443,6 +443,16 @@ export type GetBalanceConfig = { minContextSlot?: number; }; +/** + * Configuration object for changing `getBlock` query behavior + */ +export type GetBlockConfig = { + /** The level of finality desired */ + commitment?: Finality; + /** The max transaction version to return in responses. If the requested transaction is a higher version, an error will be returned */ + maxSupportedTransactionVersion?: number; +}; + /** * Configuration object for changing `getBlockHeight` query behavior */ @@ -505,6 +515,16 @@ export type GetSlotLeaderConfig = { minContextSlot?: number; }; +/** + * Configuration object for changing `getTransaction` query behavior + */ +export type GetTransactionConfig = { + /** The level of finality desired */ + commitment?: Finality; + /** The max transaction version to return in responses. If the requested transaction is a higher version, an error will be returned */ + maxSupportedTransactionVersion?: number; +}; + /** * Configuration object for changing `getLargestAccounts` query behavior */ @@ -3592,11 +3612,14 @@ export class Connection { */ async getBlock( slot: number, - opts?: {commitment?: Finality}, + rawConfig?: GetBlockConfig, ): Promise { + const {commitment, config} = extractCommitmentFromConfig(rawConfig); const args = this._buildArgsAtLeastConfirmed( [slot], - opts && opts.commitment, + commitment as Finality, + undefined /* encoding */, + config, ); const unsafeRes = await this._rpcRequest('getBlock', args); const res = create(unsafeRes, GetBlockRpcResult); @@ -3684,11 +3707,14 @@ export class Connection { */ async getTransaction( signature: string, - opts?: {commitment?: Finality}, + rawConfig?: GetTransactionConfig, ): Promise { + const {commitment, config} = extractCommitmentFromConfig(rawConfig); const args = this._buildArgsAtLeastConfirmed( [signature], - opts && opts.commitment, + commitment as Finality, + undefined /* encoding */, + config, ); const unsafeRes = await this._rpcRequest('getTransaction', args); const res = create(unsafeRes, GetTransactionRpcResult);