@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.
@@ -3104,7 +3104,8 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
3104
3104
  const sendOptions = options && {
3105
3105
  skipPreflight: options.skipPreflight,
3106
3106
  preflightCommitment: options.preflightCommitment || options.commitment,
3107
- maxRetries: options.maxRetries
3107
+ maxRetries: options.maxRetries,
3108
+ minContextSlot: options.minContextSlot
3108
3109
  };
3109
3110
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
3110
3111
  const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
@@ -4616,9 +4617,32 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
4616
4617
  * https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
4617
4618
  */
4618
4619
 
4620
+ /** @internal */
4621
+ function extractCommitmentFromConfig(commitmentOrConfig) {
4622
+ let commitment;
4623
+ let config;
4624
+
4625
+ if (typeof commitmentOrConfig === 'string') {
4626
+ commitment = commitmentOrConfig;
4627
+ } else if (commitmentOrConfig) {
4628
+ const {
4629
+ commitment: specifiedCommitment,
4630
+ ...specifiedConfig
4631
+ } = commitmentOrConfig;
4632
+ commitment = specifiedCommitment;
4633
+ config = specifiedConfig;
4634
+ }
4635
+
4636
+ return {
4637
+ commitment,
4638
+ config
4639
+ };
4640
+ }
4619
4641
  /**
4620
4642
  * @internal
4621
4643
  */
