@solana/web3.js 1.32.0 → 1.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.browser.esm.js +541 -32
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +544 -31
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +217 -7
- package/lib/index.esm.js +541 -32
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +544 -31
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/module.flow.js +259 -7
- package/package.json +1 -1
- package/src/connection.ts +259 -29
- package/src/index.ts +1 -0
- package/src/layout.ts +15 -0
- package/src/util/cluster.ts +2 -2
- package/src/util/send-and-confirm-transaction.ts +1 -0
- package/src/vote-program.ts +386 -0
package/lib/index.cjs.js
CHANGED
|
@@ -2110,6 +2110,13 @@ const authorized = (property = 'authorized') => {
|
|
|
2110
2110
|
const lockup = (property = 'lockup') => {
|
|
2111
2111
|
return BufferLayout__namespace.struct([BufferLayout__namespace.ns64('unixTimestamp'), BufferLayout__namespace.ns64('epoch'), publicKey('custodian')], property);
|
|
2112
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
|
+
};
|
|
2113
2120
|
function getAlloc(type, fields) {
|
|
2114
2121
|
let alloc = 0;
|
|
2115
2122
|
type.layout.fields.forEach(item => {
|
|
@@ -2964,7 +2971,8 @@ const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory11111111111
|
|
|
2964
2971
|
async function sendAndConfirmTransaction(connection, transaction, signers, options) {
|
|
2965
2972
|
const sendOptions = options && {
|
|
2966
2973
|
skipPreflight: options.skipPreflight,
|
|
2967
|
-
preflightCommitment: options.preflightCommitment || options.commitment
|
|
2974
|
+
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
2975
|
+
maxRetries: options.maxRetries
|
|
2968
2976
|
};
|
|
2969
2977
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
2970
2978
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
@@ -4909,8 +4917,31 @@ const ParsedConfirmedTransactionMetaResult = superstruct.type({
|
|
|
4909
4917
|
preTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
|
|
4910
4918
|
postTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult)))
|
|
4911
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
|
+
})));
|
|
4912
4941
|
/**
|
|
4913
4942
|
* Expected JSON RPC response for the "getConfirmedBlock" message
|
|
4943
|
+
*
|
|
4944
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
|
|
4914
4945
|
*/
|
|
4915
4946
|
|
|
4916
4947
|
const GetConfirmedBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
|
|
@@ -4930,10 +4961,10 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruc
|
|
|
4930
4961
|
blockTime: superstruct.nullable(superstruct.number())
|
|
4931
4962
|
})));
|
|
4932
4963
|
/**
|
|
4933
|
-
* Expected JSON RPC response for the "
|
|
4964
|
+
* Expected JSON RPC response for the "getBlock" message
|
|
4934
4965
|
*/
|
|
4935
4966
|
|
|
4936
|
-
const
|
|
4967
|
+
const GetBlockSignaturesRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
|
|
4937
4968
|
blockhash: superstruct.string(),
|
|
4938
4969
|
previousBlockhash: superstruct.string(),
|
|
4939
4970
|
parentSlot: superstruct.number(),
|
|
@@ -4941,20 +4972,20 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(superstruct.nullable(
|
|
|
4941
4972
|
blockTime: superstruct.nullable(superstruct.number())
|
|
4942
4973
|
})));
|
|
4943
4974
|
/**
|
|
4944
|
-
* Expected JSON RPC response for the "
|
|
4975
|
+
* Expected JSON RPC response for the "getTransaction" message
|
|
4945
4976
|
*/
|
|
4946
4977
|
|
|
4947
|
-
const
|
|
4978
|
+
const GetTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
|
|
4948
4979
|
slot: superstruct.number(),
|
|
4949
4980
|
meta: ConfirmedTransactionMetaResult,
|
|
4950
4981
|
blockTime: superstruct.optional(superstruct.nullable(superstruct.number())),
|
|
4951
4982
|
transaction: ConfirmedTransactionResult
|
|
4952
4983
|
})));
|
|
4953
4984
|
/**
|
|
4954
|
-
* Expected JSON RPC response for the "
|
|
4985
|
+
* Expected parsed JSON RPC response for the "getTransaction" message
|
|
4955
4986
|
*/
|
|
4956
4987
|
|
|
4957
|
-
const
|
|
4988
|
+
const GetParsedTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
|
|
4958
4989
|
slot: superstruct.number(),
|
|
4959
4990
|
transaction: ParsedConfirmedTransactionResult,
|
|
4960
4991
|
meta: superstruct.nullable(ParsedConfirmedTransactionMetaResult),
|
|
@@ -4962,6 +4993,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(superstruct.nullabl
|
|
|
4962
4993
|
})));
|
|
4963
4994
|
/**
|
|
4964
4995
|
* Expected JSON RPC response for the "getRecentBlockhash" message
|
|
4996
|
+
*
|
|
4997
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
|
|
4965
4998
|
*/
|
|
4966
4999
|
|
|
4967
5000
|
const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(superstruct.type({
|
|
@@ -4970,6 +5003,14 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(superstruc
|
|
|
4970
5003
|
lamportsPerSignature: superstruct.number()
|
|
4971
5004
|
})
|
|
4972
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
|
+
}));
|
|
4973
5014
|
const PerfSampleResult = superstruct.type({
|
|
4974
5015
|
slot: superstruct.number(),
|
|
4975
5016
|
numTransactions: superstruct.number(),
|
|
@@ -5914,6 +5955,8 @@ class Connection {
|
|
|
5914
5955
|
/**
|
|
5915
5956
|
* Fetch a recent blockhash from the cluster, return with context
|
|
5916
5957
|
* @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
|
|
5958
|
+
*
|
|
5959
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
5917
5960
|
*/
|
|
5918
5961
|
|
|
5919
5962
|
|
|
@@ -5949,6 +5992,8 @@ class Connection {
|
|
|
5949
5992
|
}
|
|
5950
5993
|
/**
|
|
5951
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.
|
|
5952
5997
|
*/
|
|
5953
5998
|
|
|
5954
5999
|
|
|
@@ -5997,6 +6042,8 @@ class Connection {
|
|
|
5997
6042
|
/**
|
|
5998
6043
|
* Fetch a recent blockhash from the cluster
|
|
5999
6044
|
* @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
|
|
6045
|
+
*
|
|
6046
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
6000
6047
|
*/
|
|
6001
6048
|
|
|
6002
6049
|
|
|
@@ -6008,6 +6055,38 @@ class Connection {
|
|
|
6008
6055
|
throw new Error('failed to get recent blockhash: ' + e);
|
|
6009
6056
|
}
|
|
6010
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
|
+
}
|
|
6011
6090
|
/**
|
|
6012
6091
|
* Fetch the node version
|
|
6013
6092
|
*/
|
|
@@ -6046,8 +6125,8 @@ class Connection {
|
|
|
6046
6125
|
async getBlock(slot, opts) {
|
|
6047
6126
|
const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
|
|
6048
6127
|
|
|
6049
|
-
const unsafeRes = await this._rpcRequest('
|
|
6050
|
-
const res = superstruct.create(unsafeRes,
|
|
6128
|
+
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
6129
|
+
const res = superstruct.create(unsafeRes, GetBlockRpcResult);
|
|
6051
6130
|
|
|
6052
6131
|
if ('error' in res) {
|
|
6053
6132
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -6071,18 +6150,18 @@ class Connection {
|
|
|
6071
6150
|
};
|
|
6072
6151
|
}
|
|
6073
6152
|
/**
|
|
6074
|
-
* Fetch a
|
|
6153
|
+
* Fetch a confirmed or finalized transaction from the cluster.
|
|
6075
6154
|
*/
|
|
6076
6155
|
|
|
6077
6156
|
|
|
6078
6157
|
async getTransaction(signature, opts) {
|
|
6079
6158
|
const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
|
|
6080
6159
|
|
|
6081
|
-
const unsafeRes = await this._rpcRequest('
|
|
6082
|
-
const res = superstruct.create(unsafeRes,
|
|
6160
|
+
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6161
|
+
const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
|
|
6083
6162
|
|
|
6084
6163
|
if ('error' in res) {
|
|
6085
|
-
throw new Error('failed to get
|
|
6164
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6086
6165
|
}
|
|
6087
6166
|
|
|
6088
6167
|
const result = res.result;
|
|
@@ -6093,6 +6172,49 @@ class Connection {
|
|
|
6093
6172
|
}
|
|
6094
6173
|
};
|
|
6095
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
|
+
}
|
|
6096
6218
|
/**
|
|
6097
6219
|
* Fetch a list of Transactions and transaction statuses from the cluster
|
|
6098
6220
|
* for a confirmed block.
|
|
@@ -6102,18 +6224,39 @@ class Connection {
|
|
|
6102
6224
|
|
|
6103
6225
|
|
|
6104
6226
|
async getConfirmedBlock(slot, commitment) {
|
|
6105
|
-
const
|
|
6106
|
-
|
|
6107
|
-
|
|
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;
|
|
6108
6237
|
|
|
6109
6238
|
if (!result) {
|
|
6110
6239
|
throw new Error('Confirmed block ' + slot + ' not found');
|
|
6111
6240
|
}
|
|
6112
6241
|
|
|
6113
|
-
|
|
6242
|
+
const block = { ...result,
|
|
6114
6243
|
transactions: result.transactions.map(({
|
|
6115
6244
|
transaction,
|
|
6116
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
|
|
6117
6260
|
}) => {
|
|
6118
6261
|
return {
|
|
6119
6262
|
meta,
|
|
@@ -6130,7 +6273,7 @@ class Connection {
|
|
|
6130
6273
|
async getBlocks(startSlot, endSlot, commitment) {
|
|
6131
6274
|
const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
|
|
6132
6275
|
|
|
6133
|
-
const unsafeRes = await this._rpcRequest('
|
|
6276
|
+
const unsafeRes = await this._rpcRequest('getBlocks', args);
|
|
6134
6277
|
const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(superstruct.number())));
|
|
6135
6278
|
|
|
6136
6279
|
if ('error' in res) {
|
|
@@ -6139,8 +6282,36 @@ class Connection {
|
|
|
6139
6282
|
|
|
6140
6283
|
return res.result;
|
|
6141
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
|
+
}
|
|
6142
6311
|
/**
|
|
6143
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.
|
|
6144
6315
|
*/
|
|
6145
6316
|
|
|
6146
6317
|
|
|
@@ -6151,7 +6322,7 @@ class Connection {
|
|
|
6151
6322
|
});
|
|
6152
6323
|
|
|
6153
6324
|
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
|
|
6154
|
-
const res = superstruct.create(unsafeRes,
|
|
6325
|
+
const res = superstruct.create(unsafeRes, GetBlockSignaturesRpcResult);
|
|
6155
6326
|
|
|
6156
6327
|
if ('error' in res) {
|
|
6157
6328
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -6167,24 +6338,33 @@ class Connection {
|
|
|
6167
6338
|
}
|
|
6168
6339
|
/**
|
|
6169
6340
|
* Fetch a transaction details for a confirmed transaction
|
|
6341
|
+
*
|
|
6342
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
|
|
6170
6343
|
*/
|
|
6171
6344
|
|
|
6172
6345
|
|
|
6173
6346
|
async getConfirmedTransaction(signature, commitment) {
|
|
6174
|
-
const
|
|
6175
|
-
|
|
6176
|
-
|
|
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;
|
|
6177
6357
|
if (!result) return result;
|
|
6178
|
-
const
|
|
6179
|
-
|
|
6180
|
-
signatures
|
|
6181
|
-
} = result.transaction;
|
|
6358
|
+
const message = new Message(result.transaction.message);
|
|
6359
|
+
const signatures = result.transaction.signatures;
|
|
6182
6360
|
return { ...result,
|
|
6183
6361
|
transaction: Transaction.populate(message, signatures)
|
|
6184
6362
|
};
|
|
6185
6363
|
}
|
|
6186
6364
|
/**
|
|
6187
6365
|
* Fetch parsed transaction details for a confirmed transaction
|
|
6366
|
+
*
|
|
6367
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
|
|
6188
6368
|
*/
|
|
6189
6369
|
|
|
6190
6370
|
|
|
@@ -6192,7 +6372,7 @@ class Connection {
|
|
|
6192
6372
|
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6193
6373
|
|
|
6194
6374
|
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
|
|
6195
|
-
const res = superstruct.create(unsafeRes,
|
|
6375
|
+
const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6196
6376
|
|
|
6197
6377
|
if ('error' in res) {
|
|
6198
6378
|
throw new Error('failed to get confirmed transaction: ' + res.error.message);
|
|
@@ -6202,6 +6382,8 @@ class Connection {
|
|
|
6202
6382
|
}
|
|
6203
6383
|
/**
|
|
6204
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.
|
|
6205
6387
|
*/
|
|
6206
6388
|
|
|
6207
6389
|
|
|
@@ -6216,7 +6398,7 @@ class Connection {
|
|
|
6216
6398
|
});
|
|
6217
6399
|
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
6218
6400
|
const res = unsafeRes.map(unsafeRes => {
|
|
6219
|
-
const res = superstruct.create(unsafeRes,
|
|
6401
|
+
const res = superstruct.create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6220
6402
|
|
|
6221
6403
|
if ('error' in res) {
|
|
6222
6404
|
throw new Error('failed to get confirmed transactions: ' + res.error.message);
|
|
@@ -6606,6 +6788,10 @@ class Connection {
|
|
|
6606
6788
|
const skipPreflight = options && options.skipPreflight;
|
|
6607
6789
|
const preflightCommitment = options && options.preflightCommitment || this.commitment;
|
|
6608
6790
|
|
|
6791
|
+
if (options && options.maxRetries) {
|
|
6792
|
+
config.maxRetries = options.maxRetries;
|
|
6793
|
+
}
|
|
6794
|
+
|
|
6609
6795
|
if (skipPreflight) {
|
|
6610
6796
|
config.skipPreflight = skipPreflight;
|
|
6611
6797
|
}
|
|
@@ -6760,7 +6946,14 @@ class Connection {
|
|
|
6760
6946
|
this._rpcWebSocketIdleTimeout = setTimeout(() => {
|
|
6761
6947
|
this._rpcWebSocketIdleTimeout = null;
|
|
6762
6948
|
|
|
6763
|
-
|
|
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
|
+
}
|
|
6764
6957
|
}, 500);
|
|
6765
6958
|
}
|
|
6766
6959
|
|
|
@@ -8571,6 +8764,322 @@ function getPriorVoters({
|
|
|
8571
8764
|
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
8572
8765
|
}
|
|
8573
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 an authorize instruction and retrieve the instruction params.
|
|
8840
|
+
*/
|
|
8841
|
+
|
|
8842
|
+
|
|
8843
|
+
static decodeAuthorize(instruction) {
|
|
8844
|
+
this.checkProgramId(instruction.programId);
|
|
8845
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
8846
|
+
const {
|
|
8847
|
+
newAuthorized,
|
|
8848
|
+
voteAuthorizationType
|
|
8849
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.Authorize, instruction.data);
|
|
8850
|
+
return {
|
|
8851
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
8852
|
+
authorizedPubkey: instruction.keys[2].pubkey,
|
|
8853
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
8854
|
+
voteAuthorizationType: {
|
|
8855
|
+
index: voteAuthorizationType
|
|
8856
|
+
}
|
|
8857
|
+
};
|
|
8858
|
+
}
|
|
8859
|
+
/**
|
|
8860
|
+
* Decode a withdraw instruction and retrieve the instruction params.
|
|
8861
|
+
*/
|
|
8862
|
+
|
|
8863
|
+
|
|
8864
|
+
static decodeWithdraw(instruction) {
|
|
8865
|
+
this.checkProgramId(instruction.programId);
|
|
8866
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
8867
|
+
const {
|
|
8868
|
+
lamports
|
|
8869
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
|
|
8870
|
+
return {
|
|
8871
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
8872
|
+
authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
|
|
8873
|
+
lamports,
|
|
8874
|
+
toPubkey: instruction.keys[1].pubkey
|
|
8875
|
+
};
|
|
8876
|
+
}
|
|
8877
|
+
/**
|
|
8878
|
+
* @internal
|
|
8879
|
+
*/
|
|
8880
|
+
|
|
8881
|
+
|
|
8882
|
+
static checkProgramId(programId) {
|
|
8883
|
+
if (!programId.equals(VoteProgram.programId)) {
|
|
8884
|
+
throw new Error('invalid instruction; programId is not VoteProgram');
|
|
8885
|
+
}
|
|
8886
|
+
}
|
|
8887
|
+
/**
|
|
8888
|
+
* @internal
|
|
8889
|
+
*/
|
|
8890
|
+
|
|
8891
|
+
|
|
8892
|
+
static checkKeyLength(keys, expectedLength) {
|
|
8893
|
+
if (keys.length < expectedLength) {
|
|
8894
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
8895
|
+
}
|
|
8896
|
+
}
|
|
8897
|
+
|
|
8898
|
+
}
|
|
8899
|
+
/**
|
|
8900
|
+
* An enumeration of valid VoteInstructionType's
|
|
8901
|
+
*/
|
|
8902
|
+
|
|
8903
|
+
const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
8904
|
+
InitializeAccount: {
|
|
8905
|
+
index: 0,
|
|
8906
|
+
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), voteInit()])
|
|
8907
|
+
},
|
|
8908
|
+
Authorize: {
|
|
8909
|
+
index: 1,
|
|
8910
|
+
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), publicKey('newAuthorized'), BufferLayout__namespace.u32('voteAuthorizationType')])
|
|
8911
|
+
},
|
|
8912
|
+
Withdraw: {
|
|
8913
|
+
index: 3,
|
|
8914
|
+
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), BufferLayout__namespace.ns64('lamports')])
|
|
8915
|
+
}
|
|
8916
|
+
});
|
|
8917
|
+
/**
|
|
8918
|
+
* VoteAuthorize type
|
|
8919
|
+
*/
|
|
8920
|
+
|
|
8921
|
+
/**
|
|
8922
|
+
* An enumeration of valid VoteAuthorization layouts.
|
|
8923
|
+
*/
|
|
8924
|
+
const VoteAuthorizationLayout = Object.freeze({
|
|
8925
|
+
Voter: {
|
|
8926
|
+
index: 0
|
|
8927
|
+
},
|
|
8928
|
+
Withdrawer: {
|
|
8929
|
+
index: 1
|
|
8930
|
+
}
|
|
8931
|
+
});
|
|
8932
|
+
/**
|
|
8933
|
+
* Factory class for transactions to interact with the Vote program
|
|
8934
|
+
*/
|
|
8935
|
+
|
|
8936
|
+
class VoteProgram {
|
|
8937
|
+
/**
|
|
8938
|
+
* @internal
|
|
8939
|
+
*/
|
|
8940
|
+
constructor() {}
|
|
8941
|
+
/**
|
|
8942
|
+
* Public key that identifies the Vote program
|
|
8943
|
+
*/
|
|
8944
|
+
|
|
8945
|
+
|
|
8946
|
+
/**
|
|
8947
|
+
* Generate an Initialize instruction.
|
|
8948
|
+
*/
|
|
8949
|
+
static initializeAccount(params) {
|
|
8950
|
+
const {
|
|
8951
|
+
votePubkey,
|
|
8952
|
+
nodePubkey,
|
|
8953
|
+
voteInit
|
|
8954
|
+
} = params;
|
|
8955
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
|
|
8956
|
+
const data = encodeData(type, {
|
|
8957
|
+
voteInit: {
|
|
8958
|
+
nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
|
|
8959
|
+
authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
|
|
8960
|
+
authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
|
|
8961
|
+
commission: voteInit.commission
|
|
8962
|
+
}
|
|
8963
|
+
});
|
|
8964
|
+
const instructionData = {
|
|
8965
|
+
keys: [{
|
|
8966
|
+
pubkey: votePubkey,
|
|
8967
|
+
isSigner: false,
|
|
8968
|
+
isWritable: true
|
|
8969
|
+
}, {
|
|
8970
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
8971
|
+
isSigner: false,
|
|
8972
|
+
isWritable: false
|
|
8973
|
+
}, {
|
|
8974
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
8975
|
+
isSigner: false,
|
|
8976
|
+
isWritable: false
|
|
8977
|
+
}, {
|
|
8978
|
+
pubkey: nodePubkey,
|
|
8979
|
+
isSigner: true,
|
|
8980
|
+
isWritable: false
|
|
8981
|
+
}],
|
|
8982
|
+
programId: this.programId,
|
|
8983
|
+
data
|
|
8984
|
+
};
|
|
8985
|
+
return new TransactionInstruction(instructionData);
|
|
8986
|
+
}
|
|
8987
|
+
/**
|
|
8988
|
+
* Generate a transaction that creates a new Vote account.
|
|
8989
|
+
*/
|
|
8990
|
+
|
|
8991
|
+
|
|
8992
|
+
static createAccount(params) {
|
|
8993
|
+
const transaction = new Transaction();
|
|
8994
|
+
transaction.add(SystemProgram.createAccount({
|
|
8995
|
+
fromPubkey: params.fromPubkey,
|
|
8996
|
+
newAccountPubkey: params.votePubkey,
|
|
8997
|
+
lamports: params.lamports,
|
|
8998
|
+
space: this.space,
|
|
8999
|
+
programId: this.programId
|
|
9000
|
+
}));
|
|
9001
|
+
return transaction.add(this.initializeAccount({
|
|
9002
|
+
votePubkey: params.votePubkey,
|
|
9003
|
+
nodePubkey: params.voteInit.nodePubkey,
|
|
9004
|
+
voteInit: params.voteInit
|
|
9005
|
+
}));
|
|
9006
|
+
}
|
|
9007
|
+
/**
|
|
9008
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account.
|
|
9009
|
+
*/
|
|
9010
|
+
|
|
9011
|
+
|
|
9012
|
+
static authorize(params) {
|
|
9013
|
+
const {
|
|
9014
|
+
votePubkey,
|
|
9015
|
+
authorizedPubkey,
|
|
9016
|
+
newAuthorizedPubkey,
|
|
9017
|
+
voteAuthorizationType
|
|
9018
|
+
} = params;
|
|
9019
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.Authorize;
|
|
9020
|
+
const data = encodeData(type, {
|
|
9021
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
9022
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
9023
|
+
});
|
|
9024
|
+
const keys = [{
|
|
9025
|
+
pubkey: votePubkey,
|
|
9026
|
+
isSigner: false,
|
|
9027
|
+
isWritable: true
|
|
9028
|
+
}, {
|
|
9029
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
9030
|
+
isSigner: false,
|
|
9031
|
+
isWritable: false
|
|
9032
|
+
}, {
|
|
9033
|
+
pubkey: authorizedPubkey,
|
|
9034
|
+
isSigner: true,
|
|
9035
|
+
isWritable: false
|
|
9036
|
+
}];
|
|
9037
|
+
return new Transaction().add({
|
|
9038
|
+
keys,
|
|
9039
|
+
programId: this.programId,
|
|
9040
|
+
data
|
|
9041
|
+
});
|
|
9042
|
+
}
|
|
9043
|
+
/**
|
|
9044
|
+
* Generate a transaction to withdraw from a Vote account.
|
|
9045
|
+
*/
|
|
9046
|
+
|
|
9047
|
+
|
|
9048
|
+
static withdraw(params) {
|
|
9049
|
+
const {
|
|
9050
|
+
votePubkey,
|
|
9051
|
+
authorizedWithdrawerPubkey,
|
|
9052
|
+
lamports,
|
|
9053
|
+
toPubkey
|
|
9054
|
+
} = params;
|
|
9055
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
|
|
9056
|
+
const data = encodeData(type, {
|
|
9057
|
+
lamports
|
|
9058
|
+
});
|
|
9059
|
+
const keys = [{
|
|
9060
|
+
pubkey: votePubkey,
|
|
9061
|
+
isSigner: false,
|
|
9062
|
+
isWritable: true
|
|
9063
|
+
}, {
|
|
9064
|
+
pubkey: toPubkey,
|
|
9065
|
+
isSigner: false,
|
|
9066
|
+
isWritable: true
|
|
9067
|
+
}, {
|
|
9068
|
+
pubkey: authorizedWithdrawerPubkey,
|
|
9069
|
+
isSigner: true,
|
|
9070
|
+
isWritable: false
|
|
9071
|
+
}];
|
|
9072
|
+
return new Transaction().add({
|
|
9073
|
+
keys,
|
|
9074
|
+
programId: this.programId,
|
|
9075
|
+
data
|
|
9076
|
+
});
|
|
9077
|
+
}
|
|
9078
|
+
|
|
9079
|
+
}
|
|
9080
|
+
VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
|
|
9081
|
+
VoteProgram.space = 3731;
|
|
9082
|
+
|
|
8574
9083
|
/**
|
|
8575
9084
|
* Send and confirm a raw transaction
|
|
8576
9085
|
*
|
|
@@ -8600,12 +9109,12 @@ const endpoint = {
|
|
|
8600
9109
|
http: {
|
|
8601
9110
|
devnet: 'http://api.devnet.solana.com',
|
|
8602
9111
|
testnet: 'http://api.testnet.solana.com',
|
|
8603
|
-
'mainnet-beta': 'http://api.mainnet-beta.solana.com'
|
|
9112
|
+
'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
|
|
8604
9113
|
},
|
|
8605
9114
|
https: {
|
|
8606
9115
|
devnet: 'https://api.devnet.solana.com',
|
|
8607
9116
|
testnet: 'https://api.testnet.solana.com',
|
|
8608
|
-
'mainnet-beta': 'https://api.mainnet-beta.solana.com'
|
|
9117
|
+
'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
|
|
8609
9118
|
}
|
|
8610
9119
|
};
|
|
8611
9120
|
|
|
@@ -8682,6 +9191,10 @@ exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
|
|
|
8682
9191
|
exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
|
|
8683
9192
|
exports.ValidatorInfo = ValidatorInfo;
|
|
8684
9193
|
exports.VoteAccount = VoteAccount;
|
|
9194
|
+
exports.VoteAuthorizationLayout = VoteAuthorizationLayout;
|
|
9195
|
+
exports.VoteInit = VoteInit;
|
|
9196
|
+
exports.VoteInstruction = VoteInstruction;
|
|
9197
|
+
exports.VoteProgram = VoteProgram;
|
|
8685
9198
|
exports.clusterApiUrl = clusterApiUrl;
|
|
8686
9199
|
exports.sendAndConfirmRawTransaction = sendAndConfirmRawTransaction;
|
|
8687
9200
|
exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
|