@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 CHANGED
@@ -102,19 +102,6 @@ This library requires a JavaScript runtime that supports [`BigInt`](https://deve
102
102
  - React Native:
103
103
  - \>=0.7.0 using the [Hermes](https://reactnative.dev/blog/2022/07/08/hermes-as-the-default) engine ([integration guide](https://solanacookbook.com/integrations/react-native.html#how-to-use-solana-web3-js-in-a-react-native-app)):
104
104
 
105
- ## Flow Support (Discontinued)
106
-
107
- Flow types are no longer supported in new releases. The last release with Flow support is v1.37.2 and its
108
- [Flow library definition](https://flow.org/en/docs/libdefs/) is provided at
109
- https://unpkg.com/@solana/web3.js@v1.37.2/module.flow.js.
110
- Download the file and add the following line under the [libs] section of your project's `.flowconfig` to
111
- activate it:
112
-
113
- ```ini
114
- [libs]
115
- node_modules/@solana/web3.js/module.flow.js
116
- ```
117
-
118
105
  ## Releases
119
106
 
120
107
  Releases are available on [Github](https://github.com/solana-labs/solana-web3.js/releases)
@@ -2239,6 +2239,7 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
2239
2239
 
2240
2240
  if (transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null) {
2241
2241
  status = (await connection.confirmTransaction({
2242
+ abortSignal: options === null || options === void 0 ? void 0 : options.abortSignal,
2242
2243
  signature: signature,
2243
2244
  blockhash: transaction.recentBlockhash,
2244
2245
  lastValidBlockHeight: transaction.lastValidBlockHeight
@@ -2249,12 +2250,17 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
2249
2250
  } = transaction.nonceInfo;
2250
2251
  const nonceAccountPubkey = nonceInstruction.keys[0].pubkey;
2251
2252
  status = (await connection.confirmTransaction({
2253
+ abortSignal: options === null || options === void 0 ? void 0 : options.abortSignal,
2252
2254
  minContextSlot: transaction.minNonceContextSlot,
2253
2255
  nonceAccountPubkey,
2254
2256
  nonceValue: transaction.nonceInfo.nonce,
2255
2257
  signature
2256
2258
  }, options && options.commitment)).value;
2257
2259
  } else {
2260
+ if ((options === null || options === void 0 ? void 0 : options.abortSignal) != null) {
2261
+ 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.');
2262
+ }
2263
+
2258
2264
  status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
2259
2265
  }
2260
2266
 
@@ -3418,7 +3424,7 @@ function nextPowerOfTwo(n) {
3418
3424
  /**
3419
3425
  * Epoch schedule
3420
3426
  * (see https://docs.solana.com/terminology#epoch)
3421
- * Can be retrieved with the {@link connection.getEpochSchedule} method
3427
+ * Can be retrieved with the {@link Connection.getEpochSchedule} method
3422
3428
  */
3423
3429
 
3424
3430
 
@@ -3690,13 +3696,10 @@ function extractCommitmentFromConfig(commitmentOrConfig) {
3690
3696
  };
3691
3697
  }
3692
3698
  /**
3693
- * A strategy for confirming durable nonce transactions.
3699
+ * @internal
3694
3700
  */
3695
3701
 
3696
3702
 
3697
- /**
3698
- * @internal
3699
- */
3700
3703
  function createRpcResult(result) {
3701
3704
  return superstruct.union([superstruct.type({
3702
3705
  jsonrpc: superstruct.literal('2.0'),
@@ -3888,9 +3891,15 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
3888
3891
  * A performance sample
3889
3892
  */
3890
3893
 
3891
- function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
3894
+ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit, httpAgent) {
3892
3895
  const fetch = customFetch ? customFetch : fetchImpl;
3893
3896
 
3897
+ {
3898
+ if (httpAgent != null) {
3899
+ 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.');
3900
+ }
3901
+ }
3902
+
3894
3903
  let fetchWithMiddleware;
3895
3904
 
3896
3905
  if (fetchMiddleware) {
@@ -4797,6 +4806,7 @@ class Connection {
4797
4806
  let fetch;
4798
4807
  let fetchMiddleware;
4799
4808
  let disableRetryOnRateLimit;
4809
+ let httpAgent;
4800
4810
 
4801
4811
  if (commitmentOrConfig && typeof commitmentOrConfig === 'string') {
4802
4812
  this._commitment = commitmentOrConfig;
@@ -4808,11 +4818,12 @@ class Connection {
4808
4818
  fetch = commitmentOrConfig.fetch;
4809
4819
  fetchMiddleware = commitmentOrConfig.fetchMiddleware;
4810
4820
  disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit;
4821
+ httpAgent = commitmentOrConfig.httpAgent;
4811
4822
  }
4812
4823
 
4813
4824
  this._rpcEndpoint = assertEndpointUrl(endpoint);
4814
4825
  this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
4815
- this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
4826
+ this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit, httpAgent);
4816
4827
  this._rpcRequest = createRpcRequest(this._rpcClient);
4817
4828
  this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
4818
4829
  this._rpcWebSocket = new rpcWebsockets.Client(this._rpcWsEndpoint, {
@@ -5303,7 +5314,14 @@ class Connection {
5303
5314
  if (typeof strategy == 'string') {
5304
5315
  rawSignature = strategy;
5305
5316
  } else {
5317
+ var _config$abortSignal;
5318
+
5306
5319
  const config = strategy;
5320
+
5321
+ if ((_config$abortSignal = config.abortSignal) !== null && _config$abortSignal !== void 0 && _config$abortSignal.aborted) {
5322
+ return Promise.reject(config.abortSignal.reason);
5323
+ }
5324
+
5307
5325
  rawSignature = config.signature;
5308
5326
  }
5309
5327
 
@@ -5335,6 +5353,22 @@ class Connection {
5335
5353
  }
5336
5354
  }
5337
5355
 
5356
+ getCancellationPromise(signal) {
5357
+ return new Promise((_, reject) => {
5358
+ if (signal == null) {
5359
+ return;
5360
+ }
5361
+
5362
+ if (signal.aborted) {
5363
+ reject(signal.reason);
5364
+ } else {
5365
+ signal.addEventListener('abort', () => {
5366
+ reject(signal.reason);
5367
+ });
5368
+ }
5369
+ });
5370
+ }
5371
+
5338
5372
  getTransactionConfirmationPromise({
5339
5373
  commitment,
5340
5374
  signature
@@ -5453,6 +5487,7 @@ class Connection {
5453
5487
  async confirmTransactionUsingBlockHeightExceedanceStrategy({
5454
5488
  commitment,
5455
5489
  strategy: {
5490
+ abortSignal,
5456
5491
  lastValidBlockHeight,
5457
5492
  signature
5458
5493
  }
@@ -5491,10 +5526,11 @@ class Connection {
5491
5526
  commitment,
5492
5527
  signature
5493
5528
  });
5529
+ const cancellationPromise = this.getCancellationPromise(abortSignal);
5494
5530
  let result;
5495
5531
 
5496
5532
  try {
5497
- const outcome = await Promise.race([confirmationPromise, expiryPromise]);
5533
+ const outcome = await Promise.race([cancellationPromise, confirmationPromise, expiryPromise]);
5498
5534
 
5499
5535
  if (outcome.__type === exports.TransactionStatus.PROCESSED) {
5500
5536
  result = outcome.response;
@@ -5512,6 +5548,7 @@ class Connection {
5512
5548
  async confirmTransactionUsingDurableNonceStrategy({
5513
5549
  commitment,
5514
5550
  strategy: {
5551
+ abortSignal,
5515
5552
  minContextSlot,
5516
5553
  nonceAccountPubkey,
5517
5554
  nonceValue,
@@ -5569,10 +5606,11 @@ class Connection {
5569
5606
  commitment,
5570
5607
  signature
5571
5608
  });
5609
+ const cancellationPromise = this.getCancellationPromise(abortSignal);
5572
5610
  let result;
5573
5611
 
5574
5612
  try {
5575
- const outcome = await Promise.race([confirmationPromise, expiryPromise]);
5613
+ const outcome = await Promise.race([cancellationPromise, confirmationPromise, expiryPromise]);
5576
5614
 
5577
5615
  if (outcome.__type === exports.TransactionStatus.PROCESSED) {
5578
5616
  result = outcome.response;