@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.
@@ -4325,6 +4325,16 @@ const ConfirmedTransactionResult = type({
4325
4325
  addressTableLookups: optional(array(AddressTableLookupStruct))
4326
4326
  })
4327
4327
  });
4328
+ const AnnotatedAccountKey = type({
4329
+ pubkey: PublicKeyFromString,
4330
+ signer: boolean(),
4331
+ writable: boolean(),
4332
+ source: optional(union([literal('transaction'), literal('lookupTable')]))
4333
+ });
4334
+ const ConfirmedTransactionAccountsModeResult = type({
4335
+ accountKeys: array(AnnotatedAccountKey),
4336
+ signatures: array(string())
4337
+ });
4328
4338
  const ParsedInstructionResult = type({
4329
4339
  parsed: unknown(),
4330
4340
  program: string(),
@@ -4359,12 +4369,7 @@ const ParsedOrRawInstruction = coerce(InstructionResult, UnknownInstructionResul
4359
4369
  const ParsedConfirmedTransactionResult = type({
4360
4370
  signatures: array(string()),
4361
4371
  message: type({
4362
- accountKeys: array(type({
4363
- pubkey: PublicKeyFromString,
4364
- signer: boolean(),
4365
- writable: boolean(),
4366
- source: optional(union([literal('transaction'), literal('lookupTable')]))
4367
- })),
4372
+ accountKeys: array(AnnotatedAccountKey),
4368
4373
  instructions: array(ParsedOrRawInstruction),
4369
4374
  recentBlockhash: string(),
4370
4375
  addressTableLookups: optional(nullable(array(AddressTableLookupStruct)))
@@ -4423,6 +4428,14 @@ const ParsedConfirmedTransactionMetaResult = type({
4423
4428
  computeUnitsConsumed: optional(number())
4424
4429
  });
4425
4430
  const TransactionVersionStruct = union([literal(0), literal('legacy')]);
4431
+ /** @internal */
4432
+
4433
+ const RewardsResult = type({
4434
+ pubkey: string(),
4435
+ lamports: number(),
4436
+ postBalance: nullable(number()),
4437
+ rewardType: nullable(string())
4438
+ });
4426
4439
  /**
4427
4440
  * Expected JSON RPC response for the "getBlock" message
4428
4441
  */
@@ -4436,12 +4449,36 @@ const GetBlockRpcResult = jsonRpcResult(nullable(type({
4436
4449
  meta: nullable(ConfirmedTransactionMetaResult),
4437
4450
  version: optional(TransactionVersionStruct)
4438
4451
  })),
4439
- rewards: optional(array(type({
4440
- pubkey: string(),
4441
- lamports: number(),
4442
- postBalance: nullable(number()),
4443
- rewardType: nullable(string())
4444
- }))),
4452
+ rewards: optional(array(RewardsResult)),
4453
+ blockTime: nullable(number()),
4454
+ blockHeight: nullable(number())
4455
+ })));
4456
+ /**
4457
+ * Expected JSON RPC response for the "getBlock" message when `transactionDetails` is `none`
4458
+ */
4459
+
4460
+ const GetNoneModeBlockRpcResult = jsonRpcResult(nullable(type({
4461
+ blockhash: string(),
4462
+ previousBlockhash: string(),
4463
+ parentSlot: number(),
4464
+ rewards: optional(array(RewardsResult)),
4465
+ blockTime: nullable(number()),
4466
+ blockHeight: nullable(number())
4467
+ })));
4468
+ /**
4469
+ * Expected JSON RPC response for the "getBlock" message when `transactionDetails` is `accounts`
4470
+ */
4471
+
4472
+ const GetAccountsModeBlockRpcResult = jsonRpcResult(nullable(type({
4473
+ blockhash: string(),
4474
+ previousBlockhash: string(),
4475
+ parentSlot: number(),
4476
+ transactions: array(type({
4477
+ transaction: ConfirmedTransactionAccountsModeResult,
4478
+ meta: nullable(ConfirmedTransactionMetaResult),
4479
+ version: optional(TransactionVersionStruct)
4480
+ })),
4481
+ rewards: optional(array(RewardsResult)),
4445
4482
  blockTime: nullable(number()),
4446
4483
  blockHeight: nullable(number())
4447
4484
  })));
@@ -4458,12 +4495,36 @@ const GetParsedBlockRpcResult = jsonRpcResult(nullable(type({
4458
4495
  meta: nullable(ParsedConfirmedTransactionMetaResult),
4459
4496
  version: optional(TransactionVersionStruct)
4460
4497
  })),
4461
- rewards: optional(array(type({
4462
- pubkey: string(),
4463
- lamports: number(),
4464
- postBalance: nullable(number()),
4465
- rewardType: nullable(string())
4466
- }))),
4498
+ rewards: optional(array(RewardsResult)),
4499
+ blockTime: nullable(number()),
4500
+ blockHeight: nullable(number())
4501
+ })));
4502
+ /**
4503
+ * Expected parsed JSON RPC response for the "getBlock" message when `transactionDetails` is `accounts`
4504
+ */
4505
+
4506
+ const GetParsedAccountsModeBlockRpcResult = jsonRpcResult(nullable(type({
4507
+ blockhash: string(),
4508
+ previousBlockhash: string(),
4509
+ parentSlot: number(),
4510
+ transactions: array(type({
4511
+ transaction: ConfirmedTransactionAccountsModeResult,
4512
+ meta: nullable(ParsedConfirmedTransactionMetaResult),
4513
+ version: optional(TransactionVersionStruct)
4514
+ })),
4515
+ rewards: optional(array(RewardsResult)),
4516
+ blockTime: nullable(number()),
4517
+ blockHeight: nullable(number())
4518
+ })));
4519
+ /**
4520
+ * Expected parsed JSON RPC response for the "getBlock" message when `transactionDetails` is `none`
4521
+ */
4522
+
4523
+ const GetParsedNoneModeBlockRpcResult = jsonRpcResult(nullable(type({
4524
+ blockhash: string(),
4525
+ previousBlockhash: string(),
4526
+ parentSlot: number(),
4527
+ rewards: optional(array(RewardsResult)),
4467
4528
  blockTime: nullable(number()),
4468
4529
  blockHeight: nullable(number())
4469
4530
  })));
@@ -4481,12 +4542,7 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
4481
4542
  transaction: ConfirmedTransactionResult,
4482
4543
  meta: nullable(ConfirmedTransactionMetaResult)
4483
4544
  })),
