@solana/web3.js 1.67.1 → 1.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -2100,6 +2100,18 @@ declare module '@solana/web3.js' {
2100
2100
  export type GetBlockConfig = {
2101
2101
  /** The level of finality desired */
2102
2102
  commitment?: Finality;
2103
+ /**
2104
+ * Whether to populate the rewards array. If parameter not provided, the default includes rewards.
2105
+ */
2106
+ rewards?: boolean;
2107
+ /**
2108
+ * Level of transaction detail to return, either "full", "accounts", "signatures", or "none". If
2109
+ * parameter not provided, the default detail level is "full". If "accounts" are requested,
2110
+ * transaction details only include signatures and an annotated list of accounts in each
2111
+ * transaction. Transaction metadata is limited to only: fee, err, pre_balances, post_balances,
2112
+ * pre_token_balances, and post_token_balances.
2113
+ */
2114
+ transactionDetails?: 'accounts' | 'full' | 'none' | 'signatures';
2103
2115
  };
2104
2116
  /**
2105
2117
  * Configuration object for changing `getBlock` query behavior
@@ -2109,6 +2121,18 @@ declare module '@solana/web3.js' {
2109
2121
  commitment?: Finality;
2110
2122
  /** The max transaction version to return in responses. If the requested transaction is a higher version, an error will be returned */
2111
2123
  maxSupportedTransactionVersion?: number;
2124
+ /**
2125
+ * Whether to populate the rewards array. If parameter not provided, the default includes rewards.
2126
+ */
2127
+ rewards?: boolean;
2128
+ /**
2129
+ * Level of transaction detail to return, either "full", "accounts", "signatures", or "none". If
2130
+ * parameter not provided, the default detail level is "full". If "accounts" are requested,
2131
+ * transaction details only include signatures and an annotated list of accounts in each
2132
+ * transaction. Transaction metadata is limited to only: fee, err, pre_balances, post_balances,
2133
+ * pre_token_balances, and post_token_balances.
2134
+ */
2135
+ transactionDetails?: 'accounts' | 'full' | 'none' | 'signatures';
2112
2136
  };
2113
2137
  /**
2114
2138
  * Configuration object for changing `getStakeMinimumDelegation` query behavior
@@ -2603,6 +2627,14 @@ declare module '@solana/web3.js' {
2603
2627
  /** The unix timestamp of when the block was processed */
2604
2628
  blockTime: number | null;
2605
2629
  };
2630
+ /**
2631
+ * A processed block fetched from the RPC API where the `transactionDetails` mode is `accounts`
2632
+ */
2633
+ export type AccountsModeBlockResponse = VersionedAccountsModeBlockResponse;
2634
+ /**
2635
+ * A processed block fetched from the RPC API where the `transactionDetails` mode is `none`
2636
+ */
2637
+ export type NoneModeBlockResponse = VersionedNoneModeBlockResponse;
2606
2638
  /**
2607
2639
  * A block with parsed transactions
2608
2640
  */
@@ -2638,6 +2670,31 @@ declare module '@solana/web3.js' {
2638
2670
  /** The number of blocks beneath this block */
2639
2671
  blockHeight: number | null;
2640
2672
  };
2673
+ /**
2674
+ * A block with parsed transactions where the `transactionDetails` mode is `accounts`
2675
+ */
2676
+ export type ParsedAccountsModeBlockResponse = Omit<
2677
+ ParsedBlockResponse,
2678
+ 'transactions'
2679
+ > & {
2680
+ transactions: Array<
2681
+ Omit<ParsedBlockResponse['transactions'][number], 'transaction'> & {
2682
+ transaction: Pick<
2683
+ ParsedBlockResponse['transactions'][number]['transaction'],
2684
+ 'signatures'
2685
+ > & {
2686
+ accountKeys: ParsedMessageAccount[];
2687
+ };
2688
+ }
2689
+ >;
2690
+ };
2691
+ /**
2692
+ * A block with parsed transactions where the `transactionDetails` mode is `none`
2693
+ */
2694
+ export type ParsedNoneModeBlockResponse = Omit<
2695
+ ParsedBlockResponse,
2696
+ 'transactions'
2697
+ >;
2641
2698
  /**
2642
2699
  * A processed block fetched from the RPC API
2643
2700
  */
