@solana/web3.js 1.31.0 → 1.32.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
@@ -1840,6 +1840,10 @@ class PublicKey extends Struct {
1840
1840
  toBase58() {
1841
1841
  return bs58__default["default"].encode(this.toBytes());
1842
1842
  }
1843
+
1844
+ toJSON() {
1845
+ return this.toBase58();
1846
+ }
1843
1847
  /**
1844
1848
  * Return the byte array representation of the public key
1845
1849
  */
@@ -2479,8 +2483,9 @@ class Transaction {
2479
2483
  }); // Sort. Prioritizing first by signer, then by writable
2480
2484
 
2481
2485
  accountMetas.sort(function (x, y) {
2486
+ const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
2482
2487
  const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
2483
- const checkWritable = x.isWritable === y.isWritable ? 0 : x.isWritable ? -1 : 1;
2488
+ const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
2484
2489
  return checkSigner || checkWritable;
2485
2490
  }); // Cull duplicate account metas
2486
2491
 
@@ -2936,11 +2941,14 @@ class Transaction {
2936
2941
  }
2937
2942
 
2938
2943
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
2944
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
2945
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2939
2946
  const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
2940
2947
  const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
2941
2948
  const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
2949
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
2950
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2942
2951
  const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2943
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2944
2952
 
2945
2953
  /**
2946
2954
  * Sign, send and confirm a transaction.
@@ -4358,16 +4366,15 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
4358
4366
  let fetchWithMiddleware;
4359
4367
 
4360
4368
  if (fetchMiddleware) {
4361
- fetchWithMiddleware = (url, options) => {
4362
- return new Promise((resolve, reject) => {
4363
- fetchMiddleware(url, options, async (url, options) => {
4364
- try {
4365
- resolve(await fetch__default["default"](url, options));
4366
- } catch (error) {
4367
- reject(error);
4368
- }
4369
- });
4369
+ fetchWithMiddleware = async (url, options) => {
4370
+ const modifiedFetchArgs = await new Promise((resolve, reject) => {
4371
+ try {
4372
+ fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
4373
+ } catch (error) {
4374
+ reject(error);
4375
+ }
4370
4376
  });
4377
+ return await fetch__default["default"](...modifiedFetchArgs);
4371
4378
  };
4372
4379
  }
4373
4380
 
@@ -4861,6 +4868,7 @@ const ParsedConfirmedTransactionResult = superstruct.type({
4861
4868
  const TokenBalanceResult = superstruct.type({
4862
4869
  accountIndex: superstruct.number(),
4863
4870
  mint: superstruct.string(),
4871
+ owner: superstruct.optional(superstruct.string()),
4864
4872
  uiTokenAmount: TokenAmountResult
4865
4873
  });
4866
4874
  /**
@@ -5464,13 +5472,25 @@ class Connection {
5464
5472
  */
5465
5473
 
5466
5474
 
5467
- async getMultipleAccountsInfo(publicKeys, commitment) {
5475
+ async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
5468
5476
  const keys = publicKeys.map(key => key.toBase58());
5477
+ let commitment;
5478
+ let encoding = 'base64';
5479
+
5480
+ if (configOrCommitment) {
5481
+ if (typeof configOrCommitment === 'string') {
5482
+ commitment = configOrCommitment;
5483
+ encoding = 'base64';
5484
+ } else {
5485
+ commitment = configOrCommitment.commitment;
5486
+ encoding = configOrCommitment.encoding || 'base64';
5487
+ }
5488
+ }
5469
5489
 
5470
- const args = this._buildArgs([keys], commitment, 'base64');
5490
+ const args = this._buildArgs([keys], commitment, encoding);
5471
5491
 
5472
5492
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
5473
- const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.array(superstruct.nullable(AccountInfoResult))));
5493
+ const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.array(superstruct.nullable(ParsedAccountInfoResult))));
5474
5494
 
5475
5495
  if ('error' in res) {
5476
5496
  throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
@@ -5951,6 +5971,29 @@ class Connection {
5951
5971
  value: value !== null ? value.feeCalculator : null
5952
5972
  };
5953
5973
  }
