@solana/web3.js 1.30.2 → 1.32.2

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.cjs.js CHANGED
@@ -15,7 +15,7 @@ var RpcClient = require('jayson/lib/client/browser');
15
15
  var http = require('http');
16
16
  var https = require('https');
17
17
  var secp256k1 = require('secp256k1');
18
- var jsSha3 = require('js-sha3');
18
+ var sha3 = require('js-sha3');
19
19
 
20
20
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
21
 
@@ -38,7 +38,6 @@ function _interopNamespace(e) {
38
38
  }
39
39
 
40
40
  var nacl__default = /*#__PURE__*/_interopDefaultLegacy(nacl);
41
- var nacl__namespace = /*#__PURE__*/_interopNamespace(nacl);
42
41
  var BN__default = /*#__PURE__*/_interopDefaultLegacy(BN);
43
42
  var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
44
43
  var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
@@ -47,6 +46,7 @@ var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
47
46
  var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
48
47
  var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
49
48
  var secp256k1__default = /*#__PURE__*/_interopDefaultLegacy(secp256k1);
49
+ var sha3__default = /*#__PURE__*/_interopDefaultLegacy(sha3);
50
50
 
51
51
  const toBuffer = arr => {
52
52
  if (buffer.Buffer.isBuffer(arr)) {
@@ -1840,6 +1840,10 @@ class PublicKey extends Struct {
1840
1840
  toBase58() {
1841
1841
  return bs58__default["default"].encode(this.toBytes());
1842
1842
  }
1843
+
1844
+ toJSON() {
1845
+ return this.toBase58();
1846
+ }
1843
1847
  /**
1844
1848
  * Return the byte array representation of the public key
1845
1849
  */
@@ -2029,9 +2033,9 @@ class Account {
2029
2033
  this._keypair = void 0;
2030
2034
 
2031
2035
  if (secretKey) {
2032
- this._keypair = nacl__namespace.sign.keyPair.fromSecretKey(toBuffer(secretKey));
2036
+ this._keypair = nacl__default["default"].sign.keyPair.fromSecretKey(toBuffer(secretKey));
2033
2037
  } else {
2034
- this._keypair = nacl__namespace.sign.keyPair();
2038
+ this._keypair = nacl__default["default"].sign.keyPair();
2035
2039
  }
2036
2040
  }
2037
2041
  /**
@@ -2479,8 +2483,9 @@ class Transaction {
2479
2483
  }); // Sort. Prioritizing first by signer, then by writable
2480
2484
 
2481
2485
  accountMetas.sort(function (x, y) {
2486
+ const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
2482
2487
  const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
2483
- const checkWritable = x.isWritable === y.isWritable ? 0 : x.isWritable ? -1 : 1;
2488
+ const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
2484
2489
  return checkSigner || checkWritable;
2485
2490
  }); // Cull duplicate account metas
2486
2491
 
@@ -2936,11 +2941,14 @@ class Transaction {
2936
2941
  }
2937
2942
 
2938
2943
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
2944
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
2945
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2939
2946
  const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
2940
2947
  const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
2941
2948
  const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
2949
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
2950
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2942
2951
  const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2943
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2944
2952
 
2945
2953
  /**
2946
2954
  * Sign, send and confirm a transaction.
@@ -2956,7 +2964,8 @@ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions111111111111
2956
2964
  async function sendAndConfirmTransaction(connection, transaction, signers, options) {
2957
2965
  const sendOptions = options && {
2958
2966
  skipPreflight: options.skipPreflight,
2959
- preflightCommitment: options.preflightCommitment || options.commitment
2967
+ preflightCommitment: options.preflightCommitment || options.commitment,
2968
+ maxRetries: options.maxRetries
2960
2969
  };
2961
2970
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
2962
2971
  const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
@@ -4358,16 +4367,15 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
4358
4367
  let fetchWithMiddleware;
4359
4368
 
4360
4369
  if (fetchMiddleware) {
4361
- fetchWithMiddleware = (url, options) => {
4362
- return new Promise((resolve, reject) => {
4363
- fetchMiddleware(url, options, async (url, options) => {
4364
- try {
4365
- resolve(await fetch__default["default"](url, options));
4366
- } catch (error) {
4367
- reject(error);
4368
- }
4369
- });
4370
+ fetchWithMiddleware = async (url, options) => {
4371
+ const modifiedFetchArgs = await new Promise((resolve, reject) => {
4372
+ try {
4373
+ fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
4374
+ } catch (error) {
4375
+ reject(error);
4376
+ }
4370
4377
  });
4378
+ return await fetch__default["default"](...modifiedFetchArgs);
4371
4379
  };
4372
4380
  }
4373
4381
 
@@ -4861,6 +4869,7 @@ const ParsedConfirmedTransactionResult = superstruct.type({
4861
4869
  const TokenBalanceResult = superstruct.type({
4862
4870
  accountIndex: superstruct.number(),
4863
4871
  mint: superstruct.string(),
4872
+ owner: superstruct.optional(superstruct.string()),
4864
4873
  uiTokenAmount: TokenAmountResult
4865
4874
  });
4866
4875
  /**
@@ -4901,8 +4910,31 @@ const ParsedConfirmedTransactionMetaResult = superstruct.type({
4901
4910
  preTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
4902
4911
  postTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult)))
4903
4912
  });
4913
+ /**
4914
+ * Expected JSON RPC response for the "getBlock" message
4915
+ */
4916
+
4917
+ const GetBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4918
+ blockhash: superstruct.string(),
4919
+ previousBlockhash: superstruct.string(),
4920
+ parentSlot: superstruct.number(),
4921
+ transactions: superstruct.array(superstruct.type({
4922
+ transaction: ConfirmedTransactionResult,
4923
+ meta: superstruct.nullable(ConfirmedTransactionMetaResult)
4924
+ })),
4925
+ rewards: superstruct.optional(superstruct.array(superstruct.type({
4926
+ pubkey: superstruct.string(),
4927
+ lamports: superstruct.number(),
4928
+ postBalance: superstruct.nullable(superstruct.number()),
4929
+ rewardType: superstruct.nullable(superstruct.string())
4930
+ }))),
4931
+ blockTime: superstruct.nullable(superstruct.number()),
4932
+ blockHeight: superstruct.nullable(superstruct.number())
4933
+ })));
4904
4934
  /**
4905
4935
  * Expected JSON RPC response for the "getConfirmedBlock" message
4936
+ *
4937
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
4906
4938
  */
