@solana/web3.js 1.31.0 → 1.33.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.
package/lib/index.esm.js CHANGED
@@ -1805,6 +1805,10 @@ class PublicKey extends Struct {
1805
1805
  toBase58() {
1806
1806
  return bs58.encode(this.toBytes());
1807
1807
  }
1808
+
1809
+ toJSON() {
1810
+ return this.toBase58();
1811
+ }
1808
1812
  /**
1809
1813
  * Return the byte array representation of the public key
1810
1814
  */
@@ -2071,6 +2075,13 @@ const authorized = (property = 'authorized') => {
2071
2075
  const lockup = (property = 'lockup') => {
2072
2076
  return BufferLayout.struct([BufferLayout.ns64('unixTimestamp'), BufferLayout.ns64('epoch'), publicKey('custodian')], property);
2073
2077
  };
2078
+ /**
2079
+ * Layout for a VoteInit object
2080
+ */
2081
+
2082
+ const voteInit = (property = 'voteInit') => {
2083
+ return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
2084
+ };
2074
2085
  function getAlloc(type, fields) {
2075
2086
  let alloc = 0;
2076
2087
  type.layout.fields.forEach(item => {
@@ -2444,8 +2455,9 @@ class Transaction {
2444
2455
  }); // Sort. Prioritizing first by signer, then by writable
2445
2456
 
2446
2457
  accountMetas.sort(function (x, y) {
2458
+ const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
2447
2459
  const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
2448
- const checkWritable = x.isWritable === y.isWritable ? 0 : x.isWritable ? -1 : 1;
2460
+ const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
2449
2461
  return checkSigner || checkWritable;
2450
2462
  }); // Cull duplicate account metas
2451
2463
 
@@ -2901,11 +2913,14 @@ class Transaction {
2901
2913
  }
2902
2914
 
2903
2915
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
2916
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
2917
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2904
2918
  const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
2905
2919
  const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
2906
2920
  const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
2921
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
2922
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2907
2923
  const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2908
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2909
2924
 
2910
2925
  /**
2911
2926
  * Sign, send and confirm a transaction.
@@ -2921,7 +2936,8 @@ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions111111111111
2921
2936
  async function sendAndConfirmTransaction(connection, transaction, signers, options) {
2922
2937
  const sendOptions = options && {
2923
2938
  skipPreflight: options.skipPreflight,
2924
- preflightCommitment: options.preflightCommitment || options.commitment
2939
+ preflightCommitment: options.preflightCommitment || options.commitment,
2940
+ maxRetries: options.maxRetries
2925
2941
  };
2926
2942
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
2927
2943
  const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
@@ -4323,16 +4339,15 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
4323
4339
  let fetchWithMiddleware;
4324
4340
 
4325
4341
  if (fetchMiddleware) {
4326
- fetchWithMiddleware = (url, options) => {
4327
- return new Promise((resolve, reject) => {
4328
- fetchMiddleware(url, options, async (url, options) => {
4329
- try {
4330
- resolve(await fetch(url, options));
4331
- } catch (error) {
4332
- reject(error);
4333
- }
4334
- });
4342
+ fetchWithMiddleware = async (url, options) => {
4343
+ const modifiedFetchArgs = await new Promise((resolve, reject) => {
4344
+ try {
4345
+ fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
4346
+ } catch (error) {
4347
+ reject(error);
4348
+ }
4335
4349
  });
4350
+ return await fetch(...modifiedFetchArgs);
4336
4351
  };
4337
4352
  }
4338
4353
 
@@ -4826,6 +4841,7 @@ const ParsedConfirmedTransactionResult = type({
4826
4841
  const TokenBalanceResult = type({
4827
4842
  accountIndex: number(),
4828
4843
  mint: string(),
4844
+ owner: optional(string()),
4829
4845
  uiTokenAmount: TokenAmountResult
4830
4846
  });
4831
4847
  /**
@@ -4866,8 +4882,31 @@ const ParsedConfirmedTransactionMetaResult = type({
4866
4882
  preTokenBalances: optional(nullable(array(TokenBalanceResult))),
4867
4883
  postTokenBalances: optional(nullable(array(TokenBalanceResult)))
4868
4884
  });
4885
+ /**
4886
+ * Expected JSON RPC response for the "getBlock" message
4887
+ */
4888
+
4889
+ const GetBlockRpcResult = jsonRpcResult(nullable(type({
4890
+ blockhash: string(),
4891
+ previousBlockhash: string(),
4892
+ parentSlot: number(),
4893
+ transactions: array(type({
4894
+ transaction: ConfirmedTransactionResult,
4895
+ meta: nullable(ConfirmedTransactionMetaResult)
4896
+ })),
4897
+ rewards: optional(array(type({
4898
+ pubkey: string(),
4899
+ lamports: number(),
4900
+ postBalance: nullable(number()),
4901
+ rewardType: nullable(string())
4902
+ }))),
4903
+ blockTime: nullable(number()),
4904
+ blockHeight: nullable(number())
4905
+ })));
4869
4906
  /**
4870
4907
  * Expected JSON RPC response for the "getConfirmedBlock" message
4908
+ *
4909
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
4871
4910
  */
4872
4911
 
4873
4912
  const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
@@ -4887,10 +4926,10 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
4887
4926
  blockTime: nullable(number())
4888
4927
  })));
