@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.iife.js CHANGED
@@ -11124,6 +11124,10 @@ var solanaWeb3 = (function (exports) {
11124
11124
  toBase58() {
11125
11125
  return bs58$1.encode(this.toBytes());
11126
11126
  }
11127
+
11128
+ toJSON() {
11129
+ return this.toBase58();
11130
+ }
11127
11131
  /**
11128
11132
  * Return the byte array representation of the public key
11129
11133
  */
@@ -11313,9 +11317,9 @@ var solanaWeb3 = (function (exports) {
11313
11317
  this._keypair = void 0;
11314
11318
 
11315
11319
  if (secretKey) {
11316
- this._keypair = naclFast.exports.sign.keyPair.fromSecretKey(toBuffer(secretKey));
11320
+ this._keypair = nacl.sign.keyPair.fromSecretKey(toBuffer(secretKey));
11317
11321
  } else {
11318
- this._keypair = naclFast.exports.sign.keyPair();
11322
+ this._keypair = nacl.sign.keyPair();
11319
11323
  }
11320
11324
  }
11321
11325
  /**
@@ -14347,8 +14351,9 @@ var solanaWeb3 = (function (exports) {
14347
14351
  }); // Sort. Prioritizing first by signer, then by writable
14348
14352
 
14349
14353
  accountMetas.sort(function (x, y) {
14354
+ const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
14350
14355
  const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
14351
- const checkWritable = x.isWritable === y.isWritable ? 0 : x.isWritable ? -1 : 1;
14356
+ const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
14352
14357
  return checkSigner || checkWritable;
14353
14358
  }); // Cull duplicate account metas
14354
14359
 
@@ -14804,11 +14809,14 @@ var solanaWeb3 = (function (exports) {
14804
14809
  }
14805
14810
 
14806
14811
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
14812
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
14813
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
14807
14814
  const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
14808
14815
  const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
14809
14816
  const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
14817
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
14818
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
14810
14819
  const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
14811
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
14812
14820
 
14813
14821
  /**
14814
14822
  * Sign, send and confirm a transaction.
@@ -14824,7 +14832,8 @@ var solanaWeb3 = (function (exports) {
14824
14832
  async function sendAndConfirmTransaction(connection, transaction, signers, options) {
14825
14833
  const sendOptions = options && {
14826
14834
  skipPreflight: options.skipPreflight,
14827
- preflightCommitment: options.preflightCommitment || options.commitment
14835
+ preflightCommitment: options.preflightCommitment || options.commitment,
14836
+ maxRetries: options.maxRetries
14828
14837
  };
14829
14838
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
14830
14839
  const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
@@ -19850,16 +19859,15 @@ var solanaWeb3 = (function (exports) {
19850
19859
  let fetchWithMiddleware;
19851
19860
 
19852
19861
  if (fetchMiddleware) {
19853
- fetchWithMiddleware = (url, options) => {
19854
- return new Promise((resolve, reject) => {
19855
- fetchMiddleware(url, options, async (url, options) => {
19856
- try {
19857
- resolve(await fetch(url, options));
19858
- } catch (error) {
19859
- reject(error);
19860
- }
19861
- });
19862
+ fetchWithMiddleware = async (url, options) => {
19863
+ const modifiedFetchArgs = await new Promise((resolve, reject) => {
19864
+ try {
19865
+ fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
19866
+ } catch (error) {
19867
+ reject(error);
19868
+ }
19862
19869
  });
19870
+ return await fetch(...modifiedFetchArgs);
19863
19871
  };
19864
19872
  }
19865
19873
 
@@ -20352,6 +20360,7 @@ var solanaWeb3 = (function (exports) {
20352
20360
  const TokenBalanceResult = type({
20353
20361
  accountIndex: number(),
20354
20362
  mint: string(),
20363
+ owner: optional(string()),
20355
20364
  uiTokenAmount: TokenAmountResult
20356
20365
  });
20357
20366
  /**
@@ -20392,8 +20401,31 @@ var solanaWeb3 = (function (exports) {
20392
20401
  preTokenBalances: optional(nullable(array(TokenBalanceResult))),
20393
20402
  postTokenBalances: optional(nullable(array(TokenBalanceResult)))
20394
20403
  });
20404
+ /**
20405
+ * Expected JSON RPC response for the "getBlock" message
20406
+ */
20407
+
20408
+ const GetBlockRpcResult = jsonRpcResult(nullable(type({
20409
+ blockhash: string(),
20410
+ previousBlockhash: string(),
20411
+ parentSlot: number(),
20412
+ transactions: array(type({
20413
+ transaction: ConfirmedTransactionResult,
20414
+ meta: nullable(ConfirmedTransactionMetaResult)
20415
+ })),
20416
+ rewards: optional(array(type({
20417
+ pubkey: string(),
20418
+ lamports: number(),
20419
+ postBalance: nullable(number()),
20420
+ rewardType: nullable(string())
20421
+ }))),
20422
+ blockTime: nullable(number()),
20423
+ blockHeight: nullable(number())
20424
+ })));
20395
20425
  /**
20396
20426
  * Expected JSON RPC response for the "getConfirmedBlock" message
20427
+ *
20428
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
20397
20429
  */
20398
20430
 
20399
20431
  const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
@@ -20413,10 +20445,10 @@ var solanaWeb3 = (function (exports) {
20413
20445
  blockTime: nullable(number())
20414
20446
  })));
20415
20447
  /**
20416
- * Expected JSON RPC response for the "getConfirmedBlockSignatures" message
20448
+ * Expected JSON RPC response for the "getBlock" message
20417
20449
  */
20418
20450
 
20419
- const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
20451
+ const GetBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
20420
20452
  blockhash: string(),
20421
20453
  previousBlockhash: string(),
20422
20454
  parentSlot: number(),
@@ -20424,20 +20456,20 @@ var solanaWeb3 = (function (exports) {
20424
20456
  blockTime: nullable(number())
20425
20457
  })));
