@solana/web3.js 1.68.1 → 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.
@@ -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'),
@@ -5303,7 +5306,14 @@ class Connection {
5303
5306
  if (typeof strategy == 'string') {
5304
5307
  rawSignature = strategy;
5305
5308
  } else {
5309
+ var _config$abortSignal;
5310
+
5306
5311
  const config = strategy;
5312
+
5313
+ if ((_config$abortSignal = config.abortSignal) !== null && _config$abortSignal !== void 0 && _config$abortSignal.aborted) {
5314
+ return Promise.reject(config.abortSignal.reason);
5315
+ }
5316
+
5307
5317
  rawSignature = config.signature;
5308
5318
  }
5309
5319
 
@@ -5335,6 +5345,22 @@ class Connection {
5335
5345
  }
5336
5346
  }
5337
5347
 
5348
+ getCancellationPromise(signal) {
5349
+ return new Promise((_, reject) => {
5350
+ if (signal == null) {
5351
+ return;
5352
+ }
5353
+
5354
+ if (signal.aborted) {
5355
+ reject(signal.reason);
5356
+ } else {
5357
+ signal.addEventListener('abort', () => {
5358
+ reject(signal.reason);
5359
+ });
5360
+ }
5361
+ });
5362
+ }
5363
+
5338
5364
  getTransactionConfirmationPromise({
5339
5365
  commitment,
5340
5366
  signature
@@ -5453,6 +5479,7 @@ class Connection {
5453
5479
  async confirmTransactionUsingBlockHeightExceedanceStrategy({
5454
5480
  commitment,
5455
5481
  strategy: {
5482
+ abortSignal,
5456
5483
  lastValidBlockHeight,
5457
5484
  signature
5458
5485
  }
@@ -5491,10 +5518,11 @@ class Connection {
5491
5518
  commitment,
5492
5519
  signature
5493
5520
  });
5521
+ const cancellationPromise = this.getCancellationPromise(abortSignal);
5494
5522
  let result;
5495
5523
 
5496
5524
  try {
5497
- const outcome = await Promise.race([confirmationPromise, expiryPromise]);
5525
+ const outcome = await Promise.race([cancellationPromise, confirmationPromise, expiryPromise]);
5498
5526
 
5499
5527
  if (outcome.__type === exports.TransactionStatus.PROCESSED) {
5500
5528
  result = outcome.response;
@@ -5512,6 +5540,7 @@ class Connection {
5512
5540
  async confirmTransactionUsingDurableNonceStrategy({
5513
5541
  commitment,
5514
5542
  strategy: {
5543
+ abortSignal,
5515
5544
  minContextSlot,
5516
5545
  nonceAccountPubkey,
5517
5546
  nonceValue,
@@ -5569,10 +5598,11 @@ class Connection {
5569
5598
  commitment,
5570
5599
  signature
5571
5600
  });
5601
+ const cancellationPromise = this.getCancellationPromise(abortSignal);
5572
5602
  let result;
5573
5603
 
5574
5604
  try {
5575
- const outcome = await Promise.race([confirmationPromise, expiryPromise]);
5605
+ const outcome = await Promise.race([cancellationPromise, confirmationPromise, expiryPromise]);
5576
5606
 
5577
5607
  if (outcome.__type === exports.TransactionStatus.PROCESSED) {
5578
5608
  result = outcome.response;