4889
4928
  /**
4890
- * Expected JSON RPC response for the "getConfirmedBlockSignatures" message
4929
+ * Expected JSON RPC response for the "getBlock" message
4891
4930
  */
4892
4931
 
4893
- const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
4932
+ const GetBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
4894
4933
  blockhash: string(),
4895
4934
  previousBlockhash: string(),
4896
4935
  parentSlot: number(),
@@ -4898,20 +4937,20 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
4898
4937
  blockTime: nullable(number())
4899
4938
  })));
4900
4939
  /**
4901
- * Expected JSON RPC response for the "getConfirmedTransaction" message
4940
+ * Expected JSON RPC response for the "getTransaction" message
4902
4941
  */
4903
4942
 
4904
- const GetConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
4943
+ const GetTransactionRpcResult = jsonRpcResult(nullable(type({
4905
4944
  slot: number(),
4906
4945
  meta: ConfirmedTransactionMetaResult,
4907
4946
  blockTime: optional(nullable(number())),
4908
4947
  transaction: ConfirmedTransactionResult
4909
4948
  })));
4910
4949
  /**
4911
- * Expected JSON RPC response for the "getConfirmedTransaction" message
4950
+ * Expected parsed JSON RPC response for the "getTransaction" message
4912
4951
  */
4913
4952
 
4914
- const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
4953
+ const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
4915
4954
  slot: number(),
4916
4955
  transaction: ParsedConfirmedTransactionResult,
4917
4956
  meta: nullable(ParsedConfirmedTransactionMetaResult),
@@ -4919,6 +4958,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
4919
4958
  })));
4920
4959
  /**
4921
4960
  * Expected JSON RPC response for the "getRecentBlockhash" message
4961
+ *
4962
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
4922
4963
  */
4923
4964
 
4924
4965
  const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
@@ -4927,6 +4968,14 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
4927
4968
  lamportsPerSignature: number()
4928
4969
  })
4929
4970
  }));
4971
+ /**
4972
+ * Expected JSON RPC response for the "getLatestBlockhash" message
4973
+ */
4974
+
4975
+ const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(type({
4976
+ blockhash: string(),
4977
+ lastValidBlockHeight: number()
4978
+ }));
4930
4979
  const PerfSampleResult = type({
4931
4980
  slot: number(),
4932
4981
  numTransactions: number(),
@@ -5429,13 +5478,25 @@ class Connection {
5429
5478
  */
5430
5479
 
5431
5480
 
5432
- async getMultipleAccountsInfo(publicKeys, commitment) {
5481
+ async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
5433
5482
  const keys = publicKeys.map(key => key.toBase58());
5483
+ let commitment;
5484
+ let encoding = 'base64';
5485
+
5486
+ if (configOrCommitment) {
5487
+ if (typeof configOrCommitment === 'string') {
5488
+ commitment = configOrCommitment;
5489
+ encoding = 'base64';
5490
+ } else {
5491
+ commitment = configOrCommitment.commitment;
5492
+ encoding = configOrCommitment.encoding || 'base64';
5493
+ }
5494
+ }
5434
5495
 
5435
- const args = this._buildArgs([keys], commitment, 'base64');
5496
+ const args = this._buildArgs([keys], commitment, encoding);
5436
5497
 
5437
5498
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
5438
- const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(AccountInfoResult))));
5499
+ const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))));
5439
5500
 
