@solana/web3.js 1.45.1 → 1.46.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.
@@ -3133,7 +3133,8 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
3133
3133
  const sendOptions = options && {
3134
3134
  skipPreflight: options.skipPreflight,
3135
3135
  preflightCommitment: options.preflightCommitment || options.commitment,
3136
- maxRetries: options.maxRetries
3136
+ maxRetries: options.maxRetries,
3137
+ minContextSlot: options.minContextSlot
3137
3138
  };
3138
3139
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
3139
3140
  const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
@@ -4645,9 +4646,32 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
4645
4646
  * https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
4646
4647
  */
4647
4648
 
4649
+ /** @internal */
4650
+ function extractCommitmentFromConfig(commitmentOrConfig) {
4651
+ let commitment;
4652
+ let config;
4653
+
4654
+ if (typeof commitmentOrConfig === 'string') {
4655
+ commitment = commitmentOrConfig;
4656
+ } else if (commitmentOrConfig) {
4657
+ const {
4658
+ commitment: specifiedCommitment,
4659
+ ...specifiedConfig
4660
+ } = commitmentOrConfig;
4661
+ commitment = specifiedCommitment;
4662
+ config = specifiedConfig;
4663
+ }
4664
+
4665
+ return {
4666
+ commitment,
4667
+ config
4668
+ };
4669
+ }
4648
4670
  /**
4649
4671
  * @internal
4650
4672
  */