@@ -2676,6 +2733,31 @@ declare module '@solana/web3.js' {
2676
2733
  /** The unix timestamp of when the block was processed */
2677
2734
  blockTime: number | null;
2678
2735
  };
2736
+ /**
2737
+ * A processed block fetched from the RPC API where the `transactionDetails` mode is `accounts`
2738
+ */
2739
+ export type VersionedAccountsModeBlockResponse = Omit<
2740
+ VersionedBlockResponse,
2741
+ 'transactions'
2742
+ > & {
2743
+ transactions: Array<
2744
+ Omit<VersionedBlockResponse['transactions'][number], 'transaction'> & {
2745
+ transaction: Pick<
2746
+ VersionedBlockResponse['transactions'][number]['transaction'],
2747
+ 'signatures'
2748
+ > & {
2749
+ accountKeys: ParsedMessageAccount[];
2750
+ };
2751
+ }
2752
+ >;
2753
+ };
2754
+ /**
2755
+ * A processed block fetched from the RPC API where the `transactionDetails` mode is `none`
2756
+ */
2757
+ export type VersionedNoneModeBlockResponse = Omit<
2758
+ VersionedBlockResponse,
2759
+ 'transactions'
2760
+ >;
2679
2761
  /**
2680
2762
  * A confirmed block on the ledger
2681
2763
  *
@@ -3534,7 +3616,7 @@ declare module '@solana/web3.js' {
3534
3616
  * Fetch the fee for a message from the cluster, return with context
3535
3617
  */
3536
3618
  getFeeForMessage(
3537
- message: Message,
3619
+ message: VersionedMessage,
3538
3620
  commitment?: Commitment,
3539
3621
  ): Promise<RpcResponseAndContext<number>>;
3540
3622
  /**
@@ -3579,6 +3661,26 @@ declare module '@solana/web3.js' {
3579
3661
  slot: number,
3580
3662
  rawConfig?: GetBlockConfig,
3581
3663
  ): Promise<BlockResponse | null>;
3664
+ /**
3665
+ * @deprecated Instead, call `getBlock` using a `GetVersionedBlockConfig` by
3666
+ * setting the `maxSupportedTransactionVersion` property.
3667
+ */
3668
+ getBlock(
3669
+ slot: number,
3670
+ rawConfig: GetBlockConfig & {
3671
+ transactionDetails: 'accounts';
3672
+ },
3673
+ ): Promise<AccountsModeBlockResponse | null>;
3674
+ /**
3675
+ * @deprecated Instead, call `getBlock` using a `GetVersionedBlockConfig` by
3676
+ * setting the `maxSupportedTransactionVersion` property.
3677
+ */
3678
+ getBlock(
3679
+ slot: number,
3680
+ rawConfig: GetBlockConfig & {
3681
+ transactionDetails: 'none';
3682
+ },
3683
+ ): Promise<NoneModeBlockResponse | null>;
3582
3684
  /**
3583
3685
  * Fetch a processed block from the cluster.
3584
3686
  */
@@ -3586,13 +3688,37 @@ declare module '@solana/web3.js' {
3586
3688
  slot: number,
3587
3689
  rawConfig?: GetVersionedBlockConfig,
3588
3690
  ): Promise<VersionedBlockResponse | null>;
3691
+ getBlock(
3692
+ slot: number,
3693
+ rawConfig: GetVersionedBlockConfig & {
3694
+ transactionDetails: 'accounts';
3695
+ },
3696
+ ): Promise<VersionedAccountsModeBlockResponse | null>;
3697
+ getBlock(
3698
+ slot: number,
3699
+ rawConfig: GetVersionedBlockConfig & {
3700
+ transactionDetails: 'none';
3701
+ },
3702
+ ): Promise<VersionedNoneModeBlockResponse | null>;
3589
3703
  /**
3590
3704
  * Fetch parsed transaction details for a confirmed or finalized block
3591
3705
  */
