@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.cjs.js CHANGED
@@ -4421,6 +4421,16 @@ const ConfirmedTransactionResult = superstruct.type({
4421
4421
  addressTableLookups: superstruct.optional(superstruct.array(AddressTableLookupStruct))
4422
4422
  })
4423
4423
  });
4424
+ const AnnotatedAccountKey = superstruct.type({
4425
+ pubkey: PublicKeyFromString,
4426
+ signer: superstruct.boolean(),
4427
+ writable: superstruct.boolean(),
4428
+ source: superstruct.optional(superstruct.union([superstruct.literal('transaction'), superstruct.literal('lookupTable')]))
4429
+ });
4430
+ const ConfirmedTransactionAccountsModeResult = superstruct.type({
4431
+ accountKeys: superstruct.array(AnnotatedAccountKey),
4432
+ signatures: superstruct.array(superstruct.string())
4433
+ });
4424
4434
  const ParsedInstructionResult = superstruct.type({
4425
4435
  parsed: superstruct.unknown(),
4426
4436
  program: superstruct.string(),
@@ -4455,12 +4465,7 @@ const ParsedOrRawInstruction = superstruct.coerce(InstructionResult, UnknownInst
4455
4465
  const ParsedConfirmedTransactionResult = superstruct.type({
4456
4466
  signatures: superstruct.array(superstruct.string()),
4457
4467
  message: superstruct.type({
4458
- accountKeys: superstruct.array(superstruct.type({
4459
- pubkey: PublicKeyFromString,
4460
- signer: superstruct.boolean(),
4461
- writable: superstruct.boolean(),
4462
- source: superstruct.optional(superstruct.union([superstruct.literal('transaction'), superstruct.literal('lookupTable')]))
4463
- })),
4468
+ accountKeys: superstruct.array(AnnotatedAccountKey),
4464
4469
  instructions: superstruct.array(ParsedOrRawInstruction),
4465
4470
  recentBlockhash: superstruct.string(),
4466
4471
  addressTableLookups: superstruct.optional(superstruct.nullable(superstruct.array(AddressTableLookupStruct)))
@@ -4519,6 +4524,14 @@ const ParsedConfirmedTransactionMetaResult = superstruct.type({
4519
4524
  computeUnitsConsumed: superstruct.optional(superstruct.number())
4520
4525
  });
4521
4526
  const TransactionVersionStruct = superstruct.union([superstruct.literal(0), superstruct.literal('legacy')]);
4527
+ /** @internal */
4528
+
4529
+ const RewardsResult = superstruct.type({
4530
+ pubkey: superstruct.string(),
4531
+ lamports: superstruct.number(),
4532
+ postBalance: superstruct.nullable(superstruct.number()),
4533
+ rewardType: superstruct.nullable(superstruct.string())
4534
+ });
4522
4535
  /**
4523
4536
  * Expected JSON RPC response for the "getBlock" message
4524
4537
  */
@@ -4532,12 +4545,36 @@ const GetBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4532
4545
  meta: superstruct.nullable(ConfirmedTransactionMetaResult),
4533
4546
  version: superstruct.optional(TransactionVersionStruct)
4534
4547
  })),
4535
- rewards: superstruct.optional(superstruct.array(superstruct.type({
4536
- pubkey: superstruct.string(),
4537
- lamports: superstruct.number(),
4538
- postBalance: superstruct.nullable(superstruct.number()),
4539
- rewardType: superstruct.nullable(superstruct.string())
4540
- }))),
4548
+ rewards: superstruct.optional(superstruct.array(RewardsResult)),
4549
+ blockTime: superstruct.nullable(superstruct.number()),
4550
+ blockHeight: superstruct.nullable(superstruct.number())
4551
+ })));
4552
+ /**
4553
+ * Expected JSON RPC response for the "getBlock" message when `transactionDetails` is `none`
4554
+ */
4555
+
4556
+ const GetNoneModeBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4557
+ blockhash: superstruct.string(),
4558
+ previousBlockhash: superstruct.string(),
4559
+ parentSlot: superstruct.number(),
4560
+ rewards: superstruct.optional(superstruct.array(RewardsResult)),
4561
+ blockTime: superstruct.nullable(superstruct.number()),
4562
+ blockHeight: superstruct.nullable(superstruct.number())
4563
+ })));
4564
+ /**
4565
+ * Expected JSON RPC response for the "getBlock" message when `transactionDetails` is `accounts`
4566
+ */
4567
+
4568
+ const GetAccountsModeBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4569
+ blockhash: superstruct.string(),
4570
+ previousBlockhash: superstruct.string(),
4571
+ parentSlot: superstruct.number(),
4572
+ transactions: superstruct.array(superstruct.type({
4573
+ transaction: ConfirmedTransactionAccountsModeResult,
4574
+ meta: superstruct.nullable(ConfirmedTransactionMetaResult),
4575
+ version: superstruct.optional(TransactionVersionStruct)
4576
+ })),
4577
+ rewards: superstruct.optional(superstruct.array(RewardsResult)),
4541
4578
  blockTime: superstruct.nullable(superstruct.number()),