4673
+
4674
+
4651
4675
  function createRpcResult(result) {
4652
4676
  return superstruct.union([superstruct.type({
4653
4677
  jsonrpc: superstruct.literal('2.0'),
@@ -5514,7 +5538,7 @@ const LogsNotificationResult = superstruct.type({
5514
5538
 
5515
5539
  /** @internal */
5516
5540
  const COMMON_HTTP_HEADERS = {
5517
- 'solana-client': `js/${(_process$env$npm_pack = "1.45.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5541
+ 'solana-client': `js/${(_process$env$npm_pack = "1.46.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5518
5542
  };
5519
5543
  /**
5520
5544
  * A connection to a fullnode JSON RPC endpoint
@@ -5684,8 +5708,16 @@ class Connection {
5684
5708
  */
5685
5709
 
5686
5710
 
5687
- async getBalanceAndContext(publicKey, commitment) {
5688
- const args = this._buildArgs([publicKey.toBase58()], commitment);
5711
+ async getBalanceAndContext(publicKey, commitmentOrConfig) {
5712
+ /** @internal */
5713
+ const {
5714
+ commitment,
5715
+ config
5716
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5717
+
5718
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
5719
+ /* encoding */
5720
+ , config);
5689
5721
 
5690
5722
  const unsafeRes = await this._rpcRequest('getBalance', args);
5691
5723
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.number()));
@@ -5701,8 +5733,8 @@ class Connection {
5701
5733
  */
5702
5734
 
5703
5735
 
5704
- async getBalance(publicKey, commitment) {
5705
- return await this.getBalanceAndContext(publicKey, commitment).then(x => x.value).catch(e => {
5736
+ async getBalance(publicKey, commitmentOrConfig) {
5737
+ return await this.getBalanceAndContext(publicKey, commitmentOrConfig).then(x => x.value).catch(e => {
5706
5738
  throw new Error('failed to get balance of account ' + publicKey.toBase58() + ': ' + e);
5707
5739
  });
5708
5740
  }
@@ -5824,7 +5856,11 @@ class Connection {
5824
5856
  */
5825
5857
 
5826
5858
 
5827
- async getTokenAccountsByOwner(ownerAddress, filter, commitment) {
5859
+ async getTokenAccountsByOwner(ownerAddress, filter, commitmentOrConfig) {
5860
+ const {
5861
+ commitment,
5862
+ config
5863
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5828
5864
  let _args = [ownerAddress.toBase58()];
5829
5865
 
5830
5866
  if ('mint' in filter) {
@@ -5837,7 +5873,7 @@ class Connection {
5837
5873
  });
5838
5874
  }
5839
5875
 
5840
- const args = this._buildArgs(_args, commitment, 'base64');
5876
+ const args = this._buildArgs(_args, commitment, 'base64', config);
5841
5877
 
5842
5878
  const unsafeRes = await this._rpcRequest('getTokenAccountsByOwner', args);
5843
5879
  const res = superstruct.create(unsafeRes, GetTokenAccountsByOwner);
@@ -5921,8 +5957,13 @@ class Connection {
5921
5957
  */
5922
5958
 
5923
5959
 
5924
- async getAccountInfoAndContext(publicKey, commitment) {
5925
- const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64');
5960
+ async getAccountInfoAndContext(publicKey, commitmentOrConfig) {
5961
+ const {
5962
+ commitment,
5963
+ config
5964
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5965
+
5966
+ const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64', config);
5926
5967
 
5927
5968
  const unsafeRes = await this._rpcRequest('getAccountInfo', args);
5928
5969
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.nullable(AccountInfoResult)));
@@ -5955,9 +5996,9 @@ class Connection {
5955
5996
  */
5956
5997
 
5957
5998
 
5958
- async getAccountInfo(publicKey, commitment) {
5999
+ async getAccountInfo(publicKey, commitmentOrConfig) {
5959
6000
  try {
5960
- const res = await this.getAccountInfoAndContext(publicKey, commitment);
6001
+ const res = await this.getAccountInfoAndContext(publicKey, commitmentOrConfig);
5961
6002
  return res.value;
5962
6003
  } catch (e) {
5963
6004
  throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + e);
@@ -5968,10 +6009,14 @@ class Connection {
5968
6009
  */
5969
6010
 
5970
6011
 
5971
- async getMultipleAccountsInfoAndContext(publicKeys, commitment) {
6012
+ async getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig) {
6013
+ const {
6014
+ commitment,
6015
+ config
6016
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5972
6017
  const keys = publicKeys.map(key => key.toBase58());
5973
6018
 
5974
- const args = this._buildArgs([keys], commitment, 'base64');
6019
+ const args = this._buildArgs([keys], commitment, 'base64', config);
5975
6020
 
5976
6021
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
5977
6022
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.array(superstruct.nullable(AccountInfoResult))));
@@ -5987,8 +6032,8 @@ class Connection {
5987
6032
  */
5988
6033
 
5989
6034
 
5990
- async getMultipleAccountsInfo(publicKeys, commitment) {
5991
- const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitment);
6035
+ async getMultipleAccountsInfo(publicKeys, commitmentOrConfig) {
6036
+ const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig);
5992
6037
  return res.value;
5993
6038
  }
5994
6039
  /**
@@ -5996,10 +6041,17 @@ class Connection {
5996
6041
  */
5997
6042
 
5998
6043
 
5999
- async getStakeActivation(publicKey, commitment, epoch) {
6000
- const args = this._buildArgs([publicKey.toBase58()], commitment, undefined, epoch !== undefined ? {
6001
- epoch
6002
- } : undefined);
6044
+ async getStakeActivation(publicKey, commitmentOrConfig, epoch) {
6045
+ const {
6046
+ commitment,
6047
+ config
6048
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6049
+
6050
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
6051
+ /* encoding */
6052
+ , { ...config,
6053
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
6054
+ });
6003
6055
 
6004
6056
  const unsafeRes = await this._rpcRequest('getStakeActivation', args);
6005
6057
  const res = superstruct.create(unsafeRes, jsonRpcResult(StakeActivationResult));
@@ -6018,28 +6070,16 @@ class Connection {
6018
6070
 
6019
6071
 
6020
6072
  async getProgramAccounts(programId, configOrCommitment) {
6021
- const extra = {};
6022
- let commitment;
6023
- let encoding;
6024
-
6025
- if (configOrCommitment) {
6026
- if (typeof configOrCommitment === 'string') {
6027
- commitment = configOrCommitment;
6028
- } else {
6029
- commitment = configOrCommitment.commitment;
6030
- encoding = configOrCommitment.encoding;
6031
-
6032
- if (configOrCommitment.dataSlice) {
6033
- extra.dataSlice = configOrCommitment.dataSlice;
6034
- }
6035
-
6036
- if (configOrCommitment.filters) {
6037
- extra.filters = configOrCommitment.filters;
6038
- }
6039
- }
6040
- }
6073
+ const {
6074
+ commitment,
6075
+ config
6076
+ } = extractCommitmentFromConfig(configOrCommitment);
6077
+ const {
6078
+ encoding,
6079
+ ...configWithoutEncoding
6080
+ } = config || {};
6041
6081
 
6042
- const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', extra);
6082
+ const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', configWithoutEncoding);
6043
6083
 
6044
6084
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
6045
6085
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(KeyedAccountInfoResult)));
@@ -6058,22 +6098,12 @@ class Connection {
6058
6098
 
6059
6099
 
6060
6100
  async getParsedProgramAccounts(programId, configOrCommitment) {
6061
- const extra = {};
6062
- let commitment;
6063
-
6064
- if (configOrCommitment) {
6065
- if (typeof configOrCommitment === 'string') {
6066
- commitment = configOrCommitment;
6067
- } else {
6068
- commitment = configOrCommitment.commitment;
6069
-
6070
- if (configOrCommitment.filters) {
6071
- extra.filters = configOrCommitment.filters;
6072
- }
6073
- }
6074
- }
6101
+ const {
6102
+ commitment,
6103
+ config
6104
+ } = extractCommitmentFromConfig(configOrCommitment);
6075
6105
 
6076
- const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', extra);
6106
+ const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', config);
6077
6107
 
6078
6108
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
6079
6109
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(KeyedParsedAccountInfoResult)));
@@ -6240,8 +6270,15 @@ class Connection {
6240
6270
  */
6241
6271
 
6242
6272
 
6243
- async getSlot(commitment) {
6244
- const args = this._buildArgs([], commitment);
6273
+ async getSlot(commitmentOrConfig) {
6274
+ const {
6275
+ commitment,
6276
+ config
6277
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6278
+
6279
+ const args = this._buildArgs([], commitment, undefined
6280
+ /* encoding */
6281
+ , config);
6245
6282
 
6246
6283
  const unsafeRes = await this._rpcRequest('getSlot', args);
6247
6284
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
@@ -6257,8 +6294,15 @@ class Connection {
6257
6294
  */
6258
6295
 
6259
6296
 
6260
- async getSlotLeader(commitment) {
6261
- const args = this._buildArgs([], commitment);
6297
+ async getSlotLeader(commitmentOrConfig) {
6298
+ const {
6299
+ commitment,
6300
+ config
6301
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6302
+
6303
+ const args = this._buildArgs([], commitment, undefined
6304
+ /* encoding */
6305
+ , config);
6262
6306
 
6263
6307
  const unsafeRes = await this._rpcRequest('getSlotLeader', args);
6264
6308
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.string()));
@@ -6331,8 +6375,15 @@ class Connection {
6331
6375
  */
6332
6376
 
6333
6377
 
6334
- async getTransactionCount(commitment) {
6335
- const args = this._buildArgs([], commitment);
6378
+ async getTransactionCount(commitmentOrConfig) {
6379
+ const {
6380
+ commitment,
6381
+ config
6382
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6383
+
6384
+ const args = this._buildArgs([], commitment, undefined
6385
+ /* encoding */
6386
+ , config);
6336
6387
 
6337
6388
  const unsafeRes = await this._rpcRequest('getTransactionCount', args);
6338
6389
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
@@ -6379,9 +6430,16 @@ class Connection {
6379
6430
  */
6380
6431
 
6381
6432
 
6382
- async getInflationReward(addresses, epoch, commitment) {
6383
- const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined, {
6384
- epoch
6433
+ async getInflationReward(addresses, epoch, commitmentOrConfig) {
6434
+ const {
6435
+ commitment,
6436
+ config
6437
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6438
+
6439
+ const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined
6440
+ /* encoding */
6441
+ , { ...config,
6442
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
6385
6443
  });
6386
6444
 
6387
6445
  const unsafeRes = await this._rpcRequest('getInflationReward', args);
@@ -6398,8 +6456,15 @@ class Connection {
6398
6456
  */
6399
6457
 
6400
6458
 
6401
- async getEpochInfo(commitment) {
6402
- const args = this._buildArgs([], commitment);
6459
+ async getEpochInfo(commitmentOrConfig) {
6460
+ const {
6461
+ commitment,
6462
+ config
6463
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6464
+
6465
+ const args = this._buildArgs([], commitment, undefined
6466
+ /* encoding */
6467
+ , config);
6403
6468
 
6404
6469
  const unsafeRes = await this._rpcRequest('getEpochInfo', args);
6405
6470
  const res = superstruct.create(unsafeRes, GetEpochInfoRpcResult);
@@ -6570,9 +6635,9 @@ class Connection {
6570
6635
  */
6571
6636
 
6572
6637
 
6573
- async getLatestBlockhash(commitment) {
6638
+ async getLatestBlockhash(commitmentOrConfig) {
6574
6639
  try {
6575
- const res = await this.getLatestBlockhashAndContext(commitment);
6640
+ const res = await this.getLatestBlockhashAndContext(commitmentOrConfig);
6576
6641
  return res.value;
6577
6642
  } catch (e) {
6578
6643
  throw new Error('failed to get recent blockhash: ' + e);
@@ -6584,8 +6649,15 @@ class Connection {
6584
6649
  */
6585
6650
 
6586
6651
 
6587
- async getLatestBlockhashAndContext(commitment) {
6588
- const args = this._buildArgs([], commitment);
6652
+ async getLatestBlockhashAndContext(commitmentOrConfig) {
6653
+ const {
6654
+ commitment,
6655
+ config
6656
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6657
+
6658
+ const args = this._buildArgs([], commitment, undefined
6659
+ /* encoding */
6660
+ , config);
6589
6661
 
6590
6662
  const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
6591
6663
  const res = superstruct.create(unsafeRes, GetLatestBlockhashRpcResult);
@@ -6663,8 +6735,15 @@ class Connection {
6663
6735
  */
6664
6736
 
6665
6737
 
6666
- async getBlockHeight(commitment) {
6667
- const args = this._buildArgs([], commitment);
6738
+ async getBlockHeight(commitmentOrConfig) {
6739
+ const {
6740
+ commitment,
6741
+ config
6742
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6743
+
6744
+ const args = this._buildArgs([], commitment, undefined
6745
+ /* encoding */
6746
+ , config);
6668
6747
 
6669
6748
  const unsafeRes = await this._rpcRequest('getBlockHeight', args);
6670
6749
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
@@ -7393,6 +7472,10 @@ class Connection {
7393
7472
  config.maxRetries = options.maxRetries;
7394
7473
  }
7395
7474
 
7475
+ if (options && options.minContextSlot != null) {
7476
+ config.minContextSlot = options.minContextSlot;
7477
+ }
7478
+
7396
7479
  if (skipPreflight) {
7397
7480
  config.skipPreflight = skipPreflight;
7398
7481
  }
@@ -9800,7 +9883,8 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
9800
9883
 
9801
9884
  const sendOptions = options && {
9802
9885
  skipPreflight: options.skipPreflight,
9803
- preflightCommitment: options.preflightCommitment || options.commitment
9886
+ preflightCommitment: options.preflightCommitment || options.commitment,
9887
+ minContextSlot: options.minContextSlot
9804
9888
  };
9805
9889
  const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
9806
9890
  const commitment = options && options.commitment;