5974
+ /**
5975
+ * Fetch the fee for a message from the cluster, return with context
5976
+ */
5977
+
5978
+
5979
+ async getFeeForMessage(message, commitment) {
5980
+ const wireMessage = message.serialize().toString('base64');
5981
+
5982
+ const args = this._buildArgs([wireMessage], commitment);
5983
+
5984
+ const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
5985
+ const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.nullable(superstruct.number())));
5986
+
5987
+ if ('error' in res) {
5988
+ throw new Error('failed to get slot: ' + res.error.message);
5989
+ }
5990
+
5991
+ if (res.result === null) {
5992
+ throw new Error('invalid blockhash');
5993
+ }
5994
+
5995
+ return res.result;
5996
+ }
5954
5997
  /**
5955
5998
  * Fetch a recent blockhash from the cluster
5956
5999
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
@@ -8430,9 +8473,10 @@ const VOTE_PROGRAM_ID = new PublicKey('Vote1111111111111111111111111111111111111
8430
8473
  *
8431
8474
  * @internal
8432
8475
  */
8433
- const VoteAccountLayout = BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedVoterPubkey'), publicKey('authorizedWithdrawerPubkey'), BufferLayout__namespace.u8('commission'), BufferLayout__namespace.nu64(), // votes.length
8434
- BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('slot'), BufferLayout__namespace.u32('confirmationCount')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'votes'), BufferLayout__namespace.u8('rootSlotValid'), BufferLayout__namespace.nu64('rootSlot'), BufferLayout__namespace.nu64('epoch'), BufferLayout__namespace.nu64('credits'), BufferLayout__namespace.nu64('lastEpochCredits'), BufferLayout__namespace.nu64(), // epochCredits.length
8435
- BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('epoch'), BufferLayout__namespace.nu64('credits'), BufferLayout__namespace.nu64('prevCredits')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'epochCredits')]);
8476
+ const VoteAccountLayout = BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission'), BufferLayout__namespace.nu64(), // votes.length
8477
+ BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('slot'), BufferLayout__namespace.u32('confirmationCount')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'votes'), BufferLayout__namespace.u8('rootSlotValid'), BufferLayout__namespace.nu64('rootSlot'), BufferLayout__namespace.nu64(), // authorizedVoters.length
8478
+ BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('epoch'), publicKey('authorizedVoter')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'authorizedVoters'), BufferLayout__namespace.struct([BufferLayout__namespace.seq(BufferLayout__namespace.struct([publicKey('authorizedPubkey'), BufferLayout__namespace.nu64('epochOfLastAuthorizedSwitch'), BufferLayout__namespace.nu64('targetEpoch')]), 32, 'buf'), BufferLayout__namespace.nu64('idx'), BufferLayout__namespace.u8('isEmpty')], 'priorVoters'), BufferLayout__namespace.nu64(), // epochCredits.length
8479
+ BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('epoch'), BufferLayout__namespace.nu64('credits'), BufferLayout__namespace.nu64('prevCredits')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'epochCredits'), BufferLayout__namespace.struct([BufferLayout__namespace.nu64('slot'), BufferLayout__namespace.nu64('timestamp')], 'lastTimestamp')]);
8436
8480
 
8437
8481
  /**
8438
8482
  * VoteAccount class
@@ -8443,25 +8487,23 @@ class VoteAccount {
8443
8487
  */
8444
8488
  constructor(args) {
8445
8489
  this.nodePubkey = void 0;
8446
- this.authorizedVoterPubkey = void 0;
8447
- this.authorizedWithdrawerPubkey = void 0;
8490
+ this.authorizedWithdrawer = void 0;
8448
8491
  this.commission = void 0;
8449
- this.votes = void 0;
8450
8492
  this.rootSlot = void 0;
8451
- this.epoch = void 0;
8452
- this.credits = void 0;
8453
- this.lastEpochCredits = void 0;
8493
+ this.votes = void 0;
8494
+ this.authorizedVoters = void 0;
8495
+ this.priorVoters = void 0;
8454
8496
  this.epochCredits = void 0;
8497
+ this.lastTimestamp = void 0;
8455
8498
  this.nodePubkey = args.nodePubkey;
8456
- this.authorizedVoterPubkey = args.authorizedVoterPubkey;
8457
- this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
8499
+ this.authorizedWithdrawer = args.authorizedWithdrawer;
8458
8500
  this.commission = args.commission;
8459
- this.votes = args.votes;
8460
8501
  this.rootSlot = args.rootSlot;
8461
- this.epoch = args.epoch;
8462
- this.credits = args.credits;
8463
- this.lastEpochCredits = args.lastEpochCredits;
8502
+ this.votes = args.votes;
8503
+ this.authorizedVoters = args.authorizedVoters;
8504
+ this.priorVoters = args.priorVoters;
8464
8505
  this.epochCredits = args.epochCredits;
8506
+ this.lastTimestamp = args.lastTimestamp;
8465
8507
  }