4484
- rewards: optional(array(type({
4485
- pubkey: string(),
4486
- lamports: number(),
4487
- postBalance: nullable(number()),
4488
- rewardType: nullable(string())
4489
- }))),
4545
+ rewards: optional(array(RewardsResult)),
4490
4546
  blockTime: nullable(number())
4491
4547
  })));
4492
4548
  /**
@@ -5983,7 +6039,7 @@ class Connection {
5983
6039
 
5984
6040
 
5985
6041
  async getFeeForMessage(message, commitment) {
5986
- const wireMessage = message.serialize().toString('base64');
6042
+ const wireMessage = toBuffer(message.serialize()).toString('base64');
5987
6043
 
5988
6044
  const args = this._buildArgs([wireMessage], commitment);
5989
6045
 
@@ -6108,33 +6164,67 @@ class Connection {
6108
6164
  , config);
6109
6165
 
6110
6166
  const unsafeRes = await this._rpcRequest('getBlock', args);
6111
- const res = create(unsafeRes, GetBlockRpcResult);
6112
6167
 
6113
- if ('error' in res) {
6114
- throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
6115
- }
6168
+ try {
6169
+ switch (config === null || config === void 0 ? void 0 : config.transactionDetails) {
6170
+ case 'accounts':
6171
+ {
6172
+ const res = create(unsafeRes, GetAccountsModeBlockRpcResult);
6116
6173
 
6117
- const result = res.result;
6118
- if (!result) return result;
6119
- return { ...result,
6120
- transactions: result.transactions.map(({
6121
- transaction,
6122
- meta,
6123
- version
6124
- }) => ({
6125
- meta,
6126
- transaction: { ...transaction,
6127
- message: versionedMessageFromResponse(version, transaction.message)
6128
- },
6129
- version
6130
- }))
6131
- };
6174
+ if ('error' in res) {
6175
+ throw res.error;
6176
+ }
6177
+
6178
+ return res.result;
6179
+ }
6180
+
6181
+ case 'none':
6182
+ {
6183
+ const res = create(unsafeRes, GetNoneModeBlockRpcResult);
6184
+
6185
+ if ('error' in res) {
6186
+ throw res.error;
6187
+ }
6188
+
6189
+ return res.result;
6190
+ }
6191
+
6192
+ default:
6193
+ {
6194
+ const res = create(unsafeRes, GetBlockRpcResult);
6195
+
6196
+ if ('error' in res) {
6197
+ throw res.error;
6198
+ }
6199
+
6200
+ const {
6201
+ result
6202
+ } = res;
6203
+ return result ? { ...result,
6204
+ transactions: result.transactions.map(({
6205
+ transaction,
6206
+ meta,
6207
+ version
6208
+ }) => ({
6209
+ meta,
6210
+ transaction: { ...transaction,
6211
+ message: versionedMessageFromResponse(version, transaction.message)
6212
+ },
6213
+ version
6214
+ }))
6215
+ } : null;
6216
+ }
6217
+ }
6218
+ } catch (e) {
6219
+ throw new SolanaJSONRPCError(e, 'failed to get confirmed block');
6220
+ }
6132
6221
  }
6133
6222
  /**
6134
6223
  * Fetch parsed transaction details for a confirmed or finalized block
6135
6224
  */