4644
+
4645
+
4622
4646
  function createRpcResult(result) {
4623
4647
  return superstruct.union([superstruct.type({
4624
4648
  jsonrpc: superstruct.literal('2.0'),
@@ -5655,8 +5679,16 @@ class Connection {
5655
5679
  */
5656
5680
 
5657
5681
 
5658
- async getBalanceAndContext(publicKey, commitment) {
5659
- const args = this._buildArgs([publicKey.toBase58()], commitment);
5682
+ async getBalanceAndContext(publicKey, commitmentOrConfig) {
5683
+ /** @internal */
5684
+ const {
5685
+ commitment,
5686
+ config
5687
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5688
+
5689
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
5690
+ /* encoding */
5691
+ , config);
5660
5692
 
5661
5693
  const unsafeRes = await this._rpcRequest('getBalance', args);
5662
5694
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.number()));
@@ -5672,8 +5704,8 @@ class Connection {
5672
5704
  */
5673
5705
 
5674
5706
 
5675
- async getBalance(publicKey, commitment) {
5676
- return await this.getBalanceAndContext(publicKey, commitment).then(x => x.value).catch(e => {
5707
+ async getBalance(publicKey, commitmentOrConfig) {
5708
+ return await this.getBalanceAndContext(publicKey, commitmentOrConfig).then(x => x.value).catch(e => {
5677
5709
  throw new Error('failed to get balance of account ' + publicKey.toBase58() + ': ' + e);
5678
5710
  });
5679
5711
  }
@@ -5795,7 +5827,11 @@ class Connection {
5795
5827
  */
5796
5828
 
5797
5829
 
5798
- async getTokenAccountsByOwner(ownerAddress, filter, commitment) {
5830
+ async getTokenAccountsByOwner(ownerAddress, filter, commitmentOrConfig) {
5831
+ const {
5832
+ commitment,
5833
+ config
5834
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5799
5835
  let _args = [ownerAddress.toBase58()];
5800
5836
 
5801
5837
  if ('mint' in filter) {
@@ -5808,7 +5844,7 @@ class Connection {
5808
5844
  });
5809
5845
  }
5810
5846
 
5811
- const args = this._buildArgs(_args, commitment, 'base64');
5847
+ const args = this._buildArgs(_args, commitment, 'base64', config);
5812
5848
 
5813
5849
  const unsafeRes = await this._rpcRequest('getTokenAccountsByOwner', args);
5814
5850
  const res = superstruct.create(unsafeRes, GetTokenAccountsByOwner);
@@ -5892,8 +5928,13 @@ class Connection {
5892
5928
  */
5893
5929
 
5894
5930
 
5895
- async getAccountInfoAndContext(publicKey, commitment) {
5896
- const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64');
5931
+ async getAccountInfoAndContext(publicKey, commitmentOrConfig) {
5932
+ const {
5933
+ commitment,
5934
+ config
5935
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5936
+
5937
+ const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64', config);
5897
5938
 
5898
5939
  const unsafeRes = await this._rpcRequest('getAccountInfo', args);
5899
5940
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.nullable(AccountInfoResult)));
@@ -5926,9 +5967,9 @@ class Connection {
5926
5967
  */
5927
5968
 
5928
5969
 
5929
- async getAccountInfo(publicKey, commitment) {
5970
+ async getAccountInfo(publicKey, commitmentOrConfig) {
5930
5971
  try {
5931
- const res = await this.getAccountInfoAndContext(publicKey, commitment);
5972
+ const res = await this.getAccountInfoAndContext(publicKey, commitmentOrConfig);
5932
5973
  return res.value;
5933
5974
  } catch (e) {
5934
5975
  throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + e);
@@ -5939,10 +5980,14 @@ class Connection {
5939
5980
  */
5940
5981
 
5941
5982
 
5942
- async getMultipleAccountsInfoAndContext(publicKeys, commitment) {
5983
+ async getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig) {
5984
+ const {
5985
+ commitment,
5986
+ config
5987
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5943
5988
  const keys = publicKeys.map(key => key.toBase58());
5944
5989
 
5945
- const args = this._buildArgs([keys], commitment, 'base64');
5990
+ const args = this._buildArgs([keys], commitment, 'base64', config);
5946
5991
 
5947
5992
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
5948
5993
  const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.array(superstruct.nullable(AccountInfoResult))));
@@ -5958,8 +6003,8 @@ class Connection {
5958
6003
  */
5959
6004
 
5960
6005
 
5961
- async getMultipleAccountsInfo(publicKeys, commitment) {
5962
- const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitment);
6006
+ async getMultipleAccountsInfo(publicKeys, commitmentOrConfig) {
6007
+ const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig);
5963
6008
  return res.value;
5964
6009
  }
5965
6010
  /**
@@ -5967,10 +6012,17 @@ class Connection {
5967
6012
  */
5968
6013
 
5969
6014
 
5970
- async getStakeActivation(publicKey, commitment, epoch) {
5971
- const args = this._buildArgs([publicKey.toBase58()], commitment, undefined, epoch !== undefined ? {
5972
- epoch
5973
- } : undefined);
6015
+ async getStakeActivation(publicKey, commitmentOrConfig, epoch) {
6016
+ const {
6017
+ commitment,
6018
+ config
6019
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6020
+
6021
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
6022
+ /* encoding */
6023
+ , { ...config,
6024
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
6025
+ });
5974
6026
 
5975
6027
  const unsafeRes = await this._rpcRequest('getStakeActivation', args);
5976
6028
  const res = superstruct.create(unsafeRes, jsonRpcResult(StakeActivationResult));
@@ -5989,28 +6041,16 @@ class Connection {
5989
6041
 
5990
6042
 
5991
6043
  async getProgramAccounts(programId, configOrCommitment) {
5992
- const extra = {};
5993
- let commitment;
5994
- let encoding;
5995
-
5996
- if (configOrCommitment) {
5997
- if (typeof configOrCommitment === 'string') {
5998
- commitment = configOrCommitment;
5999
- } else {
6000
- commitment = configOrCommitment.commitment;
6001
- encoding = configOrCommitment.encoding;
6002
-
6003
- if (configOrCommitment.dataSlice) {
6004
- extra.dataSlice = configOrCommitment.dataSlice;
6005
- }
6006
-
6007
- if (configOrCommitment.filters) {
6008
- extra.filters = configOrCommitment.filters;
6009
- }
6010
- }
6011
- }
6044
+ const {
6045
+ commitment,
6046
+ config
6047
+ } = extractCommitmentFromConfig(configOrCommitment);
6048
+ const {
6049
+ encoding,
6050
+ ...configWithoutEncoding
6051
+ } = config || {};
6012
6052
 
6013
- const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', extra);
6053
+ const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', configWithoutEncoding);
6014
6054
 
6015
6055
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
6016
6056
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(KeyedAccountInfoResult)));
@@ -6029,22 +6069,12 @@ class Connection {
6029
6069
 
6030
6070
 
6031
6071
  async getParsedProgramAccounts(programId, configOrCommitment) {
6032
- const extra = {};
6033
- let commitment;
6034
-
6035
- if (configOrCommitment) {
6036
- if (typeof configOrCommitment === 'string') {
6037
- commitment = configOrCommitment;
6038
- } else {
6039
- commitment = configOrCommitment.commitment;
6040
-
6041
- if (configOrCommitment.filters) {
6042
- extra.filters = configOrCommitment.filters;
6043
- }
6044
- }
6045
- }
6072
+ const {
6073
+ commitment,
6074
+ config
6075
+ } = extractCommitmentFromConfig(configOrCommitment);
6046
6076
 
6047
- const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', extra);
6077
+ const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', config);
6048
6078
 
6049
6079
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
6050
6080
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(KeyedParsedAccountInfoResult)));
@@ -6211,8 +6241,15 @@ class Connection {
6211
6241
  */
6212
6242
 
6213
6243
 
6214
- async getSlot(commitment) {
6215
- const args = this._buildArgs([], commitment);
6244
+ async getSlot(commitmentOrConfig) {
6245
+ const {
6246
+ commitment,
6247
+ config
6248
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6249
+
6250
+ const args = this._buildArgs([], commitment, undefined
6251
+ /* encoding */
6252
+ , config);
6216
6253
 
6217
6254
  const unsafeRes = await this._rpcRequest('getSlot', args);
6218
6255
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
@@ -6228,8 +6265,15 @@ class Connection {
6228
6265
  */
6229
6266
 
6230
6267
 
6231
- async getSlotLeader(commitment) {
6232
- const args = this._buildArgs([], commitment);
6268
+ async getSlotLeader(commitmentOrConfig) {
6269
+ const {
6270
+ commitment,
6271
+ config
6272
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6273
+
6274
+ const args = this._buildArgs([], commitment, undefined
6275
+ /* encoding */
6276
+ , config);
6233
6277
 
6234
6278
  const unsafeRes = await this._rpcRequest('getSlotLeader', args);
6235
6279
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.string()));
@@ -6302,8 +6346,15 @@ class Connection {
6302
6346
  */
6303
6347
 
6304
6348
 
6305
- async getTransactionCount(commitment) {
6306
- const args = this._buildArgs([], commitment);
6349
+ async getTransactionCount(commitmentOrConfig) {
6350
+ const {
6351
+ commitment,
6352
+ config
6353
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6354
+
6355
+ const args = this._buildArgs([], commitment, undefined
6356
+ /* encoding */
6357
+ , config);
6307
6358
 
6308
6359
  const unsafeRes = await this._rpcRequest('getTransactionCount', args);
6309
6360
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
@@ -6350,9 +6401,16 @@ class Connection {
6350
6401
  */
6351
6402
 
6352
6403
 
6353
- async getInflationReward(addresses, epoch, commitment) {
6354
- const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined, {
6355
- epoch
6404
+ async getInflationReward(addresses, epoch, commitmentOrConfig) {
6405
+ const {
6406
+ commitment,
6407
+ config
6408
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6409
+
6410
+ const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined
6411
+ /* encoding */
6412
+ , { ...config,
6413
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
6356
6414
  });
6357
6415
 
6358
6416
  const unsafeRes = await this._rpcRequest('getInflationReward', args);
@@ -6369,8 +6427,15 @@ class Connection {
6369
6427
  */
6370
6428
 
6371
6429
 
6372
- async getEpochInfo(commitment) {
6373
- const args = this._buildArgs([], commitment);
6430
+ async getEpochInfo(commitmentOrConfig) {
6431
+ const {
6432
+ commitment,
6433
+ config
6434
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6435
+
6436
+ const args = this._buildArgs([], commitment, undefined
6437
+ /* encoding */
6438
+ , config);
6374
6439
 
6375
6440
  const unsafeRes = await this._rpcRequest('getEpochInfo', args);
6376
6441
  const res = superstruct.create(unsafeRes, GetEpochInfoRpcResult);
@@ -6541,9 +6606,9 @@ class Connection {
6541
6606
  */
6542
6607
 
6543
6608
 
6544
- async getLatestBlockhash(commitment) {
6609
+ async getLatestBlockhash(commitmentOrConfig) {
6545
6610
  try {
6546
- const res = await this.getLatestBlockhashAndContext(commitment);
6611
+ const res = await this.getLatestBlockhashAndContext(commitmentOrConfig);
6547
6612
  return res.value;
6548
6613
  } catch (e) {
6549
6614
  throw new Error('failed to get recent blockhash: ' + e);
@@ -6555,8 +6620,15 @@ class Connection {
6555
6620
  */
6556
6621
 
6557
6622
 
6558
- async getLatestBlockhashAndContext(commitment) {
6559
- const args = this._buildArgs([], commitment);
6623
+ async getLatestBlockhashAndContext(commitmentOrConfig) {
6624
+ const {
6625
+ commitment,
6626
+ config
6627
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6628
+
6629
+ const args = this._buildArgs([], commitment, undefined
6630
+ /* encoding */
6631
+ , config);
6560
6632
 
6561
6633
  const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
6562
6634
  const res = superstruct.create(unsafeRes, GetLatestBlockhashRpcResult);
@@ -6634,8 +6706,15 @@ class Connection {
6634
6706
  */
6635
6707
 
6636
6708
 
6637
- async getBlockHeight(commitment) {
6638
- const args = this._buildArgs([], commitment);
6709
+ async getBlockHeight(commitmentOrConfig) {
6710
+ const {
6711
+ commitment,
6712
+ config
6713
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6714
+
6715
+ const args = this._buildArgs([], commitment, undefined
6716
+ /* encoding */
6717
+ , config);
6639
6718
 
6640
6719
  const unsafeRes = await this._rpcRequest('getBlockHeight', args);
6641
6720
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
@@ -7364,6 +7443,10 @@ class Connection {
7364
7443
  config.maxRetries = options.maxRetries;
7365
7444
  }
7366
7445
 
7446
+ if (options && options.minContextSlot != null) {
7447
+ config.minContextSlot = options.minContextSlot;
7448
+ }
7449
+
7367
7450
  if (skipPreflight) {
7368
7451
  config.skipPreflight = skipPreflight;
7369
7452
  }
@@ -9773,7 +9856,8 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
9773
9856
 
9774
9857
  const sendOptions = options && {
9775
9858
  skipPreflight: options.skipPreflight,
9776
- preflightCommitment: options.preflightCommitment || options.commitment
9859
+ preflightCommitment: options.preflightCommitment || options.commitment,
9860
+ minContextSlot: options.minContextSlot
9777
9861
  };
9778
9862
  const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
9779
9863
  const commitment = options && options.commitment;