@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.
- package/lib/index.browser.esm.js +541 -32
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +544 -31
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +217 -7
- package/lib/index.esm.js +541 -32
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +544 -31
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/module.flow.js +259 -7
- package/package.json +1 -1
- package/src/connection.ts +259 -29
- package/src/index.ts +1 -0
- package/src/layout.ts +15 -0
- package/src/util/cluster.ts +2 -2
- package/src/util/send-and-confirm-transaction.ts +1 -0
- package/src/vote-program.ts +386 -0
package/lib/index.iife.js
CHANGED
|
@@ -13978,6 +13978,13 @@ var solanaWeb3 = (function (exports) {
|
|
|
13978
13978
|
const lockup = (property = 'lockup') => {
|
|
13979
13979
|
return struct([ns64('unixTimestamp'), ns64('epoch'), publicKey('custodian')], property);
|
|
13980
13980
|
};
|
|
13981
|
+
/**
|
|
13982
|
+
* Layout for a VoteInit object
|
|
13983
|
+
*/
|
|
13984
|
+
|
|
13985
|
+
const voteInit = (property = 'voteInit') => {
|
|
13986
|
+
return struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), u8('commission')], property);
|
|
13987
|
+
};
|
|
13981
13988
|
function getAlloc(type, fields) {
|
|
13982
13989
|
let alloc = 0;
|
|
13983
13990
|
type.layout.fields.forEach(item => {
|
|
@@ -14832,7 +14839,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
14832
14839
|
async function sendAndConfirmTransaction(connection, transaction, signers, options) {
|
|
14833
14840
|
const sendOptions = options && {
|
|
14834
14841
|
skipPreflight: options.skipPreflight,
|
|
14835
|
-
preflightCommitment: options.preflightCommitment || options.commitment
|
|
14842
|
+
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
14843
|
+
maxRetries: options.maxRetries
|
|
14836
14844
|
};
|
|
14837
14845
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
14838
14846
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
@@ -20400,8 +20408,31 @@ var solanaWeb3 = (function (exports) {
|
|
|
20400
20408
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
20401
20409
|
postTokenBalances: optional(nullable(array(TokenBalanceResult)))
|
|
20402
20410
|
});
|
|
20411
|
+
/**
|
|
20412
|
+
* Expected JSON RPC response for the "getBlock" message
|
|
20413
|
+
*/
|
|
20414
|
+
|
|
20415
|
+
const GetBlockRpcResult = jsonRpcResult(nullable(type({
|
|
20416
|
+
blockhash: string(),
|
|
20417
|
+
previousBlockhash: string(),
|
|
20418
|
+
parentSlot: number(),
|
|
20419
|
+
transactions: array(type({
|
|
20420
|
+
transaction: ConfirmedTransactionResult,
|
|
20421
|
+
meta: nullable(ConfirmedTransactionMetaResult)
|
|
20422
|
+
})),
|
|
20423
|
+
rewards: optional(array(type({
|
|
20424
|
+
pubkey: string(),
|
|
20425
|
+
lamports: number(),
|
|
20426
|
+
postBalance: nullable(number()),
|
|
20427
|
+
rewardType: nullable(string())
|
|
20428
|
+
}))),
|
|
20429
|
+
blockTime: nullable(number()),
|
|
20430
|
+
blockHeight: nullable(number())
|
|
20431
|
+
})));
|
|
20403
20432
|
/**
|
|
20404
20433
|
* Expected JSON RPC response for the "getConfirmedBlock" message
|
|
20434
|
+
*
|
|
20435
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
|
|
20405
20436
|
*/
|
|
20406
20437
|
|
|
20407
20438
|
const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
|
|
@@ -20421,10 +20452,10 @@ var solanaWeb3 = (function (exports) {
|
|
|
20421
20452
|
blockTime: nullable(number())
|
|
20422
20453
|
})));
|
|
20423
20454
|
/**
|
|
20424
|
-
* Expected JSON RPC response for the "
|
|
20455
|
+
* Expected JSON RPC response for the "getBlock" message
|
|
20425
20456
|
*/
|
|
20426
20457
|
|
|
20427
|
-
const
|
|
20458
|
+
const GetBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
|
|
20428
20459
|
blockhash: string(),
|
|
20429
20460
|
previousBlockhash: string(),
|
|
20430
20461
|
parentSlot: number(),
|
|
@@ -20432,20 +20463,20 @@ var solanaWeb3 = (function (exports) {
|
|
|
20432
20463
|
blockTime: nullable(number())
|
|
20433
20464
|
})));
|
|
20434
20465
|
/**
|
|
20435
|
-
* Expected JSON RPC response for the "
|
|
20466
|
+
* Expected JSON RPC response for the "getTransaction" message
|
|
20436
20467
|
*/
|
|
20437
20468
|
|
|
20438
|
-
const
|
|
20469
|
+
const GetTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
20439
20470
|
slot: number(),
|
|
20440
20471
|
meta: ConfirmedTransactionMetaResult,
|
|
20441
20472
|
blockTime: optional(nullable(number())),
|
|
20442
20473
|
transaction: ConfirmedTransactionResult
|
|
20443
20474
|
})));
|
|
20444
20475
|
/**
|
|
20445
|
-
* Expected JSON RPC response for the "
|
|
20476
|
+
* Expected parsed JSON RPC response for the "getTransaction" message
|
|
20446
20477
|
*/
|
|
20447
20478
|
|
|
20448
|
-
const
|
|
20479
|
+
const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
20449
20480
|
slot: number(),
|
|
20450
20481
|
transaction: ParsedConfirmedTransactionResult,
|
|
20451
20482
|
meta: nullable(ParsedConfirmedTransactionMetaResult),
|
|
@@ -20453,6 +20484,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
20453
20484
|
})));
|
|
20454
20485
|
/**
|
|
20455
20486
|
* Expected JSON RPC response for the "getRecentBlockhash" message
|
|
20487
|
+
*
|
|
20488
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
|
|
20456
20489
|
*/
|
|
20457
20490
|
|
|
20458
20491
|
const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
|
|
@@ -20461,6 +20494,14 @@ var solanaWeb3 = (function (exports) {
|
|
|
20461
20494
|
lamportsPerSignature: number()
|
|
20462
20495
|
})
|
|
20463
20496
|
}));
|
|
20497
|
+
/**
|
|
20498
|
+
* Expected JSON RPC response for the "getLatestBlockhash" message
|
|
20499
|
+
*/
|
|
20500
|
+
|
|
20501
|
+
const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(type({
|
|
20502
|
+
blockhash: string(),
|
|
20503
|
+
lastValidBlockHeight: number()
|
|
20504
|
+
}));
|
|
20464
20505
|
const PerfSampleResult = type({
|
|
20465
20506
|
slot: number(),
|
|
20466
20507
|
numTransactions: number(),
|
|
@@ -21405,6 +21446,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
21405
21446
|
/**
|
|
21406
21447
|
* Fetch a recent blockhash from the cluster, return with context
|
|
21407
21448
|
* @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
|
|
21449
|
+
*
|
|
21450
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
21408
21451
|
*/
|
|
21409
21452
|
|
|
21410
21453
|
|
|
@@ -21440,6 +21483,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
21440
21483
|
}
|
|
21441
21484
|
/**
|
|
21442
21485
|
* Fetch the fee calculator for a recent blockhash from the cluster, return with context
|
|
21486
|
+
*
|
|
21487
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
|
|
21443
21488
|
*/
|
|
21444
21489
|
|
|
21445
21490
|
|
|
@@ -21488,6 +21533,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
21488
21533
|
/**
|
|
21489
21534
|
* Fetch a recent blockhash from the cluster
|
|
21490
21535
|
* @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
|
|
21536
|
+
*
|
|
21537
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
21491
21538
|
*/
|
|
21492
21539
|
|
|
21493
21540
|
|
|
@@ -21499,6 +21546,38 @@ var solanaWeb3 = (function (exports) {
|
|
|
21499
21546
|
throw new Error('failed to get recent blockhash: ' + e);
|
|
21500
21547
|
}
|
|
21501
21548
|
}
|
|
21549
|
+
/**
|
|
21550
|
+
* Fetch the latest blockhash from the cluster
|
|
21551
|
+
* @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
|
|
21552
|
+
*/
|
|
21553
|
+
|
|
21554
|
+
|
|
21555
|
+
async getLatestBlockhash(commitment) {
|
|
21556
|
+
try {
|
|
21557
|
+
const res = await this.getLatestBlockhashAndContext(commitment);
|
|
21558
|
+
return res.value;
|
|
21559
|
+
} catch (e) {
|
|
21560
|
+
throw new Error('failed to get recent blockhash: ' + e);
|
|
21561
|
+
}
|
|
21562
|
+
}
|
|
21563
|
+
/**
|
|
21564
|
+
* Fetch the latest blockhash from the cluster
|
|
21565
|
+
* @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
|
|
21566
|
+
*/
|
|
21567
|
+
|
|
21568
|
+
|
|
21569
|
+
async getLatestBlockhashAndContext(commitment) {
|
|
21570
|
+
const args = this._buildArgs([], commitment);
|
|
21571
|
+
|
|
21572
|
+
const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
|
|
21573
|
+
const res = create(unsafeRes, GetLatestBlockhashRpcResult);
|
|
21574
|
+
|
|
21575
|
+
if ('error' in res) {
|
|
21576
|
+
throw new Error('failed to get latest blockhash: ' + res.error.message);
|
|
21577
|
+
}
|
|
21578
|
+
|
|
21579
|
+
return res.result;
|
|
21580
|
+
}
|
|
21502
21581
|
/**
|
|
21503
21582
|
* Fetch the node version
|
|
21504
21583
|
*/
|
|
@@ -21537,8 +21616,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
21537
21616
|
async getBlock(slot, opts) {
|
|
21538
21617
|
const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
|
|
21539
21618
|
|
|
21540
|
-
const unsafeRes = await this._rpcRequest('
|
|
21541
|
-
const res = create(unsafeRes,
|
|
21619
|
+
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
21620
|
+
const res = create(unsafeRes, GetBlockRpcResult);
|
|
21542
21621
|
|
|
21543
21622
|
if ('error' in res) {
|
|
21544
21623
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -21562,18 +21641,18 @@ var solanaWeb3 = (function (exports) {
|
|
|
21562
21641
|
};
|
|
21563
21642
|
}
|
|
21564
21643
|
/**
|
|
21565
|
-
* Fetch a
|
|
21644
|
+
* Fetch a confirmed or finalized transaction from the cluster.
|
|
21566
21645
|
*/
|
|
21567
21646
|
|
|
21568
21647
|
|
|
21569
21648
|
async getTransaction(signature, opts) {
|
|
21570
21649
|
const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
|
|
21571
21650
|
|
|
21572
|
-
const unsafeRes = await this._rpcRequest('
|
|
21573
|
-
const res = create(unsafeRes,
|
|
21651
|
+
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
21652
|
+
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
21574
21653
|
|
|
21575
21654
|
if ('error' in res) {
|
|
21576
|
-
throw new Error('failed to get
|
|
21655
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
21577
21656
|
}
|
|
21578
21657
|
|
|
21579
21658
|
const result = res.result;
|
|
@@ -21584,6 +21663,49 @@ var solanaWeb3 = (function (exports) {
|
|
|
21584
21663
|
}
|
|
21585
21664
|
};
|
|
21586
21665
|
}
|
|
21666
|
+
/**
|
|
21667
|
+
* Fetch parsed transaction details for a confirmed or finalized transaction
|
|
21668
|
+
*/
|
|
21669
|
+
|
|
21670
|
+
|
|
21671
|
+
async getParsedTransaction(signature, commitment) {
|
|
21672
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
21673
|
+
|
|
21674
|
+
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
21675
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
21676
|
+
|
|
21677
|
+
if ('error' in res) {
|
|
21678
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
21679
|
+
}
|
|
21680
|
+
|
|
21681
|
+
return res.result;
|
|
21682
|
+
}
|
|
21683
|
+
/**
|
|
21684
|
+
* Fetch parsed transaction details for a batch of confirmed transactions
|
|
21685
|
+
*/
|
|
21686
|
+
|
|
21687
|
+
|
|
21688
|
+
async getParsedTransactions(signatures, commitment) {
|
|
21689
|
+
const batch = signatures.map(signature => {
|
|
21690
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
21691
|
+
|
|
21692
|
+
return {
|
|
21693
|
+
methodName: 'getTransaction',
|
|
21694
|
+
args
|
|
21695
|
+
};
|
|
21696
|
+
});
|
|
21697
|
+
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
21698
|
+
const res = unsafeRes.map(unsafeRes => {
|
|
21699
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
21700
|
+
|
|
21701
|
+
if ('error' in res) {
|
|
21702
|
+
throw new Error('failed to get transactions: ' + res.error.message);
|
|
21703
|
+
}
|
|
21704
|
+
|
|
21705
|
+
return res.result;
|
|
21706
|
+
});
|
|
21707
|
+
return res;
|
|
21708
|
+
}
|
|
21587
21709
|
/**
|
|
21588
21710
|
* Fetch a list of Transactions and transaction statuses from the cluster
|
|
21589
21711
|
* for a confirmed block.
|
|
@@ -21593,18 +21715,39 @@ var solanaWeb3 = (function (exports) {
|
|
|
21593
21715
|
|
|
21594
21716
|
|
|
21595
21717
|
async getConfirmedBlock(slot, commitment) {
|
|
21596
|
-
const
|
|
21597
|
-
|
|
21598
|
-
|
|
21718
|
+
const args = this._buildArgsAtLeastConfirmed([slot], commitment);
|
|
21719
|
+
|
|
21720
|
+
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
|
|
21721
|
+
const res = create(unsafeRes, GetConfirmedBlockRpcResult);
|
|
21722
|
+
|
|
21723
|
+
if ('error' in res) {
|
|
21724
|
+
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
21725
|
+
}
|
|
21726
|
+
|
|
21727
|
+
const result = res.result;
|
|
21599
21728
|
|
|
21600
21729
|
if (!result) {
|
|
21601
21730
|
throw new Error('Confirmed block ' + slot + ' not found');
|
|
21602
21731
|
}
|
|
21603
21732
|
|
|
21604
|
-
|
|
21733
|
+
const block = { ...result,
|
|
21605
21734
|
transactions: result.transactions.map(({
|
|
21606
21735
|
transaction,
|
|
21607
21736
|
meta
|
|
21737
|
+
}) => {
|
|
21738
|
+
const message = new Message(transaction.message);
|
|
21739
|
+
return {
|
|
21740
|
+
meta,
|
|
21741
|
+
transaction: { ...transaction,
|
|
21742
|
+
message
|
|
21743
|
+
}
|
|
21744
|
+
};
|
|
21745
|
+
})
|
|
21746
|
+
};
|
|
21747
|
+
return { ...block,
|
|
21748
|
+
transactions: block.transactions.map(({
|
|
21749
|
+
transaction,
|
|
21750
|
+
meta
|
|
21608
21751
|
}) => {
|
|
21609
21752
|
return {
|
|
21610
21753
|
meta,
|
|
@@ -21621,7 +21764,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
21621
21764
|
async getBlocks(startSlot, endSlot, commitment) {
|
|
21622
21765
|
const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
|
|
21623
21766
|
|
|
21624
|
-
const unsafeRes = await this._rpcRequest('
|
|
21767
|
+
const unsafeRes = await this._rpcRequest('getBlocks', args);
|
|
21625
21768
|
const res = create(unsafeRes, jsonRpcResult(array(number())));
|
|
21626
21769
|
|
|
21627
21770
|
if ('error' in res) {
|
|
@@ -21630,8 +21773,36 @@ var solanaWeb3 = (function (exports) {
|
|
|
21630
21773
|
|
|
21631
21774
|
return res.result;
|
|
21632
21775
|
}
|
|
21776
|
+
/**
|
|
21777
|
+
* Fetch a list of Signatures from the cluster for a block, excluding rewards
|
|
21778
|
+
*/
|
|
21779
|
+
|
|
21780
|
+
|
|
21781
|
+
async getBlockSignatures(slot, commitment) {
|
|
21782
|
+
const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
|
|
21783
|
+
transactionDetails: 'signatures',
|
|
21784
|
+
rewards: false
|
|
21785
|
+
});
|
|
21786
|
+
|
|
21787
|
+
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
21788
|
+
const res = create(unsafeRes, GetBlockSignaturesRpcResult);
|
|
21789
|
+
|
|
21790
|
+
if ('error' in res) {
|
|
21791
|
+
throw new Error('failed to get block: ' + res.error.message);
|
|
21792
|
+
}
|
|
21793
|
+
|
|
21794
|
+
const result = res.result;
|
|
21795
|
+
|
|
21796
|
+
if (!result) {
|
|
21797
|
+
throw new Error('Block ' + slot + ' not found');
|
|
21798
|
+
}
|
|
21799
|
+
|
|
21800
|
+
return result;
|
|
21801
|
+
}
|
|
21633
21802
|
/**
|
|
21634
21803
|
* Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
|
|
21804
|
+
*
|
|
21805
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
|
|
21635
21806
|
*/
|
|
21636
21807
|
|
|
21637
21808
|
|
|
@@ -21642,7 +21813,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
21642
21813
|
});
|
|
21643
21814
|
|
|
21644
21815
|
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
|
|
21645
|
-
const res = create(unsafeRes,
|
|
21816
|
+
const res = create(unsafeRes, GetBlockSignaturesRpcResult);
|
|
21646
21817
|
|
|
21647
21818
|
if ('error' in res) {
|
|
21648
21819
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -21658,24 +21829,33 @@ var solanaWeb3 = (function (exports) {
|
|
|
21658
21829
|
}
|
|
21659
21830
|
/**
|
|
21660
21831
|
* Fetch a transaction details for a confirmed transaction
|
|
21832
|
+
*
|
|
21833
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
|
|
21661
21834
|
*/
|
|
21662
21835
|
|
|
21663
21836
|
|
|
21664
21837
|
async getConfirmedTransaction(signature, commitment) {
|
|
21665
|
-
const
|
|
21666
|
-
|
|
21667
|
-
|
|
21838
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment);
|
|
21839
|
+
|
|
21840
|
+
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
|
|
21841
|
+
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
21842
|
+
|
|
21843
|
+
if ('error' in res) {
|
|
21844
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
21845
|
+
}
|
|
21846
|
+
|
|
21847
|
+
const result = res.result;
|
|
21668
21848
|
if (!result) return result;
|
|
21669
|
-
const
|
|
21670
|
-
|
|
21671
|
-
signatures
|
|
21672
|
-
} = result.transaction;
|
|
21849
|
+
const message = new Message(result.transaction.message);
|
|
21850
|
+
const signatures = result.transaction.signatures;
|
|
21673
21851
|
return { ...result,
|
|
21674
21852
|
transaction: Transaction.populate(message, signatures)
|
|
21675
21853
|
};
|
|
21676
21854
|
}
|
|
21677
21855
|
/**
|
|
21678
21856
|
* Fetch parsed transaction details for a confirmed transaction
|
|
21857
|
+
*
|
|
21858
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
|
|
21679
21859
|
*/
|
|
21680
21860
|
|
|
21681
21861
|
|
|
@@ -21683,7 +21863,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
21683
21863
|
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
21684
21864
|
|
|
21685
21865
|
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
|
|
21686
|
-
const res = create(unsafeRes,
|
|
21866
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
21687
21867
|
|
|
21688
21868
|
if ('error' in res) {
|
|
21689
21869
|
throw new Error('failed to get confirmed transaction: ' + res.error.message);
|
|
@@ -21693,6 +21873,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
21693
21873
|
}
|
|
21694
21874
|
/**
|
|
21695
21875
|
* Fetch parsed transaction details for a batch of confirmed transactions
|
|
21876
|
+
*
|
|
21877
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
|
|
21696
21878
|
*/
|
|
21697
21879
|
|
|
21698
21880
|
|
|
@@ -21707,7 +21889,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
21707
21889
|
});
|
|
21708
21890
|
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
21709
21891
|
const res = unsafeRes.map(unsafeRes => {
|
|
21710
|
-
const res = create(unsafeRes,
|
|
21892
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
21711
21893
|
|
|
21712
21894
|
if ('error' in res) {
|
|
21713
21895
|
throw new Error('failed to get confirmed transactions: ' + res.error.message);
|
|
@@ -22097,6 +22279,10 @@ var solanaWeb3 = (function (exports) {
|
|
|
22097
22279
|
const skipPreflight = options && options.skipPreflight;
|
|
22098
22280
|
const preflightCommitment = options && options.preflightCommitment || this.commitment;
|
|
22099
22281
|
|
|
22282
|
+
if (options && options.maxRetries) {
|
|
22283
|
+
config.maxRetries = options.maxRetries;
|
|
22284
|
+
}
|
|
22285
|
+
|
|
22100
22286
|
if (skipPreflight) {
|
|
22101
22287
|
config.skipPreflight = skipPreflight;
|
|
22102
22288
|
}
|
|
@@ -22251,7 +22437,14 @@ var solanaWeb3 = (function (exports) {
|
|
|
22251
22437
|
this._rpcWebSocketIdleTimeout = setTimeout(() => {
|
|
22252
22438
|
this._rpcWebSocketIdleTimeout = null;
|
|
22253
22439
|
|
|
22254
|
-
|
|
22440
|
+
try {
|
|
22441
|
+
this._rpcWebSocket.close();
|
|
22442
|
+
} catch (err) {
|
|
22443
|
+
// swallow error if socket has already been closed.
|
|
22444
|
+
if (err instanceof Error) {
|
|
22445
|
+
console.log(`Error when closing socket connection: ${err.message}`);
|
|
22446
|
+
}
|
|
22447
|
+
}
|
|
22255
22448
|
}, 500);
|
|
22256
22449
|
}
|
|
22257
22450
|
|
|
@@ -28896,6 +29089,322 @@ var solanaWeb3 = (function (exports) {
|
|
|
28896
29089
|
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
28897
29090
|
}
|
|
28898
29091
|
|
|
29092
|
+
/**
|
|
29093
|
+
* Vote account info
|
|
29094
|
+
*/
|
|
29095
|
+
|
|
29096
|
+
class VoteInit {
|
|
29097
|
+
/** [0, 100] */
|
|
29098
|
+
constructor(nodePubkey, authorizedVoter, authorizedWithdrawer, commission) {
|
|
29099
|
+
this.nodePubkey = void 0;
|
|
29100
|
+
this.authorizedVoter = void 0;
|
|
29101
|
+
this.authorizedWithdrawer = void 0;
|
|
29102
|
+
this.commission = void 0;
|
|
29103
|
+
this.nodePubkey = nodePubkey;
|
|
29104
|
+
this.authorizedVoter = authorizedVoter;
|
|
29105
|
+
this.authorizedWithdrawer = authorizedWithdrawer;
|
|
29106
|
+
this.commission = commission;
|
|
29107
|
+
}
|
|
29108
|
+
|
|
29109
|
+
}
|
|
29110
|
+
/**
|
|
29111
|
+
* Create vote account transaction params
|
|
29112
|
+
*/
|
|
29113
|
+
|
|
29114
|
+
/**
|
|
29115
|
+
* Vote Instruction class
|
|
29116
|
+
*/
|
|
29117
|
+
class VoteInstruction {
|
|
29118
|
+
/**
|
|
29119
|
+
* @internal
|
|
29120
|
+
*/
|
|
29121
|
+
constructor() {}
|
|
29122
|
+
/**
|
|
29123
|
+
* Decode a vote instruction and retrieve the instruction type.
|
|
29124
|
+
*/
|
|
29125
|
+
|
|
29126
|
+
|
|
29127
|
+
static decodeInstructionType(instruction) {
|
|
29128
|
+
this.checkProgramId(instruction.programId);
|
|
29129
|
+
const instructionTypeLayout = u32('instruction');
|
|
29130
|
+
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
29131
|
+
let type;
|
|
29132
|
+
|
|
29133
|
+
for (const [ixType, layout] of Object.entries(VOTE_INSTRUCTION_LAYOUTS)) {
|
|
29134
|
+
if (layout.index == typeIndex) {
|
|
29135
|
+
type = ixType;
|
|
29136
|
+
break;
|
|
29137
|
+
}
|
|
29138
|
+
}
|
|
29139
|
+
|
|
29140
|
+
if (!type) {
|
|
29141
|
+
throw new Error('Instruction type incorrect; not a VoteInstruction');
|
|
29142
|
+
}
|
|
29143
|
+
|
|
29144
|
+
return type;
|
|
29145
|
+
}
|
|
29146
|
+
/**
|
|
29147
|
+
* Decode an initialize vote instruction and retrieve the instruction params.
|
|
29148
|
+
*/
|
|
29149
|
+
|
|
29150
|
+
|
|
29151
|
+
static decodeInitializeAccount(instruction) {
|
|
29152
|
+
this.checkProgramId(instruction.programId);
|
|
29153
|
+
this.checkKeyLength(instruction.keys, 4);
|
|
29154
|
+
const {
|
|
29155
|
+
voteInit
|
|
29156
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.InitializeAccount, instruction.data);
|
|
29157
|
+
return {
|
|
29158
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
29159
|
+
nodePubkey: instruction.keys[3].pubkey,
|
|
29160
|
+
voteInit: new VoteInit(new PublicKey(voteInit.nodePubkey), new PublicKey(voteInit.authorizedVoter), new PublicKey(voteInit.authorizedWithdrawer), voteInit.commission)
|
|
29161
|
+
};
|
|
29162
|
+
}
|
|
29163
|
+
/**
|
|
29164
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
29165
|
+
*/
|
|
29166
|
+
|
|
29167
|
+
|
|
29168
|
+
static decodeAuthorize(instruction) {
|
|
29169
|
+
this.checkProgramId(instruction.programId);
|
|
29170
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
29171
|
+
const {
|
|
29172
|
+
newAuthorized,
|
|
29173
|
+
voteAuthorizationType
|
|
29174
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.Authorize, instruction.data);
|
|
29175
|
+
return {
|
|
29176
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
29177
|
+
authorizedPubkey: instruction.keys[2].pubkey,
|
|
29178
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
29179
|
+
voteAuthorizationType: {
|
|
29180
|
+
index: voteAuthorizationType
|
|
29181
|
+
}
|
|
29182
|
+
};
|
|
29183
|
+
}
|
|
29184
|
+
/**
|
|
29185
|
+
* Decode a withdraw instruction and retrieve the instruction params.
|
|
29186
|
+
*/
|
|
29187
|
+
|
|
29188
|
+
|
|
29189
|
+
static decodeWithdraw(instruction) {
|
|
29190
|
+
this.checkProgramId(instruction.programId);
|
|
29191
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
29192
|
+
const {
|
|
29193
|
+
lamports
|
|
29194
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
|
|
29195
|
+
return {
|
|
29196
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
29197
|
+
authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
|
|
29198
|
+
lamports,
|
|
29199
|
+
toPubkey: instruction.keys[1].pubkey
|
|
29200
|
+
};
|
|
29201
|
+
}
|
|
29202
|
+
/**
|
|
29203
|
+
* @internal
|
|
29204
|
+
*/
|
|
29205
|
+
|
|
29206
|
+
|
|
29207
|
+
static checkProgramId(programId) {
|
|
29208
|
+
if (!programId.equals(VoteProgram.programId)) {
|
|
29209
|
+
throw new Error('invalid instruction; programId is not VoteProgram');
|
|
29210
|
+
}
|
|
29211
|
+
}
|
|
29212
|
+
/**
|
|
29213
|
+
* @internal
|
|
29214
|
+
*/
|
|
29215
|
+
|
|
29216
|
+
|
|
29217
|
+
static checkKeyLength(keys, expectedLength) {
|
|
29218
|
+
if (keys.length < expectedLength) {
|
|
29219
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
29220
|
+
}
|
|
29221
|
+
}
|
|
29222
|
+
|
|
29223
|
+
}
|
|
29224
|
+
/**
|
|
29225
|
+
* An enumeration of valid VoteInstructionType's
|
|
29226
|
+
*/
|
|
29227
|
+
|
|
29228
|
+
const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
29229
|
+
InitializeAccount: {
|
|
29230
|
+
index: 0,
|
|
29231
|
+
layout: struct([u32('instruction'), voteInit()])
|
|
29232
|
+
},
|
|
29233
|
+
Authorize: {
|
|
29234
|
+
index: 1,
|
|
29235
|
+
layout: struct([u32('instruction'), publicKey('newAuthorized'), u32('voteAuthorizationType')])
|
|
29236
|
+
},
|
|
29237
|
+
Withdraw: {
|
|
29238
|
+
index: 3,
|
|
29239
|
+
layout: struct([u32('instruction'), ns64('lamports')])
|
|
29240
|
+
}
|
|
29241
|
+
});
|
|
29242
|
+
/**
|
|
29243
|
+
* VoteAuthorize type
|
|
29244
|
+
*/
|
|
29245
|
+
|
|
29246
|
+
/**
|
|
29247
|
+
* An enumeration of valid VoteAuthorization layouts.
|
|
29248
|
+
*/
|
|
29249
|
+
const VoteAuthorizationLayout = Object.freeze({
|
|
29250
|
+
Voter: {
|
|
29251
|
+
index: 0
|
|
29252
|
+
},
|
|
29253
|
+
Withdrawer: {
|
|
29254
|
+
index: 1
|
|
29255
|
+
}
|
|
29256
|
+
});
|
|
29257
|
+
/**
|
|
29258
|
+
* Factory class for transactions to interact with the Vote program
|
|
29259
|
+
*/
|
|
29260
|
+
|
|
29261
|
+
class VoteProgram {
|
|
29262
|
+
/**
|
|
29263
|
+
* @internal
|
|
29264
|
+
*/
|
|
29265
|
+
constructor() {}
|
|
29266
|
+
/**
|
|
29267
|
+
* Public key that identifies the Vote program
|
|
29268
|
+
*/
|
|
29269
|
+
|
|
29270
|
+
|
|
29271
|
+
/**
|
|
29272
|
+
* Generate an Initialize instruction.
|
|
29273
|
+
*/
|
|
29274
|
+
static initializeAccount(params) {
|
|
29275
|
+
const {
|
|
29276
|
+
votePubkey,
|
|
29277
|
+
nodePubkey,
|
|
29278
|
+
voteInit
|
|
29279
|
+
} = params;
|
|
29280
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
|
|
29281
|
+
const data = encodeData(type, {
|
|
29282
|
+
voteInit: {
|
|
29283
|
+
nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
|
|
29284
|
+
authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
|
|
29285
|
+
authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
|
|
29286
|
+
commission: voteInit.commission
|
|
29287
|
+
}
|
|
29288
|
+
});
|
|
29289
|
+
const instructionData = {
|
|
29290
|
+
keys: [{
|
|
29291
|
+
pubkey: votePubkey,
|
|
29292
|
+
isSigner: false,
|
|
29293
|
+
isWritable: true
|
|
29294
|
+
}, {
|
|
29295
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
29296
|
+
isSigner: false,
|
|
29297
|
+
isWritable: false
|
|
29298
|
+
}, {
|
|
29299
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
29300
|
+
isSigner: false,
|
|
29301
|
+
isWritable: false
|
|
29302
|
+
}, {
|
|
29303
|
+
pubkey: nodePubkey,
|
|
29304
|
+
isSigner: true,
|
|
29305
|
+
isWritable: false
|
|
29306
|
+
}],
|
|
29307
|
+
programId: this.programId,
|
|
29308
|
+
data
|
|
29309
|
+
};
|
|
29310
|
+
return new TransactionInstruction(instructionData);
|
|
29311
|
+
}
|
|
29312
|
+
/**
|
|
29313
|
+
* Generate a transaction that creates a new Vote account.
|
|
29314
|
+
*/
|
|
29315
|
+
|
|
29316
|
+
|
|
29317
|
+
static createAccount(params) {
|
|
29318
|
+
const transaction = new Transaction();
|
|
29319
|
+
transaction.add(SystemProgram.createAccount({
|
|
29320
|
+
fromPubkey: params.fromPubkey,
|
|
29321
|
+
newAccountPubkey: params.votePubkey,
|
|
29322
|
+
lamports: params.lamports,
|
|
29323
|
+
space: this.space,
|
|
29324
|
+
programId: this.programId
|
|
29325
|
+
}));
|
|
29326
|
+
return transaction.add(this.initializeAccount({
|
|
29327
|
+
votePubkey: params.votePubkey,
|
|
29328
|
+
nodePubkey: params.voteInit.nodePubkey,
|
|
29329
|
+
voteInit: params.voteInit
|
|
29330
|
+
}));
|
|
29331
|
+
}
|
|
29332
|
+
/**
|
|
29333
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account.
|
|
29334
|
+
*/
|
|
29335
|
+
|
|
29336
|
+
|
|
29337
|
+
static authorize(params) {
|
|
29338
|
+
const {
|
|
29339
|
+
votePubkey,
|
|
29340
|
+
authorizedPubkey,
|
|
29341
|
+
newAuthorizedPubkey,
|
|
29342
|
+
voteAuthorizationType
|
|
29343
|
+
} = params;
|
|
29344
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.Authorize;
|
|
29345
|
+
const data = encodeData(type, {
|
|
29346
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
29347
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
29348
|
+
});
|
|
29349
|
+
const keys = [{
|
|
29350
|
+
pubkey: votePubkey,
|
|
29351
|
+
isSigner: false,
|
|
29352
|
+
isWritable: true
|
|
29353
|
+
}, {
|
|
29354
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
29355
|
+
isSigner: false,
|
|
29356
|
+
isWritable: false
|
|
29357
|
+
}, {
|
|
29358
|
+
pubkey: authorizedPubkey,
|
|
29359
|
+
isSigner: true,
|
|
29360
|
+
isWritable: false
|
|
29361
|
+
}];
|
|
29362
|
+
return new Transaction().add({
|
|
29363
|
+
keys,
|
|
29364
|
+
programId: this.programId,
|
|
29365
|
+
data
|
|
29366
|
+
});
|
|
29367
|
+
}
|
|
29368
|
+
/**
|
|
29369
|
+
* Generate a transaction to withdraw from a Vote account.
|
|
29370
|
+
*/
|
|
29371
|
+
|
|
29372
|
+
|
|
29373
|
+
static withdraw(params) {
|
|
29374
|
+
const {
|
|
29375
|
+
votePubkey,
|
|
29376
|
+
authorizedWithdrawerPubkey,
|
|
29377
|
+
lamports,
|
|
29378
|
+
toPubkey
|
|
29379
|
+
} = params;
|
|
29380
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
|
|
29381
|
+
const data = encodeData(type, {
|
|
29382
|
+
lamports
|
|
29383
|
+
});
|
|
29384
|
+
const keys = [{
|
|
29385
|
+
pubkey: votePubkey,
|
|
29386
|
+
isSigner: false,
|
|
29387
|
+
isWritable: true
|
|
29388
|
+
}, {
|
|
29389
|
+
pubkey: toPubkey,
|
|
29390
|
+
isSigner: false,
|
|
29391
|
+
isWritable: true
|
|
29392
|
+
}, {
|
|
29393
|
+
pubkey: authorizedWithdrawerPubkey,
|
|
29394
|
+
isSigner: true,
|
|
29395
|
+
isWritable: false
|
|
29396
|
+
}];
|
|
29397
|
+
return new Transaction().add({
|
|
29398
|
+
keys,
|
|
29399
|
+
programId: this.programId,
|
|
29400
|
+
data
|
|
29401
|
+
});
|
|
29402
|
+
}
|
|
29403
|
+
|
|
29404
|
+
}
|
|
29405
|
+
VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
|
|
29406
|
+
VoteProgram.space = 3731;
|
|
29407
|
+
|
|
28899
29408
|
/**
|
|
28900
29409
|
* Send and confirm a raw transaction
|
|
28901
29410
|
*
|
|
@@ -28925,12 +29434,12 @@ var solanaWeb3 = (function (exports) {
|
|
|
28925
29434
|
http: {
|
|
28926
29435
|
devnet: 'http://api.devnet.solana.com',
|
|
28927
29436
|
testnet: 'http://api.testnet.solana.com',
|
|
28928
|
-
'mainnet-beta': 'http://api.mainnet-beta.solana.com'
|
|
29437
|
+
'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
|
|
28929
29438
|
},
|
|
28930
29439
|
https: {
|
|
28931
29440
|
devnet: 'https://api.devnet.solana.com',
|
|
28932
29441
|
testnet: 'https://api.testnet.solana.com',
|
|
28933
|
-
'mainnet-beta': 'https://api.mainnet-beta.solana.com'
|
|
29442
|
+
'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
|
|
28934
29443
|
}
|
|
28935
29444
|
};
|
|
28936
29445
|
|
|
@@ -29007,6 +29516,10 @@ var solanaWeb3 = (function (exports) {
|
|
|
29007
29516
|
exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
|
|
29008
29517
|
exports.ValidatorInfo = ValidatorInfo;
|
|
29009
29518
|
exports.VoteAccount = VoteAccount;
|
|
29519
|
+
exports.VoteAuthorizationLayout = VoteAuthorizationLayout;
|
|
29520
|
+
exports.VoteInit = VoteInit;
|
|
29521
|
+
exports.VoteInstruction = VoteInstruction;
|
|
29522
|
+
exports.VoteProgram = VoteProgram;
|
|
29010
29523
|
exports.clusterApiUrl = clusterApiUrl;
|
|
29011
29524
|
exports.sendAndConfirmRawTransaction = sendAndConfirmRawTransaction;
|
|
29012
29525
|
exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
|