@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.
package/lib/index.esm.js CHANGED
@@ -3126,7 +3126,8 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
3126
3126
  const sendOptions = options && {
3127
3127
  skipPreflight: options.skipPreflight,
3128
3128
  preflightCommitment: options.preflightCommitment || options.commitment,
3129
- maxRetries: options.maxRetries
3129
+ maxRetries: options.maxRetries,
3130
+ minContextSlot: options.minContextSlot
3130
3131
  };
3131
3132
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
3132
3133
  const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
@@ -4690,9 +4691,32 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
4690
4691
  * https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
4691
4692
  */
4692
4693
 
4694
+ /** @internal */
4695
+ function extractCommitmentFromConfig(commitmentOrConfig) {
4696
+ let commitment;
4697
+ let config;
4698
+
4699
+ if (typeof commitmentOrConfig === 'string') {
4700
+ commitment = commitmentOrConfig;
4701
+ } else if (commitmentOrConfig) {
4702
+ const {
4703
+ commitment: specifiedCommitment,
4704
+ ...specifiedConfig
4705
+ } = commitmentOrConfig;
4706
+ commitment = specifiedCommitment;
4707
+ config = specifiedConfig;
4708
+ }
4709
+
4710
+ return {
4711
+ commitment,
4712
+ config
4713
+ };
4714
+ }
4693
4715
  /**
4694
4716
  * @internal
4695
4717
  */