4907
4939
 
4908
4940
  const GetConfirmedBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
@@ -4922,10 +4954,10 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruc
4922
4954
  blockTime: superstruct.nullable(superstruct.number())
4923
4955
  })));
4924
4956
  /**
4925
- * Expected JSON RPC response for the "getConfirmedBlockSignatures" message
4957
+ * Expected JSON RPC response for the "getBlock" message
4926
4958
  */
4927
4959
 
4928
- const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4960
+ const GetBlockSignaturesRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4929
4961
  blockhash: superstruct.string(),
4930
4962
  previousBlockhash: superstruct.string(),
4931
4963
  parentSlot: superstruct.number(),
@@ -4933,20 +4965,20 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(superstruct.nullable(
4933
4965
  blockTime: superstruct.nullable(superstruct.number())
4934
4966
  })));
4935
4967
  /**
4936
- * Expected JSON RPC response for the "getConfirmedTransaction" message
4968
+ * Expected JSON RPC response for the "getTransaction" message
4937
4969
  */
4938
4970
 
4939
- const GetConfirmedTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4971
+ const GetTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4940
4972
  slot: superstruct.number(),
4941
4973
  meta: ConfirmedTransactionMetaResult,
4942
4974
  blockTime: superstruct.optional(superstruct.nullable(superstruct.number())),
4943
4975
  transaction: ConfirmedTransactionResult
4944
4976
  })));
4945
4977
  /**
4946
- * Expected JSON RPC response for the "getConfirmedTransaction" message
4978
+ * Expected parsed JSON RPC response for the "getTransaction" message
4947
4979
  */
4948
4980
 
4949
- const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4981
+ const GetParsedTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
4950
4982
  slot: superstruct.number(),
4951
4983
  transaction: ParsedConfirmedTransactionResult,
4952
4984
  meta: superstruct.nullable(ParsedConfirmedTransactionMetaResult),
@@ -4954,6 +4986,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(superstruct.nullabl
4954
4986
  })));
4955
4987
  /**
4956
4988
  * Expected JSON RPC response for the "getRecentBlockhash" message
4989
+ *
4990
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
4957
4991
  */
4958
4992
 
4959
4993
  const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(superstruct.type({
@@ -4962,6 +4996,14 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(superstruc
4962
4996
  lamportsPerSignature: superstruct.number()
4963
4997
  })
4964
4998
  }));
