@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/lib/index.cjs.js CHANGED
@@ -11,11 +11,11 @@ var sha256 = require('@noble/hashes/sha256');
11
11
  var borsh = require('borsh');
12
12
  var BufferLayout = require('@solana/buffer-layout');
13
13
  var bigintBuffer = require('bigint-buffer');
14
+ var https = require('https');
14
15
  var superstruct = require('superstruct');
15
16
  var rpcWebsockets = require('rpc-websockets');
16
17
  var RpcClient = require('jayson/lib/client/browser');
17
18
  var http = require('http');
18
- var https = require('https');
19
19
  var nodeFetch = require('node-fetch');
20
20
  var sha3 = require('@noble/hashes/sha3');
21
21
  var hmac = require('@noble/hashes/hmac');
@@ -45,9 +45,9 @@ var ed25519__namespace = /*#__PURE__*/_interopNamespace(ed25519);
45
45
  var BN__default = /*#__PURE__*/_interopDefaultLegacy(BN);
46
46
  var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
47
47
  var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
48
+ var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
48
49
  var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
49
50
  var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
50
- var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
51
51
  var nodeFetch__namespace = /*#__PURE__*/_interopNamespace(nodeFetch);
52
52
  var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
53
53
 
@@ -2245,6 +2245,7 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
2245
2245
 
