@solana/web3.js 1.54.1 → 1.56.1

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
@@ -896,16 +896,24 @@ class MessageV0 {
896
896
 
897
897
  // eslint-disable-next-line no-redeclare
898
898
  const VersionedMessage = {
899
- deserialize: serializedMessage => {
899
+ deserializeMessageVersion(serializedMessage) {
900
900
  const prefix = serializedMessage[0];
901
901
  const maskedPrefix = prefix & VERSION_PREFIX_MASK; // if the highest bit of the prefix is not set, the message is not versioned
902
902
 
903
903
  if (maskedPrefix === prefix) {
904
- return Message.from(serializedMessage);
904
+ return 'legacy';
905
905
  } // the lower 7 bits of the prefix indicate the message version
906
906
 
907
907
 
908
- const version = maskedPrefix;
908
+ return maskedPrefix;
909
+ },
910
+
911
+ deserialize: serializedMessage => {
912
+ const version = VersionedMessage.deserializeMessageVersion(serializedMessage);
913
+
914
+ if (version === 'legacy') {
915
+ return Message.from(serializedMessage);
916
+ }
909
917
 
910
918
  if (version === 0) {
911
919
  return MessageV0.deserialize(serializedMessage);
@@ -3289,6 +3297,28 @@ function notificationResultAndContext(value) {
3289
3297
  value
3290
3298
  });
3291
3299
  }
3300
+ /**
3301
+ * @internal
3302
+ */
3303
+
3304
+
3305
+ function versionedMessageFromResponse(version, response) {
3306
+ if (version === 0) {
3307
+ return new MessageV0({
3308
+ header: response.header,
3309
+ staticAccountKeys: response.accountKeys.map(accountKey => new PublicKey(accountKey)),
3310
+ recentBlockhash: response.recentBlockhash,
3311
+ compiledInstructions: response.instructions.map(ix => ({
3312
+ programIdIndex: ix.programIdIndex,
3313
+ accountKeyIndexes: ix.accounts,
3314
+ data: bs58__default["default"].decode(ix.data)
3315
+ })),
3316
+ addressTableLookups: response.addressTableLookups
3317
+ });
3318
+ } else {
3319
+ return new Message(response);
3320
+ }
3321
+ }
3292
3322
  /**
3293
3323
  * The level of commitment desired when querying state
3294
3324
  * <pre>
@@ -3852,6 +3882,11 @@ const GetSignatureStatusesRpcResult = jsonRpcResultAndContext(superstruct.array(
3852
3882
  */
3853
3883
 
3854
3884
  const GetMinimumBalanceForRentExemptionRpcResult = jsonRpcResult(superstruct.number());
3885
+ const AddressTableLookupStruct = superstruct.type({
3886
+ accountKey: PublicKeyFromString,
3887
+ writableIndexes: superstruct.array(superstruct.number()),
3888
+ readonlyIndexes: superstruct.array(superstruct.number())
3889
+ });
3855
3890
  const ConfirmedTransactionResult = superstruct.type({
3856
3891
  signatures: superstruct.array(superstruct.string()),
3857
3892
  message: superstruct.type({
@@ -3866,7 +3901,8 @@ const ConfirmedTransactionResult = superstruct.type({
3866
3901
  data: superstruct.string(),
3867
3902
  programIdIndex: superstruct.number()
3868
3903
  })),
3869
- recentBlockhash: superstruct.string()
3904
+ recentBlockhash: superstruct.string(),
3905
+ addressTableLookups: superstruct.optional(superstruct.array(AddressTableLookupStruct))
3870
3906
  })
3871
3907
  });
3872
3908
  const ParsedInstructionResult = superstruct.type({
@@ -3909,7 +3945,8 @@ const ParsedConfirmedTransactionResult = superstruct.type({
3909
3945
  writable: superstruct.boolean()
3910
3946
  })),
3911
3947
  instructions: superstruct.array(ParsedOrRawInstruction),
3912
- recentBlockhash: superstruct.string()
3948
+ recentBlockhash: superstruct.string(),
3949
+ addressTableLookups: superstruct.optional(superstruct.nullable(superstruct.array(AddressTableLookupStruct)))
3913
3950
  })
3914
3951
  });
