@solana/web3.js 1.68.0 → 1.69.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
@@ -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'),
@@ -5369,7 +5372,14 @@ class Connection {
5369
5372
  if (typeof strategy == 'string') {
5370
5373
  rawSignature = strategy;
5371
5374
  } else {
5375
+ var _config$abortSignal;
5376
+
5372
5377
  const config = strategy;
5378
+
5379
+ if ((_config$abortSignal = config.abortSignal) !== null && _config$abortSignal !== void 0 && _config$abortSignal.aborted) {
5380
+ return Promise.reject(config.abortSignal.reason);
5381
+ }
5382
+
5373
5383
  rawSignature = config.signature;
5374
5384
  }
5375
5385
 
@@ -5401,6 +5411,22 @@ class Connection {
5401
5411
  }
5402
5412
  }
5403
5413
 
5414
+ getCancellationPromise(signal) {
5415
+ return new Promise((_, reject) => {
5416
+ if (signal == null) {
5417
+ return;
5418
+ }
5419
+
5420
+ if (signal.aborted) {
5421
+ reject(signal.reason);
5422
+ } else {
5423
+ signal.addEventListener('abort', () => {
5424
+ reject(signal.reason);
5425
+ });
5426
+ }
5427
+ });
5428
+ }
5429
+
5404
5430
  getTransactionConfirmationPromise({
5405
5431
  commitment,
5406
5432
  signature
@@ -5504,7 +5530,7 @@ class Connection {
5504
5530
  disposeSignatureSubscriptionStateChangeObserver = undefined;
5505
5531
  }
5506
5532
 
5507
- if (signatureSubscriptionId) {
5533
+ if (signatureSubscriptionId != null) {
5508
5534
  this.removeSignatureListener(signatureSubscriptionId);
5509
5535
  signatureSubscriptionId = undefined;
5510
5536
  }
@@ -5519,6 +5545,7 @@ class Connection {
5519
5545
  async confirmTransactionUsingBlockHeightExceedanceStrategy({
5520
5546
  commitment,
5521
5547
  strategy: {
5548
+ abortSignal,
5522
5549
  lastValidBlockHeight,
5523
5550
  signature
5524
5551
  }
@@ -5557,10 +5584,11 @@ class Connection {
5557
5584
  commitment,
5558
5585
  signature
5559
5586
  });
5587
+ const cancellationPromise = this.getCancellationPromise(abortSignal);
5560
5588
  let result;
5561
5589
 
5562
5590
  try {
5563
- const outcome = await Promise.race([confirmationPromise, expiryPromise]);
5591
+ const outcome = await Promise.race([cancellationPromise, confirmationPromise, expiryPromise]);
5564
5592
 
5565
5593
  if (outcome.__type === exports.TransactionStatus.PROCESSED) {
5566
5594
  result = outcome.response;
@@ -5578,6 +5606,7 @@ class Connection {
5578
5606
  async confirmTransactionUsingDurableNonceStrategy({
5579
5607
  commitment,
5580
5608
  strategy: {
5609
+ abortSignal,
5581
5610
  minContextSlot,
5582
5611
  nonceAccountPubkey,
5583
5612
  nonceValue,
@@ -5635,10 +5664,11 @@ class Connection {
5635
5664
  commitment,
5636
5665
  signature
5637
5666
  });
5667
+ const cancellationPromise = this.getCancellationPromise(abortSignal);
5638
5668
  let result;
5639
5669
 
5640
5670
  try {
5641
- const outcome = await Promise.race([confirmationPromise, expiryPromise]);
5671
+ const outcome = await Promise.race([cancellationPromise, confirmationPromise, expiryPromise]);
5642
5672
 
5643
5673
  if (outcome.__type === exports.TransactionStatus.PROCESSED) {
5644
5674
  result = outcome.response;