2246
2246
  if (transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null) {
2247
2247
  status = (await connection.confirmTransaction({
2248
+ abortSignal: options === null || options === void 0 ? void 0 : options.abortSignal,
2248
2249
  signature: signature,
2249
2250
  blockhash: transaction.recentBlockhash,
2250
2251
  lastValidBlockHeight: transaction.lastValidBlockHeight
@@ -2255,12 +2256,17 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
2255
2256
  } = transaction.nonceInfo;
2256
2257
  const nonceAccountPubkey = nonceInstruction.keys[0].pubkey;
2257
2258
  status = (await connection.confirmTransaction({
2259
+ abortSignal: options === null || options === void 0 ? void 0 : options.abortSignal,
2258
2260
  minContextSlot: transaction.minNonceContextSlot,
2259
2261
  nonceAccountPubkey,
2260
2262
  nonceValue: transaction.nonceInfo.nonce,
2261
2263
  signature
2262
2264
  }, options && options.commitment)).value;
2263
2265
  } else {
2266
+ if ((options === null || options === void 0 ? void 0 : options.abortSignal) != null) {
2267
+ 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.');
2268
+ }
2269
+
2264
2270
  status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
2265
2271
  }
2266
2272
 
@@ -3473,7 +3479,7 @@ function nextPowerOfTwo(n) {
3473
3479
  /**
3474
3480
  * Epoch schedule
3475
3481
  * (see https://docs.solana.com/terminology#epoch)
3476
- * Can be retrieved with the {@link connection.getEpochSchedule} method
3482
+ * Can be retrieved with the {@link Connection.getEpochSchedule} method
3477
3483
  */
3478
3484
 
3479
3485
 
@@ -3748,13 +3754,10 @@ function extractCommitmentFromConfig(commitmentOrConfig) {
3748
3754
  };
3749
3755
  }
3750
3756
  /**
3751
- * A strategy for confirming durable nonce transactions.
3757
+ * @internal
3752
3758
  */
3753
3759
 
3754
3760
 
3755
- /**
3756
- * @internal
3757
- */
3758
3761
  function createRpcResult(result) {
3759
3762
  return superstruct.union([superstruct.type({
3760
3763
  jsonrpc: superstruct.literal('2.0'),
@@ -3946,14 +3949,34 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
3946
3949
  * A performance sample
3947
3950
  */
3948
3951
 
3949
- function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
3952
+ function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit, httpAgent) {
3950
3953
  const fetch = customFetch ? customFetch : fetchImpl;
3951
3954
  let agentManager;
3952
3955
 
3953
3956
  {
3954
- agentManager = new AgentManager(url.startsWith('https:')
3955
- /* useHttps */
3956
- );
3957
+ if (httpAgent == null) {
3958
+ {
3959
+ agentManager = new AgentManager(url.startsWith('https:')
3960
+ /* useHttps */
3961
+ );
3962
+ }
3963
+ } else {
3964
+ if (httpAgent !== false) {
3965
+ const isHttps = url.startsWith('https:');
3966
+
3967
+ if (isHttps && !(httpAgent instanceof https.Agent)) {
3968
+ throw new Error('The endpoint `' + url + '` can only be paired with an `https.Agent`. You have, instead, supplied an ' + '`http.Agent` through `httpAgent`.');
3969
+ } else if (!isHttps && httpAgent instanceof https.Agent) {
3970
+ throw new Error('The endpoint `' + url + '` can only be paired with an `http.Agent`. You have, instead, supplied an ' + '`https.Agent` through `httpAgent`.');
3971
+ }
3972
+
3973
+ agentManager = {
3974
+ requestEnd() {},
3975
+
3976
+ requestStart: () => httpAgent
3977
+ };
3978
+ }
3979
+ }
3957
3980
  }
3958
3981
 
3959
3982
  let fetchWithMiddleware;
@@ -4863,6 +4886,7 @@ class Connection {
4863
4886
  let fetch;
4864
4887
  let fetchMiddleware;
4865
4888
  let disableRetryOnRateLimit;
4889
+ let httpAgent;
4866
4890
 
4867
4891
  if (commitmentOrConfig && typeof commitmentOrConfig === 'string') {
4868
4892
  this._commitment = commitmentOrConfig;
@@ -4874,11 +4898,12 @@ class Connection {
4874
4898
  fetch = commitmentOrConfig.fetch;
4875
4899
  fetchMiddleware = commitmentOrConfig.fetchMiddleware;
4876
4900
  disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit;
4901
+ httpAgent = commitmentOrConfig.httpAgent;
4877
4902
  }
4878
4903
 
4879
4904
  this._rpcEndpoint = assertEndpointUrl(endpoint);
4880
4905
  this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
4881
- this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
4906
+ this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit, httpAgent);
4882
4907
  this._rpcRequest = createRpcRequest(this._rpcClient);
4883
4908
  this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
4884
4909
  this._rpcWebSocket = new rpcWebsockets.Client(this._rpcWsEndpoint, {
@@ -5369,7 +5394,14 @@ class Connection {
5369
5394
  if (typeof strategy == 'string') {
5370
5395
  rawSignature = strategy;
5371
5396
  } else {
5397
+ var _config$abortSignal;
5398
+
5372
5399
  const config = strategy;
5400
+
5401
+ if ((_config$abortSignal = config.abortSignal) !== null && _config$abortSignal !== void 0 && _config$abortSignal.aborted) {
5402
+ return Promise.reject(config.abortSignal.reason);
5403
+ }
5404
+
5373
5405
  rawSignature = config.signature;
5374
5406
  }
5375
5407
 
@@ -5401,6 +5433,22 @@ class Connection {
5401
5433
  }
5402
5434
  }
5403
5435
 
5436
+ getCancellationPromise(signal) {
5437
+ return new Promise((_, reject) => {
5438
+ if (signal == null) {
5439
+ return;
5440
+ }
5441
+
5442
+ if (signal.aborted) {
5443
+ reject(signal.reason);
5444
+ } else {
5445
+ signal.addEventListener('abort', () => {
5446
+ reject(signal.reason);
5447
+ });
5448
+ }
5449
+ });
5450
+ }
5451
+
5404
5452
  getTransactionConfirmationPromise({
5405
5453
  commitment,
5406
5454
  signature
@@ -5519,6 +5567,7 @@ class Connection {
5519
5567
  async confirmTransactionUsingBlockHeightExceedanceStrategy({
5520
5568
  commitment,
5521
5569
  strategy: {
5570
+ abortSignal,
5522
5571
  lastValidBlockHeight,
5523
5572
  signature
5524
5573
  }
@@ -5557,10 +5606,11 @@ class Connection {
5557
5606
  commitment,
5558
5607
  signature
5559
5608
  });
5609
+ const cancellationPromise = this.getCancellationPromise(abortSignal);
5560
5610
  let result;
5561
5611
 
5562
5612
  try {
5563
- const outcome = await Promise.race([confirmationPromise, expiryPromise]);
5613
+ const outcome = await Promise.race([cancellationPromise, confirmationPromise, expiryPromise]);
5564
5614
 
5565
5615
  if (outcome.__type === exports.TransactionStatus.PROCESSED) {
5566
5616
  result = outcome.response;
@@ -5578,6 +5628,7 @@ class Connection {
5578
5628
  async confirmTransactionUsingDurableNonceStrategy({
5579
5629
  commitment,
5580
5630
  strategy: {
5631
+ abortSignal,
5581
5632
  minContextSlot,
5582
5633
  nonceAccountPubkey,
5583
5634
  nonceValue,
@@ -5635,10 +5686,11 @@ class Connection {
5635
5686
  commitment,
5636
5687
  signature
5637
5688
  });
5689
+ const cancellationPromise = this.getCancellationPromise(abortSignal);
5638
5690
  let result;
5639
5691
 
5640
5692
  try {
5641
- const outcome = await Promise.race([confirmationPromise, expiryPromise]);
5693
+ const outcome = await Promise.race([cancellationPromise, confirmationPromise, expiryPromise]);
5642
5694
 
5643
5695
  if (outcome.__type === exports.TransactionStatus.PROCESSED) {
5644
5696
  result = outcome.response;