3915
3952
  const TokenBalanceResult = superstruct.type({
@@ -3962,6 +3999,7 @@ const ParsedConfirmedTransactionMetaResult = superstruct.type({
3962
3999
  postTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
3963
4000
  loadedAddresses: superstruct.optional(LoadedAddressesResult)
3964
4001
  });
4002
+ const TransactionVersionStruct = superstruct.union([superstruct.literal(0), superstruct.literal('legacy')]);
3965
4003
  /**
3966
4004
  * Expected JSON RPC response for the "getBlock" message
3967
4005
  */
@@ -3972,7 +4010,8 @@ const GetBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
3972
4010
  parentSlot: superstruct.number(),
3973
4011
  transactions: superstruct.array(superstruct.type({
3974
4012
  transaction: ConfirmedTransactionResult,
3975
- meta: superstruct.nullable(ConfirmedTransactionMetaResult)
4013
+ meta: superstruct.nullable(ConfirmedTransactionMetaResult),
4014
+ version: superstruct.optional(TransactionVersionStruct)
3976
4015
  })),
3977
4016
  rewards: superstruct.optional(superstruct.array(superstruct.type({
3978
4017
  pubkey: superstruct.string(),
@@ -4024,7 +4063,8 @@ const GetTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.t
4024
4063
  slot: superstruct.number(),
4025
4064
  meta: ConfirmedTransactionMetaResult,
4026
4065
  blockTime: superstruct.optional(superstruct.nullable(superstruct.number())),
4027
- transaction: ConfirmedTransactionResult
4066
+ transaction: ConfirmedTransactionResult,
4067
+ version: superstruct.optional(TransactionVersionStruct)
4028
4068
  })));
4029
4069
  /**
4030
4070
  * Expected parsed JSON RPC response for the "getTransaction" message
@@ -4034,7 +4074,8 @@ const GetParsedTransactionRpcResult = jsonRpcResult(superstruct.nullable(superst
4034
4074
  slot: superstruct.number(),
4035
4075
  transaction: ParsedConfirmedTransactionResult,
4036
4076
  meta: superstruct.nullable(ParsedConfirmedTransactionMetaResult),
4037
- blockTime: superstruct.optional(superstruct.nullable(superstruct.number()))
4077
+ blockTime: superstruct.optional(superstruct.nullable(superstruct.number())),
4078
+ version: superstruct.optional(TransactionVersionStruct)
4038
4079
  })));
4039
4080
  /**
4040
4081
  * Expected JSON RPC response for the "getRecentBlockhash" message
@@ -5277,9 +5318,16 @@ class Connection {
5277
5318
  }
5278
5319
  /**
5279
5320
  * Fetch a processed block from the cluster.
5321
+ *
5322
+ * @deprecated Instead, call `getBlock` using a `GetVersionedBlockConfig` by
5323
+ * setting the `maxSupportedTransactionVersion` property.
5280
5324
  */
5281
5325
 
5282
5326
 
5327
+ /**
5328
+ * Fetch a processed block from the cluster.
5329
+ */
5330
+ // eslint-disable-next-line no-dupe-class-members
5283
5331
  async getBlock(slot, rawConfig) {
5284
5332
  const {
5285
5333
  commitment,
@@ -5302,16 +5350,15 @@ class Connection {
5302
5350
  return { ...result,
5303
5351
  transactions: result.transactions.map(({
5304
5352
  transaction,
5305
- meta
5306
- }) => {
5307
- const message = new Message(transaction.message);
5308
- return {
5309
- meta,
5310
- transaction: { ...transaction,
5311
- message
5312
- }
5313
- };
5314
- })
5353
+ meta,
5354
+ version
5355
+ }) => ({
5356
+ meta,
5357
+ transaction: { ...transaction,
5358
+ message: versionedMessageFromResponse(version, transaction.message)
5359
+ },
5360
+ version
5361
+ }))
5315
5362
  };
5316
5363
  }
5317
5364
  /*
@@ -5371,9 +5418,17 @@ class Connection {
5371
5418
  }
5372
5419
  /**
5373
5420
  * Fetch a confirmed or finalized transaction from the cluster.
5421
+ *
5422
+ * @deprecated Instead, call `getTransaction` using a
5423
+ * `GetVersionedTransactionConfig` by setting the
5424
+ * `maxSupportedTransactionVersion` property.
5374
5425
  */
5375
5426
 
5376
5427
 
5428
+ /**
5429
+ * Fetch a confirmed or finalized transaction from the cluster.
5430
+ */
5431
+ // eslint-disable-next-line no-dupe-class-members
5377
5432
  async getTransaction(signature, rawConfig) {
5378
5433
  const {
5379
5434
  commitment,
@@ -5395,7 +5450,7 @@ class Connection {
5395
5450
  if (!result) return result;
5396
5451
  return { ...result,
5397
5452
  transaction: { ...result.transaction,
5398
- message: new Message(result.transaction.message)
5453
+ message: versionedMessageFromResponse(result.version, result.transaction.message)
5399
5454
  }
5400
5455
  };
5401
5456
  }
@@ -5454,9 +5509,19 @@ class Connection {
5454
5509
  /**
5455
5510
  * Fetch transaction details for a batch of confirmed transactions.
5456
5511
  * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
5512
+ *
5513
+ * @deprecated Instead, call `getTransactions` using a
5514
+ * `GetVersionedTransactionConfig` by setting the
5515
+ * `maxSupportedTransactionVersion` property.
5457
5516
  */
5458
5517
 
5459
5518
 
5519
+ /**
5520
+ * Fetch transaction details for a batch of confirmed transactions.
5521
+ * Similar to {@link getParsedTransactions} but returns a {@link
5522
+ * VersionedTransactionResponse}.
5523
+ */
5524
+ // eslint-disable-next-line no-dupe-class-members
5460
5525
  async getTransactions(signatures, commitmentOrConfig) {
5461
5526
  const {
5462
5527
  commitment,
@@ -5484,7 +5549,7 @@ class Connection {
5484
5549
  if (!result) return result;
5485
5550
  return { ...result,
5486
5551
  transaction: { ...result.transaction,
5487
- message: new Message(result.transaction.message)
5552
+ message: versionedMessageFromResponse(result.version, result.transaction.message)
5488
5553
  }
5489
5554
  };
5490
5555
  });