3592
3706
  getParsedBlock(
3593
3707
  slot: number,
3594
3708
  rawConfig?: GetVersionedBlockConfig,
3595
- ): Promise<ParsedBlockResponse | null>;
3709
+ ): Promise<ParsedAccountsModeBlockResponse>;
3710
+ getParsedBlock(
3711
+ slot: number,
3712
+ rawConfig: GetVersionedBlockConfig & {
3713
+ transactionDetails: 'accounts';
3714
+ },
3715
+ ): Promise<ParsedAccountsModeBlockResponse>;
3716
+ getParsedBlock(
3717
+ slot: number,
3718
+ rawConfig: GetVersionedBlockConfig & {
3719
+ transactionDetails: 'none';
3720
+ },
3721
+ ): Promise<ParsedNoneModeBlockResponse>;
3596
3722
  getBlockHeight(
3597
3723
  commitmentOrConfig?: Commitment | GetBlockHeightConfig,
3598
3724
  ): Promise<number>;
package/lib/index.esm.js CHANGED
@@ -4388,6 +4388,16 @@ const ConfirmedTransactionResult = type({
4388
4388
  addressTableLookups: optional(array(AddressTableLookupStruct))
4389
4389
  })
4390
4390
  });
4391
+ const AnnotatedAccountKey = type({
4392
+ pubkey: PublicKeyFromString,
4393
+ signer: boolean(),
4394
+ writable: boolean(),
4395
+ source: optional(union([literal('transaction'), literal('lookupTable')]))
4396
+ });
4397
+ const ConfirmedTransactionAccountsModeResult = type({
4398
+ accountKeys: array(AnnotatedAccountKey),
4399
+ signatures: array(string())
4400
+ });
4391
4401
  const ParsedInstructionResult = type({
4392
4402
  parsed: unknown(),
4393
4403
  program: string(),
@@ -4422,12 +4432,7 @@ const ParsedOrRawInstruction = coerce(InstructionResult, UnknownInstructionResul
4422
4432
  const ParsedConfirmedTransactionResult = type({
4423
4433
  signatures: array(string()),
4424
4434
  message: type({
4425
- accountKeys: array(type({
4426
- pubkey: PublicKeyFromString,
4427
- signer: boolean(),
4428
- writable: boolean(),
4429
- source: optional(union([literal('transaction'), literal('lookupTable')]))
4430
- })),
4435
+ accountKeys: array(AnnotatedAccountKey),
4431
4436
  instructions: array(ParsedOrRawInstruction),
4432
4437
  recentBlockhash: string(),
4433
4438
  addressTableLookups: optional(nullable(array(AddressTableLookupStruct)))
@@ -4486,6 +4491,14 @@ const ParsedConfirmedTransactionMetaResult = type({
4486
4491
  computeUnitsConsumed: optional(number())
4487
4492
  });
4488
4493
  const TransactionVersionStruct = union([literal(0), literal('legacy')]);
4494
+ /** @internal */
4495
+
4496
+ const RewardsResult = type({
4497
+ pubkey: string(),
4498
+ lamports: number(),
4499
+ postBalance: nullable(number()),
4500
+ rewardType: nullable(string())
4501
+ });
4489
4502
  /**
4490
4503
  * Expected JSON RPC response for the "getBlock" message
4491
4504
  */
@@ -4499,12 +4512,36 @@ const GetBlockRpcResult = jsonRpcResult(nullable(type({
4499
4512
  meta: nullable(ConfirmedTransactionMetaResult),
4500
4513
  version: optional(TransactionVersionStruct)
4501
4514
  })),
4502
- rewards: optional(array(type({
4503
- pubkey: string(),
4504
- lamports: number(),
4505
- postBalance: nullable(number()),
4506
- rewardType: nullable(string())
4507
- }))),
4515
+ rewards: optional(array(RewardsResult)),
4516
+ blockTime: nullable(number()),
4517
+ blockHeight: nullable(number())
4518
+ })));
4519
+ /**
4520
+ * Expected JSON RPC response for the "getBlock" message when `transactionDetails` is `none`
4521
+ */
4522
+
4523
+ const GetNoneModeBlockRpcResult = jsonRpcResult(nullable(type({
4524
+ blockhash: string(),
4525
+ previousBlockhash: string(),
4526
+ parentSlot: number(),
4527
+ rewards: optional(array(RewardsResult)),
4528
+ blockTime: nullable(number()),
4529
+ blockHeight: nullable(number())
4530
+ })));
4531
+ /**
4532
+ * Expected JSON RPC response for the "getBlock" message when `transactionDetails` is `accounts`
4533
+ */
4534
+
4535
+ const GetAccountsModeBlockRpcResult = jsonRpcResult(nullable(type({
4536
+ blockhash: string(),
4537
+ previousBlockhash: string(),
4538
+ parentSlot: number(),
4539
+ transactions: array(type({
4540
+ transaction: ConfirmedTransactionAccountsModeResult,
4541
+ meta: nullable(ConfirmedTransactionMetaResult),
4542
+ version: optional(TransactionVersionStruct)
4543
+ })),
4544
+ rewards: optional(array(RewardsResult)),
4508
4545
  blockTime: nullable(number()),
4509
4546
  blockHeight: nullable(number())
4510
4547
  })));
@@ -4521,12 +4558,36 @@ const GetParsedBlockRpcResult = jsonRpcResult(nullable(type({
4521
4558
  meta: nullable(ParsedConfirmedTransactionMetaResult),
4522
4559
  version: optional(TransactionVersionStruct)
4523
4560
  })),
4524
- rewards: optional(array(type({
4525
- pubkey: string(),
4526
- lamports: number(),
4527
- postBalance: nullable(number()),
4528
- rewardType: nullable(string())
4529
- }))),
4561
+ rewards: optional(array(RewardsResult)),
4562
+ blockTime: nullable(number()),
4563
+ blockHeight: nullable(number())
4564
+ })));
4565
+ /**
4566
+ * Expected parsed JSON RPC response for the "getBlock" message when `transactionDetails` is `accounts`
4567
+ */
4568
+
4569
+ const GetParsedAccountsModeBlockRpcResult = jsonRpcResult(nullable(type({
4570
+ blockhash: string(),
4571
+ previousBlockhash: string(),
4572
+ parentSlot: number(),
4573
+ transactions: array(type({
4574
+ transaction: ConfirmedTransactionAccountsModeResult,
4575
+ meta: nullable(ParsedConfirmedTransactionMetaResult),
4576
+ version: optional(TransactionVersionStruct)
4577
+ })),
4578
+ rewards: optional(array(RewardsResult)),
4579
+ blockTime: nullable(number()),
4580
+ blockHeight: nullable(number())
4581
+ })));
4582
+ /**
4583
+ * Expected parsed JSON RPC response for the "getBlock" message when `transactionDetails` is `none`
4584
+ */
4585
+
4586
+ const GetParsedNoneModeBlockRpcResult = jsonRpcResult(nullable(type({
4587
+ blockhash: string(),
4588
+ previousBlockhash: string(),
4589
+ parentSlot: number(),
4590
+ rewards: optional(array(RewardsResult)),
4530
4591
  blockTime: nullable(number()),
4531
4592
  blockHeight: nullable(number())
4532
4593
  })));
@@ -4544,12 +4605,7 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
4544
4605
  transaction: ConfirmedTransactionResult,
4545
4606
  meta: nullable(ConfirmedTransactionMetaResult)
4546
4607
  })),