8466
8508
  /**
8467
8509
  * Deserialize VoteAccount from the account data.
@@ -8472,7 +8514,8 @@ class VoteAccount {
8472
8514
 
8473
8515
 
8474
8516
  static fromAccountData(buffer) {
8475
- const va = VoteAccountLayout.decode(toBuffer(buffer), 0);
8517
+ const versionOffset = 4;
8518
+ const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
8476
8519
  let rootSlot = va.rootSlot;
8477
8520
 
8478
8521
  if (!va.rootSlotValid) {
@@ -8481,20 +8524,53 @@ class VoteAccount {
8481
8524
 
8482
8525
  return new VoteAccount({
8483
8526
  nodePubkey: new PublicKey(va.nodePubkey),
8484
- authorizedVoterPubkey: new PublicKey(va.authorizedVoterPubkey),
8485
- authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
8527
+ authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
8486
8528
  commission: va.commission,
8487
8529
  votes: va.votes,
8488
8530
  rootSlot,
8489
- epoch: va.epoch,
8490
- credits: va.credits,
8491
- lastEpochCredits: va.lastEpochCredits,
8492
- epochCredits: va.epochCredits
8531
+ authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
8532
+ priorVoters: getPriorVoters(va.priorVoters),
8533
+ epochCredits: va.epochCredits,
8534
+ lastTimestamp: va.lastTimestamp
8493
8535
  });
8494
8536
  }
8495
8537
 
8496
8538
  }
8497
8539
 
8540
+ function parseAuthorizedVoter({
8541
+ epoch,
8542
+ authorizedVoter
8543
+ }) {
8544
+ return {
8545
+ epoch,
8546
+ authorizedVoter: new PublicKey(authorizedVoter)
8547
+ };
8548
+ }
8549
+
8550
+ function parsePriorVoters({
8551
+ authorizedPubkey,
8552
+ epochOfLastAuthorizedSwitch,
8553
+ targetEpoch
8554
+ }) {
8555
+ return {
8556
+ authorizedPubkey: new PublicKey(authorizedPubkey),
8557
+ epochOfLastAuthorizedSwitch,
8558
+ targetEpoch
8559
+ };
8560
+ }
8561
+
8562
+ function getPriorVoters({
8563
+ buf,
8564
+ idx,
8565
+ isEmpty
8566
+ }) {
8567
+ if (isEmpty) {
8568
+ return [];
8569
+ }
8570
+
8571
+ return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
8572
+ }
8573
+
8498
8574
  /**
8499
8575
  * Send and confirm a raw transaction
8500
8576
  *
@@ -8584,10 +8660,13 @@ exports.STAKE_CONFIG_ID = STAKE_CONFIG_ID;
8584
8660
  exports.STAKE_INSTRUCTION_LAYOUTS = STAKE_INSTRUCTION_LAYOUTS;
8585
8661
  exports.SYSTEM_INSTRUCTION_LAYOUTS = SYSTEM_INSTRUCTION_LAYOUTS;
8586
8662
  exports.SYSVAR_CLOCK_PUBKEY = SYSVAR_CLOCK_PUBKEY;
8663
+ exports.SYSVAR_EPOCH_SCHEDULE_PUBKEY = SYSVAR_EPOCH_SCHEDULE_PUBKEY;
8587
8664
  exports.SYSVAR_INSTRUCTIONS_PUBKEY = SYSVAR_INSTRUCTIONS_PUBKEY;
8588
8665
  exports.SYSVAR_RECENT_BLOCKHASHES_PUBKEY = SYSVAR_RECENT_BLOCKHASHES_PUBKEY;
8589
8666
  exports.SYSVAR_RENT_PUBKEY = SYSVAR_RENT_PUBKEY;
8590
8667
  exports.SYSVAR_REWARDS_PUBKEY = SYSVAR_REWARDS_PUBKEY;
8668
+ exports.SYSVAR_SLOT_HASHES_PUBKEY = SYSVAR_SLOT_HASHES_PUBKEY;
8669
+ exports.SYSVAR_SLOT_HISTORY_PUBKEY = SYSVAR_SLOT_HISTORY_PUBKEY;
8591
8670
  exports.SYSVAR_STAKE_HISTORY_PUBKEY = SYSVAR_STAKE_HISTORY_PUBKEY;
8592
8671
  exports.Secp256k1Program = Secp256k1Program;
8593
8672
  exports.SendTransactionError = SendTransactionError;