@solana/web3.js 1.68.1 → 1.70.0-pr-29130

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.
@@ -2209,6 +2209,7 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
2209
2209
 
2210
2210
  if (transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null) {
2211
2211
  status = (await connection.confirmTransaction({
2212
+ abortSignal: options === null || options === void 0 ? void 0 : options.abortSignal,
2212
2213
  signature: signature,
2213
2214
  blockhash: transaction.recentBlockhash,
2214
2215
  lastValidBlockHeight: transaction.lastValidBlockHeight
@@ -2219,12 +2220,17 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
2219
2220
  } = transaction.nonceInfo;
2220
2221
  const nonceAccountPubkey = nonceInstruction.keys[0].pubkey;
2221
2222
  status = (await connection.confirmTransaction({
2223
+ abortSignal: options === null || options === void 0 ? void 0 : options.abortSignal,
2222
2224
  minContextSlot: transaction.minNonceContextSlot,
2223
2225
  nonceAccountPubkey,
2224
2226
  nonceValue: transaction.nonceInfo.nonce,
2225
2227
  signature
2226
2228
  }, options && options.commitment)).value;
2227
2229
  } else {
2230
+ if ((options === null || options === void 0 ? void 0 : options.abortSignal) != null) {
2231
+ 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.');
2232
+ }
2233
+
2228
2234
  status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
2229
2235
  }
2230
2236
 
@@ -3388,7 +3394,7 @@ function nextPowerOfTwo(n) {
3388
3394
  /**
3389
3395
  * Epoch schedule
3390
3396
  * (see https://docs.solana.com/terminology#epoch)
3391
- * Can be retrieved with the {@link connection.getEpochSchedule} method
3397
+ * Can be retrieved with the {@link Connection.getEpochSchedule} method
3392
3398
  */
3393
3399
 
3394
3400
 
@@ -3660,13 +3666,10 @@ function extractCommitmentFromConfig(commitmentOrConfig) {
3660
3666
  };
3661
3667
  }
3662
3668
  /**
3663
- * A strategy for confirming durable nonce transactions.
3669
+ * @internal
3664
3670
  */
3665
3671
 
3666
3672
 
3667
- /**
3668
- * @internal
3669
- */
3670
3673
  function createRpcResult(result) {
3671
3674
  return union([type({
3672
3675
  jsonrpc: literal('2.0'),
@@ -3858,8 +3861,15 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(type({
3858
3861
  * A performance sample
3859
3862
  */
3860
3863
 
3861
- function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
3864
+ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit, httpAgent) {
3862
3865
  const fetch = customFetch ? customFetch : fetchImpl;
3866
+ let agent;
3867
+
3868
+ {
3869
+ if (httpAgent != null) {
3870
+ console.warn('You have supplied an `httpAgent` when creating a `Connection` in a browser environment.' + 'It has been ignored; `httpAgent` is only used in Node environments.');
3871
+ }
3872
+ }
3863
3873
 
3864
3874
  let fetchWithMiddleware;
3865
3875
 
@@ -3877,7 +3887,6 @@ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disable
3877
3887
  }
3878
3888
 
3879
3889
  const clientBrowser = new RpcClient(async (request, callback) => {
3880
- const agent = undefined;
3881
3890
  const options = {
3882
3891
  method: 'POST',
3883
3892
  body: request,
@@ -3929,7 +3938,6 @@ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disable
3929
3938
  }
3930
3939
  } catch (err) {
3931
3940
  if (err instanceof Error) callback(err);
3932
- } finally {
3933
3941
  }
3934
3942
  }, {});
3935
3943
  return clientBrowser;
@@ -4767,6 +4775,7 @@ class Connection {
4767
4775
  let fetch;
4768
4776
  let fetchMiddleware;
4769
4777
  let disableRetryOnRateLimit;
4778
+ let httpAgent;
4770
4779
 
4771
4780
  if (commitmentOrConfig && typeof commitmentOrConfig === 'string') {
4772
4781
  this._commitment = commitmentOrConfig;
@@ -4778,11 +4787,12 @@ class Connection {
4778
4787
  fetch = commitmentOrConfig.fetch;
4779
4788
  fetchMiddleware = commitmentOrConfig.fetchMiddleware;
4780
4789
  disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit;
4790
+ httpAgent = commitmentOrConfig.httpAgent;
4781
4791
  }
4782
4792
 
4783
4793
  this._rpcEndpoint = assertEndpointUrl(endpoint);
4784
4794
  this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
4785
- this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
4795
+ this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit, httpAgent);
4786
4796
  this._rpcRequest = createRpcRequest(this._rpcClient);
4787
4797
  this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
4788
4798
  this._rpcWebSocket = new Client(this._rpcWsEndpoint, {
@@ -5273,7 +5283,14 @@ class Connection {
5273
5283
  if (typeof strategy == 'string') {
5274
5284
  rawSignature = strategy;
5275
5285
  } else {
5286
+ var _config$abortSignal;
5287
+
5276
5288
  const config = strategy;
5289
+
5290
+ if ((_config$abortSignal = config.abortSignal) !== null && _config$abortSignal !== void 0 && _config$abortSignal.aborted) {
5291
+ return Promise.reject(config.abortSignal.reason);
5292
+ }
5293
+
5277
5294
  rawSignature = config.signature;
5278
5295
  }
5279
5296
 
@@ -5305,6 +5322,22 @@ class Connection {
5305
5322
  }
5306
5323
  }
5307
5324
 
5325
+ getCancellationPromise(signal) {
5326
+ return new Promise((_, reject) => {
5327
+ if (signal == null) {
5328
+ return;
5329
+ }
5330
+
5331
+ if (signal.aborted) {
5332
+ reject(signal.reason);
5333
+ } else {
5334
+ signal.addEventListener('abort', () => {
5335
+ reject(signal.reason);
5336
+ });
5337
+ }
5338
+ });
5339
+ }
5340
+
5308
5341
  getTransactionConfirmationPromise({
5309
5342
  commitment,
5310
5343
  signature
@@ -5423,6 +5456,7 @@ class Connection {
5423
5456
  async confirmTransactionUsingBlockHeightExceedanceStrategy({
5424
5457
  commitment,
5425
5458
  strategy: {
5459
+ abortSignal,
5426
5460
  lastValidBlockHeight,
5427
5461
  signature
5428
5462
  }
@@ -5461,10 +5495,11 @@ class Connection {
5461
5495
  commitment,
5462
5496
  signature
5463
5497
  });
5498
+ const cancellationPromise = this.getCancellationPromise(abortSignal);
5464
5499
  let result;
5465
5500
 
5466
5501
  try {
5467
- const outcome = await Promise.race([confirmationPromise, expiryPromise]);
5502
+ const outcome = await Promise.race([cancellationPromise, confirmationPromise, expiryPromise]);
5468
5503
 
5469
5504
  if (outcome.__type === TransactionStatus.PROCESSED) {
5470
5505
  result = outcome.response;
@@ -5482,6 +5517,7 @@ class Connection {
5482
5517
  async confirmTransactionUsingDurableNonceStrategy({
5483
5518
  commitment,
5484
5519
  strategy: {
5520
+ abortSignal,
5485
5521
  minContextSlot,
5486
5522
  nonceAccountPubkey,
5487
5523
  nonceValue,
@@ -5539,10 +5575,11 @@ class Connection {
5539
5575
  commitment,
5540
5576
  signature
5541
5577
  });
5578
+ const cancellationPromise = this.getCancellationPromise(abortSignal);
5542
5579
  let result;
5543
5580
 
5544
5581
  try {
5545
- const outcome = await Promise.race([confirmationPromise, expiryPromise]);
5582
+ const outcome = await Promise.race([cancellationPromise, confirmationPromise, expiryPromise]);
5546
5583
 
5547
5584
  if (outcome.__type === TransactionStatus.PROCESSED) {
5548
5585
  result = outcome.response;