@solana/web3.js 1.45.0 → 1.46.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.
@@ -3073,7 +3073,8 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
3073
3073
  const sendOptions = options && {
3074
3074
  skipPreflight: options.skipPreflight,
3075
3075
  preflightCommitment: options.preflightCommitment || options.commitment,
3076
- maxRetries: options.maxRetries
3076
+ maxRetries: options.maxRetries,
3077
+ minContextSlot: options.minContextSlot
3077
3078
  };
3078
3079
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
3079
3080
  const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
@@ -4585,9 +4586,32 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
4585
4586
  * https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
4586
4587
  */
4587
4588
 
4589
+ /** @internal */
4590
+ function extractCommitmentFromConfig(commitmentOrConfig) {
4591
+ let commitment;
4592
+ let config;
4593
+
4594
+ if (typeof commitmentOrConfig === 'string') {
4595
+ commitment = commitmentOrConfig;
4596
+ } else if (commitmentOrConfig) {
4597
+ const {
4598
+ commitment: specifiedCommitment,
4599
+ ...specifiedConfig
4600
+ } = commitmentOrConfig;
4601
+ commitment = specifiedCommitment;
4602
+ config = specifiedConfig;
4603
+ }
4604
+
4605
+ return {
4606
+ commitment,
4607
+ config
4608
+ };
4609
+ }
4588
4610
  /**
4589
4611
  * @internal
4590
4612
  */