4999
+ /**
5000
+ * Expected JSON RPC response for the "getLatestBlockhash" message
5001
+ */
5002
+
5003
+ const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(superstruct.type({
5004
+ blockhash: superstruct.string(),
5005
+ lastValidBlockHeight: superstruct.number()
5006
+ }));
4965
5007
  const PerfSampleResult = superstruct.type({
4966
5008
  slot: superstruct.number(),
4967
5009
  numTransactions: superstruct.number(),
@@ -5464,13 +5506,25 @@ class Connection {
5464
5506
  */
5465
5507
 
5466
5508
 
5467
- async getMultipleAccountsInfo(publicKeys, commitment) {
5509
+ async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
5468
5510
  const keys = publicKeys.map(key => key.toBase58());
5511
+ let commitment;
5512
+ let encoding = 'base64';
5469
5513
 
5470
- const args = this._buildArgs([keys], commitment, 'base64');
5514
+ if (configOrCommitment) {
5515
+ if (typeof configOrCommitment === 'string') {
5516
+ commitment = configOrCommitment;
5517
+ encoding = 'base64';
5518
+ } else {
5519
+ commitment = configOrCommitment.commitment;
5520
+ encoding = configOrCommitment.encoding || 'base64';
5521
+ }
5522
+ }
5523
+
5524
+ const args = this._buildArgs([keys], commitment, encoding);
5471
5525
 
5472
5526
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
5473
- const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.array(superstruct.nullable(AccountInfoResult))));
5527
+ const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.array(superstruct.nullable(ParsedAccountInfoResult))));
5474
5528
 
5475
5529
  if ('error' in res) {
5476
5530
  throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
@@ -5894,6 +5948,8 @@ class Connection {
5894
5948
  /**
5895
5949
  * Fetch a recent blockhash from the cluster, return with context
5896
5950
  * @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
5951
+ *
5952
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
5897
5953
  */
5898
5954
 
5899
5955
 
@@ -5929,6 +5985,8 @@ class Connection {
5929
5985
  }
5930
5986
  /**
5931
5987
  * Fetch the fee calculator for a recent blockhash from the cluster, return with context
5988
+ *
5989
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
5932
5990
  */
5933
5991
 
5934
5992
 
@@ -5951,9 +6009,34 @@ class Connection {
5951
6009
  value: value !== null ? value.feeCalculator : null
5952
6010
  };
5953
6011
  }
6012
+ /**
6013
+ * Fetch the fee for a message from the cluster, return with context
6014
+ */
6015
+
6016
+
6017
+ async getFeeForMessage(message, commitment) {
6018
+ const wireMessage = message.serialize().toString('base64');
6019
+
6020
+ const args = this._buildArgs([wireMessage], commitment);
6021
+
6022
+ const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
6023
+ const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.nullable(superstruct.number())));
6024
+
6025
+ if ('error' in res) {
6026
+ throw new Error('failed to get slot: ' + res.error.message);
6027
+ }
6028
+
6029
+ if (res.result === null) {
6030
+ throw new Error('invalid blockhash');
6031
+ }
6032
+
6033
+ return res.result;
6034
+ }
5954
6035
  /**
5955
6036
  * Fetch a recent blockhash from the cluster
5956
6037
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
6038
+ *
6039
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
5957
6040
  */
5958
6041
 
5959
6042
 
@@ -5965,6 +6048,38 @@ class Connection {
5965
6048
  throw new Error('failed to get recent blockhash: ' + e);
5966
6049
  }
5967
6050
  }
6051
+ /**
6052
+ * Fetch the latest blockhash from the cluster
6053
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6054
+ */
6055
+
6056
+
6057
+ async getLatestBlockhash(commitment) {
6058
+ try {
6059
+ const res = await this.getLatestBlockhashAndContext(commitment);
6060
+ return res.value;
6061
+ } catch (e) {
6062
+ throw new Error('failed to get recent blockhash: ' + e);
6063
+ }
6064
+ }
6065
+ /**
6066
+ * Fetch the latest blockhash from the cluster
6067
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6068
+ */
6069
+
6070
+
6071
+ async getLatestBlockhashAndContext(commitment) {
6072
+ const args = this._buildArgs([], commitment);
6073
+
6074
+ const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
6075
+ const res = superstruct.create(unsafeRes, GetLatestBlockhashRpcResult);
6076
+
6077
+ if ('error' in res) {
6078
+ throw new Error('failed to get latest blockhash: ' + res.error.message);
6079
+ }
6080
+
6081
+ return res.result;
6082
+ }
5968
6083
  /**
5969
6084
  * Fetch the node version
5970
6085
  */
