@solana/web3.js 1.32.0 → 1.34.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.
@@ -2068,6 +2068,13 @@ const authorized = (property = 'authorized') => {
2068
2068
  const lockup = (property = 'lockup') => {
2069
2069
  return BufferLayout.struct([BufferLayout.ns64('unixTimestamp'), BufferLayout.ns64('epoch'), publicKey('custodian')], property);
2070
2070
  };
2071
+ /**
2072
+ * Layout for a VoteInit object
2073
+ */
2074
+
2075
+ const voteInit = (property = 'voteInit') => {
2076
+ return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
2077
+ };
2071
2078
  function getAlloc(type, fields) {
2072
2079
  let alloc = 0;
2073
2080
  type.layout.fields.forEach(item => {
@@ -2922,7 +2929,8 @@ const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory11111111111
2922
2929
  async function sendAndConfirmTransaction(connection, transaction, signers, options) {
2923
2930
  const sendOptions = options && {
2924
2931
  skipPreflight: options.skipPreflight,
2925
- preflightCommitment: options.preflightCommitment || options.commitment
2932
+ preflightCommitment: options.preflightCommitment || options.commitment,
2933
+ maxRetries: options.maxRetries
2926
2934
  };
2927
2935
  const signature = await connection.sendTransaction(transaction, signers, sendOptions);
2928
2936
  const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
@@ -5373,8 +5381,31 @@ const ParsedConfirmedTransactionMetaResult = type({
5373
5381
  preTokenBalances: optional(nullable(array(TokenBalanceResult))),
5374
5382
  postTokenBalances: optional(nullable(array(TokenBalanceResult)))
5375
5383
  });
5384
+ /**
5385
+ * Expected JSON RPC response for the "getBlock" message
5386
+ */
5387
+
5388
+ const GetBlockRpcResult = jsonRpcResult(nullable(type({
5389
+ blockhash: string(),
5390
+ previousBlockhash: string(),
5391
+ parentSlot: number(),
5392
+ transactions: array(type({
5393
+ transaction: ConfirmedTransactionResult,
5394
+ meta: nullable(ConfirmedTransactionMetaResult)
5395
+ })),
5396
+ rewards: optional(array(type({
5397
+ pubkey: string(),
5398
+ lamports: number(),
5399
+ postBalance: nullable(number()),
5400
+ rewardType: nullable(string())
5401
+ }))),
5402
+ blockTime: nullable(number()),
5403
+ blockHeight: nullable(number())
5404
+ })));
5376
5405
  /**
5377
5406
  * Expected JSON RPC response for the "getConfirmedBlock" message
5407
+ *
5408
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
5378
5409
  */
5379
5410
 
5380
5411
  const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
@@ -5394,10 +5425,10 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
5394
5425
  blockTime: nullable(number())
5395
5426
  })));
5396
5427
  /**
5397
- * Expected JSON RPC response for the "getConfirmedBlockSignatures" message
5428
+ * Expected JSON RPC response for the "getBlock" message
5398
5429
  */
5399
5430
 
5400
- const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
5431
+ const GetBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
5401
5432
  blockhash: string(),
5402
5433
  previousBlockhash: string(),
5403
5434
  parentSlot: number(),
@@ -5405,20 +5436,20 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
5405
5436
  blockTime: nullable(number())
5406
5437
  })));
5407
5438
  /**
5408
- * Expected JSON RPC response for the "getConfirmedTransaction" message
5439
+ * Expected JSON RPC response for the "getTransaction" message
5409
5440
  */
5410
5441
 
5411
- const GetConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
5442
+ const GetTransactionRpcResult = jsonRpcResult(nullable(type({
5412
5443
  slot: number(),
5413
5444
  meta: ConfirmedTransactionMetaResult,
5414
5445
  blockTime: optional(nullable(number())),
5415
5446
  transaction: ConfirmedTransactionResult
5416
5447
  })));
5417
5448
  /**
5418
- * Expected JSON RPC response for the "getConfirmedTransaction" message
5449
+ * Expected parsed JSON RPC response for the "getTransaction" message
5419
5450
  */
5420
5451
 
