@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.esm.js
CHANGED
|
@@ -2075,6 +2075,13 @@ const authorized = (property = 'authorized') => {
|
|
|
2075
2075
|
const lockup = (property = 'lockup') => {
|
|
2076
2076
|
return BufferLayout.struct([BufferLayout.ns64('unixTimestamp'), BufferLayout.ns64('epoch'), publicKey('custodian')], property);
|
|
2077
2077
|
};
|
|
2078
|
+
/**
|
|
2079
|
+
* Layout for a VoteInit object
|
|
2080
|
+
*/
|
|
2081
|
+
|
|
2082
|
+
const voteInit = (property = 'voteInit') => {
|
|
2083
|
+
return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
|
|
2084
|
+
};
|
|
2078
2085
|
function getAlloc(type, fields) {
|
|
2079
2086
|
let alloc = 0;
|
|
2080
2087
|
type.layout.fields.forEach(item => {
|
|
@@ -2929,7 +2936,8 @@ const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory11111111111
|
|
|
2929
2936
|
async function sendAndConfirmTransaction(connection, transaction, signers, options) {
|
|
2930
2937
|
const sendOptions = options && {
|
|
2931
2938
|
skipPreflight: options.skipPreflight,
|
|
2932
|
-
preflightCommitment: options.preflightCommitment || options.commitment
|
|
2939
|
+
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
2940
|
+
maxRetries: options.maxRetries
|
|
2933
2941
|
};
|
|
2934
2942
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
2935
2943
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
@@ -4874,8 +4882,31 @@ const ParsedConfirmedTransactionMetaResult = type({
|
|
|
4874
4882
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
4875
4883
|
postTokenBalances: optional(nullable(array(TokenBalanceResult)))
|
|
4876
4884
|
});
|
|
4885
|
+
/**
|
|
4886
|
+
* Expected JSON RPC response for the "getBlock" message
|
|
4887
|
+
*/
|
|
4888
|
+
|
|
4889
|
+
const GetBlockRpcResult = jsonRpcResult(nullable(type({
|
|
4890
|
+
blockhash: string(),
|
|
4891
|
+
previousBlockhash: string(),
|
|
4892
|
+
parentSlot: number(),
|
|
4893
|
+
transactions: array(type({
|
|
4894
|
+
transaction: ConfirmedTransactionResult,
|
|
4895
|
+
meta: nullable(ConfirmedTransactionMetaResult)
|
|
4896
|
+
})),
|
|
4897
|
+
rewards: optional(array(type({
|
|
4898
|
+
pubkey: string(),
|
|
4899
|
+
lamports: number(),
|
|
4900
|
+
postBalance: nullable(number()),
|
|
4901
|
+
rewardType: nullable(string())
|
|
4902
|
+
}))),
|
|
4903
|
+
blockTime: nullable(number()),
|
|
4904
|
+
blockHeight: nullable(number())
|
|
4905
|
+
})));
|
|
4877
4906
|
/**
|
|
4878
4907
|
* Expected JSON RPC response for the "getConfirmedBlock" message
|
|
4908
|
+
*
|
|
4909
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
|
|
4879
4910
|
*/
|
|
4880
4911
|
|
|
4881
4912
|
const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
|
|
@@ -4895,10 +4926,10 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
|
|
|
4895
4926
|
blockTime: nullable(number())
|
|
4896
4927
|
})));
|
|
4897
4928
|
/**
|
|
4898
|
-
* Expected JSON RPC response for the "
|
|
4929
|
+
* Expected JSON RPC response for the "getBlock" message
|
|
4899
4930
|
*/
|
|
4900
4931
|
|
|
4901
|
-
const
|
|
4932
|
+
const GetBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
|
|
4902
4933
|
blockhash: string(),
|
|
4903
4934
|
previousBlockhash: string(),
|
|
4904
4935
|
parentSlot: number(),
|
|
@@ -4906,20 +4937,20 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
|
|
|
4906
4937
|
blockTime: nullable(number())
|
|
4907
4938
|
})));
|
|
4908
4939
|
/**
|
|
4909
|
-
* Expected JSON RPC response for the "
|
|
4940
|
+
* Expected JSON RPC response for the "getTransaction" message
|
|
4910
4941
|
*/
|
|
4911
4942
|
|
|
4912
|
-
const
|
|
4943
|
+
const GetTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
4913
4944
|
slot: number(),
|
|
4914
4945
|
meta: ConfirmedTransactionMetaResult,
|
|
4915
4946
|
blockTime: optional(nullable(number())),
|
|
4916
4947
|
transaction: ConfirmedTransactionResult
|
|
4917
4948
|
})));
|
|
4918
4949
|
/**
|
|
4919
|
-
* Expected JSON RPC response for the "
|
|
4950
|
+
* Expected parsed JSON RPC response for the "getTransaction" message
|
|
4920
4951
|
*/
|
|
4921
4952
|
|
|
4922
|
-
const
|
|
4953
|
+
const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
4923
4954
|
slot: number(),
|
|
4924
4955
|
transaction: ParsedConfirmedTransactionResult,
|
|
4925
4956
|
meta: nullable(ParsedConfirmedTransactionMetaResult),
|
|
@@ -4927,6 +4958,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
|
4927
4958
|
})));
|
|
4928
4959
|
/**
|
|
4929
4960
|
* Expected JSON RPC response for the "getRecentBlockhash" message
|
|
4961
|
+
*
|
|
4962
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
|
|
4930
4963
|
*/
|
|
4931
4964
|
|
|
4932
4965
|
const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
|
|
@@ -4935,6 +4968,14 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
|
|
|
4935
4968
|
lamportsPerSignature: number()
|
|
4936
4969
|
})
|
|
4937
4970
|
}));
|
|
4971
|
+
/**
|
|
4972
|
+
* Expected JSON RPC response for the "getLatestBlockhash" message
|
|
4973
|
+
*/
|
|
4974
|
+
|
|
4975
|
+
const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(type({
|
|
4976
|
+
blockhash: string(),
|
|
4977
|
+
lastValidBlockHeight: number()
|
|
4978
|
+
}));
|
|
4938
4979
|
const PerfSampleResult = type({
|
|
4939
4980
|
slot: number(),
|
|
4940
4981
|
numTransactions: number(),
|
|
@@ -5879,6 +5920,8 @@ class Connection {
|
|
|
5879
5920
|
/**
|
|
5880
5921
|
* Fetch a recent blockhash from the cluster, return with context
|
|
5881
5922
|
* @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
|
|
5923
|
+
*
|
|
5924
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
5882
5925
|
*/
|
|
5883
5926
|
|
|
5884
5927
|
|
|
@@ -5914,6 +5957,8 @@ class Connection {
|
|
|
5914
5957
|
}
|
|
5915
5958
|
/**
|
|
5916
5959
|
* Fetch the fee calculator for a recent blockhash from the cluster, return with context
|
|
5960
|
+
*
|
|
5961
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
|
|
5917
5962
|
*/
|
|
5918
5963
|
|
|
5919
5964
|
|
|
@@ -5962,6 +6007,8 @@ class Connection {
|
|
|
5962
6007
|
/**
|
|
5963
6008
|
* Fetch a recent blockhash from the cluster
|
|
5964
6009
|
* @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
|
|
6010
|
+
*
|
|
6011
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
5965
6012
|
*/
|
|
5966
6013
|
|
|
5967
6014
|
|
|
@@ -5973,6 +6020,38 @@ class Connection {
|
|
|
5973
6020
|
throw new Error('failed to get recent blockhash: ' + e);
|
|
5974
6021
|
}
|
|
5975
6022
|
}
|
|
6023
|
+
/**
|
|
6024
|
+
* Fetch the latest blockhash from the cluster
|
|
6025
|
+
* @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
|
|
6026
|
+
*/
|
|
6027
|
+
|
|
6028
|
+
|
|
6029
|
+
async getLatestBlockhash(commitment) {
|
|
6030
|
+
try {
|
|
6031
|
+
const res = await this.getLatestBlockhashAndContext(commitment);
|
|
6032
|
+
return res.value;
|
|
6033
|
+
} catch (e) {
|
|
6034
|
+
throw new Error('failed to get recent blockhash: ' + e);
|
|
6035
|
+
}
|
|
6036
|
+
}
|
|
6037
|
+
/**
|
|
6038
|
+
* Fetch the latest blockhash from the cluster
|
|
6039
|
+
* @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
|
|
6040
|
+
*/
|
|
6041
|
+
|
|
6042
|
+
|
|
6043
|
+
async getLatestBlockhashAndContext(commitment) {
|
|
6044
|
+
const args = this._buildArgs([], commitment);
|
|
6045
|
+
|
|
6046
|
+
const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
|
|
6047
|
+
const res = create(unsafeRes, GetLatestBlockhashRpcResult);
|
|
6048
|
+
|
|
6049
|
+
if ('error' in res) {
|
|
6050
|
+
throw new Error('failed to get latest blockhash: ' + res.error.message);
|
|
6051
|
+
}
|
|
6052
|
+
|
|
6053
|
+
return res.result;
|
|
6054
|
+
}
|
|
5976
6055
|
/**
|
|
5977
6056
|
* Fetch the node version
|
|
5978
6057
|
*/
|
|
@@ -6011,8 +6090,8 @@ class Connection {
|
|
|
6011
6090
|
async getBlock(slot, opts) {
|
|
6012
6091
|
const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
|
|
6013
6092
|
|
|
6014
|
-
const unsafeRes = await this._rpcRequest('
|
|
6015
|
-
const res = create(unsafeRes,
|
|
6093
|
+
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
6094
|
+
const res = create(unsafeRes, GetBlockRpcResult);
|
|
6016
6095
|
|
|
6017
6096
|
if ('error' in res) {
|
|
6018
6097
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -6036,18 +6115,18 @@ class Connection {
|
|
|
6036
6115
|
};
|
|
6037
6116
|
}
|
|
6038
6117
|
/**
|
|
6039
|
-
* Fetch a
|
|
6118
|
+
* Fetch a confirmed or finalized transaction from the cluster.
|
|
6040
6119
|
*/
|
|
6041
6120
|
|
|
6042
6121
|
|
|
6043
6122
|
async getTransaction(signature, opts) {
|
|
6044
6123
|
const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
|
|
6045
6124
|
|
|
6046
|
-
const unsafeRes = await this._rpcRequest('
|
|
6047
|
-
const res = create(unsafeRes,
|
|
6125
|
+
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6126
|
+
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
6048
6127
|
|
|
6049
6128
|
if ('error' in res) {
|
|
6050
|
-
throw new Error('failed to get
|
|
6129
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6051
6130
|
}
|
|
6052
6131
|
|
|
6053
6132
|
const result = res.result;
|
|
@@ -6058,6 +6137,49 @@ class Connection {
|
|
|
6058
6137
|
}
|
|
6059
6138
|
};
|
|
6060
6139
|
}
|
|
6140
|
+
/**
|
|
6141
|
+
* Fetch parsed transaction details for a confirmed or finalized transaction
|
|
6142
|
+
*/
|
|
6143
|
+
|
|
6144
|
+
|
|
6145
|
+
async getParsedTransaction(signature, commitment) {
|
|
6146
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6147
|
+
|
|
6148
|
+
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6149
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6150
|
+
|
|
6151
|
+
if ('error' in res) {
|
|
6152
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6153
|
+
}
|
|
6154
|
+
|
|
6155
|
+
return res.result;
|
|
6156
|
+
}
|
|
6157
|
+
/**
|
|
6158
|
+
* Fetch parsed transaction details for a batch of confirmed transactions
|
|
6159
|
+
*/
|
|
6160
|
+
|
|
6161
|
+
|
|
6162
|
+
async getParsedTransactions(signatures, commitment) {
|
|
6163
|
+
const batch = signatures.map(signature => {
|
|
6164
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6165
|
+
|
|
6166
|
+
return {
|
|
6167
|
+
methodName: 'getTransaction',
|
|
6168
|
+
args
|
|
6169
|
+
};
|
|
6170
|
+
});
|
|
6171
|
+
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
6172
|
+
const res = unsafeRes.map(unsafeRes => {
|
|
6173
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6174
|
+
|
|
6175
|
+
if ('error' in res) {
|
|
6176
|
+
throw new Error('failed to get transactions: ' + res.error.message);
|
|
6177
|
+
}
|
|
6178
|
+
|
|
6179
|
+
return res.result;
|
|
6180
|
+
});
|
|
6181
|
+
return res;
|
|
6182
|
+
}
|
|
6061
6183
|
/**
|
|
6062
6184
|
* Fetch a list of Transactions and transaction statuses from the cluster
|
|
6063
6185
|
* for a confirmed block.
|
|
@@ -6067,18 +6189,39 @@ class Connection {
|
|
|
6067
6189
|
|
|
6068
6190
|
|
|
6069
6191
|
async getConfirmedBlock(slot, commitment) {
|
|
6070
|
-
const
|
|
6071
|
-
|
|
6072
|
-
|
|
6192
|
+
const args = this._buildArgsAtLeastConfirmed([slot], commitment);
|
|
6193
|
+
|
|
6194
|
+
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
|
|
6195
|
+
const res = create(unsafeRes, GetConfirmedBlockRpcResult);
|
|
6196
|
+
|
|
6197
|
+
if ('error' in res) {
|
|
6198
|
+
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
6199
|
+
}
|
|
6200
|
+
|
|
6201
|
+
const result = res.result;
|
|
6073
6202
|
|
|
6074
6203
|
if (!result) {
|
|
6075
6204
|
throw new Error('Confirmed block ' + slot + ' not found');
|
|
6076
6205
|
}
|
|
6077
6206
|
|
|
6078
|
-
|
|
6207
|
+
const block = { ...result,
|
|
6079
6208
|
transactions: result.transactions.map(({
|
|
6080
6209
|
transaction,
|
|
6081
6210
|
meta
|
|
6211
|
+
}) => {
|
|
6212
|
+
const message = new Message(transaction.message);
|
|
6213
|
+
return {
|
|
6214
|
+
meta,
|
|
6215
|
+
transaction: { ...transaction,
|
|
6216
|
+
message
|
|
6217
|
+
}
|
|
6218
|
+
};
|
|
6219
|
+
})
|
|
6220
|
+
};
|
|
6221
|
+
return { ...block,
|
|
6222
|
+
transactions: block.transactions.map(({
|
|
6223
|
+
transaction,
|
|
6224
|
+
meta
|
|
6082
6225
|
}) => {
|
|
6083
6226
|
return {
|
|
6084
6227
|
meta,
|
|
@@ -6095,7 +6238,7 @@ class Connection {
|
|
|
6095
6238
|
async getBlocks(startSlot, endSlot, commitment) {
|
|
6096
6239
|
const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
|
|
6097
6240
|
|
|
6098
|
-
const unsafeRes = await this._rpcRequest('
|
|
6241
|
+
const unsafeRes = await this._rpcRequest('getBlocks', args);
|
|
6099
6242
|
const res = create(unsafeRes, jsonRpcResult(array(number())));
|
|
6100
6243
|
|
|
6101
6244
|
if ('error' in res) {
|
|
@@ -6104,8 +6247,36 @@ class Connection {
|
|
|
6104
6247
|
|
|
6105
6248
|
return res.result;
|
|
6106
6249
|
}
|
|
6250
|
+
/**
|
|
6251
|
+
* Fetch a list of Signatures from the cluster for a block, excluding rewards
|
|
6252
|
+
*/
|
|
6253
|
+
|
|
6254
|
+
|
|
6255
|
+
async getBlockSignatures(slot, commitment) {
|
|
6256
|
+
const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
|
|
6257
|
+
transactionDetails: 'signatures',
|
|
6258
|
+
rewards: false
|
|
6259
|
+
});
|
|
6260
|
+
|
|
6261
|
+
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
6262
|
+
const res = create(unsafeRes, GetBlockSignaturesRpcResult);
|
|
6263
|
+
|
|
6264
|
+
if ('error' in res) {
|
|
6265
|
+
throw new Error('failed to get block: ' + res.error.message);
|
|
6266
|
+
}
|
|
6267
|
+
|
|
6268
|
+
const result = res.result;
|
|
6269
|
+
|
|
6270
|
+
if (!result) {
|
|
6271
|
+
throw new Error('Block ' + slot + ' not found');
|
|
6272
|
+
}
|
|
6273
|
+
|
|
6274
|
+
return result;
|
|
6275
|
+
}
|
|
6107
6276
|
/**
|
|
6108
6277
|
* Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
|
|
6278
|
+
*
|
|
6279
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
|
|
6109
6280
|
*/
|
|
6110
6281
|
|
|
6111
6282
|
|
|
@@ -6116,7 +6287,7 @@ class Connection {
|
|
|
6116
6287
|
});
|
|
6117
6288
|
|
|
6118
6289
|
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
|
|
6119
|
-
const res = create(unsafeRes,
|
|
6290
|
+
const res = create(unsafeRes, GetBlockSignaturesRpcResult);
|
|
6120
6291
|
|
|
6121
6292
|
if ('error' in res) {
|
|
6122
6293
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -6132,24 +6303,33 @@ class Connection {
|
|
|
6132
6303
|
}
|
|
6133
6304
|
/**
|
|
6134
6305
|
* Fetch a transaction details for a confirmed transaction
|
|
6306
|
+
*
|
|
6307
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
|
|
6135
6308
|
*/
|
|
6136
6309
|
|
|
6137
6310
|
|
|
6138
6311
|
async getConfirmedTransaction(signature, commitment) {
|
|
6139
|
-
const
|
|
6140
|
-
|
|
6141
|
-
|
|
6312
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment);
|
|
6313
|
+
|
|
6314
|
+
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
|
|
6315
|
+
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
6316
|
+
|
|
6317
|
+
if ('error' in res) {
|
|
6318
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6319
|
+
}
|
|
6320
|
+
|
|
6321
|
+
const result = res.result;
|
|
6142
6322
|
if (!result) return result;
|
|
6143
|
-
const
|
|
6144
|
-
|
|
6145
|
-
signatures
|
|
6146
|
-
} = result.transaction;
|
|
6323
|
+
const message = new Message(result.transaction.message);
|
|
6324
|
+
const signatures = result.transaction.signatures;
|
|
6147
6325
|
return { ...result,
|
|
6148
6326
|
transaction: Transaction.populate(message, signatures)
|
|
6149
6327
|
};
|
|
6150
6328
|
}
|
|
6151
6329
|
/**
|
|
6152
6330
|
* Fetch parsed transaction details for a confirmed transaction
|
|
6331
|
+
*
|
|
6332
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
|
|
6153
6333
|
*/
|
|
6154
6334
|
|
|
6155
6335
|
|
|
@@ -6157,7 +6337,7 @@ class Connection {
|
|
|
6157
6337
|
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6158
6338
|
|
|
6159
6339
|
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
|
|
6160
|
-
const res = create(unsafeRes,
|
|
6340
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6161
6341
|
|
|
6162
6342
|
if ('error' in res) {
|
|
6163
6343
|
throw new Error('failed to get confirmed transaction: ' + res.error.message);
|
|
@@ -6167,6 +6347,8 @@ class Connection {
|
|
|
6167
6347
|
}
|
|
6168
6348
|
/**
|
|
6169
6349
|
* Fetch parsed transaction details for a batch of confirmed transactions
|
|
6350
|
+
*
|
|
6351
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
|
|
6170
6352
|
*/
|
|
6171
6353
|
|
|
6172
6354
|
|
|
@@ -6181,7 +6363,7 @@ class Connection {
|
|
|
6181
6363
|
});
|
|
6182
6364
|
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
6183
6365
|
const res = unsafeRes.map(unsafeRes => {
|
|
6184
|
-
const res = create(unsafeRes,
|
|
6366
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6185
6367
|
|
|
6186
6368
|
if ('error' in res) {
|
|
6187
6369
|
throw new Error('failed to get confirmed transactions: ' + res.error.message);
|
|
@@ -6571,6 +6753,10 @@ class Connection {
|
|
|
6571
6753
|
const skipPreflight = options && options.skipPreflight;
|
|
6572
6754
|
const preflightCommitment = options && options.preflightCommitment || this.commitment;
|
|
6573
6755
|
|
|
6756
|
+
if (options && options.maxRetries) {
|
|
6757
|
+
config.maxRetries = options.maxRetries;
|
|
6758
|
+
}
|
|
6759
|
+
|
|
6574
6760
|
if (skipPreflight) {
|
|
6575
6761
|
config.skipPreflight = skipPreflight;
|
|
6576
6762
|
}
|
|
@@ -6725,7 +6911,14 @@ class Connection {
|
|
|
6725
6911
|
this._rpcWebSocketIdleTimeout = setTimeout(() => {
|
|
6726
6912
|
this._rpcWebSocketIdleTimeout = null;
|
|
6727
6913
|
|
|
6728
|
-
|
|
6914
|
+
try {
|
|
6915
|
+
this._rpcWebSocket.close();
|
|
6916
|
+
} catch (err) {
|
|
6917
|
+
// swallow error if socket has already been closed.
|
|
6918
|
+
if (err instanceof Error) {
|
|
6919
|
+
console.log(`Error when closing socket connection: ${err.message}`);
|
|
6920
|
+
}
|
|
6921
|
+
}
|
|
6729
6922
|
}, 500);
|
|
6730
6923
|
}
|
|
6731
6924
|
|
|
@@ -8536,6 +8729,322 @@ function getPriorVoters({
|
|
|
8536
8729
|
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
8537
8730
|
}
|
|
8538
8731
|
|
|
8732
|
+
/**
|
|
8733
|
+
* Vote account info
|
|
8734
|
+
*/
|
|
8735
|
+
|
|
8736
|
+
class VoteInit {
|
|
8737
|
+
/** [0, 100] */
|
|
8738
|
+
constructor(nodePubkey, authorizedVoter, authorizedWithdrawer, commission) {
|
|
8739
|
+
this.nodePubkey = void 0;
|
|
8740
|
+
this.authorizedVoter = void 0;
|
|
8741
|
+
this.authorizedWithdrawer = void 0;
|
|
8742
|
+
this.commission = void 0;
|
|
8743
|
+
this.nodePubkey = nodePubkey;
|
|
8744
|
+
this.authorizedVoter = authorizedVoter;
|
|
8745
|
+
this.authorizedWithdrawer = authorizedWithdrawer;
|
|
8746
|
+
this.commission = commission;
|
|
8747
|
+
}
|
|
8748
|
+
|
|
8749
|
+
}
|
|
8750
|
+
/**
|
|
8751
|
+
* Create vote account transaction params
|
|
8752
|
+
*/
|
|
8753
|
+
|
|
8754
|
+
/**
|
|
8755
|
+
* Vote Instruction class
|
|
8756
|
+
*/
|
|
8757
|
+
class VoteInstruction {
|
|
8758
|
+
/**
|
|
8759
|
+
* @internal
|
|
8760
|
+
*/
|
|
8761
|
+
constructor() {}
|
|
8762
|
+
/**
|
|
8763
|
+
* Decode a vote instruction and retrieve the instruction type.
|
|
8764
|
+
*/
|
|
8765
|
+
|
|
8766
|
+
|
|
8767
|
+
static decodeInstructionType(instruction) {
|
|
8768
|
+
this.checkProgramId(instruction.programId);
|
|
8769
|
+
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
8770
|
+
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
8771
|
+
let type;
|
|
8772
|
+
|
|
8773
|
+
for (const [ixType, layout] of Object.entries(VOTE_INSTRUCTION_LAYOUTS)) {
|
|
8774
|
+
if (layout.index == typeIndex) {
|
|
8775
|
+
type = ixType;
|
|
8776
|
+
break;
|
|
8777
|
+
}
|
|
8778
|
+
}
|
|
8779
|
+
|
|
8780
|
+
if (!type) {
|
|
8781
|
+
throw new Error('Instruction type incorrect; not a VoteInstruction');
|
|
8782
|
+
}
|
|
8783
|
+
|
|
8784
|
+
return type;
|
|
8785
|
+
}
|
|
8786
|
+
/**
|
|
8787
|
+
* Decode an initialize vote instruction and retrieve the instruction params.
|
|
8788
|
+
*/
|
|
8789
|
+
|
|
8790
|
+
|
|
8791
|
+
static decodeInitializeAccount(instruction) {
|
|
8792
|
+
this.checkProgramId(instruction.programId);
|
|
8793
|
+
this.checkKeyLength(instruction.keys, 4);
|
|
8794
|
+
const {
|
|
8795
|
+
voteInit
|
|
8796
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.InitializeAccount, instruction.data);
|
|
8797
|
+
return {
|
|
8798
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
8799
|
+
nodePubkey: instruction.keys[3].pubkey,
|
|
8800
|
+
voteInit: new VoteInit(new PublicKey(voteInit.nodePubkey), new PublicKey(voteInit.authorizedVoter), new PublicKey(voteInit.authorizedWithdrawer), voteInit.commission)
|
|
8801
|
+
};
|
|
8802
|
+
}
|
|
8803
|
+
/**
|
|
8804
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
8805
|
+
*/
|
|
8806
|
+
|
|
8807
|
+
|
|
8808
|
+
static decodeAuthorize(instruction) {
|
|
8809
|
+
this.checkProgramId(instruction.programId);
|
|
8810
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
8811
|
+
const {
|
|
8812
|
+
newAuthorized,
|
|
8813
|
+
voteAuthorizationType
|
|
8814
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.Authorize, instruction.data);
|
|
8815
|
+
return {
|
|
8816
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
8817
|
+
authorizedPubkey: instruction.keys[2].pubkey,
|
|
8818
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
8819
|
+
voteAuthorizationType: {
|
|
8820
|
+
index: voteAuthorizationType
|
|
8821
|
+
}
|
|
8822
|
+
};
|
|
8823
|
+
}
|
|
8824
|
+
/**
|
|
8825
|
+
* Decode a withdraw instruction and retrieve the instruction params.
|
|
8826
|
+
*/
|
|
8827
|
+
|
|
8828
|
+
|
|
8829
|
+
static decodeWithdraw(instruction) {
|
|
8830
|
+
this.checkProgramId(instruction.programId);
|
|
8831
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
8832
|
+
const {
|
|
8833
|
+
lamports
|
|
8834
|
+
} = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
|
|
8835
|
+
return {
|
|
8836
|
+
votePubkey: instruction.keys[0].pubkey,
|
|
8837
|
+
authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
|
|
8838
|
+
lamports,
|
|
8839
|
+
toPubkey: instruction.keys[1].pubkey
|
|
8840
|
+
};
|
|
8841
|
+
}
|
|
8842
|
+
/**
|
|
8843
|
+
* @internal
|
|
8844
|
+
*/
|
|
8845
|
+
|
|
8846
|
+
|
|
8847
|
+
static checkProgramId(programId) {
|
|
8848
|
+
if (!programId.equals(VoteProgram.programId)) {
|
|
8849
|
+
throw new Error('invalid instruction; programId is not VoteProgram');
|
|
8850
|
+
}
|
|
8851
|
+
}
|
|
8852
|
+
/**
|
|
8853
|
+
* @internal
|
|
8854
|
+
*/
|
|
8855
|
+
|
|
8856
|
+
|
|
8857
|
+
static checkKeyLength(keys, expectedLength) {
|
|
8858
|
+
if (keys.length < expectedLength) {
|
|
8859
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
8860
|
+
}
|
|
8861
|
+
}
|
|
8862
|
+
|
|
8863
|
+
}
|
|
8864
|
+
/**
|
|
8865
|
+
* An enumeration of valid VoteInstructionType's
|
|
8866
|
+
*/
|
|
8867
|
+
|
|
8868
|
+
const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
8869
|
+
InitializeAccount: {
|
|
8870
|
+
index: 0,
|
|
8871
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteInit()])
|
|
8872
|
+
},
|
|
8873
|
+
Authorize: {
|
|
8874
|
+
index: 1,
|
|
8875
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), publicKey('newAuthorized'), BufferLayout.u32('voteAuthorizationType')])
|
|
8876
|
+
},
|
|
8877
|
+
Withdraw: {
|
|
8878
|
+
index: 3,
|
|
8879
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
8880
|
+
}
|
|
8881
|
+
});
|
|
8882
|
+
/**
|
|
8883
|
+
* VoteAuthorize type
|
|
8884
|
+
*/
|
|
8885
|
+
|
|
8886
|
+
/**
|
|
8887
|
+
* An enumeration of valid VoteAuthorization layouts.
|
|
8888
|
+
*/
|
|
8889
|
+
const VoteAuthorizationLayout = Object.freeze({
|
|
8890
|
+
Voter: {
|
|
8891
|
+
index: 0
|
|
8892
|
+
},
|
|
8893
|
+
Withdrawer: {
|
|
8894
|
+
index: 1
|
|
8895
|
+
}
|
|
8896
|
+
});
|
|
8897
|
+
/**
|
|
8898
|
+
* Factory class for transactions to interact with the Vote program
|
|
8899
|
+
*/
|
|
8900
|
+
|
|
8901
|
+
class VoteProgram {
|
|
8902
|
+
/**
|
|
8903
|
+
* @internal
|
|
8904
|
+
*/
|
|
8905
|
+
constructor() {}
|
|
8906
|
+
/**
|
|
8907
|
+
* Public key that identifies the Vote program
|
|
8908
|
+
*/
|
|
8909
|
+
|
|
8910
|
+
|
|
8911
|
+
/**
|
|
8912
|
+
* Generate an Initialize instruction.
|
|
8913
|
+
*/
|
|
8914
|
+
static initializeAccount(params) {
|
|
8915
|
+
const {
|
|
8916
|
+
votePubkey,
|
|
8917
|
+
nodePubkey,
|
|
8918
|
+
voteInit
|
|
8919
|
+
} = params;
|
|
8920
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
|
|
8921
|
+
const data = encodeData(type, {
|
|
8922
|
+
voteInit: {
|
|
8923
|
+
nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
|
|
8924
|
+
authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
|
|
8925
|
+
authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
|
|
8926
|
+
commission: voteInit.commission
|
|
8927
|
+
}
|
|
8928
|
+
});
|
|
8929
|
+
const instructionData = {
|
|
8930
|
+
keys: [{
|
|
8931
|
+
pubkey: votePubkey,
|
|
8932
|
+
isSigner: false,
|
|
8933
|
+
isWritable: true
|
|
8934
|
+
}, {
|
|
8935
|
+
pubkey: SYSVAR_RENT_PUBKEY,
|
|
8936
|
+
isSigner: false,
|
|
8937
|
+
isWritable: false
|
|
8938
|
+
}, {
|
|
8939
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
8940
|
+
isSigner: false,
|
|
8941
|
+
isWritable: false
|
|
8942
|
+
}, {
|
|
8943
|
+
pubkey: nodePubkey,
|
|
8944
|
+
isSigner: true,
|
|
8945
|
+
isWritable: false
|
|
8946
|
+
}],
|
|
8947
|
+
programId: this.programId,
|
|
8948
|
+
data
|
|
8949
|
+
};
|
|
8950
|
+
return new TransactionInstruction(instructionData);
|
|
8951
|
+
}
|
|
8952
|
+
/**
|
|
8953
|
+
* Generate a transaction that creates a new Vote account.
|
|
8954
|
+
*/
|
|
8955
|
+
|
|
8956
|
+
|
|
8957
|
+
static createAccount(params) {
|
|
8958
|
+
const transaction = new Transaction();
|
|
8959
|
+
transaction.add(SystemProgram.createAccount({
|
|
8960
|
+
fromPubkey: params.fromPubkey,
|
|
8961
|
+
newAccountPubkey: params.votePubkey,
|
|
8962
|
+
lamports: params.lamports,
|
|
8963
|
+
space: this.space,
|
|
8964
|
+
programId: this.programId
|
|
8965
|
+
}));
|
|
8966
|
+
return transaction.add(this.initializeAccount({
|
|
8967
|
+
votePubkey: params.votePubkey,
|
|
8968
|
+
nodePubkey: params.voteInit.nodePubkey,
|
|
8969
|
+
voteInit: params.voteInit
|
|
8970
|
+
}));
|
|
8971
|
+
}
|
|
8972
|
+
/**
|
|
8973
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account.
|
|
8974
|
+
*/
|
|
8975
|
+
|
|
8976
|
+
|
|
8977
|
+
static authorize(params) {
|
|
8978
|
+
const {
|
|
8979
|
+
votePubkey,
|
|
8980
|
+
authorizedPubkey,
|
|
8981
|
+
newAuthorizedPubkey,
|
|
8982
|
+
voteAuthorizationType
|
|
8983
|
+
} = params;
|
|
8984
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.Authorize;
|
|
8985
|
+
const data = encodeData(type, {
|
|
8986
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
8987
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
8988
|
+
});
|
|
8989
|
+
const keys = [{
|
|
8990
|
+
pubkey: votePubkey,
|
|
8991
|
+
isSigner: false,
|
|
8992
|
+
isWritable: true
|
|
8993
|
+
}, {
|
|
8994
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
8995
|
+
isSigner: false,
|
|
8996
|
+
isWritable: false
|
|
8997
|
+
}, {
|
|
8998
|
+
pubkey: authorizedPubkey,
|
|
8999
|
+
isSigner: true,
|
|
9000
|
+
isWritable: false
|
|
9001
|
+
}];
|
|
9002
|
+
return new Transaction().add({
|
|
9003
|
+
keys,
|
|
9004
|
+
programId: this.programId,
|
|
9005
|
+
data
|
|
9006
|
+
});
|
|
9007
|
+
}
|
|
9008
|
+
/**
|
|
9009
|
+
* Generate a transaction to withdraw from a Vote account.
|
|
9010
|
+
*/
|
|
9011
|
+
|
|
9012
|
+
|
|
9013
|
+
static withdraw(params) {
|
|
9014
|
+
const {
|
|
9015
|
+
votePubkey,
|
|
9016
|
+
authorizedWithdrawerPubkey,
|
|
9017
|
+
lamports,
|
|
9018
|
+
toPubkey
|
|
9019
|
+
} = params;
|
|
9020
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
|
|
9021
|
+
const data = encodeData(type, {
|
|
9022
|
+
lamports
|
|
9023
|
+
});
|
|
9024
|
+
const keys = [{
|
|
9025
|
+
pubkey: votePubkey,
|
|
9026
|
+
isSigner: false,
|
|
9027
|
+
isWritable: true
|
|
9028
|
+
}, {
|
|
9029
|
+
pubkey: toPubkey,
|
|
9030
|
+
isSigner: false,
|
|
9031
|
+
isWritable: true
|
|
9032
|
+
}, {
|
|
9033
|
+
pubkey: authorizedWithdrawerPubkey,
|
|
9034
|
+
isSigner: true,
|
|
9035
|
+
isWritable: false
|
|
9036
|
+
}];
|
|
9037
|
+
return new Transaction().add({
|
|
9038
|
+
keys,
|
|
9039
|
+
programId: this.programId,
|
|
9040
|
+
data
|
|
9041
|
+
});
|
|
9042
|
+
}
|
|
9043
|
+
|
|
9044
|
+
}
|
|
9045
|
+
VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
|
|
9046
|
+
VoteProgram.space = 3731;
|
|
9047
|
+
|
|
8539
9048
|
/**
|
|
8540
9049
|
* Send and confirm a raw transaction
|
|
8541
9050
|
*
|
|
@@ -8565,12 +9074,12 @@ const endpoint = {
|
|
|
8565
9074
|
http: {
|
|
8566
9075
|
devnet: 'http://api.devnet.solana.com',
|
|
8567
9076
|
testnet: 'http://api.testnet.solana.com',
|
|
8568
|
-
'mainnet-beta': 'http://api.mainnet-beta.solana.com'
|
|
9077
|
+
'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
|
|
8569
9078
|
},
|
|
8570
9079
|
https: {
|
|
8571
9080
|
devnet: 'https://api.devnet.solana.com',
|
|
8572
9081
|
testnet: 'https://api.testnet.solana.com',
|
|
8573
|
-
'mainnet-beta': 'https://api.mainnet-beta.solana.com'
|
|
9082
|
+
'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
|
|
8574
9083
|
}
|
|
8575
9084
|
};
|
|
8576
9085
|
|
|
@@ -8599,5 +9108,5 @@ function clusterApiUrl(cluster, tls) {
|
|
|
8599
9108
|
|
|
8600
9109
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
8601
9110
|
|
|
8602
|
-
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9111
|
+
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
8603
9112
|
//# sourceMappingURL=index.esm.js.map
|