4547
- rewards: optional(array(type({
4548
- pubkey: string(),
4549
- lamports: number(),
4550
- postBalance: nullable(number()),
4551
- rewardType: nullable(string())
4552
- }))),
4608
+ rewards: optional(array(RewardsResult)),
4553
4609
  blockTime: nullable(number())
4554
4610
  })));
4555
4611
  /**
@@ -6046,7 +6102,7 @@ class Connection {
6046
6102
 
6047
6103
 
6048
6104
  async getFeeForMessage(message, commitment) {
6049
- const wireMessage = message.serialize().toString('base64');
6105
+ const wireMessage = toBuffer(message.serialize()).toString('base64');
6050
6106
 
6051
6107
  const args = this._buildArgs([wireMessage], commitment);
6052
6108
 
@@ -6171,33 +6227,67 @@ class Connection {
6171
6227
  , config);
6172
6228
 
6173
6229
  const unsafeRes = await this._rpcRequest('getBlock', args);
6174
- const res = create(unsafeRes, GetBlockRpcResult);
6175
6230
 
6176
- if ('error' in res) {
6177
- throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
6178
- }
6231
+ try {
6232
+ switch (config === null || config === void 0 ? void 0 : config.transactionDetails) {
6233
+ case 'accounts':
6234
+ {
6235
+ const res = create(unsafeRes, GetAccountsModeBlockRpcResult);
6179
6236
 
6180
- const result = res.result;
6181
- if (!result) return result;
6182
- return { ...result,
6183
- transactions: result.transactions.map(({
6184
- transaction,
6185
- meta,
6186
- version
6187
- }) => ({
6188
- meta,
6189
- transaction: { ...transaction,
6190
- message: versionedMessageFromResponse(version, transaction.message)
6191
- },
6192
- version
6193
- }))
6194
- };
6237
+ if ('error' in res) {
6238
+ throw res.error;
6239
+ }
6240
+
6241
+ return res.result;
6242
+ }
6243
+
6244
+ case 'none':
6245
+ {
6246
+ const res = create(unsafeRes, GetNoneModeBlockRpcResult);
6247
+
6248
+ if ('error' in res) {
6249
+ throw res.error;
6250
+ }
6251
+
6252
+ return res.result;
6253
+ }
6254
+
6255
+ default:
6256
+ {
6257
+ const res = create(unsafeRes, GetBlockRpcResult);
6258
+
6259
+ if ('error' in res) {
6260
+ throw res.error;
6261
+ }
6262
+
6263
+ const {
6264
+ result
6265
+ } = res;
6266
+ return result ? { ...result,
6267
+ transactions: result.transactions.map(({
6268
+ transaction,
6269
+ meta,
6270
+ version
6271
+ }) => ({
6272
+ meta,
6273
+ transaction: { ...transaction,
6274
+ message: versionedMessageFromResponse(version, transaction.message)
6275
+ },
6276
+ version
6277
+ }))
6278
+ } : null;
6279
+ }
6280
+ }
6281
+ } catch (e) {
6282
+ throw new SolanaJSONRPCError(e, 'failed to get confirmed block');
6283
+ }
6195
6284
  }
6196
6285
  /**
6197
6286
  * Fetch parsed transaction details for a confirmed or finalized block
6198
6287
  */