20426
20458
  /**
20427
- * Expected JSON RPC response for the "getConfirmedTransaction" message
20459
+ * Expected JSON RPC response for the "getTransaction" message
20428
20460
  */
20429
20461
 
20430
- const GetConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
20462
+ const GetTransactionRpcResult = jsonRpcResult(nullable(type({
20431
20463
  slot: number(),
20432
20464
  meta: ConfirmedTransactionMetaResult,
20433
20465
  blockTime: optional(nullable(number())),
20434
20466
  transaction: ConfirmedTransactionResult
20435
20467
  })));
20436
20468
  /**
20437
- * Expected JSON RPC response for the "getConfirmedTransaction" message
20469
+ * Expected parsed JSON RPC response for the "getTransaction" message
20438
20470
  */
20439
20471
 
20440
- const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
20472
+ const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
20441
20473
  slot: number(),
20442
20474
  transaction: ParsedConfirmedTransactionResult,
20443
20475
  meta: nullable(ParsedConfirmedTransactionMetaResult),
@@ -20445,6 +20477,8 @@ var solanaWeb3 = (function (exports) {
20445
20477
  })));
20446
20478
  /**
20447
20479
  * Expected JSON RPC response for the "getRecentBlockhash" message
20480
+ *
20481
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
20448
20482
  */
20449
20483
 
20450
20484
  const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
@@ -20453,6 +20487,14 @@ var solanaWeb3 = (function (exports) {
20453
20487
  lamportsPerSignature: number()
20454
20488
  })
20455
20489
  }));
20490
+ /**
20491
+ * Expected JSON RPC response for the "getLatestBlockhash" message
20492
+ */
20493
+
20494
+ const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(type({
20495
+ blockhash: string(),
20496
+ lastValidBlockHeight: number()
20497
+ }));
20456
20498
  const PerfSampleResult = type({
20457
20499
  slot: number(),
20458
20500
  numTransactions: number(),
@@ -20955,13 +20997,25 @@ var solanaWeb3 = (function (exports) {
20955
20997
  */
20956
20998
 
20957
20999
 
20958
- async getMultipleAccountsInfo(publicKeys, commitment) {
21000
+ async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
20959
21001
  const keys = publicKeys.map(key => key.toBase58());
21002
+ let commitment;
21003
+ let encoding = 'base64';
21004
+
21005
+ if (configOrCommitment) {
21006
+ if (typeof configOrCommitment === 'string') {
21007
+ commitment = configOrCommitment;
21008
+ encoding = 'base64';
21009
+ } else {
21010
+ commitment = configOrCommitment.commitment;
21011
+ encoding = configOrCommitment.encoding || 'base64';
21012
+ }
21013
+ }
20960
21014
 
20961
- const args = this._buildArgs([keys], commitment, 'base64');
21015
+ const args = this._buildArgs([keys], commitment, encoding);
20962
21016
 
20963
21017
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
20964
- const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(AccountInfoResult))));
21018
+ const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))));
20965
21019
 
