@solana/web3.js 1.45.1 → 1.46.1
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 +158 -74
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +158 -74
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +158 -74
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +142 -18
- package/lib/index.esm.js +158 -74
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +158 -74
- 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/package.json
CHANGED
package/src/connection.ts
CHANGED
|
@@ -228,6 +228,8 @@ export type SendOptions = {
|
|
|
228
228
|
preflightCommitment?: Commitment;
|
|
229
229
|
/** Maximum number of times for the RPC node to retry sending the transaction to the leader. */
|
|
230
230
|
maxRetries?: number;
|
|
231
|
+
/** The minimum slot that the request can be evaluated at */
|
|
232
|
+
minContextSlot?: number;
|
|
231
233
|
};
|
|
232
234
|
|
|
233
235
|
/**
|
|
@@ -242,6 +244,8 @@ export type ConfirmOptions = {
|
|
|
242
244
|
preflightCommitment?: Commitment;
|
|
243
245
|
/** Maximum number of times for the RPC node to retry sending the transaction to the leader. */
|
|
244
246
|
maxRetries?: number;
|
|
247
|
+
/** The minimum slot that the request can be evaluated at */
|
|
248
|
+
minContextSlot?: number;
|
|
245
249
|
};
|
|
246
250
|
|
|
247
251
|
/**
|
|
@@ -272,6 +276,8 @@ export type SignaturesForAddressOptions = {
|
|
|
272
276
|
until?: TransactionSignature;
|
|
273
277
|
/** Maximum transaction signatures to return (between 1 and 1,000, default: 1,000). */
|
|
274
278
|
limit?: number;
|
|
279
|
+
/** The minimum slot that the request can be evaluated at */
|
|
280
|
+
minContextSlot?: number;
|
|
275
281
|
};
|
|
276
282
|
|
|
277
283
|
/**
|
|
@@ -297,6 +303,23 @@ export type BlockheightBasedTransactionConfirmationStrategy = {
|
|
|
297
303
|
signature: TransactionSignature;
|
|
298
304
|
} & BlockhashWithExpiryBlockHeight;
|
|
299
305
|
|
|
306
|
+
/** @internal */
|
|
307
|
+
function extractCommitmentFromConfig<TConfig>(
|
|
308
|
+
commitmentOrConfig?: Commitment | ({commitment?: Commitment} & TConfig),
|
|
309
|
+
) {
|
|
310
|
+
let commitment: Commitment | undefined;
|
|
311
|
+
let config: Omit<TConfig, 'commitment'> | undefined;
|
|
312
|
+
if (typeof commitmentOrConfig === 'string') {
|
|
313
|
+
commitment = commitmentOrConfig;
|
|
314
|
+
} else if (commitmentOrConfig) {
|
|
315
|
+
const {commitment: specifiedCommitment, ...specifiedConfig} =
|
|
316
|
+
commitmentOrConfig;
|
|
317
|
+
commitment = specifiedCommitment;
|
|
318
|
+
config = specifiedConfig;
|
|
319
|
+
}
|
|
320
|
+
return {commitment, config};
|
|
321
|
+
}
|
|
322
|
+
|
|
300
323
|
/**
|
|
301
324
|
* @internal
|
|
302
325
|
*/
|
|
@@ -399,6 +422,88 @@ export type Finality = 'confirmed' | 'finalized';
|
|
|
399
422
|
*/
|
|
400
423
|
export type LargestAccountsFilter = 'circulating' | 'nonCirculating';
|
|
401
424
|
|
|
425
|
+
/**
|
|
426
|
+
* Configuration object for changing `getAccountInfo` query behavior
|
|
427
|
+
*/
|
|
428
|
+
export type GetAccountInfoConfig = {
|
|
429
|
+
/** The level of commitment desired */
|
|
430
|
+
commitment?: Commitment;
|
|
431
|
+
/** The minimum slot that the request can be evaluated at */
|
|
432
|
+
minContextSlot?: number;
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Configuration object for changing `getBalance` query behavior
|
|
437
|
+
*/
|
|
438
|
+
export type GetBalanceConfig = {
|
|
439
|
+
/** The level of commitment desired */
|
|
440
|
+
commitment?: Commitment;
|
|
441
|
+
/** The minimum slot that the request can be evaluated at */
|
|
442
|
+
minContextSlot?: number;
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Configuration object for changing `getBlockHeight` query behavior
|
|
447
|
+
*/
|
|
448
|
+
export type GetBlockHeightConfig = {
|
|
449
|
+
/** The level of commitment desired */
|
|
450
|
+
commitment?: Commitment;
|
|
451
|
+
/** The minimum slot that the request can be evaluated at */
|
|
452
|
+
minContextSlot?: number;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Configuration object for changing `getEpochInfo` query behavior
|
|
457
|
+
*/
|
|
458
|
+
export type GetEpochInfoConfig = {
|
|
459
|
+
/** The level of commitment desired */
|
|
460
|
+
commitment?: Commitment;
|
|
461
|
+
/** The minimum slot that the request can be evaluated at */
|
|
462
|
+
minContextSlot?: number;
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Configuration object for changing `getInflationReward` query behavior
|
|
467
|
+
*/
|
|
468
|
+
export type GetInflationRewardConfig = {
|
|
469
|
+
/** The level of commitment desired */
|
|
470
|
+
commitment?: Commitment;
|
|
471
|
+
/** An epoch for which the reward occurs. If omitted, the previous epoch will be used */
|
|
472
|
+
epoch?: number;
|
|
473
|
+
/** The minimum slot that the request can be evaluated at */
|
|
474
|
+
minContextSlot?: number;
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Configuration object for changing `getLatestBlockhash` query behavior
|
|
479
|
+
*/
|
|
480
|
+
export type GetLatestBlockhashConfig = {
|
|
481
|
+
/** The level of commitment desired */
|
|
482
|
+
commitment?: Commitment;
|
|
483
|
+
/** The minimum slot that the request can be evaluated at */
|
|
484
|
+
minContextSlot?: number;
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Configuration object for changing `getSlot` query behavior
|
|
489
|
+
*/
|
|
490
|
+
export type GetSlotConfig = {
|
|
491
|
+
/** The level of commitment desired */
|
|
492
|
+
commitment?: Commitment;
|
|
493
|
+
/** The minimum slot that the request can be evaluated at */
|
|
494
|
+
minContextSlot?: number;
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Configuration object for changing `getSlotLeader` query behavior
|
|
499
|
+
*/
|
|
500
|
+
export type GetSlotLeaderConfig = {
|
|
501
|
+
/** The level of commitment desired */
|
|
502
|
+
commitment?: Commitment;
|
|
503
|
+
/** The minimum slot that the request can be evaluated at */
|
|
504
|
+
minContextSlot?: number;
|
|
505
|
+
};
|
|
506
|
+
|
|
402
507
|
/**
|
|
403
508
|
* Configuration object for changing `getLargestAccounts` query behavior
|
|
404
509
|
*/
|
|
@@ -1949,6 +2054,8 @@ export type GetProgramAccountsConfig = {
|
|
|
1949
2054
|
dataSlice?: DataSlice;
|
|
1950
2055
|
/** Optional array of filters to apply to accounts */
|
|
1951
2056
|
filters?: GetProgramAccountsFilter[];
|
|
2057
|
+
/** The minimum slot that the request can be evaluated at */
|
|
2058
|
+
minContextSlot?: number;
|
|
1952
2059
|
};
|
|
1953
2060
|
|
|
1954
2061
|
/**
|
|
@@ -1959,6 +2066,8 @@ export type GetParsedProgramAccountsConfig = {
|
|
|
1959
2066
|
commitment?: Commitment;
|
|
1960
2067
|
/** Optional array of filters to apply to accounts */
|
|
1961
2068
|
filters?: GetProgramAccountsFilter[];
|
|
2069
|
+
/** The minimum slot that the request can be evaluated at */
|
|
2070
|
+
minContextSlot?: number;
|
|
1962
2071
|
};
|
|
1963
2072
|
|
|
1964
2073
|
/**
|
|
@@ -1967,8 +2076,40 @@ export type GetParsedProgramAccountsConfig = {
|
|
|
1967
2076
|
export type GetMultipleAccountsConfig = {
|
|
1968
2077
|
/** Optional commitment level */
|
|
1969
2078
|
commitment?: Commitment;
|
|
1970
|
-
/**
|
|
1971
|
-
|
|
2079
|
+
/** The minimum slot that the request can be evaluated at */
|
|
2080
|
+
minContextSlot?: number;
|
|
2081
|
+
};
|
|
2082
|
+
|
|
2083
|
+
/**
|
|
2084
|
+
* Configuration object for `getStakeActivation`
|
|
2085
|
+
*/
|
|
2086
|
+
export type GetStakeActivationConfig = {
|
|
2087
|
+
/** Optional commitment level */
|
|
2088
|
+
commitment?: Commitment;
|
|
2089
|
+
/** Epoch for which to calculate activation details. If parameter not provided, defaults to current epoch */
|
|
2090
|
+
epoch?: number;
|
|
2091
|
+
/** The minimum slot that the request can be evaluated at */
|
|
2092
|
+
minContextSlot?: number;
|
|
2093
|
+
};
|
|
2094
|
+
|
|
2095
|
+
/**
|
|
2096
|
+
* Configuration object for `getStakeActivation`
|
|
2097
|
+
*/
|
|
2098
|
+
export type GetTokenAccountsByOwnerConfig = {
|
|
2099
|
+
/** Optional commitment level */
|
|
2100
|
+
commitment?: Commitment;
|
|
2101
|
+
/** The minimum slot that the request can be evaluated at */
|
|
2102
|
+
minContextSlot?: number;
|
|
2103
|
+
};
|
|
2104
|
+
|
|
2105
|
+
/**
|
|
2106
|
+
* Configuration object for `getStakeActivation`
|
|
2107
|
+
*/
|
|
2108
|
+
export type GetTransactionCountConfig = {
|
|
2109
|
+
/** Optional commitment level */
|
|
2110
|
+
commitment?: Commitment;
|
|
2111
|
+
/** The minimum slot that the request can be evaluated at */
|
|
2112
|
+
minContextSlot?: number;
|
|
1972
2113
|
};
|
|
1973
2114
|
|
|
1974
2115
|
/**
|
|
@@ -2377,9 +2518,17 @@ export class Connection {
|
|
|
2377
2518
|
*/
|
|
2378
2519
|
async getBalanceAndContext(
|
|
2379
2520
|
publicKey: PublicKey,
|
|
2380
|
-
|
|
2521
|
+
commitmentOrConfig?: Commitment | GetBalanceConfig,
|
|
2381
2522
|
): Promise<RpcResponseAndContext<number>> {
|
|
2382
|
-
|
|
2523
|
+
/** @internal */
|
|
2524
|
+
const {commitment, config} =
|
|
2525
|
+
extractCommitmentFromConfig(commitmentOrConfig);
|
|
2526
|
+
const args = this._buildArgs(
|
|
2527
|
+
[publicKey.toBase58()],
|
|
2528
|
+
commitment,
|
|
2529
|
+
undefined /* encoding */,
|
|
2530
|
+
config,
|
|
2531
|
+
);
|
|
2383
2532
|
const unsafeRes = await this._rpcRequest('getBalance', args);
|
|
2384
2533
|
const res = create(unsafeRes, jsonRpcResultAndContext(number()));
|
|
2385
2534
|
if ('error' in res) {
|
|
@@ -2398,9 +2547,9 @@ export class Connection {
|
|
|
2398
2547
|
*/
|
|
2399
2548
|
async getBalance(
|
|
2400
2549
|
publicKey: PublicKey,
|
|
2401
|
-
|
|
2550
|
+
commitmentOrConfig?: Commitment | GetBalanceConfig,
|
|
2402
2551
|
): Promise<number> {
|
|
2403
|
-
return await this.getBalanceAndContext(publicKey,
|
|
2552
|
+
return await this.getBalanceAndContext(publicKey, commitmentOrConfig)
|
|
2404
2553
|
.then(x => x.value)
|
|
2405
2554
|
.catch(e => {
|
|
2406
2555
|
throw new Error(
|
|
@@ -2522,12 +2671,14 @@ export class Connection {
|
|
|
2522
2671
|
async getTokenAccountsByOwner(
|
|
2523
2672
|
ownerAddress: PublicKey,
|
|
2524
2673
|
filter: TokenAccountsFilter,
|
|
2525
|
-
|
|
2674
|
+
commitmentOrConfig?: Commitment | GetTokenAccountsByOwnerConfig,
|
|
2526
2675
|
): Promise<
|
|
2527
2676
|
RpcResponseAndContext<
|
|
2528
2677
|
Array<{pubkey: PublicKey; account: AccountInfo<Buffer>}>
|
|
2529
2678
|
>
|
|
2530
2679
|
> {
|
|
2680
|
+
const {commitment, config} =
|
|
2681
|
+
extractCommitmentFromConfig(commitmentOrConfig);
|
|
2531
2682
|
let _args: any[] = [ownerAddress.toBase58()];
|
|
2532
2683
|
if ('mint' in filter) {
|
|
2533
2684
|
_args.push({mint: filter.mint.toBase58()});
|
|
@@ -2535,7 +2686,7 @@ export class Connection {
|
|
|
2535
2686
|
_args.push({programId: filter.programId.toBase58()});
|
|
2536
2687
|
}
|
|
2537
2688
|
|
|
2538
|
-
const args = this._buildArgs(_args, commitment, 'base64');
|
|
2689
|
+
const args = this._buildArgs(_args, commitment, 'base64', config);
|
|
2539
2690
|
const unsafeRes = await this._rpcRequest('getTokenAccountsByOwner', args);
|
|
2540
2691
|
const res = create(unsafeRes, GetTokenAccountsByOwner);
|
|
2541
2692
|
if ('error' in res) {
|
|
@@ -2627,9 +2778,16 @@ export class Connection {
|
|
|
2627
2778
|
*/
|
|
2628
2779
|
async getAccountInfoAndContext(
|
|
2629
2780
|
publicKey: PublicKey,
|
|
2630
|
-
|
|
2781
|
+
commitmentOrConfig?: Commitment | GetAccountInfoConfig,
|
|
2631
2782
|
): Promise<RpcResponseAndContext<AccountInfo<Buffer> | null>> {
|
|
2632
|
-
const
|
|
2783
|
+
const {commitment, config} =
|
|
2784
|
+
extractCommitmentFromConfig(commitmentOrConfig);
|
|
2785
|
+
const args = this._buildArgs(
|
|
2786
|
+
[publicKey.toBase58()],
|
|
2787
|
+
commitment,
|
|
2788
|
+
'base64',
|
|
2789
|
+
config,
|
|
2790
|
+
);
|
|
2633
2791
|
const unsafeRes = await this._rpcRequest('getAccountInfo', args);
|
|
2634
2792
|
const res = create(
|
|
2635
2793
|
unsafeRes,
|
|
@@ -2681,10 +2839,13 @@ export class Connection {
|
|
|
2681
2839
|
*/
|
|
2682
2840
|
async getAccountInfo(
|
|
2683
2841
|
publicKey: PublicKey,
|
|
2684
|
-
|
|
2842
|
+
commitmentOrConfig?: Commitment | GetAccountInfoConfig,
|
|
2685
2843
|
): Promise<AccountInfo<Buffer> | null> {
|
|
2686
2844
|
try {
|
|
2687
|
-
const res = await this.getAccountInfoAndContext(
|
|
2845
|
+
const res = await this.getAccountInfoAndContext(
|
|
2846
|
+
publicKey,
|
|
2847
|
+
commitmentOrConfig,
|
|
2848
|
+
);
|
|
2688
2849
|
return res.value;
|
|
2689
2850
|
} catch (e) {
|
|
2690
2851
|
throw new Error(
|
|
@@ -2698,10 +2859,12 @@ export class Connection {
|
|
|
2698
2859
|
*/
|
|
2699
2860
|
async getMultipleAccountsInfoAndContext(
|
|
2700
2861
|
publicKeys: PublicKey[],
|
|
2701
|
-
|
|
2862
|
+
commitmentOrConfig?: Commitment | GetMultipleAccountsConfig,
|
|
2702
2863
|
): Promise<RpcResponseAndContext<(AccountInfo<Buffer> | null)[]>> {
|
|
2864
|
+
const {commitment, config} =
|
|
2865
|
+
extractCommitmentFromConfig(commitmentOrConfig);
|
|
2703
2866
|
const keys = publicKeys.map(key => key.toBase58());
|
|
2704
|
-
const args = this._buildArgs([keys], commitment, 'base64');
|
|
2867
|
+
const args = this._buildArgs([keys], commitment, 'base64', config);
|
|
2705
2868
|
const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
|
|
2706
2869
|
const res = create(
|
|
2707
2870
|
unsafeRes,
|
|
@@ -2720,11 +2883,11 @@ export class Connection {
|
|
|
2720
2883
|
*/
|
|
2721
2884
|
async getMultipleAccountsInfo(
|
|
2722
2885
|
publicKeys: PublicKey[],
|
|
2723
|
-
|
|
2886
|
+
commitmentOrConfig?: Commitment | GetMultipleAccountsConfig,
|
|
2724
2887
|
): Promise<(AccountInfo<Buffer> | null)[]> {
|
|
2725
2888
|
const res = await this.getMultipleAccountsInfoAndContext(
|
|
2726
2889
|
publicKeys,
|
|
2727
|
-
|
|
2890
|
+
commitmentOrConfig,
|
|
2728
2891
|
);
|
|
2729
2892
|
return res.value;
|
|
2730
2893
|
}
|
|
@@ -2734,14 +2897,19 @@ export class Connection {
|
|
|
2734
2897
|
*/
|
|
2735
2898
|
async getStakeActivation(
|
|
2736
2899
|
publicKey: PublicKey,
|
|
2737
|
-
|
|
2900
|
+
commitmentOrConfig?: Commitment | GetStakeActivationConfig,
|
|
2738
2901
|
epoch?: number,
|
|
2739
2902
|
): Promise<StakeActivationData> {
|
|
2903
|
+
const {commitment, config} =
|
|
2904
|
+
extractCommitmentFromConfig(commitmentOrConfig);
|
|
2740
2905
|
const args = this._buildArgs(
|
|
2741
2906
|
[publicKey.toBase58()],
|
|
2742
2907
|
commitment,
|
|
2743
|
-
undefined
|
|
2744
|
-
|
|
2908
|
+
undefined /* encoding */,
|
|
2909
|
+
{
|
|
2910
|
+
...config,
|
|
2911
|
+
epoch: epoch != null ? epoch : config?.epoch,
|
|
2912
|
+
},
|
|
2745
2913
|
);
|
|
2746
2914
|
|
|
2747
2915
|
const unsafeRes = await this._rpcRequest('getStakeActivation', args);
|
|
@@ -2765,31 +2933,14 @@ export class Connection {
|
|
|
2765
2933
|
programId: PublicKey,
|
|
2766
2934
|
configOrCommitment?: GetProgramAccountsConfig | Commitment,
|
|
2767
2935
|
): Promise<Array<{pubkey: PublicKey; account: AccountInfo<Buffer>}>> {
|
|
2768
|
-
const
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
let encoding;
|
|
2772
|
-
if (configOrCommitment) {
|
|
2773
|
-
if (typeof configOrCommitment === 'string') {
|
|
2774
|
-
commitment = configOrCommitment;
|
|
2775
|
-
} else {
|
|
2776
|
-
commitment = configOrCommitment.commitment;
|
|
2777
|
-
encoding = configOrCommitment.encoding;
|
|
2778
|
-
|
|
2779
|
-
if (configOrCommitment.dataSlice) {
|
|
2780
|
-
extra.dataSlice = configOrCommitment.dataSlice;
|
|
2781
|
-
}
|
|
2782
|
-
if (configOrCommitment.filters) {
|
|
2783
|
-
extra.filters = configOrCommitment.filters;
|
|
2784
|
-
}
|
|
2785
|
-
}
|
|
2786
|
-
}
|
|
2787
|
-
|
|
2936
|
+
const {commitment, config} =
|
|
2937
|
+
extractCommitmentFromConfig(configOrCommitment);
|
|
2938
|
+
const {encoding, ...configWithoutEncoding} = config || {};
|
|
2788
2939
|
const args = this._buildArgs(
|
|
2789
2940
|
[programId.toBase58()],
|
|
2790
2941
|
commitment,
|
|
2791
2942
|
encoding || 'base64',
|
|
2792
|
-
|
|
2943
|
+
configWithoutEncoding,
|
|
2793
2944
|
);
|
|
2794
2945
|
const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
|
|
2795
2946
|
const res = create(unsafeRes, jsonRpcResult(array(KeyedAccountInfoResult)));
|
|
@@ -2818,26 +2969,13 @@ export class Connection {
|
|
|
2818
2969
|
account: AccountInfo<Buffer | ParsedAccountData>;
|
|
2819
2970
|
}>
|
|
2820
2971
|
> {
|
|
2821
|
-
const
|
|
2822
|
-
|
|
2823
|
-
let commitment;
|
|
2824
|
-
if (configOrCommitment) {
|
|
2825
|
-
if (typeof configOrCommitment === 'string') {
|
|
2826
|
-
commitment = configOrCommitment;
|
|
2827
|
-
} else {
|
|
2828
|
-
commitment = configOrCommitment.commitment;
|
|
2829
|
-
|
|
2830
|
-
if (configOrCommitment.filters) {
|
|
2831
|
-
extra.filters = configOrCommitment.filters;
|
|
2832
|
-
}
|
|
2833
|
-
}
|
|
2834
|
-
}
|
|
2835
|
-
|
|
2972
|
+
const {commitment, config} =
|
|
2973
|
+
extractCommitmentFromConfig(configOrCommitment);
|
|
2836
2974
|
const args = this._buildArgs(
|
|
2837
2975
|
[programId.toBase58()],
|
|
2838
2976
|
commitment,
|
|
2839
2977
|
'jsonParsed',
|
|
2840
|
-
|
|
2978
|
+
config,
|
|
2841
2979
|
);
|
|
2842
2980
|
const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
|
|
2843
2981
|
const res = create(
|
|
@@ -3025,8 +3163,17 @@ export class Connection {
|
|
|
3025
3163
|
/**
|
|
3026
3164
|
* Fetch the current slot that the node is processing
|
|
3027
3165
|
*/
|
|
3028
|
-
async getSlot(
|
|
3029
|
-
|
|
3166
|
+
async getSlot(
|
|
3167
|
+
commitmentOrConfig?: Commitment | GetSlotConfig,
|
|
3168
|
+
): Promise<number> {
|
|
3169
|
+
const {commitment, config} =
|
|
3170
|
+
extractCommitmentFromConfig(commitmentOrConfig);
|
|
3171
|
+
const args = this._buildArgs(
|
|
3172
|
+
[],
|
|
3173
|
+
commitment,
|
|
3174
|
+
undefined /* encoding */,
|
|
3175
|
+
config,
|
|
3176
|
+
);
|
|
3030
3177
|
const unsafeRes = await this._rpcRequest('getSlot', args);
|
|
3031
3178
|
const res = create(unsafeRes, jsonRpcResult(number()));
|
|
3032
3179
|
if ('error' in res) {
|
|
@@ -3038,8 +3185,17 @@ export class Connection {
|
|
|
3038
3185
|
/**
|
|
3039
3186
|
* Fetch the current slot leader of the cluster
|
|
3040
3187
|
*/
|
|
3041
|
-
async getSlotLeader(
|
|
3042
|
-
|
|
3188
|
+
async getSlotLeader(
|
|
3189
|
+
commitmentOrConfig?: Commitment | GetSlotLeaderConfig,
|
|
3190
|
+
): Promise<string> {
|
|
3191
|
+
const {commitment, config} =
|
|
3192
|
+
extractCommitmentFromConfig(commitmentOrConfig);
|
|
3193
|
+
const args = this._buildArgs(
|
|
3194
|
+
[],
|
|
3195
|
+
commitment,
|
|
3196
|
+
undefined /* encoding */,
|
|
3197
|
+
config,
|
|
3198
|
+
);
|
|
3043
3199
|
const unsafeRes = await this._rpcRequest('getSlotLeader', args);
|
|
3044
3200
|
const res = create(unsafeRes, jsonRpcResult(string()));
|
|
3045
3201
|
if ('error' in res) {
|
|
@@ -3105,8 +3261,17 @@ export class Connection {
|
|
|
3105
3261
|
/**
|
|
3106
3262
|
* Fetch the current transaction count of the cluster
|
|
3107
3263
|
*/
|
|
3108
|
-
async getTransactionCount(
|
|
3109
|
-
|
|
3264
|
+
async getTransactionCount(
|
|
3265
|
+
commitmentOrConfig?: Commitment | GetTransactionCountConfig,
|
|
3266
|
+
): Promise<number> {
|
|
3267
|
+
const {commitment, config} =
|
|
3268
|
+
extractCommitmentFromConfig(commitmentOrConfig);
|
|
3269
|
+
const args = this._buildArgs(
|
|
3270
|
+
[],
|
|
3271
|
+
commitment,
|
|
3272
|
+
undefined /* encoding */,
|
|
3273
|
+
config,
|
|
3274
|
+
);
|
|
3110
3275
|
const unsafeRes = await this._rpcRequest('getTransactionCount', args);
|
|
3111
3276
|
const res = create(unsafeRes, jsonRpcResult(number()));
|
|
3112
3277
|
if ('error' in res) {
|
|
@@ -3149,14 +3314,17 @@ export class Connection {
|
|
|
3149
3314
|
async getInflationReward(
|
|
3150
3315
|
addresses: PublicKey[],
|
|
3151
3316
|
epoch?: number,
|
|
3152
|
-
|
|
3317
|
+
commitmentOrConfig?: Commitment | GetInflationRewardConfig,
|
|
3153
3318
|
): Promise<(InflationReward | null)[]> {
|
|
3319
|
+
const {commitment, config} =
|
|
3320
|
+
extractCommitmentFromConfig(commitmentOrConfig);
|
|
3154
3321
|
const args = this._buildArgs(
|
|
3155
3322
|
[addresses.map(pubkey => pubkey.toBase58())],
|
|
3156
3323
|
commitment,
|
|
3157
|
-
undefined
|
|
3324
|
+
undefined /* encoding */,
|
|
3158
3325
|
{
|
|
3159
|
-
|
|
3326
|
+
...config,
|
|
3327
|
+
epoch: epoch != null ? epoch : config?.epoch,
|
|
3160
3328
|
},
|
|
3161
3329
|
);
|
|
3162
3330
|
const unsafeRes = await this._rpcRequest('getInflationReward', args);
|
|
@@ -3170,8 +3338,17 @@ export class Connection {
|
|
|
3170
3338
|
/**
|
|
3171
3339
|
* Fetch the Epoch Info parameters
|
|
3172
3340
|
*/
|
|
3173
|
-
async getEpochInfo(
|
|
3174
|
-
|
|
3341
|
+
async getEpochInfo(
|
|
3342
|
+
commitmentOrConfig?: Commitment | GetEpochInfoConfig,
|
|
3343
|
+
): Promise<EpochInfo> {
|
|
3344
|
+
const {commitment, config} =
|
|
3345
|
+
extractCommitmentFromConfig(commitmentOrConfig);
|
|
3346
|
+
const args = this._buildArgs(
|
|
3347
|
+
[],
|
|
3348
|
+
commitment,
|
|
3349
|
+
undefined /* encoding */,
|
|
3350
|
+
config,
|
|
3351
|
+
);
|
|
3175
3352
|
const unsafeRes = await this._rpcRequest('getEpochInfo', args);
|
|
3176
3353
|
const res = create(unsafeRes, GetEpochInfoRpcResult);
|
|
3177
3354
|
if ('error' in res) {
|
|
@@ -3344,10 +3521,10 @@ export class Connection {
|
|
|
3344
3521
|
* @return {Promise<BlockhashWithExpiryBlockHeight>}
|
|
3345
3522
|
*/
|
|
3346
3523
|
async getLatestBlockhash(
|
|
3347
|
-
|
|
3524
|
+
commitmentOrConfig?: Commitment | GetLatestBlockhashConfig,
|
|
3348
3525
|
): Promise<BlockhashWithExpiryBlockHeight> {
|
|
3349
3526
|
try {
|
|
3350
|
-
const res = await this.getLatestBlockhashAndContext(
|
|
3527
|
+
const res = await this.getLatestBlockhashAndContext(commitmentOrConfig);
|
|
3351
3528
|
return res.value;
|
|
3352
3529
|
} catch (e) {
|
|
3353
3530
|
throw new Error('failed to get recent blockhash: ' + e);
|
|
@@ -3359,9 +3536,16 @@ export class Connection {
|
|
|
3359
3536
|
* @return {Promise<BlockhashWithExpiryBlockHeight>}
|
|
3360
3537
|
*/
|
|
3361
3538
|
async getLatestBlockhashAndContext(
|
|
3362
|
-
|
|
3539
|
+
commitmentOrConfig?: Commitment | GetLatestBlockhashConfig,
|
|
3363
3540
|
): Promise<RpcResponseAndContext<BlockhashWithExpiryBlockHeight>> {
|
|
3364
|
-
const
|
|
3541
|
+
const {commitment, config} =
|
|
3542
|
+
extractCommitmentFromConfig(commitmentOrConfig);
|
|
3543
|
+
const args = this._buildArgs(
|
|
3544
|
+
[],
|
|
3545
|
+
commitment,
|
|
3546
|
+
undefined /* encoding */,
|
|
3547
|
+
config,
|
|
3548
|
+
);
|
|
3365
3549
|
const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
|
|
3366
3550
|
const res = create(unsafeRes, GetLatestBlockhashRpcResult);
|
|
3367
3551
|
if ('error' in res) {
|
|
@@ -3433,8 +3617,17 @@ export class Connection {
|
|
|
3433
3617
|
/*
|
|
3434
3618
|
* Returns the current block height of the node
|
|
3435
3619
|
*/
|
|
3436
|
-
async getBlockHeight(
|
|
3437
|
-
|
|
3620
|
+
async getBlockHeight(
|
|
3621
|
+
commitmentOrConfig?: Commitment | GetBlockHeightConfig,
|
|
3622
|
+
): Promise<number> {
|
|
3623
|
+
const {commitment, config} =
|
|
3624
|
+
extractCommitmentFromConfig(commitmentOrConfig);
|
|
3625
|
+
const args = this._buildArgs(
|
|
3626
|
+
[],
|
|
3627
|
+
commitment,
|
|
3628
|
+
undefined /* encoding */,
|
|
3629
|
+
config,
|
|
3630
|
+
);
|
|
3438
3631
|
const unsafeRes = await this._rpcRequest('getBlockHeight', args);
|
|
3439
3632
|
const res = create(unsafeRes, jsonRpcResult(number()));
|
|
3440
3633
|
if ('error' in res) {
|
|
@@ -4250,6 +4443,9 @@ export class Connection {
|
|
|
4250
4443
|
if (options && options.maxRetries) {
|
|
4251
4444
|
config.maxRetries = options.maxRetries;
|
|
4252
4445
|
}
|
|
4446
|
+
if (options && options.minContextSlot != null) {
|
|
4447
|
+
config.minContextSlot = options.minContextSlot;
|
|
4448
|
+
}
|
|
4253
4449
|
if (skipPreflight) {
|
|
4254
4450
|
config.skipPreflight = skipPreflight;
|
|
4255
4451
|
}
|
|
@@ -68,6 +68,7 @@ export async function sendAndConfirmRawTransaction(
|
|
|
68
68
|
const sendOptions = options && {
|
|
69
69
|
skipPreflight: options.skipPreflight,
|
|
70
70
|
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
71
|
+
minContextSlot: options.minContextSlot,
|
|
71
72
|
};
|
|
72
73
|
|
|
73
74
|
const signature = await connection.sendRawTransaction(
|
|
@@ -25,6 +25,7 @@ export async function sendAndConfirmTransaction(
|
|
|
25
25
|
skipPreflight: options.skipPreflight,
|
|
26
26
|
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
27
27
|
maxRetries: options.maxRetries,
|
|
28
|
+
minContextSlot: options.minContextSlot,
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
const signature = await connection.sendTransaction(
|