5440
5501
  if ('error' in res) {
5441
5502
  throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
@@ -5859,6 +5920,8 @@ class Connection {
5859
5920
  /**
5860
5921
  * Fetch a recent blockhash from the cluster, return with context
5861
5922
  * @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
5923
+ *
5924
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
5862
5925
  */
5863
5926
 
5864
5927
 
@@ -5894,6 +5957,8 @@ class Connection {
5894
5957
  }
5895
5958
  /**
5896
5959
  * Fetch the fee calculator for a recent blockhash from the cluster, return with context
5960
+ *
5961
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
5897
5962
  */
5898
5963
 
5899
5964
 
@@ -5916,9 +5981,34 @@ class Connection {
5916
5981
  value: value !== null ? value.feeCalculator : null
5917
5982
  };
5918
5983
  }
5984
+ /**
5985
+ * Fetch the fee for a message from the cluster, return with context
5986
+ */
5987
+
5988
+
5989
+ async getFeeForMessage(message, commitment) {
5990
+ const wireMessage = message.serialize().toString('base64');
5991
+
5992
+ const args = this._buildArgs([wireMessage], commitment);
5993
+
5994
+ const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
5995
+ const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
5996
+
5997
+ if ('error' in res) {
5998
+ throw new Error('failed to get slot: ' + res.error.message);
5999
+ }
6000
+
6001
+ if (res.result === null) {
6002
+ throw new Error('invalid blockhash');
6003
+ }
6004
+
6005
+ return res.result;
6006
+ }
5919
6007
  /**
5920
6008
  * Fetch a recent blockhash from the cluster
5921
6009
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
6010
+ *
6011
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
5922
6012
  */
5923
6013
 
5924
6014
 
@@ -5930,6 +6020,38 @@ class Connection {
5930
6020
  throw new Error('failed to get recent blockhash: ' + e);
5931
6021
  }
5932
6022
  }
6023
+ /**
6024
+ * Fetch the latest blockhash from the cluster
6025
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6026
+ */
6027
+
6028
+
6029
+ async getLatestBlockhash(commitment) {
6030
+ try {
6031
+ const res = await this.getLatestBlockhashAndContext(commitment);
6032
+ return res.value;
6033
+ } catch (e) {
6034
+ throw new Error('failed to get recent blockhash: ' + e);
6035
+ }
6036
+ }
6037
+ /**
6038
+ * Fetch the latest blockhash from the cluster
6039
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6040
+ */
6041
+
6042
+
6043
+ async getLatestBlockhashAndContext(commitment) {
6044
+ const args = this._buildArgs([], commitment);
6045
+
6046
+ const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
6047
+ const res = create(unsafeRes, GetLatestBlockhashRpcResult);
6048
+
6049
+ if ('error' in res) {
6050
+ throw new Error('failed to get latest blockhash: ' + res.error.message);
6051
+ }
6052
+
6053
+ return res.result;
6054
+ }
5933
6055
  /**
5934
6056
  * Fetch the node version
5935
6057
  */
