@solana/web3.js 1.44.3 → 1.47.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({
@@ -4500,6 +4501,41 @@ class SendTransactionError extends Error {
4500
4501
  this.logs = logs;
4501
4502
  }
4502
4503
 
4504
+ } // Keep in sync with client/src/rpc_custom_errors.rs
4505
+ // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
4506
+
4507
+ const SolanaJSONRPCErrorCode = {
4508
+ JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
4509
+ JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
4510
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
4511
+ JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
4512
+ JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
4513
+ JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
4514
+ JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
4515
+ JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
4516
+ JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
4517
+ JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
4518
+ JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
4519
+ JSON_RPC_SCAN_ERROR: -32012,
4520
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
4521
+ JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
4522
+ JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
4523
+ JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
4524
+ };
4525
+ class SolanaJSONRPCError extends Error {
4526
+ constructor({
4527
+ code,
4528
+ message,
4529
+ data
4530
+ }, customMessage) {
4531
+ super(customMessage != null ? `${customMessage}: ${message}` : message);
4532
+ this.code = void 0;
4533
+ this.data = void 0;
4534
+ this.code = code;
4535
+ this.data = data;
4536
+ this.name = 'SolanaJSONRPCError';
4537
+ }
4538
+
4503
4539
  }
4504
4540
 
4505
4541
  var fetchImpl = globalThis.fetch;
@@ -4568,6 +4604,7 @@ function makeWebsocketUrl(endpoint) {
4568
4604
  return url.toString();
4569
4605
  }
4570
4606
 
4607
+ var _process$env$npm_pack;
4571
4608
  const PublicKeyFromString = coerce(instance(PublicKey), string(), value => new PublicKey(value));
4572
4609
  const RawAccountDataResult = tuple([string(), literal('base64')]);
4573
4610
  const BufferFromRawAccountData = coerce(instance(Buffer), RawAccountDataResult, value => Buffer.from(value[0], 'base64'));
@@ -4584,9 +4621,32 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
4584
4621
  * https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
4585
4622
  */
4586
4623
 
4624
+ /** @internal */
4625
+ function extractCommitmentFromConfig(commitmentOrConfig) {
4626
+ let commitment;
4627
+ let config;
4628
+
4629
+ if (typeof commitmentOrConfig === 'string') {
4630
+ commitment = commitmentOrConfig;
4631
+ } else if (commitmentOrConfig) {
4632
+ const {
4633
+ commitment: specifiedCommitment,
4634
+ ...specifiedConfig
4635
+ } = commitmentOrConfig;
4636
+ commitment = specifiedCommitment;
4637
+ config = specifiedConfig;
4638
+ }
4639
+
4640
+ return {
4641
+ commitment,
4642
+ config
4643
+ };
4644
+ }
4587
4645
  /**
4588
4646
  * @internal
4589
4647
  */
4648
+
4649
+
4590
4650
  function createRpcResult(result) {
4591
4651
  return union([type({
4592
4652
  jsonrpc: literal('2.0'),
@@ -4778,7 +4838,7 @@ function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddlewar
4778
4838
  agent,
4779
4839
  headers: Object.assign({
4780
4840
  'Content-Type': 'application/json'
4781
- }, httpHeaders || {})
4841
+ }, httpHeaders || {}, COMMON_HTTP_HEADERS)
4782
4842
  };
4783
4843
 
4784
4844
  try {
@@ -5451,9 +5511,14 @@ const LogsNotificationResult = type({
5451
5511
  * Filter for log subscriptions.
5452
5512
  */
5453
5513
 
5514
+ /** @internal */
5515
+ const COMMON_HTTP_HEADERS = {
5516
+ 'solana-client': `js/${(_process$env$npm_pack = "0.0.0-development") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
5517
+ };
5454
5518
  /**
5455
5519
  * A connection to a fullnode JSON RPC endpoint
5456
5520
  */
5521
+
5457
5522
  class Connection {
5458
5523
  /** @internal */
5459
5524
 
@@ -5618,14 +5683,22 @@ class Connection {
5618
5683
  */
5619
5684
 
5620
5685
 
5621
- async getBalanceAndContext(publicKey, commitment) {
5622
- const args = this._buildArgs([publicKey.toBase58()], commitment);
5686
+ async getBalanceAndContext(publicKey, commitmentOrConfig) {
5687
+ /** @internal */
5688
+ const {
5689
+ commitment,
5690
+ config
5691
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5692
+
5693
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
5694
+ /* encoding */
5695
+ , config);
5623
5696
 
5624
5697
  const unsafeRes = await this._rpcRequest('getBalance', args);
5625
5698
  const res = create(unsafeRes, jsonRpcResultAndContext(number()));
5626
5699
 
5627
5700
  if ('error' in res) {
5628
- throw new Error('failed to get balance for ' + publicKey.toBase58() + ': ' + res.error.message);
5701
+ throw new SolanaJSONRPCError(res.error, `failed to get balance for ${publicKey.toBase58()}`);
5629
5702
  }
5630
5703
 
5631
5704
  return res.result;
@@ -5635,8 +5708,8 @@ class Connection {
5635
5708
  */
5636
5709
 
5637
5710
 
5638
- async getBalance(publicKey, commitment) {
5639
- return await this.getBalanceAndContext(publicKey, commitment).then(x => x.value).catch(e => {
5711
+ async getBalance(publicKey, commitmentOrConfig) {
5712
+ return await this.getBalanceAndContext(publicKey, commitmentOrConfig).then(x => x.value).catch(e => {
5640
5713
  throw new Error('failed to get balance of account ' + publicKey.toBase58() + ': ' + e);
5641
5714
  });
5642
5715
  }
@@ -5650,7 +5723,7 @@ class Connection {
5650
5723
  const res = create(unsafeRes, jsonRpcResult(nullable(number())));
5651
5724
 
5652
5725
  if ('error' in res) {
5653
- throw new Error('failed to get block time for slot ' + slot + ': ' + res.error.message);
5726
+ throw new SolanaJSONRPCError(res.error, `failed to get block time for slot ${slot}`);
5654
5727
  }
5655
5728
 
5656
5729
  return res.result;
@@ -5666,7 +5739,7 @@ class Connection {
5666
5739
  const res = create(unsafeRes, jsonRpcResult(number()));
5667
5740
 
5668
5741
  if ('error' in res) {
5669
- throw new Error('failed to get minimum ledger slot: ' + res.error.message);
5742
+ throw new SolanaJSONRPCError(res.error, 'failed to get minimum ledger slot');
5670
5743
  }
5671
5744
 
5672
5745
  return res.result;
@@ -5681,7 +5754,7 @@ class Connection {
5681
5754
  const res = create(unsafeRes, SlotRpcResult);
5682
5755
 
5683
5756
  if ('error' in res) {
5684
- throw new Error('failed to get first available block: ' + res.error.message);
5757
+ throw new SolanaJSONRPCError(res.error, 'failed to get first available block');
5685
5758
  }
5686
5759
 
5687
5760
  return res.result;
@@ -5712,7 +5785,7 @@ class Connection {
5712
5785
  const res = create(unsafeRes, GetSupplyRpcResult);
5713
5786
 
5714
5787
  if ('error' in res) {
5715
- throw new Error('failed to get supply: ' + res.error.message);
5788
+ throw new SolanaJSONRPCError(res.error, 'failed to get supply');
5716
5789
  }
5717
5790
 
5718
5791
  return res.result;
@@ -5729,7 +5802,7 @@ class Connection {
5729
5802
  const res = create(unsafeRes, jsonRpcResultAndContext(TokenAmountResult));
5730
5803
 
5731
5804
  if ('error' in res) {
5732
- throw new Error('failed to get token supply: ' + res.error.message);
5805
+ throw new SolanaJSONRPCError(res.error, 'failed to get token supply');
5733
5806
  }
5734
5807
 
5735
5808
  return res.result;
@@ -5746,7 +5819,7 @@ class Connection {
5746
5819
  const res = create(unsafeRes, jsonRpcResultAndContext(TokenAmountResult));
5747
5820
 
5748
5821
  if ('error' in res) {
5749
- throw new Error('failed to get token account balance: ' + res.error.message);
5822
+ throw new SolanaJSONRPCError(res.error, 'failed to get token account balance');
5750
5823
  }
5751
5824
 
5752
5825
  return res.result;
@@ -5758,7 +5831,11 @@ class Connection {
5758
5831
  */
5759
5832
 
5760
5833
 
5761
- async getTokenAccountsByOwner(ownerAddress, filter, commitment) {
5834
+ async getTokenAccountsByOwner(ownerAddress, filter, commitmentOrConfig) {
5835
+ const {
5836
+ commitment,
5837
+ config
5838
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5762
5839
  let _args = [ownerAddress.toBase58()];
5763
5840
 
5764
5841
  if ('mint' in filter) {
@@ -5771,13 +5848,13 @@ class Connection {
5771
5848
  });
5772
5849
  }
5773
5850
 
5774
- const args = this._buildArgs(_args, commitment, 'base64');
5851
+ const args = this._buildArgs(_args, commitment, 'base64', config);
5775
5852
 
5776
5853
  const unsafeRes = await this._rpcRequest('getTokenAccountsByOwner', args);
5777
5854
  const res = create(unsafeRes, GetTokenAccountsByOwner);
5778
5855
 
5779
5856
  if ('error' in res) {
5780
- throw new Error('failed to get token accounts owned by account ' + ownerAddress.toBase58() + ': ' + res.error.message);
5857
+ throw new SolanaJSONRPCError(res.error, `failed to get token accounts owned by account ${ownerAddress.toBase58()}`);
5781
5858
  }
5782
5859
 
5783
5860
  return res.result;
@@ -5808,7 +5885,7 @@ class Connection {
5808
5885
  const res = create(unsafeRes, GetParsedTokenAccountsByOwner);
5809
5886
 
5810
5887
  if ('error' in res) {
5811
- throw new Error('failed to get token accounts owned by account ' + ownerAddress.toBase58() + ': ' + res.error.message);
5888
+ throw new SolanaJSONRPCError(res.error, `failed to get token accounts owned by account ${ownerAddress.toBase58()}`);
5812
5889
  }
5813
5890
 
5814
5891
  return res.result;
@@ -5827,7 +5904,7 @@ class Connection {
5827
5904
  const res = create(unsafeRes, GetLargestAccountsRpcResult);
5828
5905
 
5829
5906
  if ('error' in res) {
5830
- throw new Error('failed to get largest accounts: ' + res.error.message);
5907
+ throw new SolanaJSONRPCError(res.error, 'failed to get largest accounts');
5831
5908
  }
5832
5909
 
5833
5910
  return res.result;
@@ -5845,7 +5922,7 @@ class Connection {
5845
5922
  const res = create(unsafeRes, GetTokenLargestAccountsResult);
5846
5923
 
5847
5924
  if ('error' in res) {
5848
- throw new Error('failed to get token largest accounts: ' + res.error.message);
5925
+ throw new SolanaJSONRPCError(res.error, 'failed to get token largest accounts');
5849
5926
  }
5850
5927
 
5851
5928
  return res.result;
@@ -5855,14 +5932,19 @@ class Connection {
5855
5932
  */
5856
5933
 
5857
5934
 
5858
- async getAccountInfoAndContext(publicKey, commitment) {
5859
- const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64');
5935
+ async getAccountInfoAndContext(publicKey, commitmentOrConfig) {
5936
+ const {
5937
+ commitment,
5938
+ config
5939
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5940
+
5941
+ const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64', config);
5860
5942
 
5861
5943
  const unsafeRes = await this._rpcRequest('getAccountInfo', args);
5862
5944
  const res = create(unsafeRes, jsonRpcResultAndContext(nullable(AccountInfoResult)));
5863
5945
 
5864
5946
  if ('error' in res) {
5865
- throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + res.error.message);
5947
+ throw new SolanaJSONRPCError(res.error, `failed to get info about account ${publicKey.toBase58()}`);
5866
5948
  }
5867
5949
 
5868
5950
  return res.result;
@@ -5879,7 +5961,7 @@ class Connection {
5879
5961
  const res = create(unsafeRes, jsonRpcResultAndContext(nullable(ParsedAccountInfoResult)));
5880
5962
 
5881
5963
  if ('error' in res) {
5882
- throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + res.error.message);
5964
+ throw new SolanaJSONRPCError(res.error, `failed to get info about account ${publicKey.toBase58()}`);
5883
5965
  }
5884
5966
 
5885
5967
  return res.result;
@@ -5889,9 +5971,9 @@ class Connection {
5889
5971
  */
5890
5972
 
5891
5973
 
5892
- async getAccountInfo(publicKey, commitment) {
5974
+ async getAccountInfo(publicKey, commitmentOrConfig) {
5893
5975
  try {
5894
- const res = await this.getAccountInfoAndContext(publicKey, commitment);
5976
+ const res = await this.getAccountInfoAndContext(publicKey, commitmentOrConfig);
5895
5977
  return res.value;
5896
5978
  } catch (e) {
5897
5979
  throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + e);
@@ -5902,16 +5984,20 @@ class Connection {
5902
5984
  */
5903
5985
 
5904
5986
 
5905
- async getMultipleAccountsInfoAndContext(publicKeys, commitment) {
5987
+ async getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig) {
5988
+ const {
5989
+ commitment,
5990
+ config
5991
+ } = extractCommitmentFromConfig(commitmentOrConfig);
5906
5992
  const keys = publicKeys.map(key => key.toBase58());
5907
5993
 
5908
- const args = this._buildArgs([keys], commitment, 'base64');
5994
+ const args = this._buildArgs([keys], commitment, 'base64', config);
5909
5995
 
5910
5996
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
5911
5997
  const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(AccountInfoResult))));
5912
5998
 
5913
5999
  if ('error' in res) {
5914
- throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
6000
+ throw new SolanaJSONRPCError(res.error, `failed to get info for accounts ${keys}`);
5915
6001
  }
5916
6002
 
5917
6003
  return res.result;
@@ -5921,8 +6007,8 @@ class Connection {
5921
6007
  */
5922
6008
 
5923
6009
 
5924
- async getMultipleAccountsInfo(publicKeys, commitment) {
5925
- const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitment);
6010
+ async getMultipleAccountsInfo(publicKeys, commitmentOrConfig) {
6011
+ const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig);
5926
6012
  return res.value;
5927
6013
  }
5928
6014
  /**
@@ -5930,16 +6016,23 @@ class Connection {
5930
6016
  */
5931
6017
 
5932
6018
 
5933
- async getStakeActivation(publicKey, commitment, epoch) {
5934
- const args = this._buildArgs([publicKey.toBase58()], commitment, undefined, epoch !== undefined ? {
5935
- epoch
5936
- } : undefined);
6019
+ async getStakeActivation(publicKey, commitmentOrConfig, epoch) {
6020
+ const {
6021
+ commitment,
6022
+ config
6023
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6024
+
6025
+ const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
6026
+ /* encoding */
6027
+ , { ...config,
6028
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
6029
+ });
5937
6030
 
5938
6031
  const unsafeRes = await this._rpcRequest('getStakeActivation', args);
5939
6032
  const res = create(unsafeRes, jsonRpcResult(StakeActivationResult));
5940
6033
 
5941
6034
  if ('error' in res) {
5942
- throw new Error(`failed to get Stake Activation ${publicKey.toBase58()}: ${res.error.message}`);
6035
+ throw new SolanaJSONRPCError(res.error, `failed to get Stake Activation ${publicKey.toBase58()}`);
5943
6036
  }
5944
6037
 
5945
6038
  return res.result;
@@ -5952,34 +6045,22 @@ class Connection {
5952
6045
 
5953
6046
 
5954
6047
  async getProgramAccounts(programId, configOrCommitment) {
5955
- const extra = {};
5956
- let commitment;
5957
- let encoding;
5958
-
5959
- if (configOrCommitment) {
5960
- if (typeof configOrCommitment === 'string') {
5961
- commitment = configOrCommitment;
5962
- } else {
5963
- commitment = configOrCommitment.commitment;
5964
- encoding = configOrCommitment.encoding;
5965
-
5966
- if (configOrCommitment.dataSlice) {
5967
- extra.dataSlice = configOrCommitment.dataSlice;
5968
- }
5969
-
5970
- if (configOrCommitment.filters) {
5971
- extra.filters = configOrCommitment.filters;
5972
- }
5973
- }
5974
- }
6048
+ const {
6049
+ commitment,
6050
+ config
6051
+ } = extractCommitmentFromConfig(configOrCommitment);
6052
+ const {
6053
+ encoding,
6054
+ ...configWithoutEncoding
6055
+ } = config || {};
5975
6056
 
5976
- const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', extra);
6057
+ const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', configWithoutEncoding);
5977
6058
 
5978
6059
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
5979
6060
  const res = create(unsafeRes, jsonRpcResult(array(KeyedAccountInfoResult)));
5980
6061
 
5981
6062
  if ('error' in res) {
5982
- throw new Error('failed to get accounts owned by program ' + programId.toBase58() + ': ' + res.error.message);
6063
+ throw new SolanaJSONRPCError(res.error, `failed to get accounts owned by program ${programId.toBase58()}`);
5983
6064
  }
5984
6065
 
5985
6066
  return res.result;
@@ -5992,28 +6073,18 @@ class Connection {
5992
6073
 
5993
6074
 
5994
6075
  async getParsedProgramAccounts(programId, configOrCommitment) {
5995
- const extra = {};
5996
- let commitment;
5997
-
5998
- if (configOrCommitment) {
5999
- if (typeof configOrCommitment === 'string') {
6000
- commitment = configOrCommitment;
6001
- } else {
6002
- commitment = configOrCommitment.commitment;
6003
-
6004
- if (configOrCommitment.filters) {
6005
- extra.filters = configOrCommitment.filters;
6006
- }
6007
- }
6008
- }
6076
+ const {
6077
+ commitment,
6078
+ config
6079
+ } = extractCommitmentFromConfig(configOrCommitment);
6009
6080
 
6010
- const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', extra);
6081
+ const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', config);
6011
6082
 
6012
6083
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
6013
6084
  const res = create(unsafeRes, jsonRpcResult(array(KeyedParsedAccountInfoResult)));
6014
6085
 
6015
6086
  if ('error' in res) {
6016
- throw new Error('failed to get accounts owned by program ' + programId.toBase58() + ': ' + res.error.message);
6087
+ throw new SolanaJSONRPCError(res.error, `failed to get accounts owned by program ${programId.toBase58()}`);
6017
6088
  }
6018
6089
 
6019
6090
  return res.result;
@@ -6147,7 +6218,7 @@ class Connection {
6147
6218
  const res = create(unsafeRes, jsonRpcResult(array(ContactInfoResult)));
6148
6219
 
6149
6220
  if ('error' in res) {
6150
- throw new Error('failed to get cluster nodes: ' + res.error.message);
6221
+ throw new SolanaJSONRPCError(res.error, 'failed to get cluster nodes');
6151
6222
  }
6152
6223
 
6153
6224
  return res.result;
@@ -6164,7 +6235,7 @@ class Connection {
6164
6235
  const res = create(unsafeRes, GetVoteAccounts);
6165
6236
 
6166
6237
  if ('error' in res) {
6167
- throw new Error('failed to get vote accounts: ' + res.error.message);
6238
+ throw new SolanaJSONRPCError(res.error, 'failed to get vote accounts');
6168
6239
  }
6169
6240
 
6170
6241
  return res.result;
@@ -6174,14 +6245,21 @@ class Connection {
6174
6245
  */
6175
6246
 
6176
6247
 
6177
- async getSlot(commitment) {
6178
- const args = this._buildArgs([], commitment);
6248
+ async getSlot(commitmentOrConfig) {
6249
+ const {
6250
+ commitment,
6251
+ config
6252
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6253
+
6254
+ const args = this._buildArgs([], commitment, undefined
6255
+ /* encoding */
6256
+ , config);
6179
6257
 
6180
6258
  const unsafeRes = await this._rpcRequest('getSlot', args);
6181
6259
  const res = create(unsafeRes, jsonRpcResult(number()));
6182
6260
 
6183
6261
  if ('error' in res) {
6184
- throw new Error('failed to get slot: ' + res.error.message);
6262
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot');
6185
6263
  }
6186
6264
 
6187
6265
  return res.result;
@@ -6191,14 +6269,21 @@ class Connection {
6191
6269
  */
6192
6270
 
6193
6271
 
6194
- async getSlotLeader(commitment) {
6195
- const args = this._buildArgs([], commitment);
6272
+ async getSlotLeader(commitmentOrConfig) {
6273
+ const {
6274
+ commitment,
6275
+ config
6276
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6277
+
6278
+ const args = this._buildArgs([], commitment, undefined
6279
+ /* encoding */
6280
+ , config);
6196
6281
 
6197
6282
  const unsafeRes = await this._rpcRequest('getSlotLeader', args);
6198
6283
  const res = create(unsafeRes, jsonRpcResult(string()));
6199
6284
 
6200
6285
  if ('error' in res) {
6201
- throw new Error('failed to get slot leader: ' + res.error.message);
6286
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot leader');
6202
6287
  }
6203
6288
 
6204
6289
  return res.result;
@@ -6217,7 +6302,7 @@ class Connection {
6217
6302
  const res = create(unsafeRes, jsonRpcResult(array(PublicKeyFromString)));
6218
6303
 
6219
6304
  if ('error' in res) {
6220
- throw new Error('failed to get slot leaders: ' + res.error.message);
6305
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot leaders');
6221
6306
  }
6222
6307
 
6223
6308
  return res.result;
@@ -6255,7 +6340,7 @@ class Connection {
6255
6340
  const res = create(unsafeRes, GetSignatureStatusesRpcResult);
6256
6341
 
6257
6342
  if ('error' in res) {
6258
- throw new Error('failed to get signature status: ' + res.error.message);
6343
+ throw new SolanaJSONRPCError(res.error, 'failed to get signature status');
6259
6344
  }
6260
6345
 
6261
6346
  return res.result;
@@ -6265,14 +6350,21 @@ class Connection {
6265
6350
  */
6266
6351
 
6267
6352
 
6268
- async getTransactionCount(commitment) {
6269
- const args = this._buildArgs([], commitment);
6353
+ async getTransactionCount(commitmentOrConfig) {
6354
+ const {
6355
+ commitment,
6356
+ config
6357
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6358
+
6359
+ const args = this._buildArgs([], commitment, undefined
6360
+ /* encoding */
6361
+ , config);
6270
6362
 
6271
6363
  const unsafeRes = await this._rpcRequest('getTransactionCount', args);
6272
6364
  const res = create(unsafeRes, jsonRpcResult(number()));
6273
6365
 
6274
6366
  if ('error' in res) {
6275
- throw new Error('failed to get transaction count: ' + res.error.message);
6367
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction count');
6276
6368
  }
6277
6369
 
6278
6370
  return res.result;
@@ -6303,7 +6395,7 @@ class Connection {
6303
6395
  const res = create(unsafeRes, GetInflationGovernorRpcResult);
6304
6396
 
6305
6397
  if ('error' in res) {
6306
- throw new Error('failed to get inflation: ' + res.error.message);
6398
+ throw new SolanaJSONRPCError(res.error, 'failed to get inflation');
6307
6399
  }
6308
6400
 
6309
6401
  return res.result;
@@ -6313,16 +6405,23 @@ class Connection {
6313
6405
  */
6314
6406
 
6315
6407
 
6316
- async getInflationReward(addresses, epoch, commitment) {
6317
- const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined, {
6318
- epoch
6408
+ async getInflationReward(addresses, epoch, commitmentOrConfig) {
6409
+ const {
6410
+ commitment,
6411
+ config
6412
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6413
+
6414
+ const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined
6415
+ /* encoding */
6416
+ , { ...config,
6417
+ epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
6319
6418
  });
6320
6419
 
6321
6420
  const unsafeRes = await this._rpcRequest('getInflationReward', args);
6322
6421
  const res = create(unsafeRes, GetInflationRewardResult);
6323
6422
 
6324
6423
  if ('error' in res) {
6325
- throw new Error('failed to get inflation reward: ' + res.error.message);
6424
+ throw new SolanaJSONRPCError(res.error, 'failed to get inflation reward');
6326
6425
  }
6327
6426
 
6328
6427
  return res.result;
@@ -6332,14 +6431,21 @@ class Connection {
6332
6431
  */
6333
6432
 
6334
6433
 
6335
- async getEpochInfo(commitment) {
6336
- const args = this._buildArgs([], commitment);
6434
+ async getEpochInfo(commitmentOrConfig) {
6435
+ const {
6436
+ commitment,
6437
+ config
6438
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6439
+
6440
+ const args = this._buildArgs([], commitment, undefined
6441
+ /* encoding */
6442
+ , config);
6337
6443
 
6338
6444
  const unsafeRes = await this._rpcRequest('getEpochInfo', args);
6339
6445
  const res = create(unsafeRes, GetEpochInfoRpcResult);
6340
6446
 
6341
6447
  if ('error' in res) {
6342
- throw new Error('failed to get epoch info: ' + res.error.message);
6448
+ throw new SolanaJSONRPCError(res.error, 'failed to get epoch info');
6343
6449
  }
6344
6450
 
6345
6451
  return res.result;
@@ -6354,7 +6460,7 @@ class Connection {
6354
6460
  const res = create(unsafeRes, GetEpochScheduleRpcResult);
6355
6461
 
6356
6462
  if ('error' in res) {
6357
- throw new Error('failed to get epoch schedule: ' + res.error.message);
6463
+ throw new SolanaJSONRPCError(res.error, 'failed to get epoch schedule');
6358
6464
  }
6359
6465
 
6360
6466
  const epochSchedule = res.result;
@@ -6371,7 +6477,7 @@ class Connection {
6371
6477
  const res = create(unsafeRes, GetLeaderScheduleRpcResult);
6372
6478
 
6373
6479
  if ('error' in res) {
6374
- throw new Error('failed to get leader schedule: ' + res.error.message);
6480
+ throw new SolanaJSONRPCError(res.error, 'failed to get leader schedule');
6375
6481
  }
6376
6482
 
6377
6483
  return res.result;
@@ -6410,7 +6516,7 @@ class Connection {
6410
6516
  const res = create(unsafeRes, GetRecentBlockhashAndContextRpcResult);
6411
6517
 
6412
6518
  if ('error' in res) {
6413
- throw new Error('failed to get recent blockhash: ' + res.error.message);
6519
+ throw new SolanaJSONRPCError(res.error, 'failed to get recent blockhash');
6414
6520
  }
6415
6521
 
6416
6522
  return res.result;
@@ -6428,7 +6534,7 @@ class Connection {
6428
6534
  const res = create(unsafeRes, GetRecentPerformanceSamplesRpcResult);
6429
6535
 
6430
6536
  if ('error' in res) {
6431
- throw new Error('failed to get recent performance samples: ' + res.error.message);
6537
+ throw new SolanaJSONRPCError(res.error, 'failed to get recent performance samples');
6432
6538
  }
6433
6539
 
6434
6540
  return res.result;
@@ -6447,7 +6553,7 @@ class Connection {
6447
6553
  const res = create(unsafeRes, GetFeeCalculatorRpcResult);
6448
6554
 
6449
6555
  if ('error' in res) {
6450
- throw new Error('failed to get fee calculator: ' + res.error.message);
6556
+ throw new SolanaJSONRPCError(res.error, 'failed to get fee calculator');
6451
6557
  }
6452
6558
 
6453
6559
  const {
@@ -6473,7 +6579,7 @@ class Connection {
6473
6579
  const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
6474
6580
 
6475
6581
  if ('error' in res) {
6476
- throw new Error('failed to get slot: ' + res.error.message);
6582
+ throw new SolanaJSONRPCError(res.error, 'failed to get slot');
6477
6583
  }
6478
6584
 
6479
6585
  if (res.result === null) {
@@ -6504,9 +6610,9 @@ class Connection {
6504
6610
  */
6505
6611
 
6506
6612
 
6507
- async getLatestBlockhash(commitment) {
6613
+ async getLatestBlockhash(commitmentOrConfig) {
6508
6614
  try {
6509
- const res = await this.getLatestBlockhashAndContext(commitment);
6615
+ const res = await this.getLatestBlockhashAndContext(commitmentOrConfig);
6510
6616
  return res.value;
6511
6617
  } catch (e) {
6512
6618
  throw new Error('failed to get recent blockhash: ' + e);
@@ -6518,14 +6624,21 @@ class Connection {
6518
6624
  */
6519
6625
 
6520
6626
 
6521
- async getLatestBlockhashAndContext(commitment) {
6522
- const args = this._buildArgs([], commitment);
6627
+ async getLatestBlockhashAndContext(commitmentOrConfig) {
6628
+ const {
6629
+ commitment,
6630
+ config
6631
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6632
+
6633
+ const args = this._buildArgs([], commitment, undefined
6634
+ /* encoding */
6635
+ , config);
6523
6636
 
6524
6637
  const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
6525
6638
  const res = create(unsafeRes, GetLatestBlockhashRpcResult);
6526
6639
 
6527
6640
  if ('error' in res) {
6528
- throw new Error('failed to get latest blockhash: ' + res.error.message);
6641
+ throw new SolanaJSONRPCError(res.error, 'failed to get latest blockhash');
6529
6642
  }
6530
6643
 
6531
6644
  return res.result;
@@ -6540,7 +6653,7 @@ class Connection {
6540
6653
  const res = create(unsafeRes, jsonRpcResult(VersionResult));
6541
6654
 
6542
6655
  if ('error' in res) {
6543
- throw new Error('failed to get version: ' + res.error.message);
6656
+ throw new SolanaJSONRPCError(res.error, 'failed to get version');
6544
6657
  }
6545
6658
 
6546
6659
  return res.result;
@@ -6555,7 +6668,7 @@ class Connection {
6555
6668
  const res = create(unsafeRes, jsonRpcResult(string()));
6556
6669
 
6557
6670
  if ('error' in res) {
6558
- throw new Error('failed to get genesis hash: ' + res.error.message);
6671
+ throw new SolanaJSONRPCError(res.error, 'failed to get genesis hash');
6559
6672
  }
6560
6673
 
6561
6674
  return res.result;
@@ -6572,7 +6685,7 @@ class Connection {
6572
6685
  const res = create(unsafeRes, GetBlockRpcResult);
6573
6686
 
6574
6687
  if ('error' in res) {
6575
- throw new Error('failed to get confirmed block: ' + res.error.message);
6688
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
6576
6689
  }
6577
6690
 
6578
6691
  const result = res.result;
@@ -6597,14 +6710,21 @@ class Connection {
6597
6710
  */
6598
6711
 
6599
6712
 
6600
- async getBlockHeight(commitment) {
6601
- const args = this._buildArgs([], commitment);
6713
+ async getBlockHeight(commitmentOrConfig) {
6714
+ const {
6715
+ commitment,
6716
+ config
6717
+ } = extractCommitmentFromConfig(commitmentOrConfig);
6718
+
6719
+ const args = this._buildArgs([], commitment, undefined
6720
+ /* encoding */
6721
+ , config);
6602
6722
 
6603
6723
  const unsafeRes = await this._rpcRequest('getBlockHeight', args);
6604
6724
  const res = create(unsafeRes, jsonRpcResult(number()));
6605
6725
 
6606
6726
  if ('error' in res) {
6607
- throw new Error('failed to get block height information: ' + res.error.message);
6727
+ throw new SolanaJSONRPCError(res.error, 'failed to get block height information');
6608
6728
  }
6609
6729
 
6610
6730
  return res.result;
@@ -6635,7 +6755,7 @@ class Connection {
6635
6755
  const res = create(unsafeRes, BlockProductionResponseStruct);
6636
6756
 
6637
6757
  if ('error' in res) {
6638
- throw new Error('failed to get block production information: ' + res.error.message);
6758
+ throw new SolanaJSONRPCError(res.error, 'failed to get block production information');
6639
6759
  }
6640
6760
 
6641
6761
  return res.result;
@@ -6652,7 +6772,7 @@ class Connection {
6652
6772
  const res = create(unsafeRes, GetTransactionRpcResult);
6653
6773
 
6654
6774
  if ('error' in res) {
6655
- throw new Error('failed to get transaction: ' + res.error.message);
6775
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
6656
6776
  }
6657
6777
 
6658
6778
  const result = res.result;
@@ -6675,7 +6795,7 @@ class Connection {
6675
6795
  const res = create(unsafeRes, GetParsedTransactionRpcResult);
6676
6796
 
6677
6797
  if ('error' in res) {
6678
- throw new Error('failed to get transaction: ' + res.error.message);
6798
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
6679
6799
  }
6680
6800
 
6681
6801
  return res.result;
@@ -6699,7 +6819,7 @@ class Connection {
6699
6819
  const res = create(unsafeRes, GetParsedTransactionRpcResult);
6700
6820
 
6701
6821
  if ('error' in res) {
6702
- throw new Error('failed to get transactions: ' + res.error.message);
6822
+ throw new SolanaJSONRPCError(res.error, 'failed to get transactions');
6703
6823
  }
6704
6824
 
6705
6825
  return res.result;
@@ -6726,7 +6846,7 @@ class Connection {
6726
6846
  const res = create(unsafeRes, GetTransactionRpcResult);
6727
6847
 
6728
6848
  if ('error' in res) {
6729
- throw new Error('failed to get transactions: ' + res.error.message);
6849
+ throw new SolanaJSONRPCError(res.error, 'failed to get transactions');
6730
6850
  }
6731
6851
 
6732
6852
  const result = res.result;
@@ -6754,7 +6874,7 @@ class Connection {
6754
6874
  const res = create(unsafeRes, GetConfirmedBlockRpcResult);
6755
6875
 
6756
6876
  if ('error' in res) {
6757
- throw new Error('failed to get confirmed block: ' + res.error.message);
6877
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
6758
6878
  }
6759
6879
 
6760
6880
  const result = res.result;
@@ -6801,7 +6921,7 @@ class Connection {
6801
6921
  const res = create(unsafeRes, jsonRpcResult(array(number())));
6802
6922
 
6803
6923
  if ('error' in res) {
6804
- throw new Error('failed to get blocks: ' + res.error.message);
6924
+ throw new SolanaJSONRPCError(res.error, 'failed to get blocks');
6805
6925
  }
6806
6926
 
6807
6927
  return res.result;
@@ -6821,7 +6941,7 @@ class Connection {
6821
6941
  const res = create(unsafeRes, GetBlockSignaturesRpcResult);
6822
6942
 
6823
6943
  if ('error' in res) {
6824
- throw new Error('failed to get block: ' + res.error.message);
6944
+ throw new SolanaJSONRPCError(res.error, 'failed to get block');
6825
6945
  }
6826
6946
 
6827
6947
  const result = res.result;
@@ -6849,7 +6969,7 @@ class Connection {
6849
6969
  const res = create(unsafeRes, GetBlockSignaturesRpcResult);
6850
6970
 
6851
6971
  if ('error' in res) {
6852
- throw new Error('failed to get confirmed block: ' + res.error.message);
6972
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed block');
6853
6973
  }
6854
6974
 
6855
6975
  const result = res.result;
@@ -6874,7 +6994,7 @@ class Connection {
6874
6994
  const res = create(unsafeRes, GetTransactionRpcResult);
6875
6995
 
6876
6996
  if ('error' in res) {
6877
- throw new Error('failed to get transaction: ' + res.error.message);
6997
+ throw new SolanaJSONRPCError(res.error, 'failed to get transaction');
6878
6998
  }
6879
6999
 
6880
7000
  const result = res.result;
@@ -6899,7 +7019,7 @@ class Connection {
6899
7019
  const res = create(unsafeRes, GetParsedTransactionRpcResult);
6900
7020
 
6901
7021
  if ('error' in res) {
6902
- throw new Error('failed to get confirmed transaction: ' + res.error.message);
7022
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed transaction');
6903
7023
  }
6904
7024
 
6905
7025
  return res.result;
@@ -6925,7 +7045,7 @@ class Connection {
6925
7045
  const res = create(unsafeRes, GetParsedTransactionRpcResult);
6926
7046
 
6927
7047
  if ('error' in res) {
6928
- throw new Error('failed to get confirmed transactions: ' + res.error.message);
7048
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed transactions');
6929
7049
  }
6930
7050
 
6931
7051
  return res.result;
@@ -7014,7 +7134,7 @@ class Connection {
7014
7134
  const res = create(unsafeRes, GetConfirmedSignaturesForAddress2RpcResult);
7015
7135
 
7016
7136
  if ('error' in res) {
7017
- throw new Error('failed to get confirmed signatures for address: ' + res.error.message);
7137
+ throw new SolanaJSONRPCError(res.error, 'failed to get confirmed signatures for address');
7018
7138
  }
7019
7139
 
7020
7140
  return res.result;
@@ -7036,7 +7156,7 @@ class Connection {
7036
7156
  const res = create(unsafeRes, GetSignaturesForAddressRpcResult);
7037
7157
 
7038
7158
  if ('error' in res) {
7039
- throw new Error('failed to get signatures for address: ' + res.error.message);
7159
+ throw new SolanaJSONRPCError(res.error, 'failed to get signatures for address');
7040
7160
  }
7041
7161
 
7042
7162
  return res.result;
@@ -7093,7 +7213,7 @@ class Connection {
7093
7213
  const res = create(unsafeRes, RequestAirdropRpcResult);
7094
7214
 
7095
7215
  if ('error' in res) {
7096
- throw new Error('airdrop to ' + to.toBase58() + ' failed: ' + res.error.message);
7216
+ throw new SolanaJSONRPCError(res.error, `airdrop to ${to.toBase58()} failed`);
7097
7217
  }
7098
7218
 
7099
7219
  return res.result;
@@ -7327,6 +7447,10 @@ class Connection {
7327
7447
  config.maxRetries = options.maxRetries;
7328
7448
  }
7329
7449
 
7450
+ if (options && options.minContextSlot != null) {
7451
+ config.minContextSlot = options.minContextSlot;
7452
+ }
7453
+
7330
7454
  if (skipPreflight) {
7331
7455
  config.skipPreflight = skipPreflight;
7332
7456
  }
@@ -9736,7 +9860,8 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
9736
9860
 
9737
9861
  const sendOptions = options && {
9738
9862
  skipPreflight: options.skipPreflight,
9739
- preflightCommitment: options.preflightCommitment || options.commitment
9863
+ preflightCommitment: options.preflightCommitment || options.commitment,
9864
+ minContextSlot: options.minContextSlot
9740
9865
  };
9741
9866
  const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
9742
9867
  const commitment = options && options.commitment;
@@ -9788,5 +9913,5 @@ function clusterApiUrl(cluster, tls) {
9788
9913
 
9789
9914
  const LAMPORTS_PER_SOL = 1000000000;
9790
9915
 
9791
- export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionStatus, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9916
+ export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionStatus, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9792
9917
  //# sourceMappingURL=index.browser.esm.js.map