@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.
@@ -3102,7 +3102,8 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
3102
3102
  const sendOptions = options && {
3103
3103
  skipPreflight: options.skipPreflight,
3104
3104
  preflightCommitment: options.preflightCommitment || options.commitment,
3105
- maxRetries: options.maxRetries
3105
+ maxRetries: options.maxRetries,
3106
+ minContextSlot: options.minContextSlot
3106
3107
  };
3107
3108
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
3108
3109
  const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
@@ -4614,9 +4615,32 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
4614
4615
  * https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
4615
4616
  */
4616
4617
 
4618
+ /** @internal */
4619
+ function extractCommitmentFromConfig(commitmentOrConfig) {
4620
+ let commitment;
4621
+ let config;
4622
+
4623
+ if (typeof commitmentOrConfig === 'string') {
4624
+ commitment = commitmentOrConfig;
4625
+ } else if (commitmentOrConfig) {
4626
+ const {
4627
+ commitment: specifiedCommitment,
4628
+ ...specifiedConfig
4629
+ } = commitmentOrConfig;
4630
+ commitment = specifiedCommitment;
4631
+ config = specifiedConfig;
4632
+ }
4633
+
4634
+ return {
4635
+ commitment,
4636
+ config
4637
+ };
4638
+ }
4617
4639
  /**
4618
4640
  * @internal
4619
4641
  */