@@ -6003,8 +6118,8 @@ class Connection {
6003
6118
  async getBlock(slot, opts) {
6004
6119
  const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
6005
6120
 
6006
- const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6007
- const res = superstruct.create(unsafeRes, GetConfirmedBlockRpcResult);
6121
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6122
+ const res = superstruct.create(unsafeRes, GetBlockRpcResult);
6008
6123
 
6009
6124
  if ('error' in res) {
6010
6125
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -6028,18 +6143,18 @@ class Connection {
6028
6143
  };
6029
6144
  }
6030
6145
  /**
6031
- * Fetch a processed transaction from the cluster.
6146
+ * Fetch a confirmed or finalized transaction from the cluster.
6032
6147
  */
6033
6148
 
6034
6149
 
6035
6150
  async getTransaction(signature, opts) {
6036
6151
  const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
6037
6152
 
6038
- const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6039
- const res = superstruct.create(unsafeRes, GetConfirmedTransactionRpcResult);
6153
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6154
+ const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
6040
6155
 
6041
6156
  if ('error' in res) {
6042
- throw new Error('failed to get confirmed transaction: ' + res.error.message);
6157
+ throw new Error('failed to get transaction: ' + res.error.message);
6043
6158
  }
6044
6159
 
6045
6160
  const result = res.result;
@@ -6050,6 +6165,49 @@ class Connection {
6050
6165
  }
6051
6166
  };
6052
6167
  }
6168
+ /**
6169
+ * Fetch parsed transaction details for a confirmed or finalized transaction
6170
+ */
6171
+
6172
+
6173
+ async getParsedTransaction(signature, commitment) {
6174
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6175
+
6176
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6177
+ const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
6178
+
6179
+ if ('error' in res) {
6180
+ throw new Error('failed to get transaction: ' + res.error.message);
6181
+ }
6182
+
6183
+ return res.result;
6184
+ }
6185
+ /**
6186
+ * Fetch parsed transaction details for a batch of confirmed transactions
6187
+ */
6188
+
6189
+
6190
+ async getParsedTransactions(signatures, commitment) {
6191
+ const batch = signatures.map(signature => {
6192
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6193
+
6194
+ return {
6195
+ methodName: 'getTransaction',
6196
+ args
6197
+ };
6198
+ });
6199
+ const unsafeRes = await this._rpcBatchRequest(batch);
6200
+ const res = unsafeRes.map(unsafeRes => {
6201
+ const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
6202
+
6203
+ if ('error' in res) {
6204
+ throw new Error('failed to get transactions: ' + res.error.message);
6205
+ }
6206
+
6207
+ return res.result;
6208
+ });
6209
+ return res;
6210
+ }
6053
6211
  /**
6054
6212
  * Fetch a list of Transactions and transaction statuses from the cluster
6055
6213
  * for a confirmed block.
@@ -6059,18 +6217,39 @@ class Connection {
6059
6217
 
6060
6218
 
6061
6219
  async getConfirmedBlock(slot, commitment) {
6062
- const result = await this.getBlock(slot, {
6063
- commitment
6064
- });
6220
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment);
6221
+
6222
+ const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6223
+ const res = superstruct.create(unsafeRes, GetConfirmedBlockRpcResult);
6224
+
6225
+ if ('error' in res) {
6226
+ throw new Error('failed to get confirmed block: ' + res.error.message);
6227
+ }
6228
+
6229
+ const result = res.result;
6065
6230
 
6066
6231
  if (!result) {
6067
6232
  throw new Error('Confirmed block ' + slot + ' not found');
6068
6233
  }
6069
6234
 
6070
- return { ...result,
6235
+ const block = { ...result,
6071
6236
  transactions: result.transactions.map(({
6072
6237
  transaction,
6073
6238
  meta
6239
+ }) => {
6240
+ const message = new Message(transaction.message);
6241
+ return {
6242
+ meta,
6243
+ transaction: { ...transaction,
6244
+ message
6245
+ }
6246
+ };
6247
+ })
6248
+ };
6249
+ return { ...block,
6250
+ transactions: block.transactions.map(({
6251
+ transaction,
6252
+ meta
6074
6253
  }) => {
6075
6254
  return {
6076
6255
  meta,
@@ -6087,7 +6266,7 @@ class Connection {
6087
6266
  async getBlocks(startSlot, endSlot, commitment) {
6088
6267
  const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
6089
6268
 
6090
- const unsafeRes = await this._rpcRequest('getConfirmedBlocks', args);
6269
+ const unsafeRes = await this._rpcRequest('getBlocks', args);
6091
6270
  const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(superstruct.number())));
6092
6271
 
6093
6272
  if ('error' in res) {
@@ -6096,8 +6275,36 @@ class Connection {
6096
6275
 
6097
6276
  return res.result;
6098
6277
  }
6278
+ /**
6279
+ * Fetch a list of Signatures from the cluster for a block, excluding rewards
6280
+ */
6281
+
6282
+
6283
+ async getBlockSignatures(slot, commitment) {
6284
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
6285
+ transactionDetails: 'signatures',
6286
+ rewards: false
6287
+ });
6288
+
6289
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6290
+ const res = superstruct.create(unsafeRes, GetBlockSignaturesRpcResult);
6291
+
6292
+ if ('error' in res) {
6293
+ throw new Error('failed to get block: ' + res.error.message);
6294
+ }
6295
+
6296
+ const result = res.result;
6297
+
6298
+ if (!result) {
6299
+ throw new Error('Block ' + slot + ' not found');
6300
+ }
6301
+
6302
+ return result;
6303
+ }
6099
6304
  /**
6100
6305
  * Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
6306
+ *
6307
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
6101
6308
  */
