@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.cjs.js
CHANGED
|
@@ -1840,6 +1840,10 @@ class PublicKey extends Struct {
|
|
|
1840
1840
|
toBase58() {
|
|
1841
1841
|
return bs58__default["default"].encode(this.toBytes());
|
|
1842
1842
|
}
|
|
1843
|
+
|
|
1844
|
+
toJSON() {
|
|
1845
|
+
return this.toBase58();
|
|
1846
|
+
}
|
|
1843
1847
|
/**
|
|
1844
1848
|
* Return the byte array representation of the public key
|
|
1845
1849
|
*/
|
|
@@ -2106,6 +2110,13 @@ const authorized = (property = 'authorized') => {
|
|
|
2106
2110
|
const lockup = (property = 'lockup') => {
|
|
2107
2111
|
return BufferLayout__namespace.struct([BufferLayout__namespace.ns64('unixTimestamp'), BufferLayout__namespace.ns64('epoch'), publicKey('custodian')], property);
|
|
2108
2112
|
};
|
|
2113
|
+
/**
|
|
2114
|
+
* Layout for a VoteInit object
|
|
2115
|
+
*/
|
|
2116
|
+
|
|
2117
|
+
const voteInit = (property = 'voteInit') => {
|
|
2118
|
+
return BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission')], property);
|
|
2119
|
+
};
|
|
2109
2120
|
function getAlloc(type, fields) {
|
|
2110
2121
|
let alloc = 0;
|
|
2111
2122
|
type.layout.fields.forEach(item => {
|
|
@@ -2479,8 +2490,9 @@ class Transaction {
|
|
|
2479
2490
|
}); // Sort. Prioritizing first by signer, then by writable
|
|
2480
2491
|
|
|
2481
2492
|
accountMetas.sort(function (x, y) {
|
|
2493
|
+
const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
|
|
2482
2494
|
const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
|
|
2483
|
-
const checkWritable = x.isWritable === y.isWritable ?
|
|
2495
|
+
const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
|
|
2484
2496
|
return checkSigner || checkWritable;
|
|
2485
2497
|
}); // Cull duplicate account metas
|
|
2486
2498
|
|
|
@@ -2936,11 +2948,14 @@ class Transaction {
|
|
|
2936
2948
|
}
|
|
2937
2949
|
|
|
2938
2950
|
const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
2951
|
+
const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
|
|
2952
|
+
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
2939
2953
|
const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
|
|
2940
2954
|
const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
|
|
2941
2955
|
const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
|
|
2956
|
+
const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
|
|
2957
|
+
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
2942
2958
|
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
2943
|
-
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
2944
2959
|
|
|
2945
2960
|
/**
|
|
2946
2961
|
* Sign, send and confirm a transaction.
|
|
@@ -2956,7 +2971,8 @@ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions111111111111
|
|
|
2956
2971
|
async function sendAndConfirmTransaction(connection, transaction, signers, options) {
|
|
2957
2972
|
const sendOptions = options && {
|
|
2958
2973
|
skipPreflight: options.skipPreflight,
|
|
2959
|
-
preflightCommitment: options.preflightCommitment || options.commitment
|
|
2974
|
+
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
2975
|
+
maxRetries: options.maxRetries
|
|
2960
2976
|
};
|
|
2961
2977
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
2962
2978
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
@@ -4358,16 +4374,15 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
|
|
|
4358
4374
|
let fetchWithMiddleware;
|
|
4359
4375
|
|
|
4360
4376
|
if (fetchMiddleware) {
|
|
4361
|
-
fetchWithMiddleware = (url, options) => {
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
}
|
|
4369
|
-
});
|
|
4377
|
+
fetchWithMiddleware = async (url, options) => {
|
|
4378
|
+
const modifiedFetchArgs = await new Promise((resolve, reject) => {
|
|
4379
|
+
try {
|
|
4380
|
+
fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
|
|
4381
|
+
} catch (error) {
|
|
4382
|
+
reject(error);
|
|
4383
|
+
}
|
|
4370
4384
|
});
|
|
4385
|
+
return await fetch__default["default"](...modifiedFetchArgs);
|
|
4371
4386
|
};
|
|
4372
4387
|
}
|
|
4373
4388
|
|
|
@@ -4861,6 +4876,7 @@ const ParsedConfirmedTransactionResult = superstruct.type({
|
|
|
4861
4876
|
const TokenBalanceResult = superstruct.type({
|
|
4862
4877
|
accountIndex: superstruct.number(),
|
|
4863
4878
|
mint: superstruct.string(),
|
|
4879
|
+
owner: superstruct.optional(superstruct.string()),
|
|
4864
4880
|
uiTokenAmount: TokenAmountResult
|
|
4865
4881
|
});
|
|
4866
4882
|
/**
|
|
@@ -4901,8 +4917,31 @@ const ParsedConfirmedTransactionMetaResult = superstruct.type({
|
|
|
4901
4917
|
preTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
|
|
4902
4918
|
postTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult)))
|
|
4903
4919
|
});
|
|
4920
|
+
/**
|
|
4921
|
+
* Expected JSON RPC response for the "getBlock" message
|
|
4922
|
+
*/
|
|
4923
|
+
|
|
4924
|
+
const GetBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
|
|
4925
|
+
blockhash: superstruct.string(),
|
|
4926
|
+
previousBlockhash: superstruct.string(),
|
|
4927
|
+
parentSlot: superstruct.number(),
|
|
4928
|
+
transactions: superstruct.array(superstruct.type({
|
|
4929
|
+
transaction: ConfirmedTransactionResult,
|
|
4930
|
+
meta: superstruct.nullable(ConfirmedTransactionMetaResult)
|
|
4931
|
+
})),
|
|
4932
|
+
rewards: superstruct.optional(superstruct.array(superstruct.type({
|
|
4933
|
+
pubkey: superstruct.string(),
|
|
4934
|
+
lamports: superstruct.number(),
|
|
4935
|
+
postBalance: superstruct.nullable(superstruct.number()),
|
|
4936
|
+
rewardType: superstruct.nullable(superstruct.string())
|
|
4937
|
+
}))),
|
|
4938
|
+
blockTime: superstruct.nullable(superstruct.number()),
|
|
4939
|
+
blockHeight: superstruct.nullable(superstruct.number())
|
|
4940
|
+
})));
|
|
4904
4941
|
/**
|
|
4905
4942
|
* Expected JSON RPC response for the "getConfirmedBlock" message
|
|
4943
|
+
*
|
|
4944
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
|
|
4906
4945
|
*/
|
|
4907
4946
|
|
|
4908
4947
|
const GetConfirmedBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
|
|
@@ -4922,10 +4961,10 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruc
|
|
|
4922
4961
|
blockTime: superstruct.nullable(superstruct.number())
|
|
4923
4962
|
})));
|
|
4924
4963
|
/**
|
|
4925
|
-
* Expected JSON RPC response for the "
|
|
4964
|
+
* Expected JSON RPC response for the "getBlock" message
|
|
4926
4965
|
*/
|
|
4927
4966
|
|
|
4928
|
-
const
|
|
4967
|
+
const GetBlockSignaturesRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
|
|
4929
4968
|
blockhash: superstruct.string(),
|
|
4930
4969
|
previousBlockhash: superstruct.string(),
|
|
4931
4970
|
parentSlot: superstruct.number(),
|
|
@@ -4933,20 +4972,20 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(superstruct.nullable(
|
|
|
4933
4972
|
blockTime: superstruct.nullable(superstruct.number())
|
|
4934
4973
|
})));
|
|
4935
4974
|
/**
|
|
4936
|
-
* Expected JSON RPC response for the "
|
|
4975
|
+
* Expected JSON RPC response for the "getTransaction" message
|
|
4937
4976
|
*/
|
|
4938
4977
|
|
|
4939
|
-
const
|
|
4978
|
+
const GetTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
|
|
4940
4979
|
slot: superstruct.number(),
|
|
4941
4980
|
meta: ConfirmedTransactionMetaResult,
|
|
4942
4981
|
blockTime: superstruct.optional(superstruct.nullable(superstruct.number())),
|
|
4943
4982
|
transaction: ConfirmedTransactionResult
|
|
4944
4983
|
})));
|
|
4945
4984
|
/**
|
|
4946
|
-
* Expected JSON RPC response for the "
|
|
4985
|
+
* Expected parsed JSON RPC response for the "getTransaction" message
|
|
4947
4986
|
*/
|
|
4948
4987
|
|
|
4949
|
-
const
|
|
4988
|
+
const GetParsedTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
|
|
4950
4989
|
slot: superstruct.number(),
|
|
4951
4990
|
transaction: ParsedConfirmedTransactionResult,
|
|
4952
4991
|
meta: superstruct.nullable(ParsedConfirmedTransactionMetaResult),
|
|
@@ -4954,6 +4993,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(superstruct.nullabl
|
|
|
4954
4993
|
})));
|
|
4955
4994
|
/**
|
|
4956
4995
|
* Expected JSON RPC response for the "getRecentBlockhash" message
|
|
4996
|
+
*
|
|
4997
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
|
|
4957
4998
|
*/
|
|
4958
4999
|
|
|
4959
5000
|
const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(superstruct.type({
|
|
@@ -4962,6 +5003,14 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(superstruc
|
|
|
4962
5003
|
lamportsPerSignature: superstruct.number()
|
|
4963
5004
|
})
|
|
4964
5005
|
}));
|
|
5006
|
+
/**
|
|
5007
|
+
* Expected JSON RPC response for the "getLatestBlockhash" message
|
|
5008
|
+
*/
|
|
5009
|
+
|
|
5010
|
+
const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(superstruct.type({
|
|
5011
|
+
blockhash: superstruct.string(),
|
|
5012
|
+
lastValidBlockHeight: superstruct.number()
|
|
5013
|
+
}));
|
|
4965
5014
|
const PerfSampleResult = superstruct.type({
|
|
4966
5015
|
slot: superstruct.number(),
|
|
4967
5016
|
numTransactions: superstruct.number(),
|
|
@@ -5464,13 +5513,25 @@ class Connection {
|
|
|
5464
5513
|
*/
|
|
5465
5514
|
|
|
5466
5515
|
|
|
5467
|
-
async getMultipleAccountsInfo(publicKeys,
|
|
5516
|
+
async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
|
|
5468
5517
|
const keys = publicKeys.map(key => key.toBase58());
|
|
5518
|
+
let commitment;
|
|
5519
|
+
let encoding = 'base64';
|
|
5520
|
+
|
|
5521
|
+
if (configOrCommitment) {
|
|
5522
|
+
if (typeof configOrCommitment === 'string') {
|
|
5523
|
+
commitment = configOrCommitment;
|
|
5524
|
+
encoding = 'base64';
|
|
5525
|
+
} else {
|
|
5526
|
+
commitment = configOrCommitment.commitment;
|
|
5527
|
+
encoding = configOrCommitment.encoding || 'base64';
|
|
5528
|
+
}
|
|
5529
|
+
}
|
|
5469
5530
|
|
|
5470
|
-
const args = this._buildArgs([keys], commitment,
|
|
5531
|
+
const args = this._buildArgs([keys], commitment, encoding);
|
|
5471
5532
|
|
|
5472
5533
|
const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
|
|
5473
|
-
const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.array(superstruct.nullable(
|
|
5534
|
+
const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.array(superstruct.nullable(ParsedAccountInfoResult))));
|
|
5474
5535
|
|
|
5475
5536
|
if ('error' in res) {
|
|
5476
5537
|
throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
|
|
@@ -5894,6 +5955,8 @@ class Connection {
|
|
|
5894
5955
|
/**
|
|
5895
5956
|
* Fetch a recent blockhash from the cluster, return with context
|
|
5896
5957
|
* @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
|
|
5958
|
+
*
|
|
5959
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
5897
5960
|
*/
|
|
5898
5961
|
|
|
5899
5962
|
|
|
@@ -5929,6 +5992,8 @@ class Connection {
|
|
|
5929
5992
|
}
|
|
5930
5993
|
/**
|
|
5931
5994
|
* Fetch the fee calculator for a recent blockhash from the cluster, return with context
|
|
5995
|
+
*
|
|
5996
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
|
|
5932
5997
|
*/
|
|
5933
5998
|
|
|
5934
5999
|
|
|
@@ -5951,9 +6016,34 @@ class Connection {
|
|
|
5951
6016
|
value: value !== null ? value.feeCalculator : null
|
|
5952
6017
|
};
|
|
5953
6018
|
}
|
|
6019
|
+
/**
|
|
6020
|
+
* Fetch the fee for a message from the cluster, return with context
|
|
6021
|
+
*/
|
|
6022
|
+
|
|
6023
|
+
|
|
6024
|
+
async getFeeForMessage(message, commitment) {
|
|
6025
|
+
const wireMessage = message.serialize().toString('base64');
|
|
6026
|
+
|
|
6027
|
+
const args = this._buildArgs([wireMessage], commitment);
|
|
6028
|
+
|
|
6029
|
+
const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
|
|
6030
|
+
const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.nullable(superstruct.number())));
|
|
6031
|
+
|
|
6032
|
+
if ('error' in res) {
|
|
6033
|
+
throw new Error('failed to get slot: ' + res.error.message);
|
|
6034
|
+
}
|
|
6035
|
+
|
|
6036
|
+
if (res.result === null) {
|
|
6037
|
+
throw new Error('invalid blockhash');
|
|
6038
|
+
}
|
|
6039
|
+
|
|
6040
|
+
return res.result;
|
|
6041
|
+
}
|
|
5954
6042
|
/**
|
|
5955
6043
|
* Fetch a recent blockhash from the cluster
|
|
5956
6044
|
* @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
|
|
6045
|
+
*
|
|
6046
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
5957
6047
|
*/
|
|
5958
6048
|
|
|
5959
6049
|
|
|
@@ -5965,6 +6055,38 @@ class Connection {
|
|
|
5965
6055
|
throw new Error('failed to get recent blockhash: ' + e);
|
|
5966
6056
|
}
|
|
5967
6057
|
}
|
|
6058
|
+
/**
|
|
6059
|
+
* Fetch the latest blockhash from the cluster
|
|
6060
|
+
* @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
|
|
6061
|
+
*/
|
|
6062
|
+
|
|
6063
|
+
|
|
6064
|
+
async getLatestBlockhash(commitment) {
|
|
6065
|
+
try {
|
|
6066
|
+
const res = await this.getLatestBlockhashAndContext(commitment);
|
|
6067
|
+
return res.value;
|
|
6068
|
+
} catch (e) {
|
|
6069
|
+
throw new Error('failed to get recent blockhash: ' + e);
|
|
6070
|
+
}
|
|
6071
|
+
}
|
|
6072
|
+
/**
|
|
6073
|
+
* Fetch the latest blockhash from the cluster
|
|
6074
|
+
* @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
|
|
6075
|
+
*/
|
|
6076
|
+
|
|
6077
|
+
|
|
6078
|
+
async getLatestBlockhashAndContext(commitment) {
|
|
6079
|
+
const args = this._buildArgs([], commitment);
|
|
6080
|
+
|
|
6081
|
+
const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
|
|
6082
|
+
const res = superstruct.create(unsafeRes, GetLatestBlockhashRpcResult);
|
|
6083
|
+
|
|
6084
|
+
if ('error' in res) {
|
|
6085
|
+
throw new Error('failed to get latest blockhash: ' + res.error.message);
|
|
6086
|
+
}
|
|
6087
|
+
|
|
6088
|
+
return res.result;
|
|
6089
|
+
}
|
|
5968
6090
|
/**
|
|
5969
6091
|
* Fetch the node version
|
|
5970
6092
|
*/
|
|
@@ -6003,8 +6125,8 @@ class Connection {
|
|
|
6003
6125
|
async getBlock(slot, opts) {
|
|
6004
6126
|
const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
|
|
6005
6127
|
|
|
6006
|
-
const unsafeRes = await this._rpcRequest('
|
|
6007
|
-
const res = superstruct.create(unsafeRes,
|
|
6128
|
+
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
6129
|
+
const res = superstruct.create(unsafeRes, GetBlockRpcResult);
|
|
6008
6130
|
|
|
6009
6131
|
if ('error' in res) {
|
|
6010
6132
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -6028,18 +6150,18 @@ class Connection {
|
|
|
6028
6150
|
};
|
|
6029
6151
|
}
|
|
6030
6152
|
/**
|
|
6031
|
-
* Fetch a
|
|
6153
|
+
* Fetch a confirmed or finalized transaction from the cluster.
|
|
6032
6154
|
*/
|
|
6033
6155
|
|
|
6034
6156
|
|
|
6035
6157
|
async getTransaction(signature, opts) {
|
|
6036
6158
|
const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
|
|
6037
6159
|
|
|
6038
|
-
const unsafeRes = await this._rpcRequest('
|
|
6039
|
-
const res = superstruct.create(unsafeRes,
|
|
6160
|
+
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6161
|
+
const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
|
|
6040
6162
|
|
|
6041
6163
|
if ('error' in res) {
|
|
6042
|
-
throw new Error('failed to get
|
|
6164
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6043
6165
|
}
|
|
6044
6166
|
|
|
6045
6167
|
const result = res.result;
|
|
@@ -6050,6 +6172,49 @@ class Connection {
|
|
|
6050
6172
|
}
|
|
6051
6173
|
};
|
|
6052
6174
|
}
|
|
6175
|
+
/**
|
|
6176
|
+
* Fetch parsed transaction details for a confirmed or finalized transaction
|
|
6177
|
+
*/
|
|
6178
|
+
|
|
6179
|
+
|
|
6180
|
+
async getParsedTransaction(signature, commitment) {
|
|
6181
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6182
|
+
|
|
6183
|
+
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6184
|
+
const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6185
|
+
|
|
6186
|
+
if ('error' in res) {
|
|
6187
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6188
|
+
}
|
|
6189
|
+
|
|
6190
|
+
return res.result;
|
|
6191
|
+
}
|
|
6192
|
+
/**
|
|
6193
|
+
* Fetch parsed transaction details for a batch of confirmed transactions
|
|
6194
|
+
*/
|
|
6195
|
+
|
|
6196
|
+
|
|
6197
|
+
async getParsedTransactions(signatures, commitment) {
|
|
6198
|
+
const batch = signatures.map(signature => {
|
|
6199
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6200
|
+
|
|
6201
|
+
return {
|
|
6202
|
+
methodName: 'getTransaction',
|
|
6203
|
+
args
|
|
6204
|
+
};
|
|
6205
|
+
});
|
|
6206
|
+
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
6207
|
+
const res = unsafeRes.map(unsafeRes => {
|
|
6208
|
+
const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6209
|
+
|
|
6210
|
+
if ('error' in res) {
|
|
6211
|
+
throw new Error('failed to get transactions: ' + res.error.message);
|
|
6212
|
+
}
|
|
6213
|
+
|
|
6214
|
+
return res.result;
|
|
6215
|
+
});
|
|
6216
|
+
return res;
|
|
6217
|
+
}
|
|
6053
6218
|
/**
|
|
6054
6219
|
* Fetch a list of Transactions and transaction statuses from the cluster
|
|
6055
6220
|
* for a confirmed block.
|
|
@@ -6059,18 +6224,39 @@ class Connection {
|
|
|
6059
6224
|
|
|
6060
6225
|
|
|
6061
6226
|
async getConfirmedBlock(slot, commitment) {
|
|
6062
|
-
const
|
|
6063
|
-
|
|
6064
|
-
|
|
6227
|
+
const args = this._buildArgsAtLeastConfirmed([slot], commitment);
|
|
6228
|
+
|
|
6229
|
+
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
|
|
6230
|
+
const res = superstruct.create(unsafeRes, GetConfirmedBlockRpcResult);
|
|
6231
|
+
|
|
6232
|
+
if ('error' in res) {
|
|
6233
|
+
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
6234
|
+
}
|
|
6235
|
+
|
|
6236
|
+
const result = res.result;
|
|
6065
6237
|
|
|
6066
6238
|
if (!result) {
|
|
6067
6239
|
throw new Error('Confirmed block ' + slot + ' not found');
|
|
6068
6240
|
}
|
|
6069
6241
|
|
|
6070
|
-
|
|
6242
|
+
const block = { ...result,
|
|
6071
6243
|
transactions: result.transactions.map(({
|
|
6072
6244
|
transaction,
|
|
6073
6245
|
meta
|
|
6246
|
+
}) => {
|
|
6247
|
+
const message = new Message(transaction.message);
|
|
6248
|
+
return {
|
|
6249
|
+
meta,
|
|
6250
|
+
transaction: { ...transaction,
|
|
6251
|
+
message
|
|
6252
|
+
}
|
|
6253
|
+
};
|
|
6254
|
+
})
|
|
6255
|
+
};
|
|
6256
|
+
return { ...block,
|
|
6257
|
+
transactions: block.transactions.map(({
|
|
6258
|
+
transaction,
|
|
6259
|
+
meta
|
|
6074
6260
|
}) => {
|
|
6075
6261
|
return {
|
|
6076
6262
|
meta,
|
|
@@ -6087,7 +6273,7 @@ class Connection {
|
|
|
6087
6273
|
async getBlocks(startSlot, endSlot, commitment) {
|
|
6088
6274
|
const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
|
|
6089
6275
|
|
|
6090
|
-
const unsafeRes = await this._rpcRequest('
|
|
6276
|
+
const unsafeRes = await this._rpcRequest('getBlocks', args);
|
|
6091
6277
|
const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(superstruct.number())));
|
|
6092
6278
|
|
|
6093
6279
|
if ('error' in res) {
|
|
@@ -6096,8 +6282,36 @@ class Connection {
|
|
|
6096
6282
|
|
|
6097
6283
|
return res.result;
|
|
6098
6284
|
}
|
|
6285
|
+
/**
|
|
6286
|
+
* Fetch a list of Signatures from the cluster for a block, excluding rewards
|
|
6287
|
+
*/
|
|
6288
|
+
|
|
6289
|
+
|
|
6290
|
+
async getBlockSignatures(slot, commitment) {
|
|
6291
|
+
const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
|
|
6292
|
+
transactionDetails: 'signatures',
|
|
6293
|
+
rewards: false
|
|
6294
|
+
});
|
|
6295
|
+
|
|
6296
|
+
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
6297
|
+
const res = superstruct.create(unsafeRes, GetBlockSignaturesRpcResult);
|
|
6298
|
+
|
|
6299
|
+
if ('error' in res) {
|
|
6300
|
+
throw new Error('failed to get block: ' + res.error.message);
|
|
6301
|
+
}
|
|
6302
|
+
|
|
6303
|
+
const result = res.result;
|
|
6304
|
+
|
|
6305
|
+
if (!result) {
|
|
6306
|
+
throw new Error('Block ' + slot + ' not found');
|
|
6307
|
+
}
|
|
6308
|
+
|
|
6309
|
+
return result;
|
|
6310
|
+
}
|
|
6099
6311
|
/**
|
|
6100
6312
|
* Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
|
|
6313
|
+
*
|
|
6314
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
|
|
6101
6315
|
*/
|
|
6102
6316
|
|
|
6103
6317
|
|
|
@@ -6108,7 +6322,7 @@ class Connection {
|
|
|
6108
6322
|
});
|
|
6109
6323
|
|
|
6110
6324
|
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
|
|
6111
|
-
const res = superstruct.create(unsafeRes,
|
|
6325
|
+
const res = superstruct.create(unsafeRes, GetBlockSignaturesRpcResult);
|
|
6112
6326
|
|
|
6113
6327
|
if ('error' in res) {
|
|
6114
6328
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -6124,24 +6338,33 @@ class Connection {
|
|
|
6124
6338
|
}
|
|
6125
6339
|
/**
|
|
6126
6340
|
* Fetch a transaction details for a confirmed transaction
|
|
6341
|
+
*
|
|
6342
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
|
|
6127
6343
|
*/
|
|
6128
6344
|
|
|
6129
6345
|
|
|
6130
6346
|
async getConfirmedTransaction(signature, commitment) {
|
|
6131
|
-
const
|
|
6132
|
-
|
|
6133
|
-
|
|
6347
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment);
|
|
6348
|
+
|
|
6349
|
+
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
|
|
6350
|
+
const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
|
|
6351
|
+
|
|
6352
|
+
if ('error' in res) {
|
|
6353
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6354
|
+
}
|
|
6355
|
+
|
|
6356
|
+
const result = res.result;
|
|
6134
6357
|
if (!result) return result;
|
|
6135
|
-
const
|
|
6136
|
-
|
|
6137
|
-
signatures
|
|
6138
|
-
} = result.transaction;
|
|
6358
|
+
const message = new Message(result.transaction.message);
|
|
6359
|
+
const signatures = result.transaction.signatures;
|
|
6139
6360
|
return { ...result,
|
|
6140
6361
|
transaction: Transaction.populate(message, signatures)
|
|
6141
6362
|
};
|
|
6142
6363
|
}
|
|
6143
6364
|
/**
|
|
6144
6365
|
* Fetch parsed transaction details for a confirmed transaction
|
|
6366
|
+
*
|
|
6367
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
|
|
6145
6368
|
*/
|
|
6146
6369
|
|
|
6147
6370
|
|
|
@@ -6149,7 +6372,7 @@ class Connection {
|
|
|
6149
6372
|
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6150
6373
|
|
|
6151
6374
|
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
|
|
6152
|
-
const res = superstruct.create(unsafeRes,
|
|
6375
|
+
const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6153
6376
|
|
|
6154
6377
|
if ('error' in res) {
|
|
6155
6378
|
throw new Error('failed to get confirmed transaction: ' + res.error.message);
|
|
@@ -6159,6 +6382,8 @@ class Connection {
|
|
|
6159
6382
|
}
|
|
6160
6383
|
/**
|
|
6161
6384
|
* Fetch parsed transaction details for a batch of confirmed transactions
|
|
6385
|
+
*
|
|
6386
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
|
|
6162
6387
|
*/
|
|
6163
6388
|
|
|
6164
6389
|
|
|
@@ -6173,7 +6398,7 @@ class Connection {
|
|
|
6173
6398
|
});
|
|
6174
6399
|
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
6175
6400
|
const res = unsafeRes.map(unsafeRes => {
|
|
6176
|
-
const res = superstruct.create(unsafeRes,
|
|
6401
|
+
const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6177
6402
|
|
|
6178
6403
|
if ('error' in res) {
|
|
6179
6404
|
throw new Error('failed to get confirmed transactions: ' + res.error.message);
|
|
@@ -6563,6 +6788,10 @@ class Connection {
|
|
|
6563
6788
|
const skipPreflight = options && options.skipPreflight;
|
|
6564
6789
|
const preflightCommitment = options && options.preflightCommitment || this.commitment;
|
|
6565
6790
|
|
|
6791
|
+
if (options && options.maxRetries) {
|
|
6792
|
+
config.maxRetries = options.maxRetries;
|
|
6793
|
+
}
|
|
6794
|
+
|
|
6566
6795
|
if (skipPreflight) {
|
|
6567
6796
|
config.skipPreflight = skipPreflight;
|
|
6568
6797
|
}
|
|
@@ -6717,7 +6946,14 @@ class Connection {
|
|
|
6717
6946
|
this._rpcWebSocketIdleTimeout = setTimeout(() => {
|
|
6718
6947
|
this._rpcWebSocketIdleTimeout = null;
|
|
6719
6948
|
|
|
6720
|
-
|
|
6949
|
+
try {
|
|
6950
|
+
this._rpcWebSocket.close();
|
|
6951
|
+
} catch (err) {
|
|
6952
|
+
// swallow error if socket has already been closed.
|
|
6953
|
+
if (err instanceof Error) {
|
|
6954
|
+
console.log(`Error when closing socket connection: ${err.message}`);
|
|
6955
|
+
}
|
|
6956
|
+
}
|
|
6721
6957
|
}, 500);
|
|
6722
6958
|
}
|
|
6723
6959
|
|
|
@@ -8430,9 +8666,10 @@ const VOTE_PROGRAM_ID = new PublicKey('Vote1111111111111111111111111111111111111
|
|
|
8430
8666
|
*
|
|
8431
8667
|
* @internal
|
|
8432
8668
|
*/
|
|
8433
|
-
const VoteAccountLayout = BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('
|
|
8434
|
-
BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('slot'), BufferLayout__namespace.u32('confirmationCount')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'votes'), BufferLayout__namespace.u8('rootSlotValid'), BufferLayout__namespace.nu64('rootSlot'), BufferLayout__namespace.nu64(
|
|
8435
|
-
BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('epoch'), BufferLayout__namespace.nu64('
|
|
8669
|
+
const VoteAccountLayout = BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission'), BufferLayout__namespace.nu64(), // votes.length
|
|
8670
|
+
BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('slot'), BufferLayout__namespace.u32('confirmationCount')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'votes'), BufferLayout__namespace.u8('rootSlotValid'), BufferLayout__namespace.nu64('rootSlot'), BufferLayout__namespace.nu64(), // authorizedVoters.length
|
|
8671
|
+
BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('epoch'), publicKey('authorizedVoter')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'authorizedVoters'), BufferLayout__namespace.struct([BufferLayout__namespace.seq(BufferLayout__namespace.struct([publicKey('authorizedPubkey'), BufferLayout__namespace.nu64('epochOfLastAuthorizedSwitch'), BufferLayout__namespace.nu64('targetEpoch')]), 32, 'buf'), BufferLayout__namespace.nu64('idx'), BufferLayout__namespace.u8('isEmpty')], 'priorVoters'), BufferLayout__namespace.nu64(), // epochCredits.length
|
|
8672
|
+
BufferLayout__namespace.seq(BufferLayout__namespace.struct([BufferLayout__namespace.nu64('epoch'), BufferLayout__namespace.nu64('credits'), BufferLayout__namespace.nu64('prevCredits')]), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'epochCredits'), BufferLayout__namespace.struct([BufferLayout__namespace.nu64('slot'), BufferLayout__namespace.nu64('timestamp')], 'lastTimestamp')]);
|
|
8436
8673
|
|
|
8437
8674
|
/**
|
|
8438
8675
|
* VoteAccount class
|
|
@@ -8443,25 +8680,23 @@ class VoteAccount {
|
|
|
8443
8680
|
*/
|
|
8444
8681
|
constructor(args) {
|
|
8445
8682
|
this.nodePubkey = void 0;
|
|
8446
|
-
this.
|
|
8447
|
-
this.authorizedWithdrawerPubkey = void 0;
|
|
8683
|
+
this.authorizedWithdrawer = void 0;
|
|
8448
8684
|
this.commission = void 0;
|
|
8449
|
-
this.votes = void 0;
|
|
8450
8685
|
this.rootSlot = void 0;
|
|
8451
|
-
this.
|
|
8452
|
-
this.
|
|
8453
|
-
this.
|
|
8686
|
+
this.votes = void 0;
|
|
8687
|
+
this.authorizedVoters = void 0;
|
|
8688
|
+
this.priorVoters = void 0;
|
|
8454
8689
|
this.epochCredits = void 0;
|
|
8690
|
+
this.lastTimestamp = void 0;
|
|
8455
8691
|
this.nodePubkey = args.nodePubkey;
|
|
8456
|
-
this.
|
|
8457
|
-
this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
|
|
8692
|
+
this.authorizedWithdrawer = args.authorizedWithdrawer;
|
|
8458
8693
|
this.commission = args.commission;
|
|
8459
|
-
this.votes = args.votes;
|
|
8460
8694
|
this.rootSlot = args.rootSlot;
|
|
8461
|
-
this.
|
|
8462
|
-
this.
|
|
8463
|
-
this.
|
|
8695
|
+
this.votes = args.votes;
|
|
8696
|
+
this.authorizedVoters = args.authorizedVoters;
|
|
8697
|
+
this.priorVoters = args.priorVoters;
|
|
8464
8698
|
this.epochCredits = args.epochCredits;
|
|
8699
|
+
this.lastTimestamp = args.lastTimestamp;
|
|
8465
8700
|
}
|
|
8466
8701
|
/**
|
|
8467
8702
|
* Deserialize VoteAccount from the account data.
|
|
@@ -8472,7 +8707,8 @@ class VoteAccount {
|
|
|
8472
8707
|
|
|
8473
8708
|
|
|
8474
8709
|
static fromAccountData(buffer) {
|
|
8475
|
-
const
|
|
8710
|
+
const versionOffset = 4;
|
|
8711
|
+
const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
|
|
8476
8712
|
let rootSlot = va.rootSlot;
|
|
8477
8713
|
|
|
8478
8714
|
if (!va.rootSlotValid) {
|
|
@@ -8481,19 +8717,292 @@ class VoteAccount {
|
|
|
8481
8717
|
|
|
8482
8718
|
return new VoteAccount({
|
|
8483
8719
|
nodePubkey: new PublicKey(va.nodePubkey),
|
|
8484
|
-
|
|
8485
|
-
authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
|
|
8720
|
+
authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
|
|
8486
8721
|
commission: va.commission,
|
|
8487
8722
|
votes: va.votes,
|
|
8488
8723
|
rootSlot,
|
|
8489
|
-
|
|
8490
|
-
|
|
8491
|
-
|
|
8492
|
-
|
|
8724
|
+
authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
|
|
8725
|
+
priorVoters: getPriorVoters(va.priorVoters),
|
|
8726
|
+
epochCredits: va.epochCredits,
|
|
8727
|
+
lastTimestamp: va.lastTimestamp
|
|
8728
|
+
});
|
|
8729
|
+
}
|
|
8730
|
+
|
|
8731
|
+
}
|
|
8732
|
+
|
|
8733
|
+
function parseAuthorizedVoter({
|
|
8734
|
+
epoch,
|
|
8735
|
+
authorizedVoter
|
|
8736
|
+
}) {
|
|
8737
|
+
return {
|
|
8738
|
+
epoch,
|
|
8739
|
+
authorizedVoter: new PublicKey(authorizedVoter)
|
|
8740
|
+
};
|
|
8741
|
+
}
|
|
8742
|
+
|
|
8743
|
+
function parsePriorVoters({
|
|
8744
|
+
authorizedPubkey,
|
|
8745
|
+
epochOfLastAuthorizedSwitch,
|
|
8746
|
+
targetEpoch
|
|
8747
|
+
}) {
|
|
8748
|
+
return {
|
|
8749
|
+
authorizedPubkey: new PublicKey(authorizedPubkey),
|
|
8750
|
+
epochOfLastAuthorizedSwitch,
|
|
8751
|
+
targetEpoch
|
|
8752
|
+
};
|
|
8753
|
+
}
|
|
8754
|
+
|
|
8755
|
+
function getPriorVoters({
|
|
8756
|
+
buf,
|
|
8757
|
+
idx,
|
|
8758
|
+
isEmpty
|
|
8759
|
+
}) {
|
|
8760
|
+
if (isEmpty) {
|
|
8761
|
+
return [];
|
|
8762
|
+
}
|
|
8763
|
+
|
|
8764
|
+
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
8765
|
+
}
|
|
8766
|
+
|
|
8767
|
+
/**
|
|
8768
|
+
* Vote account info
|
|
8769
|
+
*/
|
|
8770
|
+
|
|
8771
|
+
class VoteInit {
|
|
8772
|
+
/** [0, 100] */
|
|
8773
|
+
constructor(nodePubkey, authorizedVoter, authorizedWithdrawer, commission) {
|
|
8774
|
+
this.nodePubkey = void 0;
|
|
8775
|
+
this.authorizedVoter = void 0;
|
|
8776
|
+
this.authorizedWithdrawer = void 0;
|
|
8777
|
+
this.commission = void 0;
|
|
8778
|
+
this.nodePubkey = nodePubkey;
|
|
8779
|
+
this.authorizedVoter = authorizedVoter;
|
|
8780
|
+
this.authorizedWithdrawer = authorizedWithdrawer;
|
|
8781
|
+
this.commission = commission;
|
|
8782
|
+
}
|
|
8783
|
+
|
|
8784
|
+
}
|
|
8785
|
+
/**
|
|
8786
|
+
* Create vote account transaction params
|
|
8787
|
+
*/
|
|
8788
|
+
|
|
8789
|
+
/**
|
|
8790
|
+
* Vote Instruction class
|
|
8791
|
+
*/
|
|
8792
|
+
class VoteInstruction {
|
|
8793
|
+
/**
|
|
8794
|
+
* @internal
|
|
8795
|
+
*/
|
|
8796
|
+
constructor() {}
|
|
8797
|
+
/**
|
|
8798
|
+
* Decode a vote instruction and retrieve the instruction type.
|
|
8799
|
+
*/
|
|
8800
|
+
|
|
8801
|
+
|
|
8802
|
+
static decodeInstructionType(instruction) {
|
|
8803
|
+
this.checkProgramId(instruction.programId);
|
|
8804
|
+
const instructionTypeLayout = BufferLayout__namespace.u32('instruction');
|
|
8805
|
+
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
8806
|
+
let type;
|
|
8807
|
+
|
|
8808
|
+
for (const [ixType, layout] of Object.entries(VOTE_INSTRUCTION_LAYOUTS)) {
|
|
8809
|
+
if (layout.index == typeIndex) {
|
|
8810
|
+
type = ixType;
|
|
8811
|
+
break;
|
|
8812
|
+
}
|
|
8813
|
+
}
|
|
8814
|
+
|
|
8815
|
+
if (!type) {
|
|
8816
|
+
throw new Error('Instruction type incorrect; not a VoteInstruction');
|
|
8817
|
+
}
|
|
8818
|
+
|
|
8819
|
+
return type;
|
|
8820
|
+
}
|
|
8821
|
+
/**
|
|
8822
|
+
* Decode an initialize vote instruction and retrieve the instruction params.
|
|
8823
|
+
*/
|
|
8824
|
+
|
|
8825
|
+
|
|
8826
|
+
static decodeInitializeAccount(instruction) {
|
|
8827
|
+
this.checkProgramId(instruction.programId);
|
|
8828
|
+
this.checkKeyLength(instruction.keys, 4);
|
|
8829
|
+
const {
|
|
8830
|
+
voteInit
|
|
8831
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.InitializeAccount, instruction.data);
|
|
8832
|
+
return {
|
|
8833
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
8834
|
+
nodePubkey: instruction.keys[3].pubkey,
|
|
8835
|
+
voteInit: new VoteInit(new PublicKey(voteInit.nodePubkey), new PublicKey(voteInit.authorizedVoter), new PublicKey(voteInit.authorizedWithdrawer), voteInit.commission)
|
|
8836
|
+
};
|
|
8837
|
+
}
|
|
8838
|
+
/**
|
|
8839
|
+
* Decode a withdraw instruction and retrieve the instruction params.
|
|
8840
|
+
*/
|
|
8841
|
+
|
|
8842
|
+
|
|
8843
|
+
static decodeWithdraw(instruction) {
|
|
8844
|
+
this.checkProgramId(instruction.programId);
|
|
8845
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
8846
|
+
const {
|
|
8847
|
+
lamports
|
|
8848
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
|
|
8849
|
+
return {
|
|
8850
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
8851
|
+
authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
|
|
8852
|
+
lamports,
|
|
8853
|
+
toPubkey: instruction.keys[1].pubkey
|
|
8854
|
+
};
|
|
8855
|
+
}
|
|
8856
|
+
/**
|
|
8857
|
+
* @internal
|
|
8858
|
+
*/
|
|
8859
|
+
|
|
8860
|
+
|
|
8861
|
+
static checkProgramId(programId) {
|
|
8862
|
+
if (!programId.equals(VoteProgram.programId)) {
|
|
8863
|
+
throw new Error('invalid instruction; programId is not VoteProgram');
|
|
8864
|
+
}
|
|
8865
|
+
}
|
|
8866
|
+
/**
|
|
8867
|
+
* @internal
|
|
8868
|
+
*/
|
|
8869
|
+
|
|
8870
|
+
|
|
8871
|
+
static checkKeyLength(keys, expectedLength) {
|
|
8872
|
+
if (keys.length < expectedLength) {
|
|
8873
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
8874
|
+
}
|
|
8875
|
+
}
|
|
8876
|
+
|
|
8877
|
+
}
|
|
8878
|
+
/**
|
|
8879
|
+
* An enumeration of valid VoteInstructionType's
|
|
8880
|
+
*/
|
|
8881
|
+
|
|
8882
|
+
const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
8883
|
+
InitializeAccount: {
|
|
8884
|
+
index: 0,
|
|
8885
|
+
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), voteInit()])
|
|
8886
|
+
},
|
|
8887
|
+
Withdraw: {
|
|
8888
|
+
index: 3,
|
|
8889
|
+
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), BufferLayout__namespace.ns64('lamports')])
|
|
8890
|
+
}
|
|
8891
|
+
});
|
|
8892
|
+
/**
|
|
8893
|
+
* Factory class for transactions to interact with the Vote program
|
|
8894
|
+
*/
|
|
8895
|
+
|
|
8896
|
+
class VoteProgram {
|
|
8897
|
+
/**
|
|
8898
|
+
* @internal
|
|
8899
|
+
*/
|
|
8900
|
+
constructor() {}
|
|
8901
|
+
/**
|
|
8902
|
+
* Public key that identifies the Vote program
|
|
8903
|
+
*/
|
|
8904
|
+
|
|
8905
|
+
|
|
8906
|
+
/**
|
|
8907
|
+
* Generate an Initialize instruction.
|
|
8908
|
+
*/
|
|
8909
|
+
static initializeAccount(params) {
|
|
8910
|
+
const {
|
|
8911
|
+
votePubkey,
|
|
8912
|
+
nodePubkey,
|
|
8913
|
+
voteInit
|
|
8914
|
+
} = params;
|
|
8915
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
|
|
8916
|
+
const data = encodeData(type, {
|
|
8917
|
+
voteInit: {
|
|
8918
|
+
nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
|
|
8919
|
+
authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
|
|
8920
|
+
authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
|
|
8921
|
+
commission: voteInit.commission
|
|
8922
|
+
}
|
|
8923
|
+
});
|
|
8924
|
+
const instructionData = {
|
|
8925
|
+
keys: [{
|
|
8926
|
+
pubkey: votePubkey,
|
|
8927
|
+
isSigner: false,
|
|
8928
|
+
isWritable: true
|
|
8929
|
+
}, {
|
|
8930
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
8931
|
+
isSigner: false,
|
|
8932
|
+
isWritable: false
|
|
8933
|
+
}, {
|
|
8934
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
8935
|
+
isSigner: false,
|
|
8936
|
+
isWritable: false
|
|
8937
|
+
}, {
|
|
8938
|
+
pubkey: nodePubkey,
|
|
8939
|
+
isSigner: true,
|
|
8940
|
+
isWritable: false
|
|
8941
|
+
}],
|
|
8942
|
+
programId: this.programId,
|
|
8943
|
+
data
|
|
8944
|
+
};
|
|
8945
|
+
return new TransactionInstruction(instructionData);
|
|
8946
|
+
}
|
|
8947
|
+
/**
|
|
8948
|
+
* Generate a transaction that creates a new Vote account.
|
|
8949
|
+
*/
|
|
8950
|
+
|
|
8951
|
+
|
|
8952
|
+
static createAccount(params) {
|
|
8953
|
+
const transaction = new Transaction();
|
|
8954
|
+
transaction.add(SystemProgram.createAccount({
|
|
8955
|
+
fromPubkey: params.fromPubkey,
|
|
8956
|
+
newAccountPubkey: params.votePubkey,
|
|
8957
|
+
lamports: params.lamports,
|
|
8958
|
+
space: this.space,
|
|
8959
|
+
programId: this.programId
|
|
8960
|
+
}));
|
|
8961
|
+
return transaction.add(this.initializeAccount({
|
|
8962
|
+
votePubkey: params.votePubkey,
|
|
8963
|
+
nodePubkey: params.voteInit.nodePubkey,
|
|
8964
|
+
voteInit: params.voteInit
|
|
8965
|
+
}));
|
|
8966
|
+
}
|
|
8967
|
+
/**
|
|
8968
|
+
* Generate a transaction to withdraw from a Vote account.
|
|
8969
|
+
*/
|
|
8970
|
+
|
|
8971
|
+
|
|
8972
|
+
static withdraw(params) {
|
|
8973
|
+
const {
|
|
8974
|
+
votePubkey,
|
|
8975
|
+
authorizedWithdrawerPubkey,
|
|
8976
|
+
lamports,
|
|
8977
|
+
toPubkey
|
|
8978
|
+
} = params;
|
|
8979
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
|
|
8980
|
+
const data = encodeData(type, {
|
|
8981
|
+
lamports
|
|
8982
|
+
});
|
|
8983
|
+
const keys = [{
|
|
8984
|
+
pubkey: votePubkey,
|
|
8985
|
+
isSigner: false,
|
|
8986
|
+
isWritable: true
|
|
8987
|
+
}, {
|
|
8988
|
+
pubkey: toPubkey,
|
|
8989
|
+
isSigner: false,
|
|
8990
|
+
isWritable: true
|
|
8991
|
+
}, {
|
|
8992
|
+
pubkey: authorizedWithdrawerPubkey,
|
|
8993
|
+
isSigner: true,
|
|
8994
|
+
isWritable: false
|
|
8995
|
+
}];
|
|
8996
|
+
return new Transaction().add({
|
|
8997
|
+
keys,
|
|
8998
|
+
programId: this.programId,
|
|
8999
|
+
data
|
|
8493
9000
|
});
|
|
8494
9001
|
}
|
|
8495
9002
|
|
|
8496
9003
|
}
|
|
9004
|
+
VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
|
|
9005
|
+
VoteProgram.space = 3731;
|
|
8497
9006
|
|
|
8498
9007
|
/**
|
|
8499
9008
|
* Send and confirm a raw transaction
|
|
@@ -8524,12 +9033,12 @@ const endpoint = {
|
|
|
8524
9033
|
http: {
|
|
8525
9034
|
devnet: 'http://api.devnet.solana.com',
|
|
8526
9035
|
testnet: 'http://api.testnet.solana.com',
|
|
8527
|
-
'mainnet-beta': 'http://api.mainnet-beta.solana.com'
|
|
9036
|
+
'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
|
|
8528
9037
|
},
|
|
8529
9038
|
https: {
|
|
8530
9039
|
devnet: 'https://api.devnet.solana.com',
|
|
8531
9040
|
testnet: 'https://api.testnet.solana.com',
|
|
8532
|
-
'mainnet-beta': 'https://api.mainnet-beta.solana.com'
|
|
9041
|
+
'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
|
|
8533
9042
|
}
|
|
8534
9043
|
};
|
|
8535
9044
|
|
|
@@ -8584,10 +9093,13 @@ exports.STAKE_CONFIG_ID = STAKE_CONFIG_ID;
|
|
|
8584
9093
|
exports.STAKE_INSTRUCTION_LAYOUTS = STAKE_INSTRUCTION_LAYOUTS;
|
|
8585
9094
|
exports.SYSTEM_INSTRUCTION_LAYOUTS = SYSTEM_INSTRUCTION_LAYOUTS;
|
|
8586
9095
|
exports.SYSVAR_CLOCK_PUBKEY = SYSVAR_CLOCK_PUBKEY;
|
|
9096
|
+
exports.SYSVAR_EPOCH_SCHEDULE_PUBKEY = SYSVAR_EPOCH_SCHEDULE_PUBKEY;
|
|
8587
9097
|
exports.SYSVAR_INSTRUCTIONS_PUBKEY = SYSVAR_INSTRUCTIONS_PUBKEY;
|
|
8588
9098
|
exports.SYSVAR_RECENT_BLOCKHASHES_PUBKEY = SYSVAR_RECENT_BLOCKHASHES_PUBKEY;
|
|
8589
9099
|
exports.SYSVAR_RENT_PUBKEY = SYSVAR_RENT_PUBKEY;
|
|
8590
9100
|
exports.SYSVAR_REWARDS_PUBKEY = SYSVAR_REWARDS_PUBKEY;
|
|
9101
|
+
exports.SYSVAR_SLOT_HASHES_PUBKEY = SYSVAR_SLOT_HASHES_PUBKEY;
|
|
9102
|
+
exports.SYSVAR_SLOT_HISTORY_PUBKEY = SYSVAR_SLOT_HISTORY_PUBKEY;
|
|
8591
9103
|
exports.SYSVAR_STAKE_HISTORY_PUBKEY = SYSVAR_STAKE_HISTORY_PUBKEY;
|
|
8592
9104
|
exports.Secp256k1Program = Secp256k1Program;
|
|
8593
9105
|
exports.SendTransactionError = SendTransactionError;
|
|
@@ -8603,6 +9115,9 @@ exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
|
|
|
8603
9115
|
exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
|
|
8604
9116
|
exports.ValidatorInfo = ValidatorInfo;
|
|
8605
9117
|
exports.VoteAccount = VoteAccount;
|
|
9118
|
+
exports.VoteInit = VoteInit;
|
|
9119
|
+
exports.VoteInstruction = VoteInstruction;
|
|
9120
|
+
exports.VoteProgram = VoteProgram;
|
|
8606
9121
|
exports.clusterApiUrl = clusterApiUrl;
|
|
8607
9122
|
exports.sendAndConfirmRawTransaction = sendAndConfirmRawTransaction;
|
|
8608
9123
|
exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
|