@solana/web3.js 1.45.0 → 1.46.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.cjs.js +157 -73
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +157 -73
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +157 -73
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +142 -18
- package/lib/index.esm.js +157 -73
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +157 -73
- 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/package.json +1 -1
- package/src/connection.ts +269 -73
- package/src/util/send-and-confirm-raw-transaction.ts +1 -0
- package/src/util/send-and-confirm-transaction.ts +1 -0
package/lib/index.cjs.js
CHANGED
|
@@ -3131,7 +3131,8 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
3131
3131
|
const sendOptions = options && {
|
|
3132
3132
|
skipPreflight: options.skipPreflight,
|
|
3133
3133
|
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
3134
|
-
maxRetries: options.maxRetries
|
|
3134
|
+
maxRetries: options.maxRetries,
|
|
3135
|
+
minContextSlot: options.minContextSlot
|
|
3135
3136
|
};
|
|
3136
3137
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
3137
3138
|
const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
|
|
@@ -4695,9 +4696,32 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
|
|
|
4695
4696
|
* https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
|
|
4696
4697
|
*/
|
|
4697
4698
|
|
|
4699
|
+
/** @internal */
|
|
4700
|
+
function extractCommitmentFromConfig(commitmentOrConfig) {
|
|
4701
|
+
let commitment;
|
|
4702
|
+
let config;
|
|
4703
|
+
|
|
4704
|
+
if (typeof commitmentOrConfig === 'string') {
|
|
4705
|
+
commitment = commitmentOrConfig;
|
|
4706
|
+
} else if (commitmentOrConfig) {
|
|
4707
|
+
const {
|
|
4708
|
+
commitment: specifiedCommitment,
|
|
4709
|
+
...specifiedConfig
|
|
4710
|
+
} = commitmentOrConfig;
|
|
4711
|
+
commitment = specifiedCommitment;
|
|
4712
|
+
config = specifiedConfig;
|
|
4713
|
+
}
|
|
4714
|
+
|
|
4715
|
+
return {
|
|
4716
|
+
commitment,
|
|
4717
|
+
config
|
|
4718
|
+
};
|
|
4719
|
+
}
|
|
4698
4720
|
/**
|
|
4699
4721
|
* @internal
|
|
4700
4722
|
*/
|
|
4723
|
+
|
|
4724
|
+
|
|
4701
4725
|
function createRpcResult(result) {
|
|
4702
4726
|
return superstruct.union([superstruct.type({
|
|
4703
4727
|
jsonrpc: superstruct.literal('2.0'),
|
|
@@ -5740,8 +5764,16 @@ class Connection {
|
|
|
5740
5764
|
*/
|
|
5741
5765
|
|
|
5742
5766
|
|
|
5743
|
-
async getBalanceAndContext(publicKey,
|
|
5744
|
-
|
|
5767
|
+
async getBalanceAndContext(publicKey, commitmentOrConfig) {
|
|
5768
|
+
/** @internal */
|
|
5769
|
+
const {
|
|
5770
|
+
commitment,
|
|
5771
|
+
config
|
|
5772
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
5773
|
+
|
|
5774
|
+
const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
|
|
5775
|
+
/* encoding */
|
|
5776
|
+
, config);
|
|
5745
5777
|
|
|
5746
5778
|
const unsafeRes = await this._rpcRequest('getBalance', args);
|
|
5747
5779
|
const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.number()));
|
|
@@ -5757,8 +5789,8 @@ class Connection {
|
|
|
5757
5789
|
*/
|
|
5758
5790
|
|
|
5759
5791
|
|
|
5760
|
-
async getBalance(publicKey,
|
|
5761
|
-
return await this.getBalanceAndContext(publicKey,
|
|
5792
|
+
async getBalance(publicKey, commitmentOrConfig) {
|
|
5793
|
+
return await this.getBalanceAndContext(publicKey, commitmentOrConfig).then(x => x.value).catch(e => {
|
|
5762
5794
|
throw new Error('failed to get balance of account ' + publicKey.toBase58() + ': ' + e);
|
|
5763
5795
|
});
|
|
5764
5796
|
}
|
|
@@ -5880,7 +5912,11 @@ class Connection {
|
|
|
5880
5912
|
*/
|
|
5881
5913
|
|
|
5882
5914
|
|
|
5883
|
-
async getTokenAccountsByOwner(ownerAddress, filter,
|
|
5915
|
+
async getTokenAccountsByOwner(ownerAddress, filter, commitmentOrConfig) {
|
|
5916
|
+
const {
|
|
5917
|
+
commitment,
|
|
5918
|
+
config
|
|
5919
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
5884
5920
|
let _args = [ownerAddress.toBase58()];
|
|
5885
5921
|
|
|
5886
5922
|
if ('mint' in filter) {
|
|
@@ -5893,7 +5929,7 @@ class Connection {
|
|
|
5893
5929
|
});
|
|
5894
5930
|
}
|
|
5895
5931
|
|
|
5896
|
-
const args = this._buildArgs(_args, commitment, 'base64');
|
|
5932
|
+
const args = this._buildArgs(_args, commitment, 'base64', config);
|
|
5897
5933
|
|
|
5898
5934
|
const unsafeRes = await this._rpcRequest('getTokenAccountsByOwner', args);
|
|
5899
5935
|
const res = superstruct.create(unsafeRes, GetTokenAccountsByOwner);
|
|
@@ -5977,8 +6013,13 @@ class Connection {
|
|
|
5977
6013
|
*/
|
|
5978
6014
|
|
|
5979
6015
|
|
|
5980
|
-
async getAccountInfoAndContext(publicKey,
|
|
5981
|
-
const
|
|
6016
|
+
async getAccountInfoAndContext(publicKey, commitmentOrConfig) {
|
|
6017
|
+
const {
|
|
6018
|
+
commitment,
|
|
6019
|
+
config
|
|
6020
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6021
|
+
|
|
6022
|
+
const args = this._buildArgs([publicKey.toBase58()], commitment, 'base64', config);
|
|
5982
6023
|
|
|
5983
6024
|
const unsafeRes = await this._rpcRequest('getAccountInfo', args);
|
|
5984
6025
|
const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.nullable(AccountInfoResult)));
|
|
@@ -6011,9 +6052,9 @@ class Connection {
|
|
|
6011
6052
|
*/
|
|
6012
6053
|
|
|
6013
6054
|
|
|
6014
|
-
async getAccountInfo(publicKey,
|
|
6055
|
+
async getAccountInfo(publicKey, commitmentOrConfig) {
|
|
6015
6056
|
try {
|
|
6016
|
-
const res = await this.getAccountInfoAndContext(publicKey,
|
|
6057
|
+
const res = await this.getAccountInfoAndContext(publicKey, commitmentOrConfig);
|
|
6017
6058
|
return res.value;
|
|
6018
6059
|
} catch (e) {
|
|
6019
6060
|
throw new Error('failed to get info about account ' + publicKey.toBase58() + ': ' + e);
|
|
@@ -6024,10 +6065,14 @@ class Connection {
|
|
|
6024
6065
|
*/
|
|
6025
6066
|
|
|
6026
6067
|
|
|
6027
|
-
async getMultipleAccountsInfoAndContext(publicKeys,
|
|
6068
|
+
async getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig) {
|
|
6069
|
+
const {
|
|
6070
|
+
commitment,
|
|
6071
|
+
config
|
|
6072
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6028
6073
|
const keys = publicKeys.map(key => key.toBase58());
|
|
6029
6074
|
|
|
6030
|
-
const args = this._buildArgs([keys], commitment, 'base64');
|
|
6075
|
+
const args = this._buildArgs([keys], commitment, 'base64', config);
|
|
6031
6076
|
|
|
6032
6077
|
const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
|
|
6033
6078
|
const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.array(superstruct.nullable(AccountInfoResult))));
|
|
@@ -6043,8 +6088,8 @@ class Connection {
|
|
|
6043
6088
|
*/
|
|
6044
6089
|
|
|
6045
6090
|
|
|
6046
|
-
async getMultipleAccountsInfo(publicKeys,
|
|
6047
|
-
const res = await this.getMultipleAccountsInfoAndContext(publicKeys,
|
|
6091
|
+
async getMultipleAccountsInfo(publicKeys, commitmentOrConfig) {
|
|
6092
|
+
const res = await this.getMultipleAccountsInfoAndContext(publicKeys, commitmentOrConfig);
|
|
6048
6093
|
return res.value;
|
|
6049
6094
|
}
|
|
6050
6095
|
/**
|
|
@@ -6052,10 +6097,17 @@ class Connection {
|
|
|
6052
6097
|
*/
|
|
6053
6098
|
|
|
6054
6099
|
|
|
6055
|
-
async getStakeActivation(publicKey,
|
|
6056
|
-
const
|
|
6057
|
-
|
|
6058
|
-
|
|
6100
|
+
async getStakeActivation(publicKey, commitmentOrConfig, epoch) {
|
|
6101
|
+
const {
|
|
6102
|
+
commitment,
|
|
6103
|
+
config
|
|
6104
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6105
|
+
|
|
6106
|
+
const args = this._buildArgs([publicKey.toBase58()], commitment, undefined
|
|
6107
|
+
/* encoding */
|
|
6108
|
+
, { ...config,
|
|
6109
|
+
epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
|
|
6110
|
+
});
|
|
6059
6111
|
|
|
6060
6112
|
const unsafeRes = await this._rpcRequest('getStakeActivation', args);
|
|
6061
6113
|
const res = superstruct.create(unsafeRes, jsonRpcResult(StakeActivationResult));
|
|
@@ -6074,28 +6126,16 @@ class Connection {
|
|
|
6074
6126
|
|
|
6075
6127
|
|
|
6076
6128
|
async getProgramAccounts(programId, configOrCommitment) {
|
|
6077
|
-
const
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
commitment = configOrCommitment.commitment;
|
|
6086
|
-
encoding = configOrCommitment.encoding;
|
|
6087
|
-
|
|
6088
|
-
if (configOrCommitment.dataSlice) {
|
|
6089
|
-
extra.dataSlice = configOrCommitment.dataSlice;
|
|
6090
|
-
}
|
|
6091
|
-
|
|
6092
|
-
if (configOrCommitment.filters) {
|
|
6093
|
-
extra.filters = configOrCommitment.filters;
|
|
6094
|
-
}
|
|
6095
|
-
}
|
|
6096
|
-
}
|
|
6129
|
+
const {
|
|
6130
|
+
commitment,
|
|
6131
|
+
config
|
|
6132
|
+
} = extractCommitmentFromConfig(configOrCommitment);
|
|
6133
|
+
const {
|
|
6134
|
+
encoding,
|
|
6135
|
+
...configWithoutEncoding
|
|
6136
|
+
} = config || {};
|
|
6097
6137
|
|
|
6098
|
-
const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64',
|
|
6138
|
+
const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', configWithoutEncoding);
|
|
6099
6139
|
|
|
6100
6140
|
const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
|
|
6101
6141
|
const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(KeyedAccountInfoResult)));
|
|
@@ -6114,22 +6154,12 @@ class Connection {
|
|
|
6114
6154
|
|
|
6115
6155
|
|
|
6116
6156
|
async getParsedProgramAccounts(programId, configOrCommitment) {
|
|
6117
|
-
const
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
if (typeof configOrCommitment === 'string') {
|
|
6122
|
-
commitment = configOrCommitment;
|
|
6123
|
-
} else {
|
|
6124
|
-
commitment = configOrCommitment.commitment;
|
|
6125
|
-
|
|
6126
|
-
if (configOrCommitment.filters) {
|
|
6127
|
-
extra.filters = configOrCommitment.filters;
|
|
6128
|
-
}
|
|
6129
|
-
}
|
|
6130
|
-
}
|
|
6157
|
+
const {
|
|
6158
|
+
commitment,
|
|
6159
|
+
config
|
|
6160
|
+
} = extractCommitmentFromConfig(configOrCommitment);
|
|
6131
6161
|
|
|
6132
|
-
const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed',
|
|
6162
|
+
const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', config);
|
|
6133
6163
|
|
|
6134
6164
|
const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
|
|
6135
6165
|
const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.array(KeyedParsedAccountInfoResult)));
|
|
@@ -6296,8 +6326,15 @@ class Connection {
|
|
|
6296
6326
|
*/
|
|
6297
6327
|
|
|
6298
6328
|
|
|
6299
|
-
async getSlot(
|
|
6300
|
-
const
|
|
6329
|
+
async getSlot(commitmentOrConfig) {
|
|
6330
|
+
const {
|
|
6331
|
+
commitment,
|
|
6332
|
+
config
|
|
6333
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6334
|
+
|
|
6335
|
+
const args = this._buildArgs([], commitment, undefined
|
|
6336
|
+
/* encoding */
|
|
6337
|
+
, config);
|
|
6301
6338
|
|
|
6302
6339
|
const unsafeRes = await this._rpcRequest('getSlot', args);
|
|
6303
6340
|
const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
|
|
@@ -6313,8 +6350,15 @@ class Connection {
|
|
|
6313
6350
|
*/
|
|
6314
6351
|
|
|
6315
6352
|
|
|
6316
|
-
async getSlotLeader(
|
|
6317
|
-
const
|
|
6353
|
+
async getSlotLeader(commitmentOrConfig) {
|
|
6354
|
+
const {
|
|
6355
|
+
commitment,
|
|
6356
|
+
config
|
|
6357
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6358
|
+
|
|
6359
|
+
const args = this._buildArgs([], commitment, undefined
|
|
6360
|
+
/* encoding */
|
|
6361
|
+
, config);
|
|
6318
6362
|
|
|
6319
6363
|
const unsafeRes = await this._rpcRequest('getSlotLeader', args);
|
|
6320
6364
|
const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.string()));
|
|
@@ -6387,8 +6431,15 @@ class Connection {
|
|
|
6387
6431
|
*/
|
|
6388
6432
|
|
|
6389
6433
|
|
|
6390
|
-
async getTransactionCount(
|
|
6391
|
-
const
|
|
6434
|
+
async getTransactionCount(commitmentOrConfig) {
|
|
6435
|
+
const {
|
|
6436
|
+
commitment,
|
|
6437
|
+
config
|
|
6438
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6439
|
+
|
|
6440
|
+
const args = this._buildArgs([], commitment, undefined
|
|
6441
|
+
/* encoding */
|
|
6442
|
+
, config);
|
|
6392
6443
|
|
|
6393
6444
|
const unsafeRes = await this._rpcRequest('getTransactionCount', args);
|
|
6394
6445
|
const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
|
|
@@ -6435,9 +6486,16 @@ class Connection {
|
|
|
6435
6486
|
*/
|
|
6436
6487
|
|
|
6437
6488
|
|
|
6438
|
-
async getInflationReward(addresses, epoch,
|
|
6439
|
-
const
|
|
6440
|
-
|
|
6489
|
+
async getInflationReward(addresses, epoch, commitmentOrConfig) {
|
|
6490
|
+
const {
|
|
6491
|
+
commitment,
|
|
6492
|
+
config
|
|
6493
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6494
|
+
|
|
6495
|
+
const args = this._buildArgs([addresses.map(pubkey => pubkey.toBase58())], commitment, undefined
|
|
6496
|
+
/* encoding */
|
|
6497
|
+
, { ...config,
|
|
6498
|
+
epoch: epoch != null ? epoch : config === null || config === void 0 ? void 0 : config.epoch
|
|
6441
6499
|
});
|
|
6442
6500
|
|
|
6443
6501
|
const unsafeRes = await this._rpcRequest('getInflationReward', args);
|
|
@@ -6454,8 +6512,15 @@ class Connection {
|
|
|
6454
6512
|
*/
|
|
6455
6513
|
|
|
6456
6514
|
|
|
6457
|
-
async getEpochInfo(
|
|
6458
|
-
const
|
|
6515
|
+
async getEpochInfo(commitmentOrConfig) {
|
|
6516
|
+
const {
|
|
6517
|
+
commitment,
|
|
6518
|
+
config
|
|
6519
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6520
|
+
|
|
6521
|
+
const args = this._buildArgs([], commitment, undefined
|
|
6522
|
+
/* encoding */
|
|
6523
|
+
, config);
|
|
6459
6524
|
|
|
6460
6525
|
const unsafeRes = await this._rpcRequest('getEpochInfo', args);
|
|
6461
6526
|
const res = superstruct.create(unsafeRes, GetEpochInfoRpcResult);
|
|
@@ -6626,9 +6691,9 @@ class Connection {
|
|
|
6626
6691
|
*/
|
|
6627
6692
|
|
|
6628
6693
|
|
|
6629
|
-
async getLatestBlockhash(
|
|
6694
|
+
async getLatestBlockhash(commitmentOrConfig) {
|
|
6630
6695
|
try {
|
|
6631
|
-
const res = await this.getLatestBlockhashAndContext(
|
|
6696
|
+
const res = await this.getLatestBlockhashAndContext(commitmentOrConfig);
|
|
6632
6697
|
return res.value;
|
|
6633
6698
|
} catch (e) {
|
|
6634
6699
|
throw new Error('failed to get recent blockhash: ' + e);
|
|
@@ -6640,8 +6705,15 @@ class Connection {
|
|
|
6640
6705
|
*/
|
|
6641
6706
|
|
|
6642
6707
|
|
|
6643
|
-
async getLatestBlockhashAndContext(
|
|
6644
|
-
const
|
|
6708
|
+
async getLatestBlockhashAndContext(commitmentOrConfig) {
|
|
6709
|
+
const {
|
|
6710
|
+
commitment,
|
|
6711
|
+
config
|
|
6712
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6713
|
+
|
|
6714
|
+
const args = this._buildArgs([], commitment, undefined
|
|
6715
|
+
/* encoding */
|
|
6716
|
+
, config);
|
|
6645
6717
|
|
|
6646
6718
|
const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
|
|
6647
6719
|
const res = superstruct.create(unsafeRes, GetLatestBlockhashRpcResult);
|
|
@@ -6719,8 +6791,15 @@ class Connection {
|
|
|
6719
6791
|
*/
|
|
6720
6792
|
|
|
6721
6793
|
|
|
6722
|
-
async getBlockHeight(
|
|
6723
|
-
const
|
|
6794
|
+
async getBlockHeight(commitmentOrConfig) {
|
|
6795
|
+
const {
|
|
6796
|
+
commitment,
|
|
6797
|
+
config
|
|
6798
|
+
} = extractCommitmentFromConfig(commitmentOrConfig);
|
|
6799
|
+
|
|
6800
|
+
const args = this._buildArgs([], commitment, undefined
|
|
6801
|
+
/* encoding */
|
|
6802
|
+
, config);
|
|
6724
6803
|
|
|
6725
6804
|
const unsafeRes = await this._rpcRequest('getBlockHeight', args);
|
|
6726
6805
|
const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
|
|
@@ -7449,6 +7528,10 @@ class Connection {
|
|
|
7449
7528
|
config.maxRetries = options.maxRetries;
|
|
7450
7529
|
}
|
|
7451
7530
|
|
|
7531
|
+
if (options && options.minContextSlot != null) {
|
|
7532
|
+
config.minContextSlot = options.minContextSlot;
|
|
7533
|
+
}
|
|
7534
|
+
|
|
7452
7535
|
if (skipPreflight) {
|
|
7453
7536
|
config.skipPreflight = skipPreflight;
|
|
7454
7537
|
}
|
|
@@ -9858,7 +9941,8 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9858
9941
|
|
|
9859
9942
|
const sendOptions = options && {
|
|
9860
9943
|
skipPreflight: options.skipPreflight,
|
|
9861
|
-
preflightCommitment: options.preflightCommitment || options.commitment
|
|
9944
|
+
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
9945
|
+
minContextSlot: options.minContextSlot
|
|
9862
9946
|
};
|
|
9863
9947
|
const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
|
|
9864
9948
|
const commitment = options && options.commitment;
|