4718
+
4719
+
4696
4720
  function createRpcResult(result) {
4697
4721
  return union([type({
4698
4722
  jsonrpc: literal('2.0'),
@@ -5565,7 +5589,7 @@ const LogsNotificationResult = type({
5565
5589
 
5566
5590
  /** @internal */
5567
5591
  const COMMON_HTTP_HEADERS = {
5568
- 'solana-client': `js/${(_process$env$npm_pack = "1.45.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5592
+ 'solana-client': `js/${(_process$env$npm_pack = "1.46.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5569
5593
  };
5570
5594
  /**
5571
5595
  * A connection to a fullnode JSON RPC endpoint
@@ -5735,8 +5759,16 @@ class Connection {
5735
5759
  */
5736
5760
 
5737
5761
 
5738
- async getBalanceAndContext(publicKey, commitment) {
5739
- const args = this._buildArgs([publicKey.toBase58()], commitment);
5762
+ async getBalanceAndContext(publicKey, commitmentOrConfig) {
5763
+ /** @internal */
5764
+ const {
5765
+ commitment,
5766
+ config
5767
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5768
+
5769
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
5770
+ /* encoding */
5771
+ , config);
5740
5772
 
5741
5773
  const unsafeRes = await this._rpcRequest('getBalance', args);
5742
5774
  const res = create(unsafeRes, jsonRpcResultAndContext(number()));
@@ -5752,8 +5784,8 @@ class Connection {
5752
5784
  */
5753
5785
 
5754
5786
 
5755
- async getBalance(publicKey, commitment) {
5756
- return await this.getBalanceAndContext(publicKey, commitment).then(x => x.value).catch(e => {
5787
+ async getBalance(publicKey, commitmentOrConfig) {
5788
+ return await this.getBalanceAndContext(publicKey, commitmentOrConfig).then(x => x.value).catch(e => {
5757
5789
  throw new Error('failed to get balance of account ' + publicKey.toBase58() + ': ' + e);
5758
5790
  });
5759
5791
  }
@@ -5875,7 +5907,11 @@ class Connection {
5875
5907
  */
5876
5908
 
5877
5909
 
5878
- async getTokenAccountsByOwner(ownerAddress, filter, commitment) {
5910
+ async getTokenAccountsByOwner(ownerAddress, filter, commitmentOrConfig) {
5911
+ const {
5912
+ commitment,
5913
+ config
5914
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5879
5915
  let _args = [ownerAddress.toBase58()];
5880
5916
 
5881
5917
  if ('mint' in filter) {
@@ -5888,7 +5924,7 @@ class Connection {
5888
5924
  });
5889
5925
  }
5890
5926
 
5891
- const args = this._buildArgs(_args, commitment, 'base64');
5927
+ const args = this._buildArgs(_args, commitment, 'base64', config);
5892
5928
 
5893
5929
  const unsafeRes = await this._rpcRequest('getTokenAccountsByOwner', args);
5894
5930
  const res = create(unsafeRes, GetTokenAccountsByOwner);
@@ -5972,8 +6008,13 @@ class Connection {
5972
6008
  */
5973
6009
 
5974
6010
 
5975
- async getAccountInfoAndContext(publicKey, commitment) {
5976
- const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64');
6011
+ async getAccountInfoAndContext(publicKey, commitmentOrConfig) {
6012
+ const {
6013
+ commitment,
6014
+ config
6015
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6016
+
6017
+ const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64', config);
5977
6018
 
5978
6019
  const unsafeRes = await this._rpcRequest('getAccountInfo', args);
5979
6020
  const res = create(unsafeRes, jsonRpcResultAndContext(nullable(AccountInfoResult)));
@@ -6006,9 +6047,9 @@ class Connection {
6006
6047
  */
6007
6048
 
6008
6049
 
6009
- async getAccountInfo(publicKey, commitment) {
6050
+ async getAccountInfo(publicKey, commitmentOrConfig) {
6010
6051
  try {
6011
- const res = await this.getAccountInfoAndContext(publicKey, commitment);
6052
+ const res = await this.getAccountInfoAndContext(publicKey, commitmentOrConfig);
6012
6053
  return res.value;
6013
6054
  } catch (e) {
6014
6055
  throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + e);
@@ -6019,10 +6060,14 @@ class Connection {
6019
6060
  */
6020
6061
 
6021
6062
 
6022
- async getMultipleAccountsInfoAndContext(publicKeys, commitment) {
6063
+ async getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig) {
6064
+ const {
6065
+ commitment,
6066
+ config
6067
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6023
6068
  const keys = publicKeys.map(key => key.toBase58());
6024
6069
 
6025
- const args = this._buildArgs([keys], commitment, 'base64');
6070
+ const args = this._buildArgs([keys], commitment, 'base64', config);
6026
6071
 
6027
6072
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
6028
6073
  const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(AccountInfoResult))));
@@ -6038,8 +6083,8 @@ class Connection {
6038
6083
  */
6039
6084
 
6040
6085
 
6041
- async getMultipleAccountsInfo(publicKeys, commitment) {
6042
- const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitment);
6086
+ async getMultipleAccountsInfo(publicKeys, commitmentOrConfig) {
6087
+ const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig);
6043
6088
  return res.value;
6044
6089
  }
6045
6090
  /**
@@ -6047,10 +6092,17 @@ class Connection {
6047
6092
  */
6048
6093
 
6049
6094
 
6050
- async getStakeActivation(publicKey, commitment, epoch) {
6051
- const args = this._buildArgs([publicKey.toBase58()], commitment, undefined, epoch !== undefined ? {
6052
- epoch
6053
- } : undefined);
6095
+ async getStakeActivation(publicKey, commitmentOrConfig, epoch) {
6096
+ const {
6097
+ commitment,
6098
+ config
6099
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6100
+
6101
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
6102
+ /* encoding */
6103
+ , { ...config,
6104
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
6105
+ });
6054
6106
 
6055
6107
  const unsafeRes = await this._rpcRequest('getStakeActivation', args);
6056
6108
  const res = create(unsafeRes, jsonRpcResult(StakeActivationResult));
@@ -6069,28 +6121,16 @@ class Connection {
6069
6121
 
6070
6122
 
6071
6123
  async getProgramAccounts(programId, configOrCommitment) {
6072
- const extra = {};
6073
- let commitment;
6074
- let encoding;
6075
-
6076
- if (configOrCommitment) {
6077
- if (typeof configOrCommitment === 'string') {
6078
- commitment = configOrCommitment;
6079
- } else {
6080
- commitment = configOrCommitment.commitment;
6081
- encoding = configOrCommitment.encoding;
6082
-
6083
- if (configOrCommitment.dataSlice) {
6084
- extra.dataSlice = configOrCommitment.dataSlice;
6085
- }
6086
-
6087
- if (configOrCommitment.filters) {
6088
- extra.filters = configOrCommitment.filters;
6089
- }
6090
- }
6091
- }
6124
+ const {
6125
+ commitment,
6126
+ config
6127
+ } = extractCommitmentFromConfig(configOrCommitment);
6128
+ const {
6129
+ encoding,
6130
+ ...configWithoutEncoding
6131
+ } = config || {};
6092
6132
 
6093
- const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', extra);
6133
+ const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', configWithoutEncoding);
6094
6134
 
6095
6135
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
6096
6136
  const res = create(unsafeRes, jsonRpcResult(array(KeyedAccountInfoResult)));
@@ -6109,22 +6149,12 @@ class Connection {
6109
6149
 
6110
6150
 
6111
6151
  async getParsedProgramAccounts(programId, configOrCommitment) {
6112
- const extra = {};
6113
- let commitment;
6114
-
6115
- if (configOrCommitment) {
6116
- if (typeof configOrCommitment === 'string') {
6117
- commitment = configOrCommitment;
6118
- } else {
6119
- commitment = configOrCommitment.commitment;
6120
-
6121
- if (configOrCommitment.filters) {
6122
- extra.filters = configOrCommitment.filters;
6123
- }
6124
- }
6125
- }
6152
+ const {
6153
+ commitment,
6154
+ config
6155
+ } = extractCommitmentFromConfig(configOrCommitment);
6126
6156
 
6127
- const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', extra);
6157
+ const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', config);
6128
6158
 
6129
6159
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
6130
6160
  const res = create(unsafeRes, jsonRpcResult(array(KeyedParsedAccountInfoResult)));
@@ -6291,8 +6321,15 @@ class Connection {
6291
6321
  */
6292
6322
 
6293
6323
 
6294
- async getSlot(commitment) {
6295
- const args = this._buildArgs([], commitment);
6324
+ async getSlot(commitmentOrConfig) {
6325
+ const {
6326
+ commitment,
6327
+ config
6328
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6329
+
6330
+ const args = this._buildArgs([], commitment, undefined
6331
+ /* encoding */
6332
+ , config);
6296
6333
 
6297
6334
  const unsafeRes = await this._rpcRequest('getSlot', args);
6298
6335
  const res = create(unsafeRes, jsonRpcResult(number()));
@@ -6308,8 +6345,15 @@ class Connection {
6308
6345
  */
6309
6346
 
6310
6347
 
6311
- async getSlotLeader(commitment) {
6312
- const args = this._buildArgs([], commitment);
6348
+ async getSlotLeader(commitmentOrConfig) {
6349
+ const {
6350
+ commitment,
6351
+ config
6352
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6353
+
6354
+ const args = this._buildArgs([], commitment, undefined
6355
+ /* encoding */
6356
+ , config);
6313
6357
 
6314
6358
  const unsafeRes = await this._rpcRequest('getSlotLeader', args);
6315
6359
  const res = create(unsafeRes, jsonRpcResult(string()));
@@ -6382,8 +6426,15 @@ class Connection {
6382
6426
  */
6383
6427
 
6384
6428
 
6385
- async getTransactionCount(commitment) {
6386
- const args = this._buildArgs([], commitment);
6429
+ async getTransactionCount(commitmentOrConfig) {
6430
+ const {
6431
+ commitment,
6432
+ config
6433
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6434
+
6435
+ const args = this._buildArgs([], commitment, undefined
6436
+ /* encoding */
6437
+ , config);
6387
6438
 
6388
6439
  const unsafeRes = await this._rpcRequest('getTransactionCount', args);
6389
6440
  const res = create(unsafeRes, jsonRpcResult(number()));
@@ -6430,9 +6481,16 @@ class Connection {
6430
6481
  */
6431
6482
 
6432
6483
 
6433
- async getInflationReward(addresses, epoch, commitment) {
6434
- const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined, {
6435
- epoch
6484
+ async getInflationReward(addresses, epoch, commitmentOrConfig) {
6485
+ const {
6486
+ commitment,
6487
+ config
6488
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6489
+
6490
+ const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined
6491
+ /* encoding */
6492
+ , { ...config,
6493
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
6436
6494
  });
6437
6495
 
6438
6496
  const unsafeRes = await this._rpcRequest('getInflationReward', args);
@@ -6449,8 +6507,15 @@ class Connection {
6449
6507
  */
6450
6508
 
6451
6509
 
6452
- async getEpochInfo(commitment) {
6453
- const args = this._buildArgs([], commitment);
6510
+ async getEpochInfo(commitmentOrConfig) {
6511
+ const {
6512
+ commitment,
6513
+ config
6514
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6515
+
6516
+ const args = this._buildArgs([], commitment, undefined
6517
+ /* encoding */
6518
+ , config);
6454
6519
 
6455
6520
  const unsafeRes = await this._rpcRequest('getEpochInfo', args);
6456
6521
  const res = create(unsafeRes, GetEpochInfoRpcResult);
@@ -6621,9 +6686,9 @@ class Connection {
6621
6686
  */
6622
6687
 
6623
6688
 
6624
- async getLatestBlockhash(commitment) {
6689
+ async getLatestBlockhash(commitmentOrConfig) {
6625
6690
  try {
6626
- const res = await this.getLatestBlockhashAndContext(commitment);
6691
+ const res = await this.getLatestBlockhashAndContext(commitmentOrConfig);
6627
6692
  return res.value;
6628
6693
  } catch (e) {
6629
6694
  throw new Error('failed to get recent blockhash: ' + e);
@@ -6635,8 +6700,15 @@ class Connection {
6635
6700
  */
6636
6701
 
6637
6702
 
6638
- async getLatestBlockhashAndContext(commitment) {
6639
- const args = this._buildArgs([], commitment);
6703
+ async getLatestBlockhashAndContext(commitmentOrConfig) {
6704
+ const {
6705
+ commitment,
6706
+ config
6707
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6708
+
6709
+ const args = this._buildArgs([], commitment, undefined
6710
+ /* encoding */
6711
+ , config);
6640
6712
 
6641
6713
  const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
6642
6714
  const res = create(unsafeRes, GetLatestBlockhashRpcResult);
@@ -6714,8 +6786,15 @@ class Connection {
6714
6786
  */
6715
6787
 
6716
6788
 
6717
- async getBlockHeight(commitment) {
6718
- const args = this._buildArgs([], commitment);
6789
+ async getBlockHeight(commitmentOrConfig) {
6790
+ const {
6791
+ commitment,
6792
+ config
6793
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6794
+
6795
+ const args = this._buildArgs([], commitment, undefined
6796
+ /* encoding */
6797
+ , config);
6719
6798
 
6720
6799
  const unsafeRes = await this._rpcRequest('getBlockHeight', args);
6721
6800
  const res = create(unsafeRes, jsonRpcResult(number()));
@@ -7444,6 +7523,10 @@ class Connection {
7444
7523
  config.maxRetries = options.maxRetries;
7445
7524
  }
7446
7525
 
7526
+ if (options && options.minContextSlot != null) {
7527
+ config.minContextSlot = options.minContextSlot;
7528
+ }
7529
+
7447
7530
  if (skipPreflight) {
7448
7531
  config.skipPreflight = skipPreflight;
7449
7532
  }
@@ -9851,7 +9934,8 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
9851
9934
 
9852
9935
  const sendOptions = options && {
9853
9936
  skipPreflight: options.skipPreflight,
9854
- preflightCommitment: options.preflightCommitment || options.commitment
9937
+ preflightCommitment: options.preflightCommitment || options.commitment,
9938
+ minContextSlot: options.minContextSlot
9855
9939
  };
9856
9940
  const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
9857
9941
  const commitment = options && options.commitment;