6136
6225
 
6137
6226
 
6227
+ // eslint-disable-next-line no-dupe-class-members
6138
6228
  async getParsedBlock(slot, rawConfig) {
6139
6229
  const {
6140
6230
  commitment,
@@ -6144,13 +6234,45 @@ class Connection {
6144
6234
  const args = this._buildArgsAtLeastConfirmed([slot], commitment, 'jsonParsed', config);
6145
6235
 
6146
6236
  const unsafeRes = await this._rpcRequest('getBlock', args);
6147
- const res = create(unsafeRes, GetParsedBlockRpcResult);
6148
6237
 
6149
- if ('error' in res) {
6150
- throw new SolanaJSONRPCError(res.error, 'failed to get block');
6151
- }
6238
+ try {
6239
+ switch (config === null || config === void 0 ? void 0 : config.transactionDetails) {
6240
+ case 'accounts':
6241
+ {
6242
+ const res = create(unsafeRes, GetParsedAccountsModeBlockRpcResult);
6152
6243
 
6153
- return res.result;
6244
+ if ('error' in res) {
6245
+ throw res.error;
6246
+ }
6247
+
6248
+ return res.result;
6249
+ }
6250
+
6251
+ case 'none':
6252
+ {
6253
+ const res = create(unsafeRes, GetParsedNoneModeBlockRpcResult);
6254
+
6255
+ if ('error' in res) {
6256
+ throw res.error;
6257
+ }
6258
+
6259
+ return res.result;
6260
+ }
6261
+
6262
+ default:
6263
+ {
6264
+ const res = create(unsafeRes, GetParsedBlockRpcResult);
6265
+
6266
+ if ('error' in res) {
6267
+ throw res.error;
6268
+ }
6269
+
6270
+ return res.result;
6271
+ }
6272
+ }
6273
+ } catch (e) {
6274
+ throw new SolanaJSONRPCError(e, 'failed to get block');
6275
+ }
6154
6276
  }
6155
6277
  /*
6156
6278
  * Returns the current block height of the node