4542
4579
  blockHeight: superstruct.nullable(superstruct.number())
4543
4580
  })));
@@ -4554,12 +4591,36 @@ const GetParsedBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.t
4554
4591
  meta: superstruct.nullable(ParsedConfirmedTransactionMetaResult),
4555
4592
  version: superstruct.optional(TransactionVersionStruct)
4556
4593
  })),
4557
- rewards: superstruct.optional(superstruct.array(superstruct.type({
4558
- pubkey: superstruct.string(),
4559
- lamports: superstruct.number(),
4560
- postBalance: superstruct.nullable(superstruct.number()),
4561
- rewardType: superstruct.nullable(superstruct.string())
4562
- }))),
4594
+ rewards: superstruct.optional(superstruct.array(RewardsResult)),
4595
+ blockTime: superstruct.nullable(superstruct.number()),
4596
+ blockHeight: superstruct.nullable(superstruct.number())
4597
+ })));
4598
+ /**
4599
+ * Expected parsed JSON RPC response for the "getBlock" message when `transactionDetails` is `accounts`
4600
+ */
4601
+
4602
+ const GetParsedAccountsModeBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4603
+ blockhash: superstruct.string(),
4604
+ previousBlockhash: superstruct.string(),
4605
+ parentSlot: superstruct.number(),
4606
+ transactions: superstruct.array(superstruct.type({
4607
+ transaction: ConfirmedTransactionAccountsModeResult,
4608
+ meta: superstruct.nullable(ParsedConfirmedTransactionMetaResult),
4609
+ version: superstruct.optional(TransactionVersionStruct)
4610
+ })),
4611
+ rewards: superstruct.optional(superstruct.array(RewardsResult)),
4612
+ blockTime: superstruct.nullable(superstruct.number()),
4613
+ blockHeight: superstruct.nullable(superstruct.number())
4614
+ })));
4615
+ /**
4616
+ * Expected parsed JSON RPC response for the "getBlock" message when `transactionDetails` is `none`
4617
+ */
4618
+
4619
+ const GetParsedNoneModeBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4620
+ blockhash: superstruct.string(),
4621
+ previousBlockhash: superstruct.string(),
4622
+ parentSlot: superstruct.number(),
4623
+ rewards: superstruct.optional(superstruct.array(RewardsResult)),
4563
4624
  blockTime: superstruct.nullable(superstruct.number()),
4564
4625
  blockHeight: superstruct.nullable(superstruct.number())
4565
4626
  })));
@@ -4577,12 +4638,7 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruc
4577
4638
  transaction: ConfirmedTransactionResult,
4578
4639
  meta: superstruct.nullable(ConfirmedTransactionMetaResult)
4579
4640
  })),
4580
- rewards: superstruct.optional(superstruct.array(superstruct.type({
4581
- pubkey: superstruct.string(),
4582
- lamports: superstruct.number(),
4583
- postBalance: superstruct.nullable(superstruct.number()),
4584
- rewardType: superstruct.nullable(superstruct.string())
4585
- }))),
4641
+ rewards: superstruct.optional(superstruct.array(RewardsResult)),
4586
4642
  blockTime: superstruct.nullable(superstruct.number())
4587
4643
  })));