6102
6309
 
6103
6310
 
@@ -6108,7 +6315,7 @@ class Connection {
6108
6315
  });
6109
6316
 
6110
6317
  const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6111
- const res = superstruct.create(unsafeRes, GetConfirmedBlockSignaturesRpcResult);
6318
+ const res = superstruct.create(unsafeRes, GetBlockSignaturesRpcResult);
6112
6319
 
6113
6320
  if ('error' in res) {
6114
6321
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -6124,24 +6331,33 @@ class Connection {
6124
6331
  }
6125
6332
  /**
6126
6333
  * Fetch a transaction details for a confirmed transaction
6334
+ *
6335
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
6127
6336
  */
6128
6337
 
6129
6338
 
6130
6339
  async getConfirmedTransaction(signature, commitment) {
6131
- const result = await this.getTransaction(signature, {
6132
- commitment
6133
- });
6340
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
6341
+
6342
+ const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6343
+ const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
6344
+
6345
+ if ('error' in res) {
6346
+ throw new Error('failed to get transaction: ' + res.error.message);
6347
+ }
6348
+
6349
+ const result = res.result;
6134
6350
  if (!result) return result;
6135
- const {
6136
- message,
6137
- signatures
6138
- } = result.transaction;
6351
+ const message = new Message(result.transaction.message);
6352
+ const signatures = result.transaction.signatures;
6139
6353
  return { ...result,
6140
6354
  transaction: Transaction.populate(message, signatures)
6141
6355
  };
6142
6356
  }
6143
6357
  /**
6144
6358
  * Fetch parsed transaction details for a confirmed transaction
6359
+ *
6360
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
6145
6361
  */
6146
6362
 
6147
6363
 
@@ -6149,7 +6365,7 @@ class Connection {
6149
6365
  const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6150
6366
 
6151
6367
  const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6152
- const res = superstruct.create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6368
+ const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
6153
6369
 
6154
6370
  if ('error' in res) {
6155
6371
  throw new Error('failed to get confirmed transaction: ' + res.error.message);
@@ -6159,6 +6375,8 @@ class Connection {
6159
6375
  }
6160
6376
  /**
6161
6377
  * Fetch parsed transaction details for a batch of confirmed transactions
6378
+ *
6379
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
6162
6380
  */
6163
6381
 
6164
6382
 
@@ -6173,7 +6391,7 @@ class Connection {
6173
6391
  });
6174
6392
  const unsafeRes = await this._rpcBatchRequest(batch);
6175
6393
  const res = unsafeRes.map(unsafeRes => {
6176
- const res = superstruct.create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6394
+ const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
6177
6395
 
6178
6396
  if ('error' in res) {
6179
6397
  throw new Error('failed to get confirmed transactions: ' + res.error.message);
@@ -6563,6 +6781,10 @@ class Connection {
6563
6781
  const skipPreflight = options && options.skipPreflight;
6564
6782
  const preflightCommitment = options && options.preflightCommitment || this.commitment;
6565
6783
 
6784
+ if (options && options.maxRetries) {
6785
+ config.maxRetries = options.maxRetries;
6786
+ }
6787
+
6566
6788
  if (skipPreflight) {
6567
6789
  config.skipPreflight = skipPreflight;
6568
6790
  }
@@ -6717,7 +6939,14 @@ class Connection {
6717
6939
  this._rpcWebSocketIdleTimeout = setTimeout(() => {
6718
6940
  this._rpcWebSocketIdleTimeout = null;
6719
6941
 
6720
- this._rpcWebSocket.close();
6942
+ try {
6943
+ this._rpcWebSocket.close();
6944
+ } catch (err) {
6945
+ // swallow error if socket has already been closed.
6946
+ if (err instanceof Error) {
6947
+ console.log(`Error when closing socket connection: ${err.message}`);
6948
+ }
6949
+ }
6721
6950
  }, 500);
6722
6951
  }
6723
6952
 
@@ -7288,7 +7517,7 @@ class Keypair {
7288
7517
  if (keypair) {
7289
7518
  this._keypair = keypair;
7290
7519
  } else {
7291
- this._keypair = nacl__namespace.sign.keyPair();
7520
+ this._keypair = nacl__default["default"].sign.keyPair();
7292
7521
  }
7293
7522
  }
7294
7523
  /**
@@ -7297,7 +7526,7 @@ class Keypair {
7297
7526
 
7298
7527
 
7299
7528
  static generate() {
7300
- return new Keypair(nacl__namespace.sign.keyPair());
7529
+ return new Keypair(nacl__default["default"].sign.keyPair());
7301
7530
  }
7302
7531
  /**
7303
7532
  * Create a keypair from a raw secret key byte array.
@@ -7314,14 +7543,14 @@ class Keypair {
7314
7543
 
7315
7544
 
7316
7545
  static fromSecretKey(secretKey, options) {
7317
- const keypair = nacl__namespace.sign.keyPair.fromSecretKey(secretKey);
7546
+ const keypair = nacl__default["default"].sign.keyPair.fromSecretKey(secretKey);
7318
7547
 
7319
7548
  if (!options || !options.skipValidation) {
7320
7549
  const encoder = new TextEncoder();
7321
7550
  const signData = encoder.encode('@solana/web3.js-validation-v1');
7322
- const signature = nacl__namespace.sign.detached(signData, keypair.secretKey);
7551
+ const signature = nacl__default["default"].sign.detached(signData, keypair.secretKey);
7323
7552
 
7324
- if (!nacl__namespace.sign.detached.verify(signData, signature, keypair.publicKey)) {
7553
+ if (!nacl__default["default"].sign.detached.verify(signData, signature, keypair.publicKey)) {
7325
7554
  throw new Error('provided secretKey is invalid');
7326
7555
  }
7327
7556
  }
@@ -7336,7 +7565,7 @@ class Keypair {
7336
7565
 
7337
7566
 
7338
7567
  static fromSeed(seed) {
7339
- return new Keypair(nacl__namespace.sign.keyPair.fromSeed(seed));
7568
+ return new Keypair(nacl__default["default"].sign.keyPair.fromSeed(seed));
7340
7569
  }
7341
7570
  /**
7342
7571
  * The public key for this keypair
@@ -8228,7 +8457,7 @@ class Secp256k1Program {
8228
8457
  assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
8229
8458
 
8230
8459
  try {
8231
- return buffer.Buffer.from(jsSha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
8460
+ return buffer.Buffer.from(sha3__default["default"].keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
8232
8461
  } catch (error) {
8233
8462
  throw new Error(`Error constructing Ethereum address: ${error}`);
8234
8463
  }
@@ -8326,7 +8555,7 @@ class Secp256k1Program {
8326
8555
  const privateKey = toBuffer(pkey);
8327
8556
  const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
8328
8557
 
8329
- const messageHash = buffer.Buffer.from(jsSha3.keccak_256.update(toBuffer(message)).digest());
8558
+ const messageHash = buffer.Buffer.from(sha3__default["default"].keccak_256.update(toBuffer(message)).digest());
8330
8559
  const {
8331
8560
  signature,
8332
8561
  recid: recoveryId
@@ -8430,9 +8659,10 @@ const VOTE_PROGRAM_ID = new PublicKey('Vote1111111111111111111111111111111111111
8430
8659
  *
8431
8660
  * @internal
8432
8661
  */
8433
- const VoteAccountLayout = BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedVoterPubkey'), publicKey('authorizedWithdrawerPubkey'), BufferLayout__namespace.u8('commission'), BufferLayout__namespace.nu64(), // votes.length
8434
- BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('slot'), BufferLayout__namespace.u32('confirmationCount')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'votes'), BufferLayout__namespace.u8('rootSlotValid'), BufferLayout__namespace.nu64('rootSlot'), BufferLayout__namespace.nu64('epoch'), BufferLayout__namespace.nu64('credits'), BufferLayout__namespace.nu64('lastEpochCredits'), BufferLayout__namespace.nu64(), // epochCredits.length
8435
- BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('epoch'), BufferLayout__namespace.nu64('credits'), BufferLayout__namespace.nu64('prevCredits')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'epochCredits')]);
8662
+ const VoteAccountLayout = BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission'), BufferLayout__namespace.nu64(), // votes.length
8663
+ BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('slot'), BufferLayout__namespace.u32('confirmationCount')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'votes'), BufferLayout__namespace.u8('rootSlotValid'), BufferLayout__namespace.nu64('rootSlot'), BufferLayout__namespace.nu64(), // authorizedVoters.length
8664
+ BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('epoch'), publicKey('authorizedVoter')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'authorizedVoters'), BufferLayout__namespace.struct([BufferLayout__namespace.seq(BufferLayout__namespace.struct([publicKey('authorizedPubkey'), BufferLayout__namespace.nu64('epochOfLastAuthorizedSwitch'), BufferLayout__namespace.nu64('targetEpoch')]), 32, 'buf'), BufferLayout__namespace.nu64('idx'), BufferLayout__namespace.u8('isEmpty')], 'priorVoters'), BufferLayout__namespace.nu64(), // epochCredits.length
8665
+ BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('epoch'), BufferLayout__namespace.nu64('credits'), BufferLayout__namespace.nu64('prevCredits')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'epochCredits'), BufferLayout__namespace.struct([BufferLayout__namespace.nu64('slot'), BufferLayout__namespace.nu64('timestamp')], 'lastTimestamp')]);
8436
8666
 