5421
- const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
5452
+ const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
5422
5453
  slot: number(),
5423
5454
  transaction: ParsedConfirmedTransactionResult,
5424
5455
  meta: nullable(ParsedConfirmedTransactionMetaResult),
@@ -5426,6 +5457,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
5426
5457
  })));
5427
5458
  /**
5428
5459
  * Expected JSON RPC response for the "getRecentBlockhash" message
5460
+ *
5461
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
5429
5462
  */
5430
5463
 
5431
5464
  const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
@@ -5434,6 +5467,14 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
5434
5467
  lamportsPerSignature: number()
5435
5468
  })
5436
5469
  }));
5470
+ /**
5471
+ * Expected JSON RPC response for the "getLatestBlockhash" message
5472
+ */
5473
+
5474
+ const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(type({
5475
+ blockhash: string(),
5476
+ lastValidBlockHeight: number()
5477
+ }));
5437
5478
  const PerfSampleResult = type({
5438
5479
  slot: number(),
5439
5480
  numTransactions: number(),
@@ -6378,6 +6419,8 @@ class Connection {
6378
6419
  /**
6379
6420
  * Fetch a recent blockhash from the cluster, return with context
6380
6421
  * @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
6422
+ *
6423
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
6381
6424
  */
6382
6425
 
6383
6426
 
@@ -6413,6 +6456,8 @@ class Connection {
6413
6456
  }
6414
6457
  /**
6415
6458
  * Fetch the fee calculator for a recent blockhash from the cluster, return with context
6459
+ *
6460
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
6416
6461
  */
6417
6462
 
6418
6463
 
@@ -6461,6 +6506,8 @@ class Connection {
6461
6506
  /**
6462
6507
  * Fetch a recent blockhash from the cluster
6463
6508
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
6509
+ *
6510
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
6464
6511
  */
6465
6512
 
6466
6513
 
@@ -6472,6 +6519,38 @@ class Connection {
6472
6519
  throw new Error('failed to get recent blockhash: ' + e);
6473
6520
  }
6474
6521
  }
6522
+ /**
6523
+ * Fetch the latest blockhash from the cluster
6524
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6525
+ */
6526
+
6527
+
6528
+ async getLatestBlockhash(commitment) {
6529
+ try {
6530
+ const res = await this.getLatestBlockhashAndContext(commitment);
6531
+ return res.value;
6532
+ } catch (e) {
6533
+ throw new Error('failed to get recent blockhash: ' + e);
6534
+ }
6535
+ }
6536
+ /**
6537
+ * Fetch the latest blockhash from the cluster
6538
+ * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6539
+ */
6540
+
6541
+
6542
+ async getLatestBlockhashAndContext(commitment) {
6543
+ const args = this._buildArgs([], commitment);
6544
+
6545
+ const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
6546
+ const res = create(unsafeRes, GetLatestBlockhashRpcResult);
6547
+
6548
+ if ('error' in res) {
6549
+ throw new Error('failed to get latest blockhash: ' + res.error.message);
6550
+ }
6551
+
6552
+ return res.result;
6553
+ }
6475
6554
  /**
6476
6555
  * Fetch the node version
6477
6556
  */
@@ -6510,8 +6589,8 @@ class Connection {
6510
6589
  async getBlock(slot, opts) {
6511
6590
  const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
6512
6591
 
6513
- const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6514
- const res = create(unsafeRes, GetConfirmedBlockRpcResult);
6592
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6593
+ const res = create(unsafeRes, GetBlockRpcResult);
6515
6594
 
6516
6595
  if ('error' in res) {
6517
6596
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -6535,18 +6614,18 @@ class Connection {
6535
6614
  };
6536
6615
  }
6537
6616
  /**
6538
- * Fetch a processed transaction from the cluster.
6617
+ * Fetch a confirmed or finalized transaction from the cluster.
6539
6618
  */
6540
6619
 
6541
6620
 
6542
6621
  async getTransaction(signature, opts) {
6543
6622
  const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
6544
6623
 
6545
- const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6546
- const res = create(unsafeRes, GetConfirmedTransactionRpcResult);
6624
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6625
+ const res = create(unsafeRes, GetTransactionRpcResult);
6547
6626
 
6548
6627
  if ('error' in res) {
6549
- throw new Error('failed to get confirmed transaction: ' + res.error.message);
6628
+ throw new Error('failed to get transaction: ' + res.error.message);
6550
6629
  }
6551
6630
 
6552
6631
  const result = res.result;
@@ -6557,6 +6636,49 @@ class Connection {
6557
6636
  }
6558
6637
  };
6559
6638
  }
6639
+ /**
6640
+ * Fetch parsed transaction details for a confirmed or finalized transaction
6641
+ */
6642
+
6643
+
6644
+ async getParsedTransaction(signature, commitment) {
6645
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6646
+
6647
+ const unsafeRes = await this._rpcRequest('getTransaction', args);
6648
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6649
+
6650
+ if ('error' in res) {
6651
+ throw new Error('failed to get transaction: ' + res.error.message);
6652
+ }
6653
+
6654
+ return res.result;
6655
+ }
6656
+ /**
6657
+ * Fetch parsed transaction details for a batch of confirmed transactions
6658
+ */
6659
+
6660
+
6661
+ async getParsedTransactions(signatures, commitment) {
6662
+ const batch = signatures.map(signature => {
6663
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6664
+
6665
+ return {
6666
+ methodName: 'getTransaction',
6667
+ args
6668
+ };
6669
+ });
6670
+ const unsafeRes = await this._rpcBatchRequest(batch);
6671
+ const res = unsafeRes.map(unsafeRes => {
6672
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6673
+
6674
+ if ('error' in res) {
6675
+ throw new Error('failed to get transactions: ' + res.error.message);
6676
+ }
6677
+
6678
+ return res.result;
6679
+ });
6680
+ return res;
6681
+ }
6560
6682
  /**
6561
6683
  * Fetch a list of Transactions and transaction statuses from the cluster
6562
6684
  * for a confirmed block.
@@ -6566,18 +6688,39 @@ class Connection {
6566
6688
 
6567
6689
 
6568
6690
  async getConfirmedBlock(slot, commitment) {
6569
- const result = await this.getBlock(slot, {
6570
- commitment
6571
- });
6691
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment);
6692
+
6693
+ const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6694
+ const res = create(unsafeRes, GetConfirmedBlockRpcResult);
6695
+
6696
+ if ('error' in res) {
6697
+ throw new Error('failed to get confirmed block: ' + res.error.message);
6698
+ }
6699
+
6700
+ const result = res.result;
6572
6701
 
6573
6702
  if (!result) {
6574
6703
  throw new Error('Confirmed block ' + slot + ' not found');
6575
6704
  }
6576
6705
 
6577
- return { ...result,
6706
+ const block = { ...result,
6578
6707
  transactions: result.transactions.map(({
6579
6708
  transaction,
6580
6709
  meta
6710
+ }) => {
6711
+ const message = new Message(transaction.message);
6712
+ return {
6713
+ meta,
6714
+ transaction: { ...transaction,
6715
+ message
6716
+ }
6717
+ };
6718
+ })
6719
+ };
6720
+ return { ...block,
6721
+ transactions: block.transactions.map(({
6722
+ transaction,
6723
+ meta
6581
6724
  }) => {
6582
6725
  return {
6583
6726
  meta,
@@ -6594,7 +6737,7 @@ class Connection {
6594
6737
  async getBlocks(startSlot, endSlot, commitment) {
6595
6738
  const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
6596
6739
 
6597
- const unsafeRes = await this._rpcRequest('getConfirmedBlocks', args);
6740
+ const unsafeRes = await this._rpcRequest('getBlocks', args);
6598
6741
  const res = create(unsafeRes, jsonRpcResult(array(number())));
6599
6742
 
6600
6743
  if ('error' in res) {
@@ -6603,8 +6746,36 @@ class Connection {
6603
6746
 
6604
6747
  return res.result;
6605
6748
  }
6749
+ /**
6750
+ * Fetch a list of Signatures from the cluster for a block, excluding rewards
6751
+ */
6752
+
6753
+
6754
+ async getBlockSignatures(slot, commitment) {
6755
+ const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
6756
+ transactionDetails: 'signatures',
6757
+ rewards: false
6758
+ });
6759
+
6760
+ const unsafeRes = await this._rpcRequest('getBlock', args);
6761
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
6762
+
6763
+ if ('error' in res) {
6764
+ throw new Error('failed to get block: ' + res.error.message);
6765
+ }
6766
+
6767
+ const result = res.result;
6768
+
6769
+ if (!result) {
6770
+ throw new Error('Block ' + slot + ' not found');
6771
+ }
6772
+
6773
+ return result;
6774
+ }
6606
6775
  /**
6607
6776
  * Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
6777
+ *
6778
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
6608
6779
  */
6609
6780
 
6610
6781
 
@@ -6615,7 +6786,7 @@ class Connection {
6615
6786
  });
6616
6787
 
6617
6788
  const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
6618
- const res = create(unsafeRes, GetConfirmedBlockSignaturesRpcResult);
6789
+ const res = create(unsafeRes, GetBlockSignaturesRpcResult);
6619
6790
 
6620
6791
  if ('error' in res) {
6621
6792
  throw new Error('failed to get confirmed block: ' + res.error.message);
@@ -6631,24 +6802,33 @@ class Connection {
6631
6802
  }
6632
6803
  /**
6633
6804
  * Fetch a transaction details for a confirmed transaction
6805
+ *
6806
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
6634
6807
  */
6635
6808
 
6636
6809
 
6637
6810
  async getConfirmedTransaction(signature, commitment) {
6638
- const result = await this.getTransaction(signature, {
6639
- commitment
6640
- });
6811
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
6812
+
6813
+ const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6814
+ const res = create(unsafeRes, GetTransactionRpcResult);
6815
+
6816
+ if ('error' in res) {
6817
+ throw new Error('failed to get transaction: ' + res.error.message);
6818
+ }
6819
+
6820
+ const result = res.result;
6641
6821
  if (!result) return result;
6642
- const {
6643
- message,
6644
- signatures
6645
- } = result.transaction;
6822
+ const message = new Message(result.transaction.message);
6823
+ const signatures = result.transaction.signatures;
6646
6824
  return { ...result,
6647
6825
  transaction: Transaction.populate(message, signatures)
6648
6826
  };
6649
6827
  }
6650
6828
  /**
6651
6829
  * Fetch parsed transaction details for a confirmed transaction
6830
+ *
6831
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
6652
6832
  */
6653
6833
 
6654
6834
 
@@ -6656,7 +6836,7 @@ class Connection {
6656
6836
  const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
6657
6837
 
6658
6838
  const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
6659
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6839
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6660
6840
 
6661
6841
  if ('error' in res) {
6662
6842
  throw new Error('failed to get confirmed transaction: ' + res.error.message);
@@ -6666,6 +6846,8 @@ class Connection {
6666
6846
  }
6667
6847
  /**
6668
6848
  * Fetch parsed transaction details for a batch of confirmed transactions
6849
+ *
6850
+ * @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
6669
6851
  */
6670
6852
 
6671
6853
 
@@ -6680,7 +6862,7 @@ class Connection {
6680
6862
  });
6681
6863
  const unsafeRes = await this._rpcBatchRequest(batch);
6682
6864
  const res = unsafeRes.map(unsafeRes => {
6683
- const res = create(unsafeRes, GetParsedConfirmedTransactionRpcResult);
6865
+ const res = create(unsafeRes, GetParsedTransactionRpcResult);
6684
6866
 
6685
6867
  if ('error' in res) {
6686
6868
  throw new Error('failed to get confirmed transactions: ' + res.error.message);
@@ -7070,6 +7252,10 @@ class Connection {
7070
7252
  const skipPreflight = options && options.skipPreflight;
7071
7253
  const preflightCommitment = options && options.preflightCommitment || this.commitment;
7072
7254
 
7255
+ if (options && options.maxRetries) {
7256
+ config.maxRetries = options.maxRetries;
7257
+ }
7258
+
7073
7259
  if (skipPreflight) {
7074
7260
  config.skipPreflight = skipPreflight;
7075
7261
  }
@@ -7224,7 +7410,14 @@ class Connection {
7224
7410
  this._rpcWebSocketIdleTimeout = setTimeout(() => {
7225
7411
  this._rpcWebSocketIdleTimeout = null;
7226
7412
 
7227
- this._rpcWebSocket.close();
7413
+ try {
7414
+ this._rpcWebSocket.close();
7415
+ } catch (err) {
7416
+ // swallow error if socket has already been closed.
7417
+ if (err instanceof Error) {
7418
+ console.log(`Error when closing socket connection: ${err.message}`);
7419
+ }
7420
+ }
7228
7421
  }, 500);
7229
7422
  }
7230
7423
 
@@ -9035,6 +9228,322 @@ function getPriorVoters({
9035
9228
  return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
9036
9229
  }
9037
9230
 
9231
+ /**
9232
+ * Vote account info
9233
+ */
9234
+
9235
+ class VoteInit {
9236
+ /** [0, 100] */
9237
+ constructor(nodePubkey, authorizedVoter, authorizedWithdrawer, commission) {
9238
+ this.nodePubkey = void 0;
9239
+ this.authorizedVoter = void 0;
9240
+ this.authorizedWithdrawer = void 0;
9241
+ this.commission = void 0;
9242
+ this.nodePubkey = nodePubkey;
9243
+ this.authorizedVoter = authorizedVoter;
9244
+ this.authorizedWithdrawer = authorizedWithdrawer;
9245
+ this.commission = commission;
9246
+ }
9247
+
9248
+ }
9249
+ /**
9250
+ * Create vote account transaction params
9251
+ */
9252
+
9253
+ /**
9254
+ * Vote Instruction class
9255
+ */
9256
+ class VoteInstruction {
9257
+ /**
9258
+ * @internal
9259
+ */
9260
+ constructor() {}
9261
+ /**
9262
+ * Decode a vote instruction and retrieve the instruction type.
9263
+ */
9264
+
9265
+
9266
+ static decodeInstructionType(instruction) {
9267
+ this.checkProgramId(instruction.programId);
9268
+ const instructionTypeLayout = BufferLayout.u32('instruction');
9269
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
9270
+ let type;
9271
+
9272
+ for (const [ixType, layout] of Object.entries(VOTE_INSTRUCTION_LAYOUTS)) {
9273
+ if (layout.index == typeIndex) {
9274
+ type = ixType;
9275
+ break;
9276
+ }
9277
+ }
9278
+
9279
+ if (!type) {
9280
+ throw new Error('Instruction type incorrect; not a VoteInstruction');
9281
+ }
9282
+
9283
+ return type;
9284
+ }
9285
+ /**
9286
+ * Decode an initialize vote instruction and retrieve the instruction params.
9287
+ */
9288
+
9289
+
9290
+ static decodeInitializeAccount(instruction) {
9291
+ this.checkProgramId(instruction.programId);
9292
+ this.checkKeyLength(instruction.keys, 4);
9293
+ const {
9294
+ voteInit
9295
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.InitializeAccount, instruction.data);
9296
+ return {
9297
+ votePubkey: instruction.keys[0].pubkey,
9298
+ nodePubkey: instruction.keys[3].pubkey,
9299
+ voteInit: new VoteInit(new PublicKey(voteInit.nodePubkey), new PublicKey(voteInit.authorizedVoter), new PublicKey(voteInit.authorizedWithdrawer), voteInit.commission)
9300
+ };
9301
+ }
9302
+ /**
9303
+ * Decode an authorize instruction and retrieve the instruction params.
9304
+ */
9305
+
9306
+
9307
+ static decodeAuthorize(instruction) {
9308
+ this.checkProgramId(instruction.programId);
9309
+ this.checkKeyLength(instruction.keys, 3);
9310
+ const {
9311
+ newAuthorized,
9312
+ voteAuthorizationType
9313
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.Authorize, instruction.data);
9314
+ return {
9315
+ votePubkey: instruction.keys[0].pubkey,
9316
+ authorizedPubkey: instruction.keys[2].pubkey,
9317
+ newAuthorizedPubkey: new PublicKey(newAuthorized),
9318
+ voteAuthorizationType: {
9319
+ index: voteAuthorizationType
9320
+ }
9321
+ };
9322
+ }
9323
+ /**
9324
+ * Decode a withdraw instruction and retrieve the instruction params.
9325
+ */
9326
+
9327
+
9328
+ static decodeWithdraw(instruction) {
9329
+ this.checkProgramId(instruction.programId);
9330
+ this.checkKeyLength(instruction.keys, 3);
9331
+ const {
9332
+ lamports
9333
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
9334
+ return {
9335
+ votePubkey: instruction.keys[0].pubkey,
9336
+ authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
9337
+ lamports,
9338
+ toPubkey: instruction.keys[1].pubkey
9339
+ };
9340
+ }
9341
+ /**
9342
+ * @internal
9343
+ */
9344
+
9345
+
9346
+ static checkProgramId(programId) {
9347
+ if (!programId.equals(VoteProgram.programId)) {
9348
+ throw new Error('invalid instruction; programId is not VoteProgram');
9349
+ }
9350
+ }
9351
+ /**
9352
+ * @internal
9353
+ */
9354
+
9355
+
9356
+ static checkKeyLength(keys, expectedLength) {
9357
+ if (keys.length < expectedLength) {
9358
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
9359
+ }
9360
+ }
9361
+
9362
+ }
9363
+ /**
9364
+ * An enumeration of valid VoteInstructionType's
9365
+ */
9366
+
9367
+ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
9368
+ InitializeAccount: {
9369
+ index: 0,
9370
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteInit()])
9371
+ },
9372
+ Authorize: {
9373
+ index: 1,
9374
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), publicKey('newAuthorized'), BufferLayout.u32('voteAuthorizationType')])
9375
+ },
9376
+ Withdraw: {
9377
+ index: 3,
9378
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
9379
+ }
9380
+ });
9381
+ /**
9382
+ * VoteAuthorize type
9383
+ */
9384
+
9385
+ /**
9386
+ * An enumeration of valid VoteAuthorization layouts.
9387
+ */
9388
+ const VoteAuthorizationLayout = Object.freeze({
9389
+ Voter: {
9390
+ index: 0
9391
+ },
9392
+ Withdrawer: {
9393
+ index: 1
9394
+ }
9395
+ });
9396
+ /**
9397
+ * Factory class for transactions to interact with the Vote program
9398
+ */
9399
+
9400
+ class VoteProgram {
9401
+ /**
9402
+ * @internal
9403
+ */
9404
+ constructor() {}
9405
+ /**
9406
+ * Public key that identifies the Vote program
9407
+ */
9408
+
9409
+
9410
+ /**
9411
+ * Generate an Initialize instruction.
9412
+ */
9413
+ static initializeAccount(params) {
9414
+ const {
9415
+ votePubkey,
9416
+ nodePubkey,
9417
+ voteInit
9418
+ } = params;
9419
+ const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
9420
+ const data = encodeData(type, {
9421
+ voteInit: {
9422
+ nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
9423
+ authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
9424
+ authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
9425
+ commission: voteInit.commission
9426
+ }
9427
+ });
9428
+ const instructionData = {
9429
+ keys: [{
9430
+ pubkey: votePubkey,
9431
+ isSigner: false,
9432
+ isWritable: true
9433
+ }, {
9434
+ pubkey: SYSVAR_RENT_PUBKEY,
9435
+ isSigner: false,
9436
+ isWritable: false
9437
+ }, {
9438
+ pubkey: SYSVAR_CLOCK_PUBKEY,
9439
+ isSigner: false,
9440
+ isWritable: false
9441
+ }, {
9442
+ pubkey: nodePubkey,
9443
+ isSigner: true,
9444
+ isWritable: false
9445
+ }],
9446
+ programId: this.programId,
9447
+ data
9448
+ };
9449
+ return new TransactionInstruction(instructionData);
9450
+ }
9451
+ /**
9452
+ * Generate a transaction that creates a new Vote account.
9453
+ */
9454
+
9455
+
9456
+ static createAccount(params) {
9457
+ const transaction = new Transaction();
9458
+ transaction.add(SystemProgram.createAccount({
9459
+ fromPubkey: params.fromPubkey,
9460
+ newAccountPubkey: params.votePubkey,
9461
+ lamports: params.lamports,
9462
+ space: this.space,
9463
+ programId: this.programId
9464
+ }));
9465
+ return transaction.add(this.initializeAccount({
9466
+ votePubkey: params.votePubkey,
9467
+ nodePubkey: params.voteInit.nodePubkey,
9468
+ voteInit: params.voteInit
9469
+ }));
9470
+ }
9471
+ /**
9472
+ * Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account.
9473
+ */
9474
+
9475
+
9476
+ static authorize(params) {
9477
+ const {
9478
+ votePubkey,
9479
+ authorizedPubkey,
9480
+ newAuthorizedPubkey,
9481
+ voteAuthorizationType
9482
+ } = params;
9483
+ const type = VOTE_INSTRUCTION_LAYOUTS.Authorize;
9484
+ const data = encodeData(type, {
9485
+ newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
9486
+ voteAuthorizationType: voteAuthorizationType.index
9487
+ });
9488
+ const keys = [{
9489
+ pubkey: votePubkey,
9490
+ isSigner: false,
9491
+ isWritable: true
9492
+ }, {
9493
+ pubkey: SYSVAR_CLOCK_PUBKEY,
9494
+ isSigner: false,
9495
+ isWritable: false
9496
+ }, {
9497
+ pubkey: authorizedPubkey,
9498
+ isSigner: true,
9499
+ isWritable: false
9500
+ }];
9501
+ return new Transaction().add({
9502
+ keys,
9503
+ programId: this.programId,
9504
+ data
9505
+ });
9506
+ }
9507
+ /**
9508
+ * Generate a transaction to withdraw from a Vote account.
9509
+ */
9510
+
9511
+
9512
+ static withdraw(params) {
9513
+ const {
9514
+ votePubkey,
9515
+ authorizedWithdrawerPubkey,
9516
+ lamports,
9517
+ toPubkey
9518
+ } = params;
9519
+ const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
9520
+ const data = encodeData(type, {
9521
+ lamports
9522
+ });
9523
+ const keys = [{
9524
+ pubkey: votePubkey,
9525
+ isSigner: false,
9526
+ isWritable: true
9527
+ }, {
9528
+ pubkey: toPubkey,
9529
+ isSigner: false,
9530
+ isWritable: true
9531
+ }, {
9532
+ pubkey: authorizedWithdrawerPubkey,
9533
+ isSigner: true,
9534
+ isWritable: false
9535
+ }];
9536
+ return new Transaction().add({
9537
+ keys,
9538
+ programId: this.programId,
9539
+ data
9540
+ });
9541
+ }
9542
+
9543
+ }
9544
+ VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
9545
+ VoteProgram.space = 3731;
9546
+
9038
9547
  /**
9039
9548
  * Send and confirm a raw transaction
9040
9549
  *
@@ -9064,12 +9573,12 @@ const endpoint = {
9064
9573
  http: {
9065
9574
  devnet: 'http://api.devnet.solana.com',
9066
9575
  testnet: 'http://api.testnet.solana.com',
9067
- 'mainnet-beta': 'http://api.mainnet-beta.solana.com'
9576
+ 'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
9068
9577
  },
9069
9578
  https: {
9070
9579
  devnet: 'https://api.devnet.solana.com',
9071
9580
  testnet: 'https://api.testnet.solana.com',
9072
- 'mainnet-beta': 'https://api.mainnet-beta.solana.com'
9581
+ 'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
9073
9582
  }
9074
9583
  };
9075
9584
 
@@ -9098,5 +9607,5 @@ function clusterApiUrl(cluster, tls) {
9098
9607
 
9099
9608
  const LAMPORTS_PER_SOL = 1000000000;
9100
9609
 
9101
- 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, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9610
+ 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, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9102
9611
  //# sourceMappingURL=index.browser.esm.js.map