@@ -5968,8 +6090,8 @@ class Connection {
5968
6090
  async getBlock(slot, opts) {
5969
6091
  const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
5970
6092
 
5971
- const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
5972
- const res = create(unsafeRes, GetConfirmedBlockRpcResult);
6093
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6094
+ const res = create(unsafeRes, GetBlockRpcResult);
5973
6095
 
5974
6096
  if ('error' in res) {
5975
6097
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -5993,18 +6115,18 @@ class Connection {
5993
6115
  };
5994
6116
  }
5995
6117
  /**
5996
- * Fetch a processed transaction from the cluster.
6118
+ * Fetch a confirmed or finalized transaction from the cluster.
5997
6119
  */
5998
6120
 
5999
6121
 
6000
6122
  async getTransaction(signature, opts) {
6001
6123
  const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
6002
6124
 
6003
- const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6004
- const res = create(unsafeRes, GetConfirmedTransactionRpcResult);
6125
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6126
+ const res = create(unsafeRes, GetTransactionRpcResult);
6005
6127
 
6006
6128
  if ('error' in res) {
6007
- throw new Error('failed to get confirmed transaction: ' + res.error.message);
6129
+ throw new Error('failed to get transaction: ' + res.error.message);
6008
6130
  }
6009
6131
 
6010
6132
  const result = res.result;
@@ -6015,6 +6137,49 @@ class Connection {
6015
6137
  }
6016
6138
  };
6017
6139
  }
6140
+ /**
6141
+ * Fetch parsed transaction details for a confirmed or finalized transaction
6142
+ */
6143
+
6144
+
6145
+ async getParsedTransaction(signature, commitment) {
6146
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6147
+
6148
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6149
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6150
+
6151
+ if ('error' in res) {
6152
+ throw new Error('failed to get transaction: ' + res.error.message);
6153
+ }
6154
+
6155
+ return res.result;
6156
+ }
6157
+ /**
6158
+ * Fetch parsed transaction details for a batch of confirmed transactions
6159
+ */
6160
+
6161
+
6162
+ async getParsedTransactions(signatures, commitment) {
6163
+ const batch = signatures.map(signature => {
6164
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6165
+
6166
+ return {
6167
+ methodName: 'getTransaction',
6168
+ args
6169
+ };
6170
+ });
6171
+ const unsafeRes = await this._rpcBatchRequest(batch);
6172
+ const res = unsafeRes.map(unsafeRes => {
6173
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6174
+
6175
+ if ('error' in res) {
6176
+ throw new Error('failed to get transactions: ' + res.error.message);
6177
+ }
6178
+
6179
+ return res.result;
6180
+ });
6181
+ return res;
6182
+ }
6018
6183
  /**
6019
6184
  * Fetch a list of Transactions and transaction statuses from the cluster
6020
6185
  * for a confirmed block.
@@ -6024,18 +6189,39 @@ class Connection {
6024
6189
 
6025
6190
 
6026
6191
  async getConfirmedBlock(slot, commitment) {
6027
- const result = await this.getBlock(slot, {
6028
- commitment
6029
- });
6192
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment);
6193
+
6194
+ const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6195
+ const res = create(unsafeRes, GetConfirmedBlockRpcResult);
6196
+
6197
+ if ('error' in res) {
6198
+ throw new Error('failed to get confirmed block: ' + res.error.message);
6199
+ }
6200
+
6201
+ const result = res.result;
6030
6202
 
6031
6203
  if (!result) {
6032
6204
  throw new Error('Confirmed block ' + slot + ' not found');
6033
6205
  }
6034
6206
 
6035
- return { ...result,
6207
+ const block = { ...result,
6036
6208
  transactions: result.transactions.map(({
6037
6209
  transaction,
6038
6210
  meta
6211
+ }) => {
6212
+ const message = new Message(transaction.message);
6213
+ return {
6214
+ meta,
6215
+ transaction: { ...transaction,
6216
+ message
6217
+ }
6218
+ };
6219
+ })
6220
+ };
6221
+ return { ...block,
6222
+ transactions: block.transactions.map(({
6223
+ transaction,
6224
+ meta
6039
6225
  }) => {
6040
6226
  return {
6041
6227
  meta,
@@ -6052,7 +6238,7 @@ class Connection {
6052
6238
  async getBlocks(startSlot, endSlot, commitment) {
6053
6239
  const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
6054
6240
 
6055
- const unsafeRes = await this._rpcRequest('getConfirmedBlocks', args);
6241
+ const unsafeRes = await this._rpcRequest('getBlocks', args);
6056
6242
  const res = create(unsafeRes, jsonRpcResult(array(number())));
6057
6243
 
6058
6244
  if ('error' in res) {
@@ -6061,8 +6247,36 @@ class Connection {
6061
6247
 
6062
6248
  return res.result;
6063
6249
  }
6250
+ /**
6251
+ * Fetch a list of Signatures from the cluster for a block, excluding rewards
6252
+ */
6253
+
6254
+
6255
+ async getBlockSignatures(slot, commitment) {
6256
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
6257
+ transactionDetails: 'signatures',
6258
+ rewards: false
6259
+ });
6260
+
6261
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6262
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
6263
+
6264
+ if ('error' in res) {
6265
+ throw new Error('failed to get block: ' + res.error.message);
6266
+ }
6267
+
6268
+ const result = res.result;
6269
+
6270
+ if (!result) {
6271
+ throw new Error('Block ' + slot + ' not found');
6272
+ }
6273
+
6274
+ return result;
6275
+ }
6064
6276
  /**
6065
6277
  * Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
6278
+ *
6279
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
6066
6280
  */
6067
6281
 
6068
6282
 
@@ -6073,7 +6287,7 @@ class Connection {
6073
6287
  });
6074
6288
 
6075
6289
  const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6076
- const res = create(unsafeRes, GetConfirmedBlockSignaturesRpcResult);
6290
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
6077
6291
 
