feat: add `maxSupportedTransactionVersion` option to `getBlock` and `getTransaction` (#26726)

This commit is contained in:
Steven Luscher 2022-07-21 21:02:05 -07:00 committed by GitHub
parent 069dd8af68
commit c971c61dfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 4 deletions

View File

@ -443,6 +443,16 @@ export type GetBalanceConfig = {
minContextSlot?: number; 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 * Configuration object for changing `getBlockHeight` query behavior
*/ */
@ -505,6 +515,16 @@ export type GetSlotLeaderConfig = {
minContextSlot?: number; 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 * Configuration object for changing `getLargestAccounts` query behavior
*/ */
@ -3592,11 +3612,14 @@ export class Connection {
*/ */
async getBlock( async getBlock(
slot: number, slot: number,
opts?: {commitment?: Finality}, rawConfig?: GetBlockConfig,
): Promise<BlockResponse | null> { ): Promise<BlockResponse | null> {
const {commitment, config} = extractCommitmentFromConfig(rawConfig);
const args = this._buildArgsAtLeastConfirmed( const args = this._buildArgsAtLeastConfirmed(
[slot], [slot],
opts && opts.commitment, commitment as Finality,
undefined /* encoding */,
config,
); );
const unsafeRes = await this._rpcRequest('getBlock', args); const unsafeRes = await this._rpcRequest('getBlock', args);
const res = create(unsafeRes, GetBlockRpcResult); const res = create(unsafeRes, GetBlockRpcResult);
@ -3684,11 +3707,14 @@ export class Connection {
*/ */
async getTransaction( async getTransaction(
signature: string, signature: string,
opts?: {commitment?: Finality}, rawConfig?: GetTransactionConfig,
): Promise<TransactionResponse | null> { ): Promise<TransactionResponse | null> {
const {commitment, config} = extractCommitmentFromConfig(rawConfig);
const args = this._buildArgsAtLeastConfirmed( const args = this._buildArgsAtLeastConfirmed(
[signature], [signature],
opts && opts.commitment, commitment as Finality,
undefined /* encoding */,
config,
); );
const unsafeRes = await this._rpcRequest('getTransaction', args); const unsafeRes = await this._rpcRequest('getTransaction', args);
const res = create(unsafeRes, GetTransactionRpcResult); const res = create(unsafeRes, GetTransactionRpcResult);