8437
8667
  /**
8438
8668
  * VoteAccount class
@@ -8443,25 +8673,23 @@ class VoteAccount {
8443
8673
  */
8444
8674
  constructor(args) {
8445
8675
  this.nodePubkey = void 0;
8446
- this.authorizedVoterPubkey = void 0;
8447
- this.authorizedWithdrawerPubkey = void 0;
8676
+ this.authorizedWithdrawer = void 0;
8448
8677
  this.commission = void 0;
8449
- this.votes = void 0;
8450
8678
  this.rootSlot = void 0;
8451
- this.epoch = void 0;
8452
- this.credits = void 0;
8453
- this.lastEpochCredits = void 0;
8679
+ this.votes = void 0;
8680
+ this.authorizedVoters = void 0;
8681
+ this.priorVoters = void 0;
8454
8682
  this.epochCredits = void 0;
8683
+ this.lastTimestamp = void 0;
8455
8684
  this.nodePubkey = args.nodePubkey;
8456
- this.authorizedVoterPubkey = args.authorizedVoterPubkey;
8457
- this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
8685
+ this.authorizedWithdrawer = args.authorizedWithdrawer;
8458
8686
  this.commission = args.commission;
8459
- this.votes = args.votes;
8460
8687
  this.rootSlot = args.rootSlot;
8461
- this.epoch = args.epoch;
8462
- this.credits = args.credits;
8463
- this.lastEpochCredits = args.lastEpochCredits;
8688
+ this.votes = args.votes;
8689
+ this.authorizedVoters = args.authorizedVoters;
8690
+ this.priorVoters = args.priorVoters;
8464
8691
  this.epochCredits = args.epochCredits;
8692
+ this.lastTimestamp = args.lastTimestamp;
8465
8693
  }