20966
21020
  if ('error' in res) {
20967
21021
  throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
@@ -21385,6 +21439,8 @@ var solanaWeb3 = (function (exports) {
21385
21439
  /**
21386
21440
  * Fetch a recent blockhash from the cluster, return with context
21387
21441
  * @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
21442
+ *
21443
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
21388
21444
  */
21389
21445
 
21390
21446
 
@@ -21420,6 +21476,8 @@ var solanaWeb3 = (function (exports) {
21420
21476
  }
21421
21477
  /**
21422
21478
  * Fetch the fee calculator for a recent blockhash from the cluster, return with context
21479
+ *
21480
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
21423
21481
  */
21424
21482
 
21425
21483
 
@@ -21442,9 +21500,34 @@ var solanaWeb3 = (function (exports) {
21442
21500
  value: value !== null ? value.feeCalculator : null
21443
21501
  };
21444
21502
  }
21503
+ /**
21504
+ * Fetch the fee for a message from the cluster, return with context
21505
+ */
21506
+
21507
+
21508
+ async getFeeForMessage(message, commitment) {
21509
+ const wireMessage = message.serialize().toString('base64');
21510
+
21511
+ const args = this._buildArgs([wireMessage], commitment);
21512
+
21513
+ const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
21514
+ const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
21515
+
21516
+ if ('error' in res) {
21517
+ throw new Error('failed to get slot: ' + res.error.message);
21518
+ }
21519
+
21520
+ if (res.result === null) {
21521
+ throw new Error('invalid blockhash');
21522
+ }
21523
+
21524
+ return res.result;
21525
+ }
21445
21526
  /**
21446
21527
  * Fetch a recent blockhash from the cluster
21447
21528
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
21529
+ *
21530
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
21448
21531
  */
21449
21532
 
21450
21533
 
@@ -21456,6 +21539,38 @@ var solanaWeb3 = (function (exports) {
21456
21539
  throw new Error('failed to get recent blockhash: ' + e);
21457
21540
  }
21458
21541
  }
21542
+ /**
21543
+ * Fetch the latest blockhash from the cluster
21544
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
21545
+ */
21546
+
21547
+
21548
+ async getLatestBlockhash(commitment) {
21549
+ try {
21550
+ const res = await this.getLatestBlockhashAndContext(commitment);
21551
+ return res.value;
21552
+ } catch (e) {
21553
+ throw new Error('failed to get recent blockhash: ' + e);
21554
+ }
21555
+ }
21556
+ /**
21557
+ * Fetch the latest blockhash from the cluster
21558
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
21559
+ */
21560
+
21561
+
21562
+ async getLatestBlockhashAndContext(commitment) {
21563
+ const args = this._buildArgs([], commitment);
21564
+
21565
+ const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
21566
+ const res = create(unsafeRes, GetLatestBlockhashRpcResult);
21567
+
21568
+ if ('error' in res) {
21569
+ throw new Error('failed to get latest blockhash: ' + res.error.message);
21570
+ }
21571
+
21572
+ return res.result;
21573
+ }
21459
21574
  /**
21460
21575
  * Fetch the node version
21461
21576
  */
@@ -21494,8 +21609,8 @@ var solanaWeb3 = (function (exports) {
21494
21609
  async getBlock(slot, opts) {
21495
21610
  const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
21496
21611
 
21497
- const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
21498
- const res = create(unsafeRes, GetConfirmedBlockRpcResult);
21612
+ const unsafeRes = await this._rpcRequest('getBlock', args);
21613
+ const res = create(unsafeRes, GetBlockRpcResult);
21499
21614
 
21500
21615
  if ('error' in res) {
21501
21616
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -21519,18 +21634,18 @@ var solanaWeb3 = (function (exports) {
21519
21634
  };
21520
21635
  }
21521
21636
  /**
21522
- * Fetch a processed transaction from the cluster.
21637
+ * Fetch a confirmed or finalized transaction from the cluster.
21523
21638
  */
21524
21639
 
21525
21640
 
21526
21641
  async getTransaction(signature, opts) {
21527
21642
  const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
21528
21643
 
21529
- const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
21530
- const res = create(unsafeRes, GetConfirmedTransactionRpcResult);
21644
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
21645
+ const res = create(unsafeRes, GetTransactionRpcResult);
21531
21646
 
21532
21647
  if ('error' in res) {
21533
- throw new Error('failed to get confirmed transaction: ' + res.error.message);
21648
+ throw new Error('failed to get transaction: ' + res.error.message);
21534
21649
  }
21535
21650
 
21536
21651
  const result = res.result;
@@ -21541,6 +21656,49 @@ var solanaWeb3 = (function (exports) {
21541
21656
  }
21542
21657
  };
21543
21658
  }
21659
+ /**
21660
+ * Fetch parsed transaction details for a confirmed or finalized transaction
21661
+ */
21662
+
21663
+
21664
+ async getParsedTransaction(signature, commitment) {
21665
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
21666
+
21667
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
21668
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
21669
+
21670
+ if ('error' in res) {
21671
+ throw new Error('failed to get transaction: ' + res.error.message);
21672
+ }
21673
+
21674
+ return res.result;
21675
+ }
21676
+ /**
21677
+ * Fetch parsed transaction details for a batch of confirmed transactions
21678
+ */
21679
+
21680
+
21681
+ async getParsedTransactions(signatures, commitment) {
21682
+ const batch = signatures.map(signature => {
21683
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
21684
+
21685
+ return {
21686
+ methodName: 'getTransaction',
21687
+ args
21688
+ };
21689
+ });
21690
+ const unsafeRes = await this._rpcBatchRequest(batch);
21691
+ const res = unsafeRes.map(unsafeRes => {
21692
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
21693
+
21694
+ if ('error' in res) {
21695
+ throw new Error('failed to get transactions: ' + res.error.message);
21696
+ }
21697
+
21698
+ return res.result;
21699
+ });
21700
+ return res;
21701
+ }
21544
21702
  /**
21545
21703
  * Fetch a list of Transactions and transaction statuses from the cluster
21546
21704
  * for a confirmed block.
@@ -21550,18 +21708,39 @@ var solanaWeb3 = (function (exports) {
21550
21708
 
21551
21709
 
21552
21710
  async getConfirmedBlock(slot, commitment) {
21553
- const result = await this.getBlock(slot, {
21554
- commitment
21555
- });
21711
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment);
21712
+
21713
+ const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
21714
+ const res = create(unsafeRes, GetConfirmedBlockRpcResult);
21715
+
21716
+ if ('error' in res) {
21717
+ throw new Error('failed to get confirmed block: ' + res.error.message);
21718
+ }
21719
+
21720
+ const result = res.result;
21556
21721
 
21557
21722
  if (!result) {
21558
21723
  throw new Error('Confirmed block ' + slot + ' not found');
21559
21724
  }
21560
21725
 
21561
- return { ...result,
21726
+ const block = { ...result,
21562
21727
  transactions: result.transactions.map(({
21563
21728
  transaction,
21564
21729
  meta
21730
+ }) => {
21731
+ const message = new Message(transaction.message);
21732
+ return {
21733
+ meta,
21734
+ transaction: { ...transaction,
21735
+ message
21736
+ }
21737
+ };
21738
+ })
21739
+ };
21740
+ return { ...block,
21741
+ transactions: block.transactions.map(({
21742
+ transaction,
21743
+ meta
21565
21744
  }) => {
21566
21745
  return {
21567
21746
  meta,
@@ -21578,7 +21757,7 @@ var solanaWeb3 = (function (exports) {
21578
21757
  async getBlocks(startSlot, endSlot, commitment) {
21579
21758
  const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
21580
21759
 
21581
- const unsafeRes = await this._rpcRequest('getConfirmedBlocks', args);
21760
+ const unsafeRes = await this._rpcRequest('getBlocks', args);
21582
21761
  const res = create(unsafeRes, jsonRpcResult(array(number())));
21583
21762
 
21584
21763
  if ('error' in res) {
@@ -21587,8 +21766,36 @@ var solanaWeb3 = (function (exports) {
21587
21766
 
21588
21767
  return res.result;
21589
21768
  }
21769
+ /**
21770
+ * Fetch a list of Signatures from the cluster for a block, excluding rewards
21771
+ */
21772
+
21773
+
21774
+ async getBlockSignatures(slot, commitment) {
21775
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
21776
+ transactionDetails: 'signatures',
21777
+ rewards: false
21778
+ });
21779
+
21780
+ const unsafeRes = await this._rpcRequest('getBlock', args);
21781
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
21782
+
21783
+ if ('error' in res) {
21784
+ throw new Error('failed to get block: ' + res.error.message);
21785
+ }
21786
+
21787
+ const result = res.result;
21788
+
21789
+ if (!result) {
21790
+ throw new Error('Block ' + slot + ' not found');
21791
+ }
21792
+
21793
+ return result;
21794
+ }
21590
21795
  /**
21591
21796
  * Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
21797
+ *
21798
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
21592
21799
  */
21593
21800
 
21594
21801
 
@@ -21599,7 +21806,7 @@ var solanaWeb3 = (function (exports) {
21599
21806
  });
21600
21807
 
21601
21808
  const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
21602
- const res = create(unsafeRes, GetConfirmedBlockSignaturesRpcResult);
21809
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
21603
21810
 
21604
21811
  if ('error' in res) {
21605
21812
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -21615,24 +21822,33 @@ var solanaWeb3 = (function (exports) {
21615
21822
  }
21616
21823
  /**
21617
21824
  * Fetch a transaction details for a confirmed transaction
21825
+ *
21826
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
21618
21827
  */
21619
21828
 
21620
21829
 
21621
21830
  async getConfirmedTransaction(signature, commitment) {
21622
- const result = await this.getTransaction(signature, {
21623
- commitment
21624
- });
21831
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
21832
+
21833
+ const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
21834
+ const res = create(unsafeRes, GetTransactionRpcResult);
21835
+
21836
+ if ('error' in res) {
21837
+ throw new Error('failed to get transaction: ' + res.error.message);
21838
+ }
21839
+
21840
+ const result = res.result;
21625
21841
  if (!result) return result;
21626
- const {
21627
- message,
21628
- signatures
21629
- } = result.transaction;
21842
+ const message = new Message(result.transaction.message);
21843
+ const signatures = result.transaction.signatures;
21630
21844
  return { ...result,
21631
21845
  transaction: Transaction.populate(message, signatures)
21632
21846
  };
21633
21847
  }
21634
21848
  /**
21635
21849
  * Fetch parsed transaction details for a confirmed transaction
21850
+ *
21851
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
21636
21852
  */
21637
21853
 
21638
21854
 
@@ -21640,7 +21856,7 @@ var solanaWeb3 = (function (exports) {
21640
21856
  const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
21641
21857
 
21642
21858
  const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
21643
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
21859
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
21644
21860
 
21645
21861
  if ('error' in res) {
21646
21862
  throw new Error('failed to get confirmed transaction: ' + res.error.message);
@@ -21650,6 +21866,8 @@ var solanaWeb3 = (function (exports) {
21650
21866
  }
21651
21867
  /**
21652
21868
  * Fetch parsed transaction details for a batch of confirmed transactions
21869
+ *
21870
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
21653
21871
  */
21654
21872
 
21655
21873
 
@@ -21664,7 +21882,7 @@ var solanaWeb3 = (function (exports) {
21664
21882
  });
21665
21883
  const unsafeRes = await this._rpcBatchRequest(batch);
21666
21884
  const res = unsafeRes.map(unsafeRes => {
21667
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
21885
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
21668
21886
 
21669
21887
  if ('error' in res) {
21670
21888
  throw new Error('failed to get confirmed transactions: ' + res.error.message);
@@ -22054,6 +22272,10 @@ var solanaWeb3 = (function (exports) {
22054
22272
  const skipPreflight = options && options.skipPreflight;
22055
22273
  const preflightCommitment = options && options.preflightCommitment || this.commitment;
22056
22274
 
22275
+ if (options && options.maxRetries) {
22276
+ config.maxRetries = options.maxRetries;
22277
+ }
22278
+
22057
22279
  if (skipPreflight) {
22058
22280
  config.skipPreflight = skipPreflight;
22059
22281
  }
@@ -22208,7 +22430,14 @@ var solanaWeb3 = (function (exports) {
22208
22430
  this._rpcWebSocketIdleTimeout = setTimeout(() => {
22209
22431
  this._rpcWebSocketIdleTimeout = null;
22210
22432
 
22211
- this._rpcWebSocket.close();
22433
+ try {
22434
+ this._rpcWebSocket.close();
22435
+ } catch (err) {
22436
+ // swallow error if socket has already been closed.
22437
+ if (err instanceof Error) {
22438
+ console.log(`Error when closing socket connection: ${err.message}`);
22439
+ }
22440
+ }
22212
22441
  }, 500);
22213
22442
  }
22214
22443
 
@@ -22779,7 +23008,7 @@ var solanaWeb3 = (function (exports) {
22779
23008
  if (keypair) {
22780
23009
  this._keypair = keypair;
22781
23010
  } else {
22782
- this._keypair = naclFast.exports.sign.keyPair();
23011
+ this._keypair = nacl.sign.keyPair();
22783
23012
  }
22784
23013
  }
22785
23014
  /**
@@ -22788,7 +23017,7 @@ var solanaWeb3 = (function (exports) {
22788
23017
 
22789
23018
 
22790
23019
  static generate() {
22791
- return new Keypair(naclFast.exports.sign.keyPair());
23020
+ return new Keypair(nacl.sign.keyPair());
22792
23021
  }
22793
23022
  /**
22794
23023
  * Create a keypair from a raw secret key byte array.
@@ -22805,14 +23034,14 @@ var solanaWeb3 = (function (exports) {
22805
23034
 
22806
23035
 
22807
23036
  static fromSecretKey(secretKey, options) {
22808
- const keypair = naclFast.exports.sign.keyPair.fromSecretKey(secretKey);
23037
+ const keypair = nacl.sign.keyPair.fromSecretKey(secretKey);
22809
23038
 
22810
23039
  if (!options || !options.skipValidation) {
22811
23040
  const encoder = new TextEncoder();
22812
23041
  const signData = encoder.encode('@solana/web3.js-validation-v1');
22813
- const signature = naclFast.exports.sign.detached(signData, keypair.secretKey);
23042
+ const signature = nacl.sign.detached(signData, keypair.secretKey);
22814
23043
 
22815
- if (!naclFast.exports.sign.detached.verify(signData, signature, keypair.publicKey)) {
23044
+ if (!nacl.sign.detached.verify(signData, signature, keypair.publicKey)) {
22816
23045
  throw new Error('provided secretKey is invalid');
22817
23046
  }
22818
23047
  }
@@ -22827,7 +23056,7 @@ var solanaWeb3 = (function (exports) {
22827
23056
 
22828
23057
 
22829
23058
  static fromSeed(seed) {
22830
- return new Keypair(naclFast.exports.sign.keyPair.fromSeed(seed));
23059
+ return new Keypair(nacl.sign.keyPair.fromSeed(seed));
22831
23060
  }
22832
23061
  /**
22833
23062
  * The public key for this keypair
@@ -27865,7 +28094,7 @@ var solanaWeb3 = (function (exports) {
27865
28094
 
27866
28095
  var secp256k1 = elliptic;
27867
28096
 
27868
- var sha3 = {exports: {}};
28097
+ var sha3$1 = {exports: {}};
27869
28098
 
27870
28099
  /**
27871
28100
  * [js-sha3]{@link https://github.com/emn178/js-sha3}
@@ -28518,7 +28747,9 @@ var solanaWeb3 = (function (exports) {
28518
28747
  }
28519
28748
  }
28520
28749
  })();
28521
- }(sha3));
28750
+ }(sha3$1));
28751
+
28752
+ var sha3 = sha3$1.exports;
28522
28753
 
28523
28754
  const {
28524
28755
  publicKeyCreate,
@@ -28551,7 +28782,7 @@ var solanaWeb3 = (function (exports) {
28551
28782
  assert$c(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
28552
28783
 
28553
28784
  try {
28554
- return buffer.Buffer.from(sha3.exports.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
28785
+ return buffer.Buffer.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
28555
28786
  } catch (error) {
28556
28787
  throw new Error(`Error constructing Ethereum address: ${error}`);
28557
28788
  }
@@ -28649,7 +28880,7 @@ var solanaWeb3 = (function (exports) {
28649
28880
  const privateKey = toBuffer(pkey);
28650
28881
  const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
28651
28882
 
28652
- const messageHash = buffer.Buffer.from(sha3.exports.keccak_256.update(toBuffer(message)).digest());
28883
+ const messageHash = buffer.Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
28653
28884
  const {
28654
28885
  signature,
28655
28886
  recid: recoveryId
@@ -28753,9 +28984,10 @@ var solanaWeb3 = (function (exports) {
28753
28984
  *
28754
28985
  * @internal
28755
28986
  */
28756
- const VoteAccountLayout = struct([publicKey('nodePubkey'), publicKey('authorizedVoterPubkey'), publicKey('authorizedWithdrawerPubkey'), u8('commission'), nu64(), // votes.length
28757
- seq(struct([nu64('slot'), u32('confirmationCount')]), offset(u32(), -8), 'votes'), u8('rootSlotValid'), nu64('rootSlot'), nu64('epoch'), nu64('credits'), nu64('lastEpochCredits'), nu64(), // epochCredits.length
28758
- seq(struct([nu64('epoch'), nu64('credits'), nu64('prevCredits')]), offset(u32(), -8), 'epochCredits')]);
28987
+ const VoteAccountLayout = struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), u8('commission'), nu64(), // votes.length
28988
+ seq(struct([nu64('slot'), u32('confirmationCount')]), offset(u32(), -8), 'votes'), u8('rootSlotValid'), nu64('rootSlot'), nu64(), // authorizedVoters.length
28989
+ seq(struct([nu64('epoch'), publicKey('authorizedVoter')]), offset(u32(), -8), 'authorizedVoters'), struct([seq(struct([publicKey('authorizedPubkey'), nu64('epochOfLastAuthorizedSwitch'), nu64('targetEpoch')]), 32, 'buf'), nu64('idx'), u8('isEmpty')], 'priorVoters'), nu64(), // epochCredits.length
28990
+ seq(struct([nu64('epoch'), nu64('credits'), nu64('prevCredits')]), offset(u32(), -8), 'epochCredits'), struct([nu64('slot'), nu64('timestamp')], 'lastTimestamp')]);
28759
28991
 
28760
28992
  /**
28761
28993
  * VoteAccount class
@@ -28766,25 +28998,23 @@ var solanaWeb3 = (function (exports) {
28766
28998
  */
28767
28999
  constructor(args) {
28768
29000
  this.nodePubkey = void 0;
28769
- this.authorizedVoterPubkey = void 0;
28770
- this.authorizedWithdrawerPubkey = void 0;
29001
+ this.authorizedWithdrawer = void 0;
28771
29002
  this.commission = void 0;
28772
- this.votes = void 0;
28773
29003
  this.rootSlot = void 0;
28774
- this.epoch = void 0;
28775
- this.credits = void 0;
28776
- this.lastEpochCredits = void 0;
29004
+ this.votes = void 0;
29005
+ this.authorizedVoters = void 0;
29006
+ this.priorVoters = void 0;
28777
29007
  this.epochCredits = void 0;
29008
+ this.lastTimestamp = void 0;
28778
29009
  this.nodePubkey = args.nodePubkey;
28779
- this.authorizedVoterPubkey = args.authorizedVoterPubkey;
28780
- this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
29010
+ this.authorizedWithdrawer = args.authorizedWithdrawer;
28781
29011
  this.commission = args.commission;
28782
- this.votes = args.votes;
28783
29012
  this.rootSlot = args.rootSlot;
28784
- this.epoch = args.epoch;
28785
- this.credits = args.credits;
28786
- this.lastEpochCredits = args.lastEpochCredits;
29013
+ this.votes = args.votes;
29014
+ this.authorizedVoters = args.authorizedVoters;
29015
+ this.priorVoters = args.priorVoters;
28787
29016
  this.epochCredits = args.epochCredits;
29017
+ this.lastTimestamp = args.lastTimestamp;
28788
29018
  }
28789
29019
  /**
28790
29020
  * Deserialize VoteAccount from the account data.
@@ -28795,7 +29025,8 @@ var solanaWeb3 = (function (exports) {
28795
29025
 
28796
29026
 
28797
29027
  static fromAccountData(buffer) {
28798
- const va = VoteAccountLayout.decode(toBuffer(buffer), 0);
29028
+ const versionOffset = 4;
29029
+ const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
28799
29030
  let rootSlot = va.rootSlot;
28800
29031
 
28801
29032
  if (!va.rootSlotValid) {
@@ -28804,20 +29035,53 @@ var solanaWeb3 = (function (exports) {
28804
29035
 
28805
29036
  return new VoteAccount({
28806
29037
  nodePubkey: new PublicKey(va.nodePubkey),
28807
- authorizedVoterPubkey: new PublicKey(va.authorizedVoterPubkey),
28808
- authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
29038
+ authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
28809
29039
  commission: va.commission,
28810
29040
  votes: va.votes,
28811
29041
  rootSlot,
28812
- epoch: va.epoch,
28813
- credits: va.credits,
28814
- lastEpochCredits: va.lastEpochCredits,
28815
- epochCredits: va.epochCredits
29042
+ authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
29043
+ priorVoters: getPriorVoters(va.priorVoters),
29044
+ epochCredits: va.epochCredits,
29045
+ lastTimestamp: va.lastTimestamp
28816
29046
  });
28817
29047
  }
28818
29048
 
28819
29049
  }
28820
29050
 
29051
+ function parseAuthorizedVoter({
29052
+ epoch,
29053
+ authorizedVoter
29054
+ }) {
29055
+ return {
29056
+ epoch,
29057
+ authorizedVoter: new PublicKey(authorizedVoter)
29058
+ };
29059
+ }
29060
+
29061
+ function parsePriorVoters({
29062
+ authorizedPubkey,
29063
+ epochOfLastAuthorizedSwitch,
29064
+ targetEpoch
29065
+ }) {
29066
+ return {
29067
+ authorizedPubkey: new PublicKey(authorizedPubkey),
29068
+ epochOfLastAuthorizedSwitch,
29069
+ targetEpoch
29070
+ };
29071
+ }
29072
+
29073
+ function getPriorVoters({
29074
+ buf,
29075
+ idx,
29076
+ isEmpty
29077
+ }) {
29078
+ if (isEmpty) {
29079
+ return [];
29080
+ }
29081
+
29082
+ return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
29083
+ }
29084
+
28821
29085
  /**
28822
29086
  * Send and confirm a raw transaction
28823
29087
  *
@@ -28847,12 +29111,12 @@ var solanaWeb3 = (function (exports) {
28847
29111
  http: {
28848
29112
  devnet: 'http://api.devnet.solana.com',
28849
29113
  testnet: 'http://api.testnet.solana.com',
28850
- 'mainnet-beta': 'http://api.mainnet-beta.solana.com'
29114
+ 'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
28851
29115
  },
28852
29116
  https: {
28853
29117
  devnet: 'https://api.devnet.solana.com',
28854
29118
  testnet: 'https://api.testnet.solana.com',
28855
- 'mainnet-beta': 'https://api.mainnet-beta.solana.com'
29119
+ 'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
28856
29120
  }
28857
29121
  };
28858
29122
 
@@ -28907,10 +29171,13 @@ var solanaWeb3 = (function (exports) {
28907
29171
  exports.STAKE_INSTRUCTION_LAYOUTS = STAKE_INSTRUCTION_LAYOUTS;
28908
29172
  exports.SYSTEM_INSTRUCTION_LAYOUTS = SYSTEM_INSTRUCTION_LAYOUTS;
28909
29173
  exports.SYSVAR_CLOCK_PUBKEY = SYSVAR_CLOCK_PUBKEY;
29174
+ exports.SYSVAR_EPOCH_SCHEDULE_PUBKEY = SYSVAR_EPOCH_SCHEDULE_PUBKEY;
28910
29175
  exports.SYSVAR_INSTRUCTIONS_PUBKEY = SYSVAR_INSTRUCTIONS_PUBKEY;
28911
29176
  exports.SYSVAR_RECENT_BLOCKHASHES_PUBKEY = SYSVAR_RECENT_BLOCKHASHES_PUBKEY;
28912
29177
  exports.SYSVAR_RENT_PUBKEY = SYSVAR_RENT_PUBKEY;
28913
29178
  exports.SYSVAR_REWARDS_PUBKEY = SYSVAR_REWARDS_PUBKEY;
29179
+ exports.SYSVAR_SLOT_HASHES_PUBKEY = SYSVAR_SLOT_HASHES_PUBKEY;
29180
+ exports.SYSVAR_SLOT_HISTORY_PUBKEY = SYSVAR_SLOT_HISTORY_PUBKEY;
28914
29181
  exports.SYSVAR_STAKE_HISTORY_PUBKEY = SYSVAR_STAKE_HISTORY_PUBKEY;
28915
29182
  exports.Secp256k1Program = Secp256k1Program;
28916
29183
  exports.SendTransactionError = SendTransactionError;