@solana/web3.js 1.31.0 → 1.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.browser.esm.js +577 -68
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +582 -67
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +221 -19
- package/lib/index.esm.js +577 -68
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +582 -67
- 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 +260 -20
- package/package.json +5 -10
- package/src/connection.ts +323 -42
- package/src/index.ts +1 -0
- package/src/layout.ts +15 -0
- package/src/publickey.ts +4 -0
- package/src/sysvar.ts +16 -4
- package/src/transaction.ts +4 -1
- package/src/util/cluster.ts +2 -2
- package/src/util/send-and-confirm-transaction.ts +1 -0
- package/src/vote-account.ts +104 -31
- package/src/vote-program.ts +290 -0
package/lib/index.browser.esm.js
CHANGED
|
@@ -1798,6 +1798,10 @@ class PublicKey extends Struct {
|
|
|
1798
1798
|
toBase58() {
|
|
1799
1799
|
return bs58.encode(this.toBytes());
|
|
1800
1800
|
}
|
|
1801
|
+
|
|
1802
|
+
toJSON() {
|
|
1803
|
+
return this.toBase58();
|
|
1804
|
+
}
|
|
1801
1805
|
/**
|
|
1802
1806
|
* Return the byte array representation of the public key
|
|
1803
1807
|
*/
|
|
@@ -2064,6 +2068,13 @@ const authorized = (property = 'authorized') => {
|
|
|
2064
2068
|
const lockup = (property = 'lockup') => {
|
|
2065
2069
|
return BufferLayout.struct([BufferLayout.ns64('unixTimestamp'), BufferLayout.ns64('epoch'), publicKey('custodian')], property);
|
|
2066
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
|
+
};
|
|
2067
2078
|
function getAlloc(type, fields) {
|
|
2068
2079
|
let alloc = 0;
|
|
2069
2080
|
type.layout.fields.forEach(item => {
|
|
@@ -2437,8 +2448,9 @@ class Transaction {
|
|
|
2437
2448
|
}); // Sort. Prioritizing first by signer, then by writable
|
|
2438
2449
|
|
|
2439
2450
|
accountMetas.sort(function (x, y) {
|
|
2451
|
+
const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
|
|
2440
2452
|
const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
|
|
2441
|
-
const checkWritable = x.isWritable === y.isWritable ?
|
|
2453
|
+
const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
|
|
2442
2454
|
return checkSigner || checkWritable;
|
|
2443
2455
|
}); // Cull duplicate account metas
|
|
2444
2456
|
|
|
@@ -2894,11 +2906,14 @@ class Transaction {
|
|
|
2894
2906
|
}
|
|
2895
2907
|
|
|
2896
2908
|
const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
2909
|
+
const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
|
|
2910
|
+
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
2897
2911
|
const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
|
|
2898
2912
|
const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
|
|
2899
2913
|
const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
|
|
2914
|
+
const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
|
|
2915
|
+
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
2900
2916
|
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
2901
|
-
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
2902
2917
|
|
|
2903
2918
|
/**
|
|
2904
2919
|
* Sign, send and confirm a transaction.
|
|
@@ -2914,7 +2929,8 @@ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions111111111111
|
|
|
2914
2929
|
async function sendAndConfirmTransaction(connection, transaction, signers, options) {
|
|
2915
2930
|
const sendOptions = options && {
|
|
2916
2931
|
skipPreflight: options.skipPreflight,
|
|
2917
|
-
preflightCommitment: options.preflightCommitment || options.commitment
|
|
2932
|
+
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
2933
|
+
maxRetries: options.maxRetries
|
|
2918
2934
|
};
|
|
2919
2935
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
2920
2936
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
@@ -4823,16 +4839,15 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
|
|
|
4823
4839
|
let fetchWithMiddleware;
|
|
4824
4840
|
|
|
4825
4841
|
if (fetchMiddleware) {
|
|
4826
|
-
fetchWithMiddleware = (url, options) => {
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
}
|
|
4834
|
-
});
|
|
4842
|
+
fetchWithMiddleware = async (url, options) => {
|
|
4843
|
+
const modifiedFetchArgs = await new Promise((resolve, reject) => {
|
|
4844
|
+
try {
|
|
4845
|
+
fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
|
|
4846
|
+
} catch (error) {
|
|
4847
|
+
reject(error);
|
|
4848
|
+
}
|
|
4835
4849
|
});
|
|
4850
|
+
return await fetch(...modifiedFetchArgs);
|
|
4836
4851
|
};
|
|
4837
4852
|
}
|
|
4838
4853
|
|
|
@@ -5325,6 +5340,7 @@ const ParsedConfirmedTransactionResult = type({
|
|
|
5325
5340
|
const TokenBalanceResult = type({
|
|
5326
5341
|
accountIndex: number(),
|
|
5327
5342
|
mint: string(),
|
|
5343
|
+
owner: optional(string()),
|
|
5328
5344
|
uiTokenAmount: TokenAmountResult
|
|
5329
5345
|
});
|
|
5330
5346
|
/**
|
|
@@ -5365,8 +5381,31 @@ const ParsedConfirmedTransactionMetaResult = type({
|
|
|
5365
5381
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
5366
5382
|
postTokenBalances: optional(nullable(array(TokenBalanceResult)))
|
|
5367
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
|
+
})));
|
|
5368
5405
|
/**
|
|
5369
5406
|
* Expected JSON RPC response for the "getConfirmedBlock" message
|
|
5407
|
+
*
|
|
5408
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
|
|
5370
5409
|
*/
|
|
5371
5410
|
|
|
5372
5411
|
const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
|
|
@@ -5386,10 +5425,10 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
|
|
|
5386
5425
|
blockTime: nullable(number())
|
|
5387
5426
|
})));
|
|
5388
5427
|
/**
|
|
5389
|
-
* Expected JSON RPC response for the "
|
|
5428
|
+
* Expected JSON RPC response for the "getBlock" message
|
|
5390
5429
|
*/
|
|
5391
5430
|
|
|
5392
|
-
const
|
|
5431
|
+
const GetBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
|
|
5393
5432
|
blockhash: string(),
|
|
5394
5433
|
previousBlockhash: string(),
|
|
5395
5434
|
parentSlot: number(),
|
|
@@ -5397,20 +5436,20 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
|
|
|
5397
5436
|
blockTime: nullable(number())
|
|
5398
5437
|
})));
|
|
5399
5438
|
/**
|
|
5400
|
-
* Expected JSON RPC response for the "
|
|
5439
|
+
* Expected JSON RPC response for the "getTransaction" message
|
|
5401
5440
|
*/
|
|
5402
5441
|
|
|
5403
|
-
const
|
|
5442
|
+
const GetTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
5404
5443
|
slot: number(),
|
|
5405
5444
|
meta: ConfirmedTransactionMetaResult,
|
|
5406
5445
|
blockTime: optional(nullable(number())),
|
|
5407
5446
|
transaction: ConfirmedTransactionResult
|
|
5408
5447
|
})));
|
|
5409
5448
|
/**
|
|
5410
|
-
* Expected JSON RPC response for the "
|
|
5449
|
+
* Expected parsed JSON RPC response for the "getTransaction" message
|
|
5411
5450
|
*/
|
|
5412
5451
|
|
|
5413
|
-
const
|
|
5452
|
+
const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
5414
5453
|
slot: number(),
|
|
5415
5454
|
transaction: ParsedConfirmedTransactionResult,
|
|
5416
5455
|
meta: nullable(ParsedConfirmedTransactionMetaResult),
|
|
@@ -5418,6 +5457,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
|
5418
5457
|
})));
|
|
5419
5458
|
/**
|
|
5420
5459
|
* Expected JSON RPC response for the "getRecentBlockhash" message
|
|
5460
|
+
*
|
|
5461
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
|
|
5421
5462
|
*/
|
|
5422
5463
|
|
|
5423
5464
|
const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
|
|
@@ -5426,6 +5467,14 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
|
|
|
5426
5467
|
lamportsPerSignature: number()
|
|
5427
5468
|
})
|
|
5428
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
|
+
}));
|
|
5429
5478
|
const PerfSampleResult = type({
|
|
5430
5479
|
slot: number(),
|
|
5431
5480
|
numTransactions: number(),
|
|
@@ -5928,13 +5977,25 @@ class Connection {
|
|
|
5928
5977
|
*/
|
|
5929
5978
|
|
|
5930
5979
|
|
|
5931
|
-
async getMultipleAccountsInfo(publicKeys,
|
|
5980
|
+
async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
|
|
5932
5981
|
const keys = publicKeys.map(key => key.toBase58());
|
|
5982
|
+
let commitment;
|
|
5983
|
+
let encoding = 'base64';
|
|
5984
|
+
|
|
5985
|
+
if (configOrCommitment) {
|
|
5986
|
+
if (typeof configOrCommitment === 'string') {
|
|
5987
|
+
commitment = configOrCommitment;
|
|
5988
|
+
encoding = 'base64';
|
|
5989
|
+
} else {
|
|
5990
|
+
commitment = configOrCommitment.commitment;
|
|
5991
|
+
encoding = configOrCommitment.encoding || 'base64';
|
|
5992
|
+
}
|
|
5993
|
+
}
|
|
5933
5994
|
|
|
5934
|
-
const args = this._buildArgs([keys], commitment,
|
|
5995
|
+
const args = this._buildArgs([keys], commitment, encoding);
|
|
5935
5996
|
|
|
5936
5997
|
const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
|
|
5937
|
-
const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(
|
|
5998
|
+
const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))));
|
|
5938
5999
|
|
|
5939
6000
|
if ('error' in res) {
|
|
5940
6001
|
throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
|
|
@@ -6358,6 +6419,8 @@ class Connection {
|
|
|
6358
6419
|
/**
|
|
6359
6420
|
* Fetch a recent blockhash from the cluster, return with context
|
|
6360
6421
|
* @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
|
|
6422
|
+
*
|
|
6423
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
6361
6424
|
*/
|
|
6362
6425
|
|
|
6363
6426
|
|
|
@@ -6393,6 +6456,8 @@ class Connection {
|
|
|
6393
6456
|
}
|
|
6394
6457
|
/**
|
|
6395
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.
|
|
6396
6461
|
*/
|
|
6397
6462
|
|
|
6398
6463
|
|
|
@@ -6415,9 +6480,34 @@ class Connection {
|
|
|
6415
6480
|
value: value !== null ? value.feeCalculator : null
|
|
6416
6481
|
};
|
|
6417
6482
|
}
|
|
6483
|
+
/**
|
|
6484
|
+
* Fetch the fee for a message from the cluster, return with context
|
|
6485
|
+
*/
|
|
6486
|
+
|
|
6487
|
+
|
|
6488
|
+
async getFeeForMessage(message, commitment) {
|
|
6489
|
+
const wireMessage = message.serialize().toString('base64');
|
|
6490
|
+
|
|
6491
|
+
const args = this._buildArgs([wireMessage], commitment);
|
|
6492
|
+
|
|
6493
|
+
const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
|
|
6494
|
+
const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
|
|
6495
|
+
|
|
6496
|
+
if ('error' in res) {
|
|
6497
|
+
throw new Error('failed to get slot: ' + res.error.message);
|
|
6498
|
+
}
|
|
6499
|
+
|
|
6500
|
+
if (res.result === null) {
|
|
6501
|
+
throw new Error('invalid blockhash');
|
|
6502
|
+
}
|
|
6503
|
+
|
|
6504
|
+
return res.result;
|
|
6505
|
+
}
|
|
6418
6506
|
/**
|
|
6419
6507
|
* Fetch a recent blockhash from the cluster
|
|
6420
6508
|
* @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
|
|
6509
|
+
*
|
|
6510
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
6421
6511
|
*/
|
|
6422
6512
|
|
|
6423
6513
|
|
|
@@ -6429,6 +6519,38 @@ class Connection {
|
|
|
6429
6519
|
throw new Error('failed to get recent blockhash: ' + e);
|
|
6430
6520
|
}
|
|
6431
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
|
+
}
|
|
6432
6554
|
/**
|
|
6433
6555
|
* Fetch the node version
|
|
6434
6556
|
*/
|
|
@@ -6467,8 +6589,8 @@ class Connection {
|
|
|
6467
6589
|
async getBlock(slot, opts) {
|
|
6468
6590
|
const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
|
|
6469
6591
|
|
|
6470
|
-
const unsafeRes = await this._rpcRequest('
|
|
6471
|
-
const res = create(unsafeRes,
|
|
6592
|
+
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
6593
|
+
const res = create(unsafeRes, GetBlockRpcResult);
|
|
6472
6594
|
|
|
6473
6595
|
if ('error' in res) {
|
|
6474
6596
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -6492,18 +6614,18 @@ class Connection {
|
|
|
6492
6614
|
};
|
|
6493
6615
|
}
|
|
6494
6616
|
/**
|
|
6495
|
-
* Fetch a
|
|
6617
|
+
* Fetch a confirmed or finalized transaction from the cluster.
|
|
6496
6618
|
*/
|
|
6497
6619
|
|
|
6498
6620
|
|
|
6499
6621
|
async getTransaction(signature, opts) {
|
|
6500
6622
|
const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
|
|
6501
6623
|
|
|
6502
|
-
const unsafeRes = await this._rpcRequest('
|
|
6503
|
-
const res = create(unsafeRes,
|
|
6624
|
+
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6625
|
+
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
6504
6626
|
|
|
6505
6627
|
if ('error' in res) {
|
|
6506
|
-
throw new Error('failed to get
|
|
6628
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6507
6629
|
}
|
|
6508
6630
|
|
|
6509
6631
|
const result = res.result;
|
|
@@ -6514,6 +6636,49 @@ class Connection {
|
|
|
6514
6636
|
}
|
|
6515
6637
|
};
|
|
6516
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
|
+
}
|
|
6517
6682
|
/**
|
|
6518
6683
|
* Fetch a list of Transactions and transaction statuses from the cluster
|
|
6519
6684
|
* for a confirmed block.
|
|
@@ -6523,18 +6688,39 @@ class Connection {
|
|
|
6523
6688
|
|
|
6524
6689
|
|
|
6525
6690
|
async getConfirmedBlock(slot, commitment) {
|
|
6526
|
-
const
|
|
6527
|
-
|
|
6528
|
-
|
|
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;
|
|
6529
6701
|
|
|
6530
6702
|
if (!result) {
|
|
6531
6703
|
throw new Error('Confirmed block ' + slot + ' not found');
|
|
6532
6704
|
}
|
|
6533
6705
|
|
|
6534
|
-
|
|
6706
|
+
const block = { ...result,
|
|
6535
6707
|
transactions: result.transactions.map(({
|
|
6536
6708
|
transaction,
|
|
6537
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
|
|
6538
6724
|
}) => {
|
|
6539
6725
|
return {
|
|
6540
6726
|
meta,
|
|
@@ -6551,7 +6737,7 @@ class Connection {
|
|
|
6551
6737
|
async getBlocks(startSlot, endSlot, commitment) {
|
|
6552
6738
|
const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
|
|
6553
6739
|
|
|
6554
|
-
const unsafeRes = await this._rpcRequest('
|
|
6740
|
+
const unsafeRes = await this._rpcRequest('getBlocks', args);
|
|
6555
6741
|
const res = create(unsafeRes, jsonRpcResult(array(number())));
|
|
6556
6742
|
|
|
6557
6743
|
if ('error' in res) {
|
|
@@ -6560,8 +6746,36 @@ class Connection {
|
|
|
6560
6746
|
|
|
6561
6747
|
return res.result;
|
|
6562
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
|
+
}
|
|
6563
6775
|
/**
|
|
6564
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.
|
|
6565
6779
|
*/
|
|
6566
6780
|
|
|
6567
6781
|
|
|
@@ -6572,7 +6786,7 @@ class Connection {
|
|
|
6572
6786
|
});
|
|
6573
6787
|
|
|
6574
6788
|
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
|
|
6575
|
-
const res = create(unsafeRes,
|
|
6789
|
+
const res = create(unsafeRes, GetBlockSignaturesRpcResult);
|
|
6576
6790
|
|
|
6577
6791
|
if ('error' in res) {
|
|
6578
6792
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -6588,24 +6802,33 @@ class Connection {
|
|
|
6588
6802
|
}
|
|
6589
6803
|
/**
|
|
6590
6804
|
* Fetch a transaction details for a confirmed transaction
|
|
6805
|
+
*
|
|
6806
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
|
|
6591
6807
|
*/
|
|
6592
6808
|
|
|
6593
6809
|
|
|
6594
6810
|
async getConfirmedTransaction(signature, commitment) {
|
|
6595
|
-
const
|
|
6596
|
-
|
|
6597
|
-
|
|
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;
|
|
6598
6821
|
if (!result) return result;
|
|
6599
|
-
const
|
|
6600
|
-
|
|
6601
|
-
signatures
|
|
6602
|
-
} = result.transaction;
|
|
6822
|
+
const message = new Message(result.transaction.message);
|
|
6823
|
+
const signatures = result.transaction.signatures;
|
|
6603
6824
|
return { ...result,
|
|
6604
6825
|
transaction: Transaction.populate(message, signatures)
|
|
6605
6826
|
};
|
|
6606
6827
|
}
|
|
6607
6828
|
/**
|
|
6608
6829
|
* Fetch parsed transaction details for a confirmed transaction
|
|
6830
|
+
*
|
|
6831
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
|
|
6609
6832
|
*/
|
|
6610
6833
|
|
|
6611
6834
|
|
|
@@ -6613,7 +6836,7 @@ class Connection {
|
|
|
6613
6836
|
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6614
6837
|
|
|
6615
6838
|
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
|
|
6616
|
-
const res = create(unsafeRes,
|
|
6839
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6617
6840
|
|
|
6618
6841
|
if ('error' in res) {
|
|
6619
6842
|
throw new Error('failed to get confirmed transaction: ' + res.error.message);
|
|
@@ -6623,6 +6846,8 @@ class Connection {
|
|
|
6623
6846
|
}
|
|
6624
6847
|
/**
|
|
6625
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.
|
|
6626
6851
|
*/
|
|
6627
6852
|
|
|
6628
6853
|
|
|
@@ -6637,7 +6862,7 @@ class Connection {
|
|
|
6637
6862
|
});
|
|
6638
6863
|
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
6639
6864
|
const res = unsafeRes.map(unsafeRes => {
|
|
6640
|
-
const res = create(unsafeRes,
|
|
6865
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6641
6866
|
|
|
6642
6867
|
if ('error' in res) {
|
|
6643
6868
|
throw new Error('failed to get confirmed transactions: ' + res.error.message);
|
|
@@ -7027,6 +7252,10 @@ class Connection {
|
|
|
7027
7252
|
const skipPreflight = options && options.skipPreflight;
|
|
7028
7253
|
const preflightCommitment = options && options.preflightCommitment || this.commitment;
|
|
7029
7254
|
|
|
7255
|
+
if (options && options.maxRetries) {
|
|
7256
|
+
config.maxRetries = options.maxRetries;
|
|
7257
|
+
}
|
|
7258
|
+
|
|
7030
7259
|
if (skipPreflight) {
|
|
7031
7260
|
config.skipPreflight = skipPreflight;
|
|
7032
7261
|
}
|
|
@@ -7181,7 +7410,14 @@ class Connection {
|
|
|
7181
7410
|
this._rpcWebSocketIdleTimeout = setTimeout(() => {
|
|
7182
7411
|
this._rpcWebSocketIdleTimeout = null;
|
|
7183
7412
|
|
|
7184
|
-
|
|
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
|
+
}
|
|
7185
7421
|
}, 500);
|
|
7186
7422
|
}
|
|
7187
7423
|
|
|
@@ -8894,9 +9130,10 @@ const VOTE_PROGRAM_ID = new PublicKey('Vote1111111111111111111111111111111111111
|
|
|
8894
9130
|
*
|
|
8895
9131
|
* @internal
|
|
8896
9132
|
*/
|
|
8897
|
-
const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('
|
|
8898
|
-
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64(
|
|
8899
|
-
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('
|
|
9133
|
+
const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission'), BufferLayout.nu64(), // votes.length
|
|
9134
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64(), // authorizedVoters.length
|
|
9135
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), publicKey('authorizedVoter')]), BufferLayout.offset(BufferLayout.u32(), -8), 'authorizedVoters'), BufferLayout.struct([BufferLayout.seq(BufferLayout.struct([publicKey('authorizedPubkey'), BufferLayout.nu64('epochOfLastAuthorizedSwitch'), BufferLayout.nu64('targetEpoch')]), 32, 'buf'), BufferLayout.nu64('idx'), BufferLayout.u8('isEmpty')], 'priorVoters'), BufferLayout.nu64(), // epochCredits.length
|
|
9136
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('prevCredits')]), BufferLayout.offset(BufferLayout.u32(), -8), 'epochCredits'), BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.nu64('timestamp')], 'lastTimestamp')]);
|
|
8900
9137
|
|
|
8901
9138
|
/**
|
|
8902
9139
|
* VoteAccount class
|
|
@@ -8907,25 +9144,23 @@ class VoteAccount {
|
|
|
8907
9144
|
*/
|
|
8908
9145
|
constructor(args) {
|
|
8909
9146
|
this.nodePubkey = void 0;
|
|
8910
|
-
this.
|
|
8911
|
-
this.authorizedWithdrawerPubkey = void 0;
|
|
9147
|
+
this.authorizedWithdrawer = void 0;
|
|
8912
9148
|
this.commission = void 0;
|
|
8913
|
-
this.votes = void 0;
|
|
8914
9149
|
this.rootSlot = void 0;
|
|
8915
|
-
this.
|
|
8916
|
-
this.
|
|
8917
|
-
this.
|
|
9150
|
+
this.votes = void 0;
|
|
9151
|
+
this.authorizedVoters = void 0;
|
|
9152
|
+
this.priorVoters = void 0;
|
|
8918
9153
|
this.epochCredits = void 0;
|
|
9154
|
+
this.lastTimestamp = void 0;
|
|
8919
9155
|
this.nodePubkey = args.nodePubkey;
|
|
8920
|
-
this.
|
|
8921
|
-
this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
|
|
9156
|
+
this.authorizedWithdrawer = args.authorizedWithdrawer;
|
|
8922
9157
|
this.commission = args.commission;
|
|
8923
|
-
this.votes = args.votes;
|
|
8924
9158
|
this.rootSlot = args.rootSlot;
|
|
8925
|
-
this.
|
|
8926
|
-
this.
|
|
8927
|
-
this.
|
|
9159
|
+
this.votes = args.votes;
|
|
9160
|
+
this.authorizedVoters = args.authorizedVoters;
|
|
9161
|
+
this.priorVoters = args.priorVoters;
|
|
8928
9162
|
this.epochCredits = args.epochCredits;
|
|
9163
|
+
this.lastTimestamp = args.lastTimestamp;
|
|
8929
9164
|
}
|
|
8930
9165
|
/**
|
|
8931
9166
|
* Deserialize VoteAccount from the account data.
|
|
@@ -8936,7 +9171,8 @@ class VoteAccount {
|
|
|
8936
9171
|
|
|
8937
9172
|
|
|
8938
9173
|
static fromAccountData(buffer) {
|
|
8939
|
-
const
|
|
9174
|
+
const versionOffset = 4;
|
|
9175
|
+
const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
|
|
8940
9176
|
let rootSlot = va.rootSlot;
|
|
8941
9177
|
|
|
8942
9178
|
if (!va.rootSlotValid) {
|
|
@@ -8945,19 +9181,292 @@ class VoteAccount {
|
|
|
8945
9181
|
|
|
8946
9182
|
return new VoteAccount({
|
|
8947
9183
|
nodePubkey: new PublicKey(va.nodePubkey),
|
|
8948
|
-
|
|
8949
|
-
authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
|
|
9184
|
+
authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
|
|
8950
9185
|
commission: va.commission,
|
|
8951
9186
|
votes: va.votes,
|
|
8952
9187
|
rootSlot,
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
|
|
8956
|
-
|
|
9188
|
+
authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
|
|
9189
|
+
priorVoters: getPriorVoters(va.priorVoters),
|
|
9190
|
+
epochCredits: va.epochCredits,
|
|
9191
|
+
lastTimestamp: va.lastTimestamp
|
|
9192
|
+
});
|
|
9193
|
+
}
|
|
9194
|
+
|
|
9195
|
+
}
|
|
9196
|
+
|
|
9197
|
+
function parseAuthorizedVoter({
|
|
9198
|
+
epoch,
|
|
9199
|
+
authorizedVoter
|
|
9200
|
+
}) {
|
|
9201
|
+
return {
|
|
9202
|
+
epoch,
|
|
9203
|
+
authorizedVoter: new PublicKey(authorizedVoter)
|
|
9204
|
+
};
|
|
9205
|
+
}
|
|
9206
|
+
|
|
9207
|
+
function parsePriorVoters({
|
|
9208
|
+
authorizedPubkey,
|
|
9209
|
+
epochOfLastAuthorizedSwitch,
|
|
9210
|
+
targetEpoch
|
|
9211
|
+
}) {
|
|
9212
|
+
return {
|
|
9213
|
+
authorizedPubkey: new PublicKey(authorizedPubkey),
|
|
9214
|
+
epochOfLastAuthorizedSwitch,
|
|
9215
|
+
targetEpoch
|
|
9216
|
+
};
|
|
9217
|
+
}
|
|
9218
|
+
|
|
9219
|
+
function getPriorVoters({
|
|
9220
|
+
buf,
|
|
9221
|
+
idx,
|
|
9222
|
+
isEmpty
|
|
9223
|
+
}) {
|
|
9224
|
+
if (isEmpty) {
|
|
9225
|
+
return [];
|
|
9226
|
+
}
|
|
9227
|
+
|
|
9228
|
+
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
9229
|
+
}
|
|
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 a withdraw instruction and retrieve the instruction params.
|
|
9304
|
+
*/
|
|
9305
|
+
|
|
9306
|
+
|
|
9307
|
+
static decodeWithdraw(instruction) {
|
|
9308
|
+
this.checkProgramId(instruction.programId);
|
|
9309
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
9310
|
+
const {
|
|
9311
|
+
lamports
|
|
9312
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
|
|
9313
|
+
return {
|
|
9314
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
9315
|
+
authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
|
|
9316
|
+
lamports,
|
|
9317
|
+
toPubkey: instruction.keys[1].pubkey
|
|
9318
|
+
};
|
|
9319
|
+
}
|
|
9320
|
+
/**
|
|
9321
|
+
* @internal
|
|
9322
|
+
*/
|
|
9323
|
+
|
|
9324
|
+
|
|
9325
|
+
static checkProgramId(programId) {
|
|
9326
|
+
if (!programId.equals(VoteProgram.programId)) {
|
|
9327
|
+
throw new Error('invalid instruction; programId is not VoteProgram');
|
|
9328
|
+
}
|
|
9329
|
+
}
|
|
9330
|
+
/**
|
|
9331
|
+
* @internal
|
|
9332
|
+
*/
|
|
9333
|
+
|
|
9334
|
+
|
|
9335
|
+
static checkKeyLength(keys, expectedLength) {
|
|
9336
|
+
if (keys.length < expectedLength) {
|
|
9337
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
9338
|
+
}
|
|
9339
|
+
}
|
|
9340
|
+
|
|
9341
|
+
}
|
|
9342
|
+
/**
|
|
9343
|
+
* An enumeration of valid VoteInstructionType's
|
|
9344
|
+
*/
|
|
9345
|
+
|
|
9346
|
+
const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
9347
|
+
InitializeAccount: {
|
|
9348
|
+
index: 0,
|
|
9349
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteInit()])
|
|
9350
|
+
},
|
|
9351
|
+
Withdraw: {
|
|
9352
|
+
index: 3,
|
|
9353
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
9354
|
+
}
|
|
9355
|
+
});
|
|
9356
|
+
/**
|
|
9357
|
+
* Factory class for transactions to interact with the Vote program
|
|
9358
|
+
*/
|
|
9359
|
+
|
|
9360
|
+
class VoteProgram {
|
|
9361
|
+
/**
|
|
9362
|
+
* @internal
|
|
9363
|
+
*/
|
|
9364
|
+
constructor() {}
|
|
9365
|
+
/**
|
|
9366
|
+
* Public key that identifies the Vote program
|
|
9367
|
+
*/
|
|
9368
|
+
|
|
9369
|
+
|
|
9370
|
+
/**
|
|
9371
|
+
* Generate an Initialize instruction.
|
|
9372
|
+
*/
|
|
9373
|
+
static initializeAccount(params) {
|
|
9374
|
+
const {
|
|
9375
|
+
votePubkey,
|
|
9376
|
+
nodePubkey,
|
|
9377
|
+
voteInit
|
|
9378
|
+
} = params;
|
|
9379
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
|
|
9380
|
+
const data = encodeData(type, {
|
|
9381
|
+
voteInit: {
|
|
9382
|
+
nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
|
|
9383
|
+
authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
|
|
9384
|
+
authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
|
|
9385
|
+
commission: voteInit.commission
|
|
9386
|
+
}
|
|
9387
|
+
});
|
|
9388
|
+
const instructionData = {
|
|
9389
|
+
keys: [{
|
|
9390
|
+
pubkey: votePubkey,
|
|
9391
|
+
isSigner: false,
|
|
9392
|
+
isWritable: true
|
|
9393
|
+
}, {
|
|
9394
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
9395
|
+
isSigner: false,
|
|
9396
|
+
isWritable: false
|
|
9397
|
+
}, {
|
|
9398
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
9399
|
+
isSigner: false,
|
|
9400
|
+
isWritable: false
|
|
9401
|
+
}, {
|
|
9402
|
+
pubkey: nodePubkey,
|
|
9403
|
+
isSigner: true,
|
|
9404
|
+
isWritable: false
|
|
9405
|
+
}],
|
|
9406
|
+
programId: this.programId,
|
|
9407
|
+
data
|
|
9408
|
+
};
|
|
9409
|
+
return new TransactionInstruction(instructionData);
|
|
9410
|
+
}
|
|
9411
|
+
/**
|
|
9412
|
+
* Generate a transaction that creates a new Vote account.
|
|
9413
|
+
*/
|
|
9414
|
+
|
|
9415
|
+
|
|
9416
|
+
static createAccount(params) {
|
|
9417
|
+
const transaction = new Transaction();
|
|
9418
|
+
transaction.add(SystemProgram.createAccount({
|
|
9419
|
+
fromPubkey: params.fromPubkey,
|
|
9420
|
+
newAccountPubkey: params.votePubkey,
|
|
9421
|
+
lamports: params.lamports,
|
|
9422
|
+
space: this.space,
|
|
9423
|
+
programId: this.programId
|
|
9424
|
+
}));
|
|
9425
|
+
return transaction.add(this.initializeAccount({
|
|
9426
|
+
votePubkey: params.votePubkey,
|
|
9427
|
+
nodePubkey: params.voteInit.nodePubkey,
|
|
9428
|
+
voteInit: params.voteInit
|
|
9429
|
+
}));
|
|
9430
|
+
}
|
|
9431
|
+
/**
|
|
9432
|
+
* Generate a transaction to withdraw from a Vote account.
|
|
9433
|
+
*/
|
|
9434
|
+
|
|
9435
|
+
|
|
9436
|
+
static withdraw(params) {
|
|
9437
|
+
const {
|
|
9438
|
+
votePubkey,
|
|
9439
|
+
authorizedWithdrawerPubkey,
|
|
9440
|
+
lamports,
|
|
9441
|
+
toPubkey
|
|
9442
|
+
} = params;
|
|
9443
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
|
|
9444
|
+
const data = encodeData(type, {
|
|
9445
|
+
lamports
|
|
9446
|
+
});
|
|
9447
|
+
const keys = [{
|
|
9448
|
+
pubkey: votePubkey,
|
|
9449
|
+
isSigner: false,
|
|
9450
|
+
isWritable: true
|
|
9451
|
+
}, {
|
|
9452
|
+
pubkey: toPubkey,
|
|
9453
|
+
isSigner: false,
|
|
9454
|
+
isWritable: true
|
|
9455
|
+
}, {
|
|
9456
|
+
pubkey: authorizedWithdrawerPubkey,
|
|
9457
|
+
isSigner: true,
|
|
9458
|
+
isWritable: false
|
|
9459
|
+
}];
|
|
9460
|
+
return new Transaction().add({
|
|
9461
|
+
keys,
|
|
9462
|
+
programId: this.programId,
|
|
9463
|
+
data
|
|
8957
9464
|
});
|
|
8958
9465
|
}
|
|
8959
9466
|
|
|
8960
9467
|
}
|
|
9468
|
+
VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
|
|
9469
|
+
VoteProgram.space = 3731;
|
|
8961
9470
|
|
|
8962
9471
|
/**
|
|
8963
9472
|
* Send and confirm a raw transaction
|
|
@@ -8988,12 +9497,12 @@ const endpoint = {
|
|
|
8988
9497
|
http: {
|
|
8989
9498
|
devnet: 'http://api.devnet.solana.com',
|
|
8990
9499
|
testnet: 'http://api.testnet.solana.com',
|
|
8991
|
-
'mainnet-beta': 'http://api.mainnet-beta.solana.com'
|
|
9500
|
+
'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
|
|
8992
9501
|
},
|
|
8993
9502
|
https: {
|
|
8994
9503
|
devnet: 'https://api.devnet.solana.com',
|
|
8995
9504
|
testnet: 'https://api.testnet.solana.com',
|
|
8996
|
-
'mainnet-beta': 'https://api.mainnet-beta.solana.com'
|
|
9505
|
+
'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
|
|
8997
9506
|
}
|
|
8998
9507
|
};
|
|
8999
9508
|
|
|
@@ -9022,5 +9531,5 @@ function clusterApiUrl(cluster, tls) {
|
|
|
9022
9531
|
|
|
9023
9532
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9024
9533
|
|
|
9025
|
-
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9534
|
+
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9026
9535
|
//# sourceMappingURL=index.browser.esm.js.map
|