8466
8694
  /**
8467
8695
  * Deserialize VoteAccount from the account data.
@@ -8472,7 +8700,8 @@ class VoteAccount {
8472
8700
 
8473
8701
 
8474
8702
  static fromAccountData(buffer) {
8475
- const va = VoteAccountLayout.decode(toBuffer(buffer), 0);
8703
+ const versionOffset = 4;
8704
+ const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
8476
8705
  let rootSlot = va.rootSlot;
8477
8706
 
8478
8707
  if (!va.rootSlotValid) {
@@ -8481,20 +8710,53 @@ class VoteAccount {
8481
8710
 
8482
8711
  return new VoteAccount({
8483
8712
  nodePubkey: new PublicKey(va.nodePubkey),
8484
- authorizedVoterPubkey: new PublicKey(va.authorizedVoterPubkey),
8485
- authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
8713
+ authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
8486
8714
  commission: va.commission,
8487
8715
  votes: va.votes,
8488
8716
  rootSlot,
8489
- epoch: va.epoch,
8490
- credits: va.credits,
8491
- lastEpochCredits: va.lastEpochCredits,
8492
- epochCredits: va.epochCredits
8717
+ authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
8718
+ priorVoters: getPriorVoters(va.priorVoters),
8719
+ epochCredits: va.epochCredits,
8720
+ lastTimestamp: va.lastTimestamp
8493
8721
  });
8494
8722
  }
8495
8723
 
8496
8724
  }
8497
8725
 
8726
+ function parseAuthorizedVoter({
8727
+ epoch,
8728
+ authorizedVoter
8729
+ }) {
8730
+ return {
8731
+ epoch,
8732
+ authorizedVoter: new PublicKey(authorizedVoter)
8733
+ };
8734
+ }
8735
+
8736
+ function parsePriorVoters({
8737
+ authorizedPubkey,
8738
+ epochOfLastAuthorizedSwitch,
8739
+ targetEpoch
8740
+ }) {
8741
+ return {
8742
+ authorizedPubkey: new PublicKey(authorizedPubkey),
8743
+ epochOfLastAuthorizedSwitch,
8744
+ targetEpoch
8745
+ };
8746
+ }
8747
+
8748
+ function getPriorVoters({
8749
+ buf,
8750
+ idx,
8751
+ isEmpty
8752
+ }) {
8753
+ if (isEmpty) {
8754
+ return [];
8755
+ }
8756
+
8757
+ return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
8758
+ }
8759
+
8498
8760
  /**
8499
8761
  * Send and confirm a raw transaction
8500
8762
  *
@@ -8524,12 +8786,12 @@ const endpoint = {
8524
8786
  http: {
8525
8787
  devnet: 'http://api.devnet.solana.com',
8526
8788
  testnet: 'http://api.testnet.solana.com',
8527
- 'mainnet-beta': 'http://api.mainnet-beta.solana.com'
8789
+ 'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
8528
8790
  },
8529
8791
  https: {
8530
8792
  devnet: 'https://api.devnet.solana.com',
8531
8793
  testnet: 'https://api.testnet.solana.com',
8532
- 'mainnet-beta': 'https://api.mainnet-beta.solana.com'
8794
+ 'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
8533
8795
  }
8534
8796
  };
8535
8797
 
@@ -8584,10 +8846,13 @@ exports.STAKE_CONFIG_ID = STAKE_CONFIG_ID;
8584
8846
  exports.STAKE_INSTRUCTION_LAYOUTS = STAKE_INSTRUCTION_LAYOUTS;
8585
8847
  exports.SYSTEM_INSTRUCTION_LAYOUTS = SYSTEM_INSTRUCTION_LAYOUTS;
8586
8848
  exports.SYSVAR_CLOCK_PUBKEY = SYSVAR_CLOCK_PUBKEY;
8849
+ exports.SYSVAR_EPOCH_SCHEDULE_PUBKEY = SYSVAR_EPOCH_SCHEDULE_PUBKEY;
8587
8850
  exports.SYSVAR_INSTRUCTIONS_PUBKEY = SYSVAR_INSTRUCTIONS_PUBKEY;
8588
8851
  exports.SYSVAR_RECENT_BLOCKHASHES_PUBKEY = SYSVAR_RECENT_BLOCKHASHES_PUBKEY;
8589
8852
  exports.SYSVAR_RENT_PUBKEY = SYSVAR_RENT_PUBKEY;
8590
8853
  exports.SYSVAR_REWARDS_PUBKEY = SYSVAR_REWARDS_PUBKEY;
8854
+ exports.SYSVAR_SLOT_HASHES_PUBKEY = SYSVAR_SLOT_HASHES_PUBKEY;
8855
+ exports.SYSVAR_SLOT_HISTORY_PUBKEY = SYSVAR_SLOT_HISTORY_PUBKEY;
8591
8856
  exports.SYSVAR_STAKE_HISTORY_PUBKEY = SYSVAR_STAKE_HISTORY_PUBKEY;
8592
8857
  exports.Secp256k1Program = Secp256k1Program;
8593
8858
  exports.SendTransactionError = SendTransactionError;