6078
6292
  if ('error' in res) {
6079
6293
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -6089,24 +6303,33 @@ class Connection {
6089
6303
  }
6090
6304
  /**
6091
6305
  * Fetch a transaction details for a confirmed transaction
6306
+ *
6307
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
6092
6308
  */
6093
6309
 
6094
6310
 
6095
6311
  async getConfirmedTransaction(signature, commitment) {
6096
- const result = await this.getTransaction(signature, {
6097
- commitment
6098
- });
6312
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
6313
+
6314
+ const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6315
+ const res = create(unsafeRes, GetTransactionRpcResult);
6316
+
6317
+ if ('error' in res) {
6318
+ throw new Error('failed to get transaction: ' + res.error.message);
6319
+ }
6320
+
6321
+ const result = res.result;
6099
6322
  if (!result) return result;
6100
- const {
6101
- message,
6102
- signatures
6103
- } = result.transaction;
6323
+ const message = new Message(result.transaction.message);
6324
+ const signatures = result.transaction.signatures;
6104
6325
  return { ...result,
6105
6326
  transaction: Transaction.populate(message, signatures)
6106
6327
  };
6107
6328
  }
6108
6329
  /**
6109
6330
  * Fetch parsed transaction details for a confirmed transaction
6331
+ *
6332
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
6110
6333
  */
6111
6334
 
6112
6335
 
@@ -6114,7 +6337,7 @@ class Connection {
6114
6337
  const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6115
6338
 
6116
6339
  const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6117
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6340
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6118
6341
 
6119
6342
  if ('error' in res) {
6120
6343
  throw new Error('failed to get confirmed transaction: ' + res.error.message);
@@ -6124,6 +6347,8 @@ class Connection {
6124
6347
  }
6125
6348
  /**
6126
6349
  * Fetch parsed transaction details for a batch of confirmed transactions
6350
+ *
6351
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
6127
6352
  */
6128
6353
 
6129
6354
 
@@ -6138,7 +6363,7 @@ class Connection {
6138
6363
  });
6139
6364
  const unsafeRes = await this._rpcBatchRequest(batch);
6140
6365
  const res = unsafeRes.map(unsafeRes => {
6141
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6366
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6142
6367
 
6143
6368
  if ('error' in res) {
6144
6369
  throw new Error('failed to get confirmed transactions: ' + res.error.message);
@@ -6528,6 +6753,10 @@ class Connection {
6528
6753
  const skipPreflight = options && options.skipPreflight;
6529
6754
  const preflightCommitment = options && options.preflightCommitment || this.commitment;
6530
6755
 
6756
+ if (options && options.maxRetries) {
6757
+ config.maxRetries = options.maxRetries;
6758
+ }
6759
+
6531
6760
  if (skipPreflight) {
6532
6761
  config.skipPreflight = skipPreflight;
6533
6762
  }
@@ -6682,7 +6911,14 @@ class Connection {
6682
6911
  this._rpcWebSocketIdleTimeout = setTimeout(() => {
6683
6912
  this._rpcWebSocketIdleTimeout = null;
6684
6913
 
6685
- this._rpcWebSocket.close();
6914
+ try {
6915
+ this._rpcWebSocket.close();
6916
+ } catch (err) {
6917
+ // swallow error if socket has already been closed.
6918
+ if (err instanceof Error) {
6919
+ console.log(`Error when closing socket connection: ${err.message}`);
6920
+ }
6921
+ }
6686
6922
  }, 500);
6687
6923
  }
6688
6924
 
@@ -8395,9 +8631,10 @@ const VOTE_PROGRAM_ID = new PublicKey('Vote1111111111111111111111111111111111111
8395
8631
  *
8396
8632
  * @internal
8397
8633
  */
8398
- const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoterPubkey'), publicKey('authorizedWithdrawerPubkey'), BufferLayout.u8('commission'), BufferLayout.nu64(), // votes.length
8399
- BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('lastEpochCredits'), BufferLayout.nu64(), // epochCredits.length
8400
- BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('prevCredits')]), BufferLayout.offset(BufferLayout.u32(), -8), 'epochCredits')]);
8634
+ const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission'), BufferLayout.nu64(), // votes.length
8635
+ BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64(), // authorizedVoters.length
8636
+ BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), publicKey('authorizedVoter')]), BufferLayout.offset(BufferLayout.u32(), -8), 'authorizedVoters'), BufferLayout.struct([BufferLayout.seq(BufferLayout.struct([publicKey('authorizedPubkey'), BufferLayout.nu64('epochOfLastAuthorizedSwitch'), BufferLayout.nu64('targetEpoch')]), 32, 'buf'), BufferLayout.nu64('idx'), BufferLayout.u8('isEmpty')], 'priorVoters'), BufferLayout.nu64(), // epochCredits.length
8637
+ BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('prevCredits')]), BufferLayout.offset(BufferLayout.u32(), -8), 'epochCredits'), BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.nu64('timestamp')], 'lastTimestamp')]);
8401
8638
 
