@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.iife.js
CHANGED
|
@@ -11124,6 +11124,10 @@ var solanaWeb3 = (function (exports) {
|
|
|
11124
11124
|
toBase58() {
|
|
11125
11125
|
return bs58$1.encode(this.toBytes());
|
|
11126
11126
|
}
|
|
11127
|
+
|
|
11128
|
+
toJSON() {
|
|
11129
|
+
return this.toBase58();
|
|
11130
|
+
}
|
|
11127
11131
|
/**
|
|
11128
11132
|
* Return the byte array representation of the public key
|
|
11129
11133
|
*/
|
|
@@ -13974,6 +13978,13 @@ var solanaWeb3 = (function (exports) {
|
|
|
13974
13978
|
const lockup = (property = 'lockup') => {
|
|
13975
13979
|
return struct([ns64('unixTimestamp'), ns64('epoch'), publicKey('custodian')], property);
|
|
13976
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
|
+
};
|
|
13977
13988
|
function getAlloc(type, fields) {
|
|
13978
13989
|
let alloc = 0;
|
|
13979
13990
|
type.layout.fields.forEach(item => {
|
|
@@ -14347,8 +14358,9 @@ var solanaWeb3 = (function (exports) {
|
|
|
14347
14358
|
}); // Sort. Prioritizing first by signer, then by writable
|
|
14348
14359
|
|
|
14349
14360
|
accountMetas.sort(function (x, y) {
|
|
14361
|
+
const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
|
|
14350
14362
|
const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
|
|
14351
|
-
const checkWritable = x.isWritable === y.isWritable ?
|
|
14363
|
+
const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
|
|
14352
14364
|
return checkSigner || checkWritable;
|
|
14353
14365
|
}); // Cull duplicate account metas
|
|
14354
14366
|
|
|
@@ -14804,11 +14816,14 @@ var solanaWeb3 = (function (exports) {
|
|
|
14804
14816
|
}
|
|
14805
14817
|
|
|
14806
14818
|
const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
14819
|
+
const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
|
|
14820
|
+
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
14807
14821
|
const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
|
|
14808
14822
|
const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
|
|
14809
14823
|
const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
|
|
14824
|
+
const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
|
|
14825
|
+
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
14810
14826
|
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
14811
|
-
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
14812
14827
|
|
|
14813
14828
|
/**
|
|
14814
14829
|
* Sign, send and confirm a transaction.
|
|
@@ -14824,7 +14839,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
14824
14839
|
async function sendAndConfirmTransaction(connection, transaction, signers, options) {
|
|
14825
14840
|
const sendOptions = options && {
|
|
14826
14841
|
skipPreflight: options.skipPreflight,
|
|
14827
|
-
preflightCommitment: options.preflightCommitment || options.commitment
|
|
14842
|
+
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
14843
|
+
maxRetries: options.maxRetries
|
|
14828
14844
|
};
|
|
14829
14845
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
14830
14846
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
@@ -19850,16 +19866,15 @@ var solanaWeb3 = (function (exports) {
|
|
|
19850
19866
|
let fetchWithMiddleware;
|
|
19851
19867
|
|
|
19852
19868
|
if (fetchMiddleware) {
|
|
19853
|
-
fetchWithMiddleware = (url, options) => {
|
|
19854
|
-
|
|
19855
|
-
|
|
19856
|
-
|
|
19857
|
-
|
|
19858
|
-
|
|
19859
|
-
|
|
19860
|
-
}
|
|
19861
|
-
});
|
|
19869
|
+
fetchWithMiddleware = async (url, options) => {
|
|
19870
|
+
const modifiedFetchArgs = await new Promise((resolve, reject) => {
|
|
19871
|
+
try {
|
|
19872
|
+
fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
|
|
19873
|
+
} catch (error) {
|
|
19874
|
+
reject(error);
|
|
19875
|
+
}
|
|
19862
19876
|
});
|
|
19877
|
+
return await fetch(...modifiedFetchArgs);
|
|
19863
19878
|
};
|
|
19864
19879
|
}
|
|
19865
19880
|
|
|
@@ -20352,6 +20367,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
20352
20367
|
const TokenBalanceResult = type({
|
|
20353
20368
|
accountIndex: number(),
|
|
20354
20369
|
mint: string(),
|
|
20370
|
+
owner: optional(string()),
|
|
20355
20371
|
uiTokenAmount: TokenAmountResult
|
|
20356
20372
|
});
|
|
20357
20373
|
/**
|
|
@@ -20392,8 +20408,31 @@ var solanaWeb3 = (function (exports) {
|
|
|
20392
20408
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
20393
20409
|
postTokenBalances: optional(nullable(array(TokenBalanceResult)))
|
|
20394
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
|
+
})));
|
|
20395
20432
|
/**
|
|
20396
20433
|
* Expected JSON RPC response for the "getConfirmedBlock" message
|
|
20434
|
+
*
|
|
20435
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
|
|
20397
20436
|
*/
|
|
20398
20437
|
|
|
20399
20438
|
const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
|
|
@@ -20413,10 +20452,10 @@ var solanaWeb3 = (function (exports) {
|
|
|
20413
20452
|
blockTime: nullable(number())
|
|
20414
20453
|
})));
|
|
20415
20454
|
/**
|
|
20416
|
-
* Expected JSON RPC response for the "
|
|
20455
|
+
* Expected JSON RPC response for the "getBlock" message
|
|
20417
20456
|
*/
|
|
20418
20457
|
|
|
20419
|
-
const
|
|
20458
|
+
const GetBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
|
|
20420
20459
|
blockhash: string(),
|
|
20421
20460
|
previousBlockhash: string(),
|
|
20422
20461
|
parentSlot: number(),
|
|
@@ -20424,20 +20463,20 @@ var solanaWeb3 = (function (exports) {
|
|
|
20424
20463
|
blockTime: nullable(number())
|
|
20425
20464
|
})));
|
|
20426
20465
|
/**
|
|
20427
|
-
* Expected JSON RPC response for the "
|
|
20466
|
+
* Expected JSON RPC response for the "getTransaction" message
|
|
20428
20467
|
*/
|
|
20429
20468
|
|
|
20430
|
-
const
|
|
20469
|
+
const GetTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
20431
20470
|
slot: number(),
|
|
20432
20471
|
meta: ConfirmedTransactionMetaResult,
|
|
20433
20472
|
blockTime: optional(nullable(number())),
|
|
20434
20473
|
transaction: ConfirmedTransactionResult
|
|
20435
20474
|
})));
|
|
20436
20475
|
/**
|
|
20437
|
-
* Expected JSON RPC response for the "
|
|
20476
|
+
* Expected parsed JSON RPC response for the "getTransaction" message
|
|
20438
20477
|
*/
|
|
20439
20478
|
|
|
20440
|
-
const
|
|
20479
|
+
const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
20441
20480
|
slot: number(),
|
|
20442
20481
|
transaction: ParsedConfirmedTransactionResult,
|
|
20443
20482
|
meta: nullable(ParsedConfirmedTransactionMetaResult),
|
|
@@ -20445,6 +20484,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
20445
20484
|
})));
|
|
20446
20485
|
/**
|
|
20447
20486
|
* Expected JSON RPC response for the "getRecentBlockhash" message
|
|
20487
|
+
*
|
|
20488
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
|
|
20448
20489
|
*/
|
|
20449
20490
|
|
|
20450
20491
|
const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
|
|
@@ -20453,6 +20494,14 @@ var solanaWeb3 = (function (exports) {
|
|
|
20453
20494
|
lamportsPerSignature: number()
|
|
20454
20495
|
})
|
|
20455
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
|
+
}));
|
|
20456
20505
|
const PerfSampleResult = type({
|
|
20457
20506
|
slot: number(),
|
|
20458
20507
|
numTransactions: number(),
|
|
@@ -20955,13 +21004,25 @@ var solanaWeb3 = (function (exports) {
|
|
|
20955
21004
|
*/
|
|
20956
21005
|
|
|
20957
21006
|
|
|
20958
|
-
async getMultipleAccountsInfo(publicKeys,
|
|
21007
|
+
async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
|
|
20959
21008
|
const keys = publicKeys.map(key => key.toBase58());
|
|
21009
|
+
let commitment;
|
|
21010
|
+
let encoding = 'base64';
|
|
21011
|
+
|
|
21012
|
+
if (configOrCommitment) {
|
|
21013
|
+
if (typeof configOrCommitment === 'string') {
|
|
21014
|
+
commitment = configOrCommitment;
|
|
21015
|
+
encoding = 'base64';
|
|
21016
|
+
} else {
|
|
21017
|
+
commitment = configOrCommitment.commitment;
|
|
21018
|
+
encoding = configOrCommitment.encoding || 'base64';
|
|
21019
|
+
}
|
|
21020
|
+
}
|
|
20960
21021
|
|
|
20961
|
-
const args = this._buildArgs([keys], commitment,
|
|
21022
|
+
const args = this._buildArgs([keys], commitment, encoding);
|
|
20962
21023
|
|
|
20963
21024
|
const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
|
|
20964
|
-
const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(
|
|
21025
|
+
const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))));
|
|
20965
21026
|
|
|
20966
21027
|
if ('error' in res) {
|
|
20967
21028
|
throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
|
|
@@ -21385,6 +21446,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
21385
21446
|
/**
|
|
21386
21447
|
* Fetch a recent blockhash from the cluster, return with context
|
|
21387
21448
|
* @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
|
|
21449
|
+
*
|
|
21450
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
21388
21451
|
*/
|
|
21389
21452
|
|
|
21390
21453
|
|
|
@@ -21420,6 +21483,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
21420
21483
|
}
|
|
21421
21484
|
/**
|
|
21422
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.
|
|
21423
21488
|
*/
|
|
21424
21489
|
|
|
21425
21490
|
|
|
@@ -21442,9 +21507,34 @@ var solanaWeb3 = (function (exports) {
|
|
|
21442
21507
|
value: value !== null ? value.feeCalculator : null
|
|
21443
21508
|
};
|
|
21444
21509
|
}
|
|
21510
|
+
/**
|
|
21511
|
+
* Fetch the fee for a message from the cluster, return with context
|
|
21512
|
+
*/
|
|
21513
|
+
|
|
21514
|
+
|
|
21515
|
+
async getFeeForMessage(message, commitment) {
|
|
21516
|
+
const wireMessage = message.serialize().toString('base64');
|
|
21517
|
+
|
|
21518
|
+
const args = this._buildArgs([wireMessage], commitment);
|
|
21519
|
+
|
|
21520
|
+
const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
|
|
21521
|
+
const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
|
|
21522
|
+
|
|
21523
|
+
if ('error' in res) {
|
|
21524
|
+
throw new Error('failed to get slot: ' + res.error.message);
|
|
21525
|
+
}
|
|
21526
|
+
|
|
21527
|
+
if (res.result === null) {
|
|
21528
|
+
throw new Error('invalid blockhash');
|
|
21529
|
+
}
|
|
21530
|
+
|
|
21531
|
+
return res.result;
|
|
21532
|
+
}
|
|
21445
21533
|
/**
|
|
21446
21534
|
* Fetch a recent blockhash from the cluster
|
|
21447
21535
|
* @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
|
|
21536
|
+
*
|
|
21537
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
21448
21538
|
*/
|
|
21449
21539
|
|
|
21450
21540
|
|
|
@@ -21456,6 +21546,38 @@ var solanaWeb3 = (function (exports) {
|
|
|
21456
21546
|
throw new Error('failed to get recent blockhash: ' + e);
|
|
21457
21547
|
}
|
|
21458
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
|
+
}
|
|
21459
21581
|
/**
|
|
21460
21582
|
* Fetch the node version
|
|
21461
21583
|
*/
|
|
@@ -21494,8 +21616,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
21494
21616
|
async getBlock(slot, opts) {
|
|
21495
21617
|
const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
|
|
21496
21618
|
|
|
21497
|
-
const unsafeRes = await this._rpcRequest('
|
|
21498
|
-
const res = create(unsafeRes,
|
|
21619
|
+
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
21620
|
+
const res = create(unsafeRes, GetBlockRpcResult);
|
|
21499
21621
|
|
|
21500
21622
|
if ('error' in res) {
|
|
21501
21623
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -21519,18 +21641,18 @@ var solanaWeb3 = (function (exports) {
|
|
|
21519
21641
|
};
|
|
21520
21642
|
}
|
|
21521
21643
|
/**
|
|
21522
|
-
* Fetch a
|
|
21644
|
+
* Fetch a confirmed or finalized transaction from the cluster.
|
|
21523
21645
|
*/
|
|
21524
21646
|
|
|
21525
21647
|
|
|
21526
21648
|
async getTransaction(signature, opts) {
|
|
21527
21649
|
const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
|
|
21528
21650
|
|
|
21529
|
-
const unsafeRes = await this._rpcRequest('
|
|
21530
|
-
const res = create(unsafeRes,
|
|
21651
|
+
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
21652
|
+
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
21531
21653
|
|
|
21532
21654
|
if ('error' in res) {
|
|
21533
|
-
throw new Error('failed to get
|
|
21655
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
21534
21656
|
}
|
|
21535
21657
|
|
|
21536
21658
|
const result = res.result;
|
|
@@ -21541,6 +21663,49 @@ var solanaWeb3 = (function (exports) {
|
|
|
21541
21663
|
}
|
|
21542
21664
|
};
|
|
21543
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
|
+
}
|
|
21544
21709
|
/**
|
|
21545
21710
|
* Fetch a list of Transactions and transaction statuses from the cluster
|
|
21546
21711
|
* for a confirmed block.
|
|
@@ -21550,18 +21715,39 @@ var solanaWeb3 = (function (exports) {
|
|
|
21550
21715
|
|
|
21551
21716
|
|
|
21552
21717
|
async getConfirmedBlock(slot, commitment) {
|
|
21553
|
-
const
|
|
21554
|
-
|
|
21555
|
-
|
|
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;
|
|
21556
21728
|
|
|
21557
21729
|
if (!result) {
|
|
21558
21730
|
throw new Error('Confirmed block ' + slot + ' not found');
|
|
21559
21731
|
}
|
|
21560
21732
|
|
|
21561
|
-
|
|
21733
|
+
const block = { ...result,
|
|
21562
21734
|
transactions: result.transactions.map(({
|
|
21563
21735
|
transaction,
|
|
21564
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
|
|
21565
21751
|
}) => {
|
|
21566
21752
|
return {
|
|
21567
21753
|
meta,
|
|
@@ -21578,7 +21764,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
21578
21764
|
async getBlocks(startSlot, endSlot, commitment) {
|
|
21579
21765
|
const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
|
|
21580
21766
|
|
|
21581
|
-
const unsafeRes = await this._rpcRequest('
|
|
21767
|
+
const unsafeRes = await this._rpcRequest('getBlocks', args);
|
|
21582
21768
|
const res = create(unsafeRes, jsonRpcResult(array(number())));
|
|
21583
21769
|
|
|
21584
21770
|
if ('error' in res) {
|
|
@@ -21587,8 +21773,36 @@ var solanaWeb3 = (function (exports) {
|
|
|
21587
21773
|
|
|
21588
21774
|
return res.result;
|
|
21589
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
|
+
}
|
|
21590
21802
|
/**
|
|
21591
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.
|
|
21592
21806
|
*/
|
|
21593
21807
|
|
|
21594
21808
|
|
|
@@ -21599,7 +21813,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
21599
21813
|
});
|
|
21600
21814
|
|
|
21601
21815
|
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
|
|
21602
|
-
const res = create(unsafeRes,
|
|
21816
|
+
const res = create(unsafeRes, GetBlockSignaturesRpcResult);
|
|
21603
21817
|
|
|
21604
21818
|
if ('error' in res) {
|
|
21605
21819
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -21615,24 +21829,33 @@ var solanaWeb3 = (function (exports) {
|
|
|
21615
21829
|
}
|
|
21616
21830
|
/**
|
|
21617
21831
|
* Fetch a transaction details for a confirmed transaction
|
|
21832
|
+
*
|
|
21833
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
|
|
21618
21834
|
*/
|
|
21619
21835
|
|
|
21620
21836
|
|
|
21621
21837
|
async getConfirmedTransaction(signature, commitment) {
|
|
21622
|
-
const
|
|
21623
|
-
|
|
21624
|
-
|
|
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;
|
|
21625
21848
|
if (!result) return result;
|
|
21626
|
-
const
|
|
21627
|
-
|
|
21628
|
-
signatures
|
|
21629
|
-
} = result.transaction;
|
|
21849
|
+
const message = new Message(result.transaction.message);
|
|
21850
|
+
const signatures = result.transaction.signatures;
|
|
21630
21851
|
return { ...result,
|
|
21631
21852
|
transaction: Transaction.populate(message, signatures)
|
|
21632
21853
|
};
|
|
21633
21854
|
}
|
|
21634
21855
|
/**
|
|
21635
21856
|
* Fetch parsed transaction details for a confirmed transaction
|
|
21857
|
+
*
|
|
21858
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
|
|
21636
21859
|
*/
|
|
21637
21860
|
|
|
21638
21861
|
|
|
@@ -21640,7 +21863,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
21640
21863
|
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
21641
21864
|
|
|
21642
21865
|
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
|
|
21643
|
-
const res = create(unsafeRes,
|
|
21866
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
21644
21867
|
|
|
21645
21868
|
if ('error' in res) {
|
|
21646
21869
|
throw new Error('failed to get confirmed transaction: ' + res.error.message);
|
|
@@ -21650,6 +21873,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
21650
21873
|
}
|
|
21651
21874
|
/**
|
|
21652
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.
|
|
21653
21878
|
*/
|
|
21654
21879
|
|
|
21655
21880
|
|
|
@@ -21664,7 +21889,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
21664
21889
|
});
|
|
21665
21890
|
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
21666
21891
|
const res = unsafeRes.map(unsafeRes => {
|
|
21667
|
-
const res = create(unsafeRes,
|
|
21892
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
21668
21893
|
|
|
21669
21894
|
if ('error' in res) {
|
|
21670
21895
|
throw new Error('failed to get confirmed transactions: ' + res.error.message);
|
|
@@ -22054,6 +22279,10 @@ var solanaWeb3 = (function (exports) {
|
|
|
22054
22279
|
const skipPreflight = options && options.skipPreflight;
|
|
22055
22280
|
const preflightCommitment = options && options.preflightCommitment || this.commitment;
|
|
22056
22281
|
|
|
22282
|
+
if (options && options.maxRetries) {
|
|
22283
|
+
config.maxRetries = options.maxRetries;
|
|
22284
|
+
}
|
|
22285
|
+
|
|
22057
22286
|
if (skipPreflight) {
|
|
22058
22287
|
config.skipPreflight = skipPreflight;
|
|
22059
22288
|
}
|
|
@@ -22208,7 +22437,14 @@ var solanaWeb3 = (function (exports) {
|
|
|
22208
22437
|
this._rpcWebSocketIdleTimeout = setTimeout(() => {
|
|
22209
22438
|
this._rpcWebSocketIdleTimeout = null;
|
|
22210
22439
|
|
|
22211
|
-
|
|
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
|
+
}
|
|
22212
22448
|
}, 500);
|
|
22213
22449
|
}
|
|
22214
22450
|
|
|
@@ -28755,9 +28991,10 @@ var solanaWeb3 = (function (exports) {
|
|
|
28755
28991
|
*
|
|
28756
28992
|
* @internal
|
|
28757
28993
|
*/
|
|
28758
|
-
const VoteAccountLayout = struct([publicKey('nodePubkey'), publicKey('
|
|
28759
|
-
seq(struct([nu64('slot'), u32('confirmationCount')]), offset(u32(), -8), 'votes'), u8('rootSlotValid'), nu64('rootSlot'), nu64(
|
|
28760
|
-
seq(struct([nu64('epoch'), nu64('
|
|
28994
|
+
const VoteAccountLayout = struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), u8('commission'), nu64(), // votes.length
|
|
28995
|
+
seq(struct([nu64('slot'), u32('confirmationCount')]), offset(u32(), -8), 'votes'), u8('rootSlotValid'), nu64('rootSlot'), nu64(), // authorizedVoters.length
|
|
28996
|
+
seq(struct([nu64('epoch'), publicKey('authorizedVoter')]), offset(u32(), -8), 'authorizedVoters'), struct([seq(struct([publicKey('authorizedPubkey'), nu64('epochOfLastAuthorizedSwitch'), nu64('targetEpoch')]), 32, 'buf'), nu64('idx'), u8('isEmpty')], 'priorVoters'), nu64(), // epochCredits.length
|
|
28997
|
+
seq(struct([nu64('epoch'), nu64('credits'), nu64('prevCredits')]), offset(u32(), -8), 'epochCredits'), struct([nu64('slot'), nu64('timestamp')], 'lastTimestamp')]);
|
|
28761
28998
|
|
|
28762
28999
|
/**
|
|
28763
29000
|
* VoteAccount class
|
|
@@ -28768,25 +29005,23 @@ var solanaWeb3 = (function (exports) {
|
|
|
28768
29005
|
*/
|
|
28769
29006
|
constructor(args) {
|
|
28770
29007
|
this.nodePubkey = void 0;
|
|
28771
|
-
this.
|
|
28772
|
-
this.authorizedWithdrawerPubkey = void 0;
|
|
29008
|
+
this.authorizedWithdrawer = void 0;
|
|
28773
29009
|
this.commission = void 0;
|
|
28774
|
-
this.votes = void 0;
|
|
28775
29010
|
this.rootSlot = void 0;
|
|
28776
|
-
this.
|
|
28777
|
-
this.
|
|
28778
|
-
this.
|
|
29011
|
+
this.votes = void 0;
|
|
29012
|
+
this.authorizedVoters = void 0;
|
|
29013
|
+
this.priorVoters = void 0;
|
|
28779
29014
|
this.epochCredits = void 0;
|
|
29015
|
+
this.lastTimestamp = void 0;
|
|
28780
29016
|
this.nodePubkey = args.nodePubkey;
|
|
28781
|
-
this.
|
|
28782
|
-
this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
|
|
29017
|
+
this.authorizedWithdrawer = args.authorizedWithdrawer;
|
|
28783
29018
|
this.commission = args.commission;
|
|
28784
|
-
this.votes = args.votes;
|
|
28785
29019
|
this.rootSlot = args.rootSlot;
|
|
28786
|
-
this.
|
|
28787
|
-
this.
|
|
28788
|
-
this.
|
|
29020
|
+
this.votes = args.votes;
|
|
29021
|
+
this.authorizedVoters = args.authorizedVoters;
|
|
29022
|
+
this.priorVoters = args.priorVoters;
|
|
28789
29023
|
this.epochCredits = args.epochCredits;
|
|
29024
|
+
this.lastTimestamp = args.lastTimestamp;
|
|
28790
29025
|
}
|
|
28791
29026
|
/**
|
|
28792
29027
|
* Deserialize VoteAccount from the account data.
|
|
@@ -28797,7 +29032,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
28797
29032
|
|
|
28798
29033
|
|
|
28799
29034
|
static fromAccountData(buffer) {
|
|
28800
|
-
const
|
|
29035
|
+
const versionOffset = 4;
|
|
29036
|
+
const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
|
|
28801
29037
|
let rootSlot = va.rootSlot;
|
|
28802
29038
|
|
|
28803
29039
|
if (!va.rootSlotValid) {
|
|
@@ -28806,19 +29042,292 @@ var solanaWeb3 = (function (exports) {
|
|
|
28806
29042
|
|
|
28807
29043
|
return new VoteAccount({
|
|
28808
29044
|
nodePubkey: new PublicKey(va.nodePubkey),
|
|
28809
|
-
|
|
28810
|
-
authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
|
|
29045
|
+
authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
|
|
28811
29046
|
commission: va.commission,
|
|
28812
29047
|
votes: va.votes,
|
|
28813
29048
|
rootSlot,
|
|
28814
|
-
|
|
28815
|
-
|
|
28816
|
-
|
|
28817
|
-
|
|
29049
|
+
authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
|
|
29050
|
+
priorVoters: getPriorVoters(va.priorVoters),
|
|
29051
|
+
epochCredits: va.epochCredits,
|
|
29052
|
+
lastTimestamp: va.lastTimestamp
|
|
29053
|
+
});
|
|
29054
|
+
}
|
|
29055
|
+
|
|
29056
|
+
}
|
|
29057
|
+
|
|
29058
|
+
function parseAuthorizedVoter({
|
|
29059
|
+
epoch,
|
|
29060
|
+
authorizedVoter
|
|
29061
|
+
}) {
|
|
29062
|
+
return {
|
|
29063
|
+
epoch,
|
|
29064
|
+
authorizedVoter: new PublicKey(authorizedVoter)
|
|
29065
|
+
};
|
|
29066
|
+
}
|
|
29067
|
+
|
|
29068
|
+
function parsePriorVoters({
|
|
29069
|
+
authorizedPubkey,
|
|
29070
|
+
epochOfLastAuthorizedSwitch,
|
|
29071
|
+
targetEpoch
|
|
29072
|
+
}) {
|
|
29073
|
+
return {
|
|
29074
|
+
authorizedPubkey: new PublicKey(authorizedPubkey),
|
|
29075
|
+
epochOfLastAuthorizedSwitch,
|
|
29076
|
+
targetEpoch
|
|
29077
|
+
};
|
|
29078
|
+
}
|
|
29079
|
+
|
|
29080
|
+
function getPriorVoters({
|
|
29081
|
+
buf,
|
|
29082
|
+
idx,
|
|
29083
|
+
isEmpty
|
|
29084
|
+
}) {
|
|
29085
|
+
if (isEmpty) {
|
|
29086
|
+
return [];
|
|
29087
|
+
}
|
|
29088
|
+
|
|
29089
|
+
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
29090
|
+
}
|
|
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 a withdraw instruction and retrieve the instruction params.
|
|
29165
|
+
*/
|
|
29166
|
+
|
|
29167
|
+
|
|
29168
|
+
static decodeWithdraw(instruction) {
|
|
29169
|
+
this.checkProgramId(instruction.programId);
|
|
29170
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
29171
|
+
const {
|
|
29172
|
+
lamports
|
|
29173
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
|
|
29174
|
+
return {
|
|
29175
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
29176
|
+
authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
|
|
29177
|
+
lamports,
|
|
29178
|
+
toPubkey: instruction.keys[1].pubkey
|
|
29179
|
+
};
|
|
29180
|
+
}
|
|
29181
|
+
/**
|
|
29182
|
+
* @internal
|
|
29183
|
+
*/
|
|
29184
|
+
|
|
29185
|
+
|
|
29186
|
+
static checkProgramId(programId) {
|
|
29187
|
+
if (!programId.equals(VoteProgram.programId)) {
|
|
29188
|
+
throw new Error('invalid instruction; programId is not VoteProgram');
|
|
29189
|
+
}
|
|
29190
|
+
}
|
|
29191
|
+
/**
|
|
29192
|
+
* @internal
|
|
29193
|
+
*/
|
|
29194
|
+
|
|
29195
|
+
|
|
29196
|
+
static checkKeyLength(keys, expectedLength) {
|
|
29197
|
+
if (keys.length < expectedLength) {
|
|
29198
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
29199
|
+
}
|
|
29200
|
+
}
|
|
29201
|
+
|
|
29202
|
+
}
|
|
29203
|
+
/**
|
|
29204
|
+
* An enumeration of valid VoteInstructionType's
|
|
29205
|
+
*/
|
|
29206
|
+
|
|
29207
|
+
const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
29208
|
+
InitializeAccount: {
|
|
29209
|
+
index: 0,
|
|
29210
|
+
layout: struct([u32('instruction'), voteInit()])
|
|
29211
|
+
},
|
|
29212
|
+
Withdraw: {
|
|
29213
|
+
index: 3,
|
|
29214
|
+
layout: struct([u32('instruction'), ns64('lamports')])
|
|
29215
|
+
}
|
|
29216
|
+
});
|
|
29217
|
+
/**
|
|
29218
|
+
* Factory class for transactions to interact with the Vote program
|
|
29219
|
+
*/
|
|
29220
|
+
|
|
29221
|
+
class VoteProgram {
|
|
29222
|
+
/**
|
|
29223
|
+
* @internal
|
|
29224
|
+
*/
|
|
29225
|
+
constructor() {}
|
|
29226
|
+
/**
|
|
29227
|
+
* Public key that identifies the Vote program
|
|
29228
|
+
*/
|
|
29229
|
+
|
|
29230
|
+
|
|
29231
|
+
/**
|
|
29232
|
+
* Generate an Initialize instruction.
|
|
29233
|
+
*/
|
|
29234
|
+
static initializeAccount(params) {
|
|
29235
|
+
const {
|
|
29236
|
+
votePubkey,
|
|
29237
|
+
nodePubkey,
|
|
29238
|
+
voteInit
|
|
29239
|
+
} = params;
|
|
29240
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
|
|
29241
|
+
const data = encodeData(type, {
|
|
29242
|
+
voteInit: {
|
|
29243
|
+
nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
|
|
29244
|
+
authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
|
|
29245
|
+
authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
|
|
29246
|
+
commission: voteInit.commission
|
|
29247
|
+
}
|
|
29248
|
+
});
|
|
29249
|
+
const instructionData = {
|
|
29250
|
+
keys: [{
|
|
29251
|
+
pubkey: votePubkey,
|
|
29252
|
+
isSigner: false,
|
|
29253
|
+
isWritable: true
|
|
29254
|
+
}, {
|
|
29255
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
29256
|
+
isSigner: false,
|
|
29257
|
+
isWritable: false
|
|
29258
|
+
}, {
|
|
29259
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
29260
|
+
isSigner: false,
|
|
29261
|
+
isWritable: false
|
|
29262
|
+
}, {
|
|
29263
|
+
pubkey: nodePubkey,
|
|
29264
|
+
isSigner: true,
|
|
29265
|
+
isWritable: false
|
|
29266
|
+
}],
|
|
29267
|
+
programId: this.programId,
|
|
29268
|
+
data
|
|
29269
|
+
};
|
|
29270
|
+
return new TransactionInstruction(instructionData);
|
|
29271
|
+
}
|
|
29272
|
+
/**
|
|
29273
|
+
* Generate a transaction that creates a new Vote account.
|
|
29274
|
+
*/
|
|
29275
|
+
|
|
29276
|
+
|
|
29277
|
+
static createAccount(params) {
|
|
29278
|
+
const transaction = new Transaction();
|
|
29279
|
+
transaction.add(SystemProgram.createAccount({
|
|
29280
|
+
fromPubkey: params.fromPubkey,
|
|
29281
|
+
newAccountPubkey: params.votePubkey,
|
|
29282
|
+
lamports: params.lamports,
|
|
29283
|
+
space: this.space,
|
|
29284
|
+
programId: this.programId
|
|
29285
|
+
}));
|
|
29286
|
+
return transaction.add(this.initializeAccount({
|
|
29287
|
+
votePubkey: params.votePubkey,
|
|
29288
|
+
nodePubkey: params.voteInit.nodePubkey,
|
|
29289
|
+
voteInit: params.voteInit
|
|
29290
|
+
}));
|
|
29291
|
+
}
|
|
29292
|
+
/**
|
|
29293
|
+
* Generate a transaction to withdraw from a Vote account.
|
|
29294
|
+
*/
|
|
29295
|
+
|
|
29296
|
+
|
|
29297
|
+
static withdraw(params) {
|
|
29298
|
+
const {
|
|
29299
|
+
votePubkey,
|
|
29300
|
+
authorizedWithdrawerPubkey,
|
|
29301
|
+
lamports,
|
|
29302
|
+
toPubkey
|
|
29303
|
+
} = params;
|
|
29304
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
|
|
29305
|
+
const data = encodeData(type, {
|
|
29306
|
+
lamports
|
|
29307
|
+
});
|
|
29308
|
+
const keys = [{
|
|
29309
|
+
pubkey: votePubkey,
|
|
29310
|
+
isSigner: false,
|
|
29311
|
+
isWritable: true
|
|
29312
|
+
}, {
|
|
29313
|
+
pubkey: toPubkey,
|
|
29314
|
+
isSigner: false,
|
|
29315
|
+
isWritable: true
|
|
29316
|
+
}, {
|
|
29317
|
+
pubkey: authorizedWithdrawerPubkey,
|
|
29318
|
+
isSigner: true,
|
|
29319
|
+
isWritable: false
|
|
29320
|
+
}];
|
|
29321
|
+
return new Transaction().add({
|
|
29322
|
+
keys,
|
|
29323
|
+
programId: this.programId,
|
|
29324
|
+
data
|
|
28818
29325
|
});
|
|
28819
29326
|
}
|
|
28820
29327
|
|
|
28821
29328
|
}
|
|
29329
|
+
VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
|
|
29330
|
+
VoteProgram.space = 3731;
|
|
28822
29331
|
|
|
28823
29332
|
/**
|
|
28824
29333
|
* Send and confirm a raw transaction
|
|
@@ -28849,12 +29358,12 @@ var solanaWeb3 = (function (exports) {
|
|
|
28849
29358
|
http: {
|
|
28850
29359
|
devnet: 'http://api.devnet.solana.com',
|
|
28851
29360
|
testnet: 'http://api.testnet.solana.com',
|
|
28852
|
-
'mainnet-beta': 'http://api.mainnet-beta.solana.com'
|
|
29361
|
+
'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
|
|
28853
29362
|
},
|
|
28854
29363
|
https: {
|
|
28855
29364
|
devnet: 'https://api.devnet.solana.com',
|
|
28856
29365
|
testnet: 'https://api.testnet.solana.com',
|
|
28857
|
-
'mainnet-beta': 'https://api.mainnet-beta.solana.com'
|
|
29366
|
+
'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
|
|
28858
29367
|
}
|
|
28859
29368
|
};
|
|
28860
29369
|
|
|
@@ -28909,10 +29418,13 @@ var solanaWeb3 = (function (exports) {
|
|
|
28909
29418
|
exports.STAKE_INSTRUCTION_LAYOUTS = STAKE_INSTRUCTION_LAYOUTS;
|
|
28910
29419
|
exports.SYSTEM_INSTRUCTION_LAYOUTS = SYSTEM_INSTRUCTION_LAYOUTS;
|
|
28911
29420
|
exports.SYSVAR_CLOCK_PUBKEY = SYSVAR_CLOCK_PUBKEY;
|
|
29421
|
+
exports.SYSVAR_EPOCH_SCHEDULE_PUBKEY = SYSVAR_EPOCH_SCHEDULE_PUBKEY;
|
|
28912
29422
|
exports.SYSVAR_INSTRUCTIONS_PUBKEY = SYSVAR_INSTRUCTIONS_PUBKEY;
|
|
28913
29423
|
exports.SYSVAR_RECENT_BLOCKHASHES_PUBKEY = SYSVAR_RECENT_BLOCKHASHES_PUBKEY;
|
|
28914
29424
|
exports.SYSVAR_RENT_PUBKEY = SYSVAR_RENT_PUBKEY;
|
|
28915
29425
|
exports.SYSVAR_REWARDS_PUBKEY = SYSVAR_REWARDS_PUBKEY;
|
|
29426
|
+
exports.SYSVAR_SLOT_HASHES_PUBKEY = SYSVAR_SLOT_HASHES_PUBKEY;
|
|
29427
|
+
exports.SYSVAR_SLOT_HISTORY_PUBKEY = SYSVAR_SLOT_HISTORY_PUBKEY;
|
|
28916
29428
|
exports.SYSVAR_STAKE_HISTORY_PUBKEY = SYSVAR_STAKE_HISTORY_PUBKEY;
|
|
28917
29429
|
exports.Secp256k1Program = Secp256k1Program;
|
|
28918
29430
|
exports.SendTransactionError = SendTransactionError;
|
|
@@ -28928,6 +29440,9 @@ var solanaWeb3 = (function (exports) {
|
|
|
28928
29440
|
exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
|
|
28929
29441
|
exports.ValidatorInfo = ValidatorInfo;
|
|
28930
29442
|
exports.VoteAccount = VoteAccount;
|
|
29443
|
+
exports.VoteInit = VoteInit;
|
|
29444
|
+
exports.VoteInstruction = VoteInstruction;
|
|
29445
|
+
exports.VoteProgram = VoteProgram;
|
|
28931
29446
|
exports.clusterApiUrl = clusterApiUrl;
|
|
28932
29447
|
exports.sendAndConfirmRawTransaction = sendAndConfirmRawTransaction;
|
|
28933
29448
|
exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
|