4613
+
4614
+
4591
4615
  function createRpcResult(result) {
4592
4616
  return union([type({
4593
4617
  jsonrpc: literal('2.0'),
@@ -5624,8 +5648,16 @@ class Connection {
5624
5648
  */
5625
5649
 
5626
5650
 
5627
- async getBalanceAndContext(publicKey, commitment) {
5628
- const args = this._buildArgs([publicKey.toBase58()], commitment);
5651
+ async getBalanceAndContext(publicKey, commitmentOrConfig) {
5652
+ /** @internal */
5653
+ const {
5654
+ commitment,
5655
+ config
5656
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5657
+
5658
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
5659
+ /* encoding */
5660
+ , config);
5629
5661
 
5630
5662
  const unsafeRes = await this._rpcRequest('getBalance', args);
5631
5663
  const res = create(unsafeRes, jsonRpcResultAndContext(number()));
@@ -5641,8 +5673,8 @@ class Connection {
5641
5673
  */
5642
5674
 
5643
5675
 
5644
- async getBalance(publicKey, commitment) {
5645
- return await this.getBalanceAndContext(publicKey, commitment).then(x => x.value).catch(e => {
5676
+ async getBalance(publicKey, commitmentOrConfig) {
5677
+ return await this.getBalanceAndContext(publicKey, commitmentOrConfig).then(x => x.value).catch(e => {
5646
5678
  throw new Error('failed to get balance of account ' + publicKey.toBase58() + ': ' + e);
5647
5679
  });
5648
5680
  }
@@ -5764,7 +5796,11 @@ class Connection {
5764
5796
  */
5765
5797
 
5766
5798
 
5767
- async getTokenAccountsByOwner(ownerAddress, filter, commitment) {
5799
+ async getTokenAccountsByOwner(ownerAddress, filter, commitmentOrConfig) {
5800
+ const {
5801
+ commitment,
5802
+ config
5803
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5768
5804
  let _args = [ownerAddress.toBase58()];
5769
5805
 
5770
5806
  if ('mint' in filter) {
@@ -5777,7 +5813,7 @@ class Connection {
5777
5813
  });
5778
5814
  }
5779
5815
 
5780
- const args = this._buildArgs(_args, commitment, 'base64');
5816
+ const args = this._buildArgs(_args, commitment, 'base64', config);
5781
5817
 
5782
5818
  const unsafeRes = await this._rpcRequest('getTokenAccountsByOwner', args);
5783
5819
  const res = create(unsafeRes, GetTokenAccountsByOwner);
@@ -5861,8 +5897,13 @@ class Connection {
5861
5897
  */
5862
5898
 
5863
5899
 
5864
- async getAccountInfoAndContext(publicKey, commitment) {
5865
- const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64');
5900
+ async getAccountInfoAndContext(publicKey, commitmentOrConfig) {
5901
+ const {
5902
+ commitment,
5903
+ config
5904
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5905
+
5906
+ const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64', config);
5866
5907
 
5867
5908
  const unsafeRes = await this._rpcRequest('getAccountInfo', args);
5868
5909
  const res = create(unsafeRes, jsonRpcResultAndContext(nullable(AccountInfoResult)));
@@ -5895,9 +5936,9 @@ class Connection {
5895
5936
  */
5896
5937
 
5897
5938
 
5898
- async getAccountInfo(publicKey, commitment) {
5939
+ async getAccountInfo(publicKey, commitmentOrConfig) {
5899
5940
  try {
5900
- const res = await this.getAccountInfoAndContext(publicKey, commitment);
5941
+ const res = await this.getAccountInfoAndContext(publicKey, commitmentOrConfig);
5901
5942
  return res.value;
5902
5943
  } catch (e) {
5903
5944
  throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + e);
@@ -5908,10 +5949,14 @@ class Connection {
5908
5949
  */
5909
5950
 
5910
5951
 
5911
- async getMultipleAccountsInfoAndContext(publicKeys, commitment) {
5952
+ async getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig) {
5953
+ const {
5954
+ commitment,
5955
+ config
5956
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5912
5957
  const keys = publicKeys.map(key => key.toBase58());
5913
5958
 
5914
- const args = this._buildArgs([keys], commitment, 'base64');
5959
+ const args = this._buildArgs([keys], commitment, 'base64', config);
5915
5960
 
5916
5961
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
5917
5962
  const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(AccountInfoResult))));
@@ -5927,8 +5972,8 @@ class Connection {
5927
5972
  */
5928
5973
 
5929
5974
 
5930
- async getMultipleAccountsInfo(publicKeys, commitment) {
5931
- const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitment);
5975
+ async getMultipleAccountsInfo(publicKeys, commitmentOrConfig) {
5976
+ const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig);
5932
5977
  return res.value;
5933
5978
  }
5934
5979
  /**
@@ -5936,10 +5981,17 @@ class Connection {
5936
5981
  */
5937
5982
 
5938
5983
 
5939
- async getStakeActivation(publicKey, commitment, epoch) {
5940
- const args = this._buildArgs([publicKey.toBase58()], commitment, undefined, epoch !== undefined ? {
5941
- epoch
5942
- } : undefined);
5984
+ async getStakeActivation(publicKey, commitmentOrConfig, epoch) {
5985
+ const {
5986
+ commitment,
5987
+ config
5988
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5989
+
5990
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
5991
+ /* encoding */
5992
+ , { ...config,
5993
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
5994
+ });
5943
5995
 
5944
5996
  const unsafeRes = await this._rpcRequest('getStakeActivation', args);
5945
5997
  const res = create(unsafeRes, jsonRpcResult(StakeActivationResult));
@@ -5958,28 +6010,16 @@ class Connection {
5958
6010
 
5959
6011
 
5960
6012
  async getProgramAccounts(programId, configOrCommitment) {
5961
- const extra = {};
5962
- let commitment;
5963
- let encoding;
5964
-
5965
- if (configOrCommitment) {
5966
- if (typeof configOrCommitment === 'string') {
5967
- commitment = configOrCommitment;
5968
- } else {
5969
- commitment = configOrCommitment.commitment;
5970
- encoding = configOrCommitment.encoding;
5971
-
5972
- if (configOrCommitment.dataSlice) {
5973
- extra.dataSlice = configOrCommitment.dataSlice;
5974
- }
5975
-
5976
- if (configOrCommitment.filters) {
5977
- extra.filters = configOrCommitment.filters;
5978
- }
5979
- }
5980
- }
6013
+ const {
6014
+ commitment,
6015
+ config
6016
+ } = extractCommitmentFromConfig(configOrCommitment);
6017
+ const {
6018
+ encoding,
6019
+ ...configWithoutEncoding
6020
+ } = config || {};
5981
6021
 
5982
- const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', extra);
6022
+ const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', configWithoutEncoding);
5983
6023
 
5984
6024
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
5985
6025
  const res = create(unsafeRes, jsonRpcResult(array(KeyedAccountInfoResult)));
@@ -5998,22 +6038,12 @@ class Connection {
5998
6038
 
5999
6039
 
6000
6040
  async getParsedProgramAccounts(programId, configOrCommitment) {
6001
- const extra = {};
6002
- let commitment;
6003
-
6004
- if (configOrCommitment) {
6005
- if (typeof configOrCommitment === 'string') {
6006
- commitment = configOrCommitment;
6007
- } else {
6008
- commitment = configOrCommitment.commitment;
6009
-
6010
- if (configOrCommitment.filters) {
6011
- extra.filters = configOrCommitment.filters;
6012
- }
6013
- }
6014
- }
6041
+ const {
6042
+ commitment,
6043
+ config
6044
+ } = extractCommitmentFromConfig(configOrCommitment);
6015
6045
 
6016
- const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', extra);
6046
+ const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', config);
6017
6047
 
6018
6048
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
6019
6049
  const res = create(unsafeRes, jsonRpcResult(array(KeyedParsedAccountInfoResult)));
@@ -6180,8 +6210,15 @@ class Connection {
6180
6210
  */
6181
6211
 
6182
6212
 
6183
- async getSlot(commitment) {
6184
- const args = this._buildArgs([], commitment);
6213
+ async getSlot(commitmentOrConfig) {
6214
+ const {
6215
+ commitment,
6216
+ config
6217
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6218
+
6219
+ const args = this._buildArgs([], commitment, undefined
6220
+ /* encoding */
6221
+ , config);
6185
6222
 
6186
6223
  const unsafeRes = await this._rpcRequest('getSlot', args);
6187
6224
  const res = create(unsafeRes, jsonRpcResult(number()));
@@ -6197,8 +6234,15 @@ class Connection {
6197
6234
  */
6198
6235
 
6199
6236
 
6200
- async getSlotLeader(commitment) {
6201
- const args = this._buildArgs([], commitment);
6237
+ async getSlotLeader(commitmentOrConfig) {
6238
+ const {
6239
+ commitment,
6240
+ config
6241
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6242
+
6243
+ const args = this._buildArgs([], commitment, undefined
6244
+ /* encoding */
6245
+ , config);
6202
6246
 
6203
6247
  const unsafeRes = await this._rpcRequest('getSlotLeader', args);
6204
6248
  const res = create(unsafeRes, jsonRpcResult(string()));
@@ -6271,8 +6315,15 @@ class Connection {
6271
6315
  */
6272
6316
 
6273
6317
 
6274
- async getTransactionCount(commitment) {
6275
- const args = this._buildArgs([], commitment);
6318
+ async getTransactionCount(commitmentOrConfig) {
6319
+ const {
6320
+ commitment,
6321
+ config
6322
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6323
+
6324
+ const args = this._buildArgs([], commitment, undefined
6325
+ /* encoding */
6326
+ , config);
6276
6327
 
6277
6328
  const unsafeRes = await this._rpcRequest('getTransactionCount', args);
6278
6329
  const res = create(unsafeRes, jsonRpcResult(number()));
@@ -6319,9 +6370,16 @@ class Connection {
6319
6370
  */
6320
6371
 
6321
6372
 
6322
- async getInflationReward(addresses, epoch, commitment) {
6323
- const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined, {
6324
- epoch
6373
+ async getInflationReward(addresses, epoch, commitmentOrConfig) {
6374
+ const {
6375
+ commitment,
6376
+ config
6377
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6378
+
6379
+ const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined
6380
+ /* encoding */
6381
+ , { ...config,
6382
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
6325
6383
  });
6326
6384
 
6327
6385
  const unsafeRes = await this._rpcRequest('getInflationReward', args);
@@ -6338,8 +6396,15 @@ class Connection {
6338
6396
  */
6339
6397
 
6340
6398
 
6341
- async getEpochInfo(commitment) {
6342
- const args = this._buildArgs([], commitment);
6399
+ async getEpochInfo(commitmentOrConfig) {
6400
+ const {
6401
+ commitment,
6402
+ config
6403
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6404
+
6405
+ const args = this._buildArgs([], commitment, undefined
6406
+ /* encoding */
6407
+ , config);
6343
6408
 
6344
6409
  const unsafeRes = await this._rpcRequest('getEpochInfo', args);
6345
6410
  const res = create(unsafeRes, GetEpochInfoRpcResult);
@@ -6510,9 +6575,9 @@ class Connection {
6510
6575
  */
6511
6576
 
6512
6577
 
6513
- async getLatestBlockhash(commitment) {
6578
+ async getLatestBlockhash(commitmentOrConfig) {
6514
6579
  try {
6515
- const res = await this.getLatestBlockhashAndContext(commitment);
6580
+ const res = await this.getLatestBlockhashAndContext(commitmentOrConfig);
6516
6581
  return res.value;
6517
6582
  } catch (e) {
6518
6583
  throw new Error('failed to get recent blockhash: ' + e);
@@ -6524,8 +6589,15 @@ class Connection {
6524
6589
  */
6525
6590
 
6526
6591
 
6527
- async getLatestBlockhashAndContext(commitment) {
6528
- const args = this._buildArgs([], commitment);
6592
+ async getLatestBlockhashAndContext(commitmentOrConfig) {
6593
+ const {
6594
+ commitment,
6595
+ config
6596
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6597
+
6598
+ const args = this._buildArgs([], commitment, undefined
6599
+ /* encoding */
6600
+ , config);
6529
6601
 
6530
6602
  const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
6531
6603
  const res = create(unsafeRes, GetLatestBlockhashRpcResult);
@@ -6603,8 +6675,15 @@ class Connection {
6603
6675
  */
6604
6676
 
6605
6677
 
6606
- async getBlockHeight(commitment) {
6607
- const args = this._buildArgs([], commitment);
6678
+ async getBlockHeight(commitmentOrConfig) {
6679
+ const {
6680
+ commitment,
6681
+ config
6682
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6683
+
6684
+ const args = this._buildArgs([], commitment, undefined
6685
+ /* encoding */
6686
+ , config);
6608
6687
 
6609
6688
  const unsafeRes = await this._rpcRequest('getBlockHeight', args);
6610
6689
  const res = create(unsafeRes, jsonRpcResult(number()));
@@ -7333,6 +7412,10 @@ class Connection {
7333
7412
  config.maxRetries = options.maxRetries;
7334
7413
  }
7335
7414
 
7415
+ if (options && options.minContextSlot != null) {
7416
+ config.minContextSlot = options.minContextSlot;
7417
+ }
7418
+
7336
7419
  if (skipPreflight) {
7337
7420
  config.skipPreflight = skipPreflight;
7338
7421
  }
@@ -9742,7 +9825,8 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
9742
9825
 
9743
9826
  const sendOptions = options && {
9744
9827
  skipPreflight: options.skipPreflight,
9745
- preflightCommitment: options.preflightCommitment || options.commitment
9828
+ preflightCommitment: options.preflightCommitment || options.commitment,
9829
+ minContextSlot: options.minContextSlot
9746
9830
  };
9747
9831
  const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
9748
9832
  const commitment = options && options.commitment;