8402
8639
  /**
8403
8640
  * VoteAccount class
@@ -8408,25 +8645,23 @@ class VoteAccount {
8408
8645
  */
8409
8646
  constructor(args) {
8410
8647
  this.nodePubkey = void 0;
8411
- this.authorizedVoterPubkey = void 0;
8412
- this.authorizedWithdrawerPubkey = void 0;
8648
+ this.authorizedWithdrawer = void 0;
8413
8649
  this.commission = void 0;
8414
- this.votes = void 0;
8415
8650
  this.rootSlot = void 0;
8416
- this.epoch = void 0;
8417
- this.credits = void 0;
8418
- this.lastEpochCredits = void 0;
8651
+ this.votes = void 0;
8652
+ this.authorizedVoters = void 0;
8653
+ this.priorVoters = void 0;
8419
8654
  this.epochCredits = void 0;
8655
+ this.lastTimestamp = void 0;
8420
8656
  this.nodePubkey = args.nodePubkey;
8421
- this.authorizedVoterPubkey = args.authorizedVoterPubkey;
8422
- this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
8657
+ this.authorizedWithdrawer = args.authorizedWithdrawer;
8423
8658
  this.commission = args.commission;
8424
- this.votes = args.votes;
8425
8659
  this.rootSlot = args.rootSlot;
8426
- this.epoch = args.epoch;
8427
- this.credits = args.credits;
8428
- this.lastEpochCredits = args.lastEpochCredits;
8660
+ this.votes = args.votes;
8661
+ this.authorizedVoters = args.authorizedVoters;
8662
+ this.priorVoters = args.priorVoters;
8429
8663
  this.epochCredits = args.epochCredits;
8664
+ this.lastTimestamp = args.lastTimestamp;
8430
8665
  }