4642
+
4643
+
4620
4644
  function createRpcResult(result) {
4621
4645
  return union([type({
4622
4646
  jsonrpc: literal('2.0'),
@@ -5483,7 +5507,7 @@ const LogsNotificationResult = type({
5483
5507
 
5484
5508
  /** @internal */
5485
5509
  const COMMON_HTTP_HEADERS = {
5486
- 'solana-client': `js/${(_process$env$npm_pack = "1.45.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5510
+ 'solana-client': `js/${(_process$env$npm_pack = "1.46.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5487
5511
  };
5488
5512
  /**
5489
5513
  * A connection to a fullnode JSON RPC endpoint
@@ -5653,8 +5677,16 @@ class Connection {
5653
5677
  */
5654
5678
 
5655
5679
 
5656
- async getBalanceAndContext(publicKey, commitment) {
5657
- const args = this._buildArgs([publicKey.toBase58()], commitment);
5680
+ async getBalanceAndContext(publicKey, commitmentOrConfig) {
5681
+ /** @internal */
5682
+ const {
5683
+ commitment,
5684
+ config
5685
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5686
+
5687
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
5688
+ /* encoding */
5689
+ , config);
5658
5690
 
5659
5691
  const unsafeRes = await this._rpcRequest('getBalance', args);
5660
5692
  const res = create(unsafeRes, jsonRpcResultAndContext(number()));
@@ -5670,8 +5702,8 @@ class Connection {
5670
5702
  */
5671
5703
 
5672
5704
 
5673
- async getBalance(publicKey, commitment) {
5674
- return await this.getBalanceAndContext(publicKey, commitment).then(x => x.value).catch(e => {
5705
+ async getBalance(publicKey, commitmentOrConfig) {
5706
+ return await this.getBalanceAndContext(publicKey, commitmentOrConfig).then(x => x.value).catch(e => {
5675
5707
  throw new Error('failed to get balance of account ' + publicKey.toBase58() + ': ' + e);
5676
5708
  });
5677
5709
  }
@@ -5793,7 +5825,11 @@ class Connection {
5793
5825
  */
5794
5826
 
5795
5827
 
5796
- async getTokenAccountsByOwner(ownerAddress, filter, commitment) {
5828
+ async getTokenAccountsByOwner(ownerAddress, filter, commitmentOrConfig) {
5829
+ const {
5830
+ commitment,
5831
+ config
5832
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5797
5833
  let _args = [ownerAddress.toBase58()];
5798
5834
 
5799
5835
  if ('mint' in filter) {
@@ -5806,7 +5842,7 @@ class Connection {
5806
5842
  });
5807
5843
  }
5808
5844
 
5809
- const args = this._buildArgs(_args, commitment, 'base64');
5845
+ const args = this._buildArgs(_args, commitment, 'base64', config);
5810
5846
 
5811
5847
  const unsafeRes = await this._rpcRequest('getTokenAccountsByOwner', args);
5812
5848
  const res = create(unsafeRes, GetTokenAccountsByOwner);
@@ -5890,8 +5926,13 @@ class Connection {
5890
5926
  */
5891
5927
 
5892
5928
 
5893
- async getAccountInfoAndContext(publicKey, commitment) {
5894
- const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64');
5929
+ async getAccountInfoAndContext(publicKey, commitmentOrConfig) {
5930
+ const {
5931
+ commitment,
5932
+ config
5933
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5934
+
5935
+ const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64', config);
5895
5936
 
5896
5937
  const unsafeRes = await this._rpcRequest('getAccountInfo', args);
5897
5938
  const res = create(unsafeRes, jsonRpcResultAndContext(nullable(AccountInfoResult)));
@@ -5924,9 +5965,9 @@ class Connection {
5924
5965
  */
5925
5966
 
5926
5967
 
5927
- async getAccountInfo(publicKey, commitment) {
5968
+ async getAccountInfo(publicKey, commitmentOrConfig) {
5928
5969
  try {
5929
- const res = await this.getAccountInfoAndContext(publicKey, commitment);
5970
+ const res = await this.getAccountInfoAndContext(publicKey, commitmentOrConfig);
5930
5971
  return res.value;
5931
5972
  } catch (e) {
5932
5973
  throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + e);
@@ -5937,10 +5978,14 @@ class Connection {
5937
5978
  */
5938
5979
 
5939
5980
 
5940
- async getMultipleAccountsInfoAndContext(publicKeys, commitment) {
5981
+ async getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig) {
5982
+ const {
5983
+ commitment,
5984
+ config
5985
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5941
5986
  const keys = publicKeys.map(key => key.toBase58());
5942
5987
 
5943
- const args = this._buildArgs([keys], commitment, 'base64');
5988
+ const args = this._buildArgs([keys], commitment, 'base64', config);
5944
5989
 
5945
5990
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
5946
5991
  const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(AccountInfoResult))));
@@ -5956,8 +6001,8 @@ class Connection {
5956
6001
  */
5957
6002
 
5958
6003
 
5959
- async getMultipleAccountsInfo(publicKeys, commitment) {
5960
- const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitment);
6004
+ async getMultipleAccountsInfo(publicKeys, commitmentOrConfig) {
6005
+ const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig);
5961
6006
  return res.value;
5962
6007
  }
5963
6008
  /**
@@ -5965,10 +6010,17 @@ class Connection {
5965
6010
  */
5966
6011
 
5967
6012
 
5968
- async getStakeActivation(publicKey, commitment, epoch) {
5969
- const args = this._buildArgs([publicKey.toBase58()], commitment, undefined, epoch !== undefined ? {
5970
- epoch
5971
- } : undefined);
6013
+ async getStakeActivation(publicKey, commitmentOrConfig, epoch) {
6014
+ const {
6015
+ commitment,
6016
+ config
6017
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6018
+
6019
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
6020
+ /* encoding */
6021
+ , { ...config,
6022
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
6023
+ });
5972
6024
 
5973
6025
  const unsafeRes = await this._rpcRequest('getStakeActivation', args);
5974
6026
  const res = create(unsafeRes, jsonRpcResult(StakeActivationResult));
@@ -5987,28 +6039,16 @@ class Connection {
5987
6039
 
5988
6040
 
5989
6041
  async getProgramAccounts(programId, configOrCommitment) {
5990
- const extra = {};
5991
- let commitment;
5992
- let encoding;
5993
-
5994
- if (configOrCommitment) {
5995
- if (typeof configOrCommitment === 'string') {
5996
- commitment = configOrCommitment;
5997
- } else {
5998
- commitment = configOrCommitment.commitment;
5999
- encoding = configOrCommitment.encoding;
6000
-
6001
- if (configOrCommitment.dataSlice) {
6002
- extra.dataSlice = configOrCommitment.dataSlice;
6003
- }
6004
-
6005
- if (configOrCommitment.filters) {
6006
- extra.filters = configOrCommitment.filters;
6007
- }
6008
- }
6009
- }
6042
+ const {
6043
+ commitment,
6044
+ config
6045
+ } = extractCommitmentFromConfig(configOrCommitment);
6046
+ const {
6047
+ encoding,
6048
+ ...configWithoutEncoding
6049
+ } = config || {};
6010
6050
 
6011
- const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', extra);
6051
+ const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', configWithoutEncoding);
6012
6052
 
6013
6053
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
6014
6054
  const res = create(unsafeRes, jsonRpcResult(array(KeyedAccountInfoResult)));
@@ -6027,22 +6067,12 @@ class Connection {
6027
6067
 
6028
6068
 
6029
6069
  async getParsedProgramAccounts(programId, configOrCommitment) {
6030
- const extra = {};
6031
- let commitment;
6032
-
6033
- if (configOrCommitment) {
6034
- if (typeof configOrCommitment === 'string') {
6035
- commitment = configOrCommitment;
6036
- } else {
6037
- commitment = configOrCommitment.commitment;
6038
-
6039
- if (configOrCommitment.filters) {
6040
- extra.filters = configOrCommitment.filters;
6041
- }
6042
- }
6043
- }
6070
+ const {
6071
+ commitment,
6072
+ config
6073
+ } = extractCommitmentFromConfig(configOrCommitment);
6044
6074
 
6045
- const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', extra);
6075
+ const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', config);
6046
6076
 
6047
6077
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
6048
6078
  const res = create(unsafeRes, jsonRpcResult(array(KeyedParsedAccountInfoResult)));
@@ -6209,8 +6239,15 @@ class Connection {
6209
6239
  */
6210
6240
 
6211
6241
 
6212
- async getSlot(commitment) {
6213
- const args = this._buildArgs([], commitment);
6242
+ async getSlot(commitmentOrConfig) {
6243
+ const {
6244
+ commitment,
6245
+ config
6246
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6247
+
6248
+ const args = this._buildArgs([], commitment, undefined
6249
+ /* encoding */
6250
+ , config);
6214
6251
 
6215
6252
  const unsafeRes = await this._rpcRequest('getSlot', args);
6216
6253
  const res = create(unsafeRes, jsonRpcResult(number()));
@@ -6226,8 +6263,15 @@ class Connection {
6226
6263
  */
6227
6264
 
6228
6265
 
6229
- async getSlotLeader(commitment) {
6230
- const args = this._buildArgs([], commitment);
6266
+ async getSlotLeader(commitmentOrConfig) {
6267
+ const {
6268
+ commitment,
6269
+ config
6270
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6271
+
6272
+ const args = this._buildArgs([], commitment, undefined
6273
+ /* encoding */
6274
+ , config);
6231
6275
 
6232
6276
  const unsafeRes = await this._rpcRequest('getSlotLeader', args);
6233
6277
  const res = create(unsafeRes, jsonRpcResult(string()));
@@ -6300,8 +6344,15 @@ class Connection {
6300
6344
  */
6301
6345
 
6302
6346
 
6303
- async getTransactionCount(commitment) {
6304
- const args = this._buildArgs([], commitment);
6347
+ async getTransactionCount(commitmentOrConfig) {
6348
+ const {
6349
+ commitment,
6350
+ config
6351
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6352
+
6353
+ const args = this._buildArgs([], commitment, undefined
6354
+ /* encoding */
6355
+ , config);
6305
6356
 
6306
6357
  const unsafeRes = await this._rpcRequest('getTransactionCount', args);
6307
6358
  const res = create(unsafeRes, jsonRpcResult(number()));
@@ -6348,9 +6399,16 @@ class Connection {
6348
6399
  */
6349
6400
 
6350
6401
 
6351
- async getInflationReward(addresses, epoch, commitment) {
6352
- const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined, {
6353
- epoch
6402
+ async getInflationReward(addresses, epoch, commitmentOrConfig) {
6403
+ const {
6404
+ commitment,
6405
+ config
6406
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6407
+
6408
+ const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined
6409
+ /* encoding */
6410
+ , { ...config,
6411
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
6354
6412
  });
6355
6413
 
6356
6414
  const unsafeRes = await this._rpcRequest('getInflationReward', args);
@@ -6367,8 +6425,15 @@ class Connection {
6367
6425
  */
6368
6426
 
6369
6427
 
6370
- async getEpochInfo(commitment) {
6371
- const args = this._buildArgs([], commitment);
6428
+ async getEpochInfo(commitmentOrConfig) {
6429
+ const {
6430
+ commitment,
6431
+ config
6432
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6433
+
6434
+ const args = this._buildArgs([], commitment, undefined
6435
+ /* encoding */
6436
+ , config);
6372
6437
 
6373
6438
  const unsafeRes = await this._rpcRequest('getEpochInfo', args);
6374
6439
  const res = create(unsafeRes, GetEpochInfoRpcResult);
@@ -6539,9 +6604,9 @@ class Connection {
6539
6604
  */
6540
6605
 
6541
6606
 
6542
- async getLatestBlockhash(commitment) {
6607
+ async getLatestBlockhash(commitmentOrConfig) {
6543
6608
  try {
6544
- const res = await this.getLatestBlockhashAndContext(commitment);
6609
+ const res = await this.getLatestBlockhashAndContext(commitmentOrConfig);
6545
6610
  return res.value;
6546
6611
  } catch (e) {
6547
6612
  throw new Error('failed to get recent blockhash: ' + e);
@@ -6553,8 +6618,15 @@ class Connection {
6553
6618
  */
6554
6619
 
6555
6620
 
6556
- async getLatestBlockhashAndContext(commitment) {
6557
- const args = this._buildArgs([], commitment);
6621
+ async getLatestBlockhashAndContext(commitmentOrConfig) {
6622
+ const {
6623
+ commitment,
6624
+ config
6625
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6626
+
6627
+ const args = this._buildArgs([], commitment, undefined
6628
+ /* encoding */
6629
+ , config);
6558
6630
 
6559
6631
  const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
6560
6632
  const res = create(unsafeRes, GetLatestBlockhashRpcResult);
@@ -6632,8 +6704,15 @@ class Connection {
6632
6704
  */
6633
6705
 
6634
6706
 
6635
- async getBlockHeight(commitment) {
6636
- const args = this._buildArgs([], commitment);
6707
+ async getBlockHeight(commitmentOrConfig) {
6708
+ const {
6709
+ commitment,
6710
+ config
6711
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6712
+
6713
+ const args = this._buildArgs([], commitment, undefined
6714
+ /* encoding */
6715
+ , config);
6637
6716
 
6638
6717
  const unsafeRes = await this._rpcRequest('getBlockHeight', args);
6639
6718
  const res = create(unsafeRes, jsonRpcResult(number()));
@@ -7362,6 +7441,10 @@ class Connection {
7362
7441
  config.maxRetries = options.maxRetries;
7363
7442
  }
7364
7443
 
7444
+ if (options && options.minContextSlot != null) {
7445
+ config.minContextSlot = options.minContextSlot;
7446
+ }
7447
+
7365
7448
  if (skipPreflight) {
7366
7449
  config.skipPreflight = skipPreflight;
7367
7450
  }
@@ -9769,7 +9852,8 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
9769
9852
 
9770
9853
  const sendOptions = options && {
9771
9854
  skipPreflight: options.skipPreflight,
9772
- preflightCommitment: options.preflightCommitment || options.commitment
9855
+ preflightCommitment: options.preflightCommitment || options.commitment,
9856
+ minContextSlot: options.minContextSlot
9773
9857
  };
9774
9858
  const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
9775
9859
  const commitment = options && options.commitment;