@solana/web3.js 1.68.1 → 1.70.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/README.md +0 -13
- package/lib/index.browser.cjs.js +47 -9
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +47 -9
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +66 -14
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +247 -234
- package/lib/index.esm.js +65 -13
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +47 -9
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +47 -9
- package/lib/index.native.js.map +1 -1
- package/package.json +6 -5
- package/src/connection.ts +120 -31
- package/src/epoch-schedule.ts +1 -1
- package/src/utils/send-and-confirm-transaction.ts +14 -1
package/lib/index.esm.js
CHANGED
|
@@ -8,11 +8,11 @@ import { serialize, deserialize, deserializeUnchecked } from 'borsh';
|
|
|
8
8
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
9
9
|
import { blob } from '@solana/buffer-layout';
|
|
10
10
|
import { toBigIntLE, toBufferLE } from 'bigint-buffer';
|
|
11
|
+
import https, { Agent } from 'https';
|
|
11
12
|
import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$1 } from 'superstruct';
|
|
12
13
|
import { Client } from 'rpc-websockets';
|
|
13
14
|
import RpcClient from 'jayson/lib/client/browser';
|
|
14
15
|
import http from 'http';
|
|
15
|
-
import https from 'https';
|
|
16
16
|
import * as nodeFetch from 'node-fetch';
|
|
17
17
|
import { keccak_256 } from '@noble/hashes/sha3';
|
|
18
18
|
import { hmac } from '@noble/hashes/hmac';
|
|
@@ -2212,6 +2212,7 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2212
2212
|
|
|
2213
2213
|
if (transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null) {
|
|
2214
2214
|
status = (await connection.confirmTransaction({
|
|
2215
|
+
abortSignal: options === null || options === void 0 ? void 0 : options.abortSignal,
|
|
2215
2216
|
signature: signature,
|
|
2216
2217
|
blockhash: transaction.recentBlockhash,
|
|
2217
2218
|
lastValidBlockHeight: transaction.lastValidBlockHeight
|
|
@@ -2222,12 +2223,17 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2222
2223
|
} = transaction.nonceInfo;
|
|
2223
2224
|
const nonceAccountPubkey = nonceInstruction.keys[0].pubkey;
|
|
2224
2225
|
status = (await connection.confirmTransaction({
|
|
2226
|
+
abortSignal: options === null || options === void 0 ? void 0 : options.abortSignal,
|
|
2225
2227
|
minContextSlot: transaction.minNonceContextSlot,
|
|
2226
2228
|
nonceAccountPubkey,
|
|
2227
2229
|
nonceValue: transaction.nonceInfo.nonce,
|
|
2228
2230
|
signature
|
|
2229
2231
|
}, options && options.commitment)).value;
|
|
2230
2232
|
} else {
|
|
2233
|
+
if ((options === null || options === void 0 ? void 0 : options.abortSignal) != null) {
|
|
2234
|
+
console.warn('sendAndConfirmTransaction(): A transaction with a deprecated confirmation strategy was ' + 'supplied along with an `abortSignal`. Only transactions having `lastValidBlockHeight` ' + 'or a combination of `nonceInfo` and `minNonceContextSlot` are abortable.');
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2231
2237
|
status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2232
2238
|
}
|
|
2233
2239
|
|
|
@@ -3440,7 +3446,7 @@ function nextPowerOfTwo(n) {
|
|
|
3440
3446
|
/**
|
|
3441
3447
|
* Epoch schedule
|
|
3442
3448
|
* (see https://docs.solana.com/terminology#epoch)
|
|
3443
|
-
* Can be retrieved with the {@link
|
|
3449
|
+
* Can be retrieved with the {@link Connection.getEpochSchedule} method
|
|
3444
3450
|
*/
|
|
3445
3451
|
|
|
3446
3452
|
|
|
@@ -3715,13 +3721,10 @@ function extractCommitmentFromConfig(commitmentOrConfig) {
|
|
|
3715
3721
|
};
|
|
3716
3722
|
}
|
|
3717
3723
|
/**
|
|
3718
|
-
*
|
|
3724
|
+
* @internal
|
|
3719
3725
|
*/
|
|
3720
3726
|
|
|
3721
3727
|
|
|
3722
|
-
/**
|
|
3723
|
-
* @internal
|
|
3724
|
-
*/
|
|
3725
3728
|
function createRpcResult(result) {
|
|
3726
3729
|
return union([type({
|
|
3727
3730
|
jsonrpc: literal('2.0'),
|
|
@@ -3913,14 +3916,34 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(type({
|
|
|
3913
3916
|
* A performance sample
|
|
3914
3917
|
*/
|
|
3915
3918
|
|
|
3916
|
-
function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
|
|
3919
|
+
function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit, httpAgent) {
|
|
3917
3920
|
const fetch = customFetch ? customFetch : fetchImpl;
|
|
3918
3921
|
let agentManager;
|
|
3919
3922
|
|
|
3920
3923
|
{
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
+
if (httpAgent == null) {
|
|
3925
|
+
{
|
|
3926
|
+
agentManager = new AgentManager(url.startsWith('https:')
|
|
3927
|
+
/* useHttps */
|
|
3928
|
+
);
|
|
3929
|
+
}
|
|
3930
|
+
} else {
|
|
3931
|
+
if (httpAgent !== false) {
|
|
3932
|
+
const isHttps = url.startsWith('https:');
|
|
3933
|
+
|
|
3934
|
+
if (isHttps && !(httpAgent instanceof Agent)) {
|
|
3935
|
+
throw new Error('The endpoint `' + url + '` can only be paired with an `https.Agent`. You have, instead, supplied an ' + '`http.Agent` through `httpAgent`.');
|
|
3936
|
+
} else if (!isHttps && httpAgent instanceof Agent) {
|
|
3937
|
+
throw new Error('The endpoint `' + url + '` can only be paired with an `http.Agent`. You have, instead, supplied an ' + '`https.Agent` through `httpAgent`.');
|
|
3938
|
+
}
|
|
3939
|
+
|
|
3940
|
+
agentManager = {
|
|
3941
|
+
requestEnd() {},
|
|
3942
|
+
|
|
3943
|
+
requestStart: () => httpAgent
|
|
3944
|
+
};
|
|
3945
|
+
}
|
|
3946
|
+
}
|
|
3924
3947
|
}
|
|
3925
3948
|
|
|
3926
3949
|
let fetchWithMiddleware;
|
|
@@ -4830,6 +4853,7 @@ class Connection {
|
|
|
4830
4853
|
let fetch;
|
|
4831
4854
|
let fetchMiddleware;
|
|
4832
4855
|
let disableRetryOnRateLimit;
|
|
4856
|
+
let httpAgent;
|
|
4833
4857
|
|
|
4834
4858
|
if (commitmentOrConfig && typeof commitmentOrConfig === 'string') {
|
|
4835
4859
|
this._commitment = commitmentOrConfig;
|
|
@@ -4841,11 +4865,12 @@ class Connection {
|
|
|
4841
4865
|
fetch = commitmentOrConfig.fetch;
|
|
4842
4866
|
fetchMiddleware = commitmentOrConfig.fetchMiddleware;
|
|
4843
4867
|
disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit;
|
|
4868
|
+
httpAgent = commitmentOrConfig.httpAgent;
|
|
4844
4869
|
}
|
|
4845
4870
|
|
|
4846
4871
|
this._rpcEndpoint = assertEndpointUrl(endpoint);
|
|
4847
4872
|
this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
|
|
4848
|
-
this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
|
|
4873
|
+
this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit, httpAgent);
|
|
4849
4874
|
this._rpcRequest = createRpcRequest(this._rpcClient);
|
|
4850
4875
|
this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
|
|
4851
4876
|
this._rpcWebSocket = new Client(this._rpcWsEndpoint, {
|
|
@@ -5336,7 +5361,14 @@ class Connection {
|
|
|
5336
5361
|
if (typeof strategy == 'string') {
|
|
5337
5362
|
rawSignature = strategy;
|
|
5338
5363
|
} else {
|
|
5364
|
+
var _config$abortSignal;
|
|
5365
|
+
|
|
5339
5366
|
const config = strategy;
|
|
5367
|
+
|
|
5368
|
+
if ((_config$abortSignal = config.abortSignal) !== null && _config$abortSignal !== void 0 && _config$abortSignal.aborted) {
|
|
5369
|
+
return Promise.reject(config.abortSignal.reason);
|
|
5370
|
+
}
|
|
5371
|
+
|
|
5340
5372
|
rawSignature = config.signature;
|
|
5341
5373
|
}
|
|
5342
5374
|
|
|
@@ -5368,6 +5400,22 @@ class Connection {
|
|
|
5368
5400
|
}
|
|
5369
5401
|
}
|
|
5370
5402
|
|
|
5403
|
+
getCancellationPromise(signal) {
|
|
5404
|
+
return new Promise((_, reject) => {
|
|
5405
|
+
if (signal == null) {
|
|
5406
|
+
return;
|
|
5407
|
+
}
|
|
5408
|
+
|
|
5409
|
+
if (signal.aborted) {
|
|
5410
|
+
reject(signal.reason);
|
|
5411
|
+
} else {
|
|
5412
|
+
signal.addEventListener('abort', () => {
|
|
5413
|
+
reject(signal.reason);
|
|
5414
|
+
});
|
|
5415
|
+
}
|
|
5416
|
+
});
|
|
5417
|
+
}
|
|
5418
|
+
|
|
5371
5419
|
getTransactionConfirmationPromise({
|
|
5372
5420
|
commitment,
|
|
5373
5421
|
signature
|
|
@@ -5486,6 +5534,7 @@ class Connection {
|
|
|
5486
5534
|
async confirmTransactionUsingBlockHeightExceedanceStrategy({
|
|
5487
5535
|
commitment,
|
|
5488
5536
|
strategy: {
|
|
5537
|
+
abortSignal,
|
|
5489
5538
|
lastValidBlockHeight,
|
|
5490
5539
|
signature
|
|
5491
5540
|
}
|
|
@@ -5524,10 +5573,11 @@ class Connection {
|
|
|
5524
5573
|
commitment,
|
|
5525
5574
|
signature
|
|
5526
5575
|
});
|
|
5576
|
+
const cancellationPromise = this.getCancellationPromise(abortSignal);
|
|
5527
5577
|
let result;
|
|
5528
5578
|
|
|
5529
5579
|
try {
|
|
5530
|
-
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5580
|
+
const outcome = await Promise.race([cancellationPromise, confirmationPromise, expiryPromise]);
|
|
5531
5581
|
|
|
5532
5582
|
if (outcome.__type === TransactionStatus.PROCESSED) {
|
|
5533
5583
|
result = outcome.response;
|
|
@@ -5545,6 +5595,7 @@ class Connection {
|
|
|
5545
5595
|
async confirmTransactionUsingDurableNonceStrategy({
|
|
5546
5596
|
commitment,
|
|
5547
5597
|
strategy: {
|
|
5598
|
+
abortSignal,
|
|
5548
5599
|
minContextSlot,
|
|
5549
5600
|
nonceAccountPubkey,
|
|
5550
5601
|
nonceValue,
|
|
@@ -5602,10 +5653,11 @@ class Connection {
|
|
|
5602
5653
|
commitment,
|
|
5603
5654
|
signature
|
|
5604
5655
|
});
|
|
5656
|
+
const cancellationPromise = this.getCancellationPromise(abortSignal);
|
|
5605
5657
|
let result;
|
|
5606
5658
|
|
|
5607
5659
|
try {
|
|
5608
|
-
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5660
|
+
const outcome = await Promise.race([cancellationPromise, confirmationPromise, expiryPromise]);
|
|
5609
5661
|
|
|
5610
5662
|
if (outcome.__type === TransactionStatus.PROCESSED) {
|
|
5611
5663
|
result = outcome.response;
|