6199
6288
 
6200
6289
 
6290
+ // eslint-disable-next-line no-dupe-class-members
6201
6291
  async getParsedBlock(slot, rawConfig) {
6202
6292
  const {
6203
6293
  commitment,
@@ -6207,13 +6297,45 @@ class Connection {
6207
6297
  const args = this._buildArgsAtLeastConfirmed([slot], commitment, 'jsonParsed', config);
6208
6298
 
6209
6299
  const unsafeRes = await this._rpcRequest('getBlock', args);
6210
- const res = create(unsafeRes, GetParsedBlockRpcResult);
6211
6300
 
6212
- if ('error' in res) {
6213
- throw new SolanaJSONRPCError(res.error, 'failed to get block');
6214
- }
6301
+ try {
6302
+ switch (config === null || config === void 0 ? void 0 : config.transactionDetails) {
6303
+ case 'accounts':
6304
+ {
6305
+ const res = create(unsafeRes, GetParsedAccountsModeBlockRpcResult);
6215
6306
 
6216
- return res.result;
6307
+ if ('error' in res) {
6308
+ throw res.error;
6309
+ }
6310
+
6311
+ return res.result;
6312
+ }
6313
+
6314
+ case 'none':
6315
+ {
6316
+ const res = create(unsafeRes, GetParsedNoneModeBlockRpcResult);
6317
+
6318
+ if ('error' in res) {
6319
+ throw res.error;
6320
+ }
6321
+
6322
+ return res.result;
6323
+ }
6324
+
6325
+ default:
6326
+ {
6327
+ const res = create(unsafeRes, GetParsedBlockRpcResult);
6328
+
6329
+ if ('error' in res) {
6330
+ throw res.error;
6331
+ }
6332
+
6333
+ return res.result;
6334
+ }
6335
+ }
6336
+ } catch (e) {
6337
+ throw new SolanaJSONRPCError(e, 'failed to get block');
6338
+ }
6217
6339
  }
6218
6340
  /*
6219
6341
  * Returns the current block height of the node