4588
4644
  /**
@@ -6079,7 +6135,7 @@ class Connection {
6079
6135
 
6080
6136
 
6081
6137
  async getFeeForMessage(message, commitment) {
6082
- const wireMessage = message.serialize().toString('base64');
6138
+ const wireMessage = toBuffer(message.serialize()).toString('base64');
6083
6139
 
6084
6140
  const args = this._buildArgs([wireMessage], commitment);
6085
6141
 
@@ -6204,33 +6260,67 @@ class Connection {
6204
6260
  , config);
6205
6261
 
6206
6262
  const unsafeRes = await this._rpcRequest('getBlock', args);
6207
- const res = superstruct.create(unsafeRes, GetBlockRpcResult);
6208
6263
 
6209
- if ('error' in res) {
6210
- throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
6211
- }
6264
+ try {
6265
+ switch (config === null || config === void 0 ? void 0 : config.transactionDetails) {
6266
+ case 'accounts':
6267
+ {
6268
+ const res = superstruct.create(unsafeRes, GetAccountsModeBlockRpcResult);
6212
6269
 
6213
- const result = res.result;
6214
- if (!result) return result;
6215
- return { ...result,
6216
- transactions: result.transactions.map(({
6217
- transaction,
6218
- meta,
6219
- version
6220
- }) => ({
6221
- meta,
6222
- transaction: { ...transaction,
6223
- message: versionedMessageFromResponse(version, transaction.message)
6224
- },
6225
- version
6226
- }))
6227
- };
6270
+ if ('error' in res) {
6271
+ throw res.error;
6272
+ }
6273
+
6274
+ return res.result;
6275
+ }
6276
+
6277
+ case 'none':
6278
+ {
6279
+ const res = superstruct.create(unsafeRes, GetNoneModeBlockRpcResult);
6280
+
6281
+ if ('error' in res) {
6282
+ throw res.error;
6283
+ }
6284
+
6285
+ return res.result;
6286
+ }
6287
+
6288
+ default:
6289
+ {
6290
+ const res = superstruct.create(unsafeRes, GetBlockRpcResult);
6291
+
6292
+ if ('error' in res) {
6293
+ throw res.error;
6294
+ }
6295
+
6296
+ const {
6297
+ result
6298
+ } = res;
6299
+ return result ? { ...result,
6300
+ transactions: result.transactions.map(({
6301
+ transaction,
6302
+ meta,
6303
+ version
6304
+ }) => ({
6305
+ meta,
6306
+ transaction: { ...transaction,
6307
+ message: versionedMessageFromResponse(version, transaction.message)
6308
+ },
6309
+ version
6310
+ }))
6311
+ } : null;
6312
+ }
6313
+ }
6314
+ } catch (e) {
6315
+ throw new SolanaJSONRPCError(e, 'failed to get confirmed block');
6316
+ }
6228
6317
  }
6229
6318
  /**
6230
6319
  * Fetch parsed transaction details for a confirmed or finalized block
6231
6320
  */
6232
6321
 
6233
6322
 
6323
+ // eslint-disable-next-line no-dupe-class-members
6234
6324
  async getParsedBlock(slot, rawConfig) {
6235
6325
  const {
6236
6326
  commitment,
@@ -6240,13 +6330,45 @@ class Connection {
6240
6330
  const args = this._buildArgsAtLeastConfirmed([slot], commitment, 'jsonParsed', config);
6241
6331
 
6242
6332
  const unsafeRes = await this._rpcRequest('getBlock', args);
6243
- const res = superstruct.create(unsafeRes, GetParsedBlockRpcResult);
6244
6333
 
6245
- if ('error' in res) {
6246
- throw new SolanaJSONRPCError(res.error, 'failed to get block');
6247
- }
6334
+ try {
6335
+ switch (config === null || config === void 0 ? void 0 : config.transactionDetails) {
6336
+ case 'accounts':
6337
+ {
6338
+ const res = superstruct.create(unsafeRes, GetParsedAccountsModeBlockRpcResult);
6248
6339
 
6249
- return res.result;
6340
+ if ('error' in res) {
6341
+ throw res.error;
6342
+ }
6343
+
6344
+ return res.result;
6345
+ }
6346
+
6347
+ case 'none':
6348
+ {
6349
+ const res = superstruct.create(unsafeRes, GetParsedNoneModeBlockRpcResult);
6350
+
6351
+ if ('error' in res) {
6352
+ throw res.error;
6353
+ }
6354
+
6355
+ return res.result;
6356
+ }
6357
+
6358
+ default:
6359
+ {
6360
+ const res = superstruct.create(unsafeRes, GetParsedBlockRpcResult);
6361
+
6362
+ if ('error' in res) {
6363
+ throw res.error;
6364
+ }
6365
+
6366
+ return res.result;
6367
+ }
6368
+ }
6369
+ } catch (e) {
6370
+ throw new SolanaJSONRPCError(e, 'failed to get block');
6371
+ }
6250
6372
  }
6251
6373
  /*
6252
6374
  * Returns the current block height of the node