8431
8666
  /**
8432
8667
  * Deserialize VoteAccount from the account data.
@@ -8437,7 +8672,8 @@ class VoteAccount {
8437
8672
 
8438
8673
 
8439
8674
  static fromAccountData(buffer) {
8440
- const va = VoteAccountLayout.decode(toBuffer(buffer), 0);
8675
+ const versionOffset = 4;
8676
+ const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
8441
8677
  let rootSlot = va.rootSlot;
8442
8678
 
8443
8679
  if (!va.rootSlotValid) {
@@ -8446,19 +8682,292 @@ class VoteAccount {
8446
8682
 
8447
8683
  return new VoteAccount({
8448
8684
  nodePubkey: new PublicKey(va.nodePubkey),
8449
- authorizedVoterPubkey: new PublicKey(va.authorizedVoterPubkey),
8450
- authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
8685
+ authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
8451
8686
  commission: va.commission,
8452
8687
  votes: va.votes,
8453
8688
  rootSlot,
8454
- epoch: va.epoch,
8455
- credits: va.credits,
8456
- lastEpochCredits: va.lastEpochCredits,
8457
- epochCredits: va.epochCredits
8689
+ authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
8690
+ priorVoters: getPriorVoters(va.priorVoters),
8691
+ epochCredits: va.epochCredits,
8692
+ lastTimestamp: va.lastTimestamp
8693
+ });
8694
+ }
8695
+
8696
+ }
8697
+
8698
+ function parseAuthorizedVoter({
8699
+ epoch,
8700
+ authorizedVoter
8701
+ }) {
8702
+ return {
8703
+ epoch,
8704
+ authorizedVoter: new PublicKey(authorizedVoter)
8705
+ };
8706
+ }
8707
+
8708
+ function parsePriorVoters({
8709
+ authorizedPubkey,
8710
+ epochOfLastAuthorizedSwitch,
8711
+ targetEpoch
8712
+ }) {
8713
+ return {
8714
+ authorizedPubkey: new PublicKey(authorizedPubkey),
8715
+ epochOfLastAuthorizedSwitch,
8716
+ targetEpoch
8717
+ };
8718
+ }
8719
+
8720
+ function getPriorVoters({
8721
+ buf,
8722
+ idx,
8723
+ isEmpty
8724
+ }) {
8725
+ if (isEmpty) {
8726
+ return [];
8727
+ }
8728
+
8729
+ return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
8730
+ }
8731
+
8732
+ /**
8733
+ * Vote account info
8734
+ */
8735
+
8736
+ class VoteInit {
8737
+ /** [0, 100] */
8738
+ constructor(nodePubkey, authorizedVoter, authorizedWithdrawer, commission) {
8739
+ this.nodePubkey = void 0;
8740
+ this.authorizedVoter = void 0;
8741
+ this.authorizedWithdrawer = void 0;
8742
+ this.commission = void 0;
8743
+ this.nodePubkey = nodePubkey;
8744
+ this.authorizedVoter = authorizedVoter;
8745
+ this.authorizedWithdrawer = authorizedWithdrawer;
8746
+ this.commission = commission;
8747
+ }
8748
+
8749
+ }
8750
+ /**
8751
+ * Create vote account transaction params
8752
+ */
8753
+
8754
+ /**
8755
+ * Vote Instruction class
8756
+ */
8757
+ class VoteInstruction {
8758
+ /**
8759
+ * @internal
8760
+ */
8761
+ constructor() {}
8762
+ /**
8763
+ * Decode a vote instruction and retrieve the instruction type.
8764
+ */
8765
+
8766
+
8767
+ static decodeInstructionType(instruction) {
8768
+ this.checkProgramId(instruction.programId);
8769
+ const instructionTypeLayout = BufferLayout.u32('instruction');
8770
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
8771
+ let type;
8772
+
8773
+ for (const [ixType, layout] of Object.entries(VOTE_INSTRUCTION_LAYOUTS)) {
8774
+ if (layout.index == typeIndex) {
8775
+ type = ixType;
8776
+ break;
8777
+ }
8778
+ }
8779
+
8780
+ if (!type) {
8781
+ throw new Error('Instruction type incorrect; not a VoteInstruction');
8782
+ }
8783
+
8784
+ return type;
8785
+ }
8786
+ /**
8787
+ * Decode an initialize vote instruction and retrieve the instruction params.
8788
+ */
8789
+
8790
+
8791
+ static decodeInitializeAccount(instruction) {
8792
+ this.checkProgramId(instruction.programId);
8793
+ this.checkKeyLength(instruction.keys, 4);
8794
+ const {
8795
+ voteInit
8796
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.InitializeAccount, instruction.data);
8797
+ return {
8798
+ votePubkey: instruction.keys[0].pubkey,
8799
+ nodePubkey: instruction.keys[3].pubkey,
8800
+ voteInit: new VoteInit(new PublicKey(voteInit.nodePubkey), new PublicKey(voteInit.authorizedVoter), new PublicKey(voteInit.authorizedWithdrawer), voteInit.commission)
8801
+ };
8802
+ }
8803
+ /**
8804
+ * Decode a withdraw instruction and retrieve the instruction params.
8805
+ */
8806
+
8807
+
8808
+ static decodeWithdraw(instruction) {
8809
+ this.checkProgramId(instruction.programId);
8810
+ this.checkKeyLength(instruction.keys, 3);
8811
+ const {
8812
+ lamports
8813
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
8814
+ return {
8815
+ votePubkey: instruction.keys[0].pubkey,
8816
+ authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
8817
+ lamports,
8818
+ toPubkey: instruction.keys[1].pubkey
8819
+ };
8820
+ }
8821
+ /**
8822
+ * @internal
8823
+ */
8824
+
8825
+
8826
+ static checkProgramId(programId) {
8827
+ if (!programId.equals(VoteProgram.programId)) {
8828
+ throw new Error('invalid instruction; programId is not VoteProgram');
8829
+ }
8830
+ }
8831
+ /**
8832
+ * @internal
8833
+ */
8834
+
8835
+
8836
+ static checkKeyLength(keys, expectedLength) {
8837
+ if (keys.length < expectedLength) {
8838
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
8839
+ }
8840
+ }
8841
+
8842
+ }
8843
+ /**
8844
+ * An enumeration of valid VoteInstructionType's
8845
+ */
8846
+
8847
+ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
8848
+ InitializeAccount: {
8849
+ index: 0,
8850
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteInit()])
8851
+ },
8852
+ Withdraw: {
8853
+ index: 3,
8854
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
8855
+ }
8856
+ });
8857
+ /**
8858
+ * Factory class for transactions to interact with the Vote program
8859
+ */
8860
+
8861
+ class VoteProgram {
8862
+ /**
8863
+ * @internal
8864
+ */
8865
+ constructor() {}
8866
+ /**
8867
+ * Public key that identifies the Vote program
8868
+ */
8869
+
8870
+
8871
+ /**
8872
+ * Generate an Initialize instruction.
8873
+ */
8874
+ static initializeAccount(params) {
8875
+ const {
8876
+ votePubkey,
8877
+ nodePubkey,
8878
+ voteInit
8879
+ } = params;
8880
+ const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
8881
+ const data = encodeData(type, {
8882
+ voteInit: {
8883
+ nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
8884
+ authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
8885
+ authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
8886
+ commission: voteInit.commission
8887
+ }
8888
+ });
8889
+ const instructionData = {
8890
+ keys: [{
8891
+ pubkey: votePubkey,
8892
+ isSigner: false,
8893
+ isWritable: true
8894
+ }, {
8895
+ pubkey: SYSVAR_RENT_PUBKEY,
8896
+ isSigner: false,
8897
+ isWritable: false
8898
+ }, {
8899
+ pubkey: SYSVAR_CLOCK_PUBKEY,
8900
+ isSigner: false,
8901
+ isWritable: false
8902
+ }, {
8903
+ pubkey: nodePubkey,
8904
+ isSigner: true,
8905
+ isWritable: false
8906
+ }],
8907
+ programId: this.programId,
8908
+ data
8909
+ };
8910
+ return new TransactionInstruction(instructionData);
8911
+ }
8912
+ /**
8913
+ * Generate a transaction that creates a new Vote account.
8914
+ */
8915
+
8916
+
8917
+ static createAccount(params) {
8918
+ const transaction = new Transaction();
8919
+ transaction.add(SystemProgram.createAccount({
8920
+ fromPubkey: params.fromPubkey,
8921
+ newAccountPubkey: params.votePubkey,
8922
+ lamports: params.lamports,
8923
+ space: this.space,
8924
+ programId: this.programId
8925
+ }));
8926
+ return transaction.add(this.initializeAccount({
8927
+ votePubkey: params.votePubkey,
8928
+ nodePubkey: params.voteInit.nodePubkey,
8929
+ voteInit: params.voteInit
8930
+ }));
8931
+ }
8932
+ /**
8933
+ * Generate a transaction to withdraw from a Vote account.
8934
+ */
8935
+
8936
+
8937
+ static withdraw(params) {
8938
+ const {
8939
+ votePubkey,
8940
+ authorizedWithdrawerPubkey,
8941
+ lamports,
8942
+ toPubkey
8943
+ } = params;
8944
+ const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
8945
+ const data = encodeData(type, {
8946
+ lamports
8947
+ });
8948
+ const keys = [{
8949
+ pubkey: votePubkey,
8950
+ isSigner: false,
8951
+ isWritable: true
8952
+ }, {
8953
+ pubkey: toPubkey,
8954
+ isSigner: false,
8955
+ isWritable: true
8956
+ }, {
8957
+ pubkey: authorizedWithdrawerPubkey,
8958
+ isSigner: true,
8959
+ isWritable: false
8960
+ }];
8961
+ return new Transaction().add({
8962
+ keys,
8963
+ programId: this.programId,
8964
+ data
8458
8965
  });
8459
8966
  }
8460
8967
 
8461
8968
  }
8969
+ VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
8970
+ VoteProgram.space = 3731;
8462
8971
 
8463
8972
  /**
8464
8973
  * Send and confirm a raw transaction
@@ -8489,12 +8998,12 @@ const endpoint = {
8489
8998
  http: {
8490
8999
  devnet: 'http://api.devnet.solana.com',
8491
9000
  testnet: 'http://api.testnet.solana.com',
8492
- 'mainnet-beta': 'http://api.mainnet-beta.solana.com'
9001
+ 'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
8493
9002
  },
8494
9003
  https: {
8495
9004
  devnet: 'https://api.devnet.solana.com',
8496
9005
  testnet: 'https://api.testnet.solana.com',
8497
- 'mainnet-beta': 'https://api.mainnet-beta.solana.com'
9006
+ 'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
8498
9007
  }
8499
9008
  };
8500
9009
 
@@ -8523,5 +9032,5 @@ function clusterApiUrl(cluster, tls) {
8523
9032
 
8524
9033
  const LAMPORTS_PER_SOL = 1000000000;
8525
9034
 
8526
- export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9035
+ export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, 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, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
8527
9036
  //# sourceMappingURL=index.esm.js.map