@solana/web3.js 1.66.5 → 1.67.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.browser.cjs.js +334 -69
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +334 -70
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +334 -69
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +81 -5
- package/lib/index.esm.js +334 -70
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +334 -69
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +334 -69
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -1
- package/src/connection.ts +320 -76
- package/src/nonce-account.ts +7 -3
- package/src/transaction/expiry-custom-errors.ts +13 -0
- package/src/transaction/legacy.ts +39 -3
- package/src/utils/send-and-confirm-raw-transaction.ts +13 -0
- package/src/utils/send-and-confirm-transaction.ts +39 -18
package/lib/index.esm.js
CHANGED
|
@@ -421,6 +421,17 @@ class TransactionExpiredTimeoutError extends Error {
|
|
|
421
421
|
Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
422
422
|
value: 'TransactionExpiredTimeoutError'
|
|
423
423
|
});
|
|
424
|
+
class TransactionExpiredNonceInvalidError extends Error {
|
|
425
|
+
constructor(signature) {
|
|
426
|
+
super(`Signature ${signature} has expired: the nonce is no longer valid.`);
|
|
427
|
+
this.signature = void 0;
|
|
428
|
+
this.signature = signature;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
}
|
|
432
|
+
Object.defineProperty(TransactionExpiredNonceInvalidError.prototype, 'name', {
|
|
433
|
+
value: 'TransactionExpiredNonceInvalidError'
|
|
434
|
+
});
|
|
424
435
|
|
|
425
436
|
class MessageAccountKeys {
|
|
426
437
|
constructor(staticAccountKeys, accountKeysFromLookups) {
|
|
@@ -1258,6 +1269,7 @@ let TransactionStatus;
|
|
|
1258
1269
|
TransactionStatus[TransactionStatus["BLOCKHEIGHT_EXCEEDED"] = 0] = "BLOCKHEIGHT_EXCEEDED";
|
|
1259
1270
|
TransactionStatus[TransactionStatus["PROCESSED"] = 1] = "PROCESSED";
|
|
1260
1271
|
TransactionStatus[TransactionStatus["TIMED_OUT"] = 2] = "TIMED_OUT";
|
|
1272
|
+
TransactionStatus[TransactionStatus["NONCE_INVALID"] = 3] = "NONCE_INVALID";
|
|
1261
1273
|
})(TransactionStatus || (TransactionStatus = {}));
|
|
1262
1274
|
|
|
1263
1275
|
const DEFAULT_SIGNATURE = Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
|
@@ -1352,6 +1364,7 @@ class Transaction {
|
|
|
1352
1364
|
this.recentBlockhash = void 0;
|
|
1353
1365
|
this.lastValidBlockHeight = void 0;
|
|
1354
1366
|
this.nonceInfo = void 0;
|
|
1367
|
+
this.minNonceContextSlot = void 0;
|
|
1355
1368
|
this._message = void 0;
|
|
1356
1369
|
this._json = void 0;
|
|
1357
1370
|
|
|
@@ -1367,7 +1380,14 @@ class Transaction {
|
|
|
1367
1380
|
this.signatures = opts.signatures;
|
|
1368
1381
|
}
|
|
1369
1382
|
|
|
1370
|
-
if (Object.prototype.hasOwnProperty.call(opts, '
|
|
1383
|
+
if (Object.prototype.hasOwnProperty.call(opts, 'nonceInfo')) {
|
|
1384
|
+
const {
|
|
1385
|
+
minContextSlot,
|
|
1386
|
+
nonceInfo
|
|
1387
|
+
} = opts;
|
|
1388
|
+
this.minNonceContextSlot = minContextSlot;
|
|
1389
|
+
this.nonceInfo = nonceInfo;
|
|
1390
|
+
} else if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
|
|
1371
1391
|
const {
|
|
1372
1392
|
blockhash,
|
|
1373
1393
|
lastValidBlockHeight
|
|
@@ -2184,11 +2204,28 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2184
2204
|
minContextSlot: options.minContextSlot
|
|
2185
2205
|
};
|
|
2186
2206
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2207
|
+
let status;
|
|
2208
|
+
|
|
2209
|
+
if (transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null) {
|
|
2210
|
+
status = (await connection.confirmTransaction({
|
|
2211
|
+
signature: signature,
|
|
2212
|
+
blockhash: transaction.recentBlockhash,
|
|
2213
|
+
lastValidBlockHeight: transaction.lastValidBlockHeight
|
|
2214
|
+
}, options && options.commitment)).value;
|
|
2215
|
+
} else if (transaction.minNonceContextSlot != null && transaction.nonceInfo != null) {
|
|
2216
|
+
const {
|
|
2217
|
+
nonceInstruction
|
|
2218
|
+
} = transaction.nonceInfo;
|
|
2219
|
+
const nonceAccountPubkey = nonceInstruction.keys[0].pubkey;
|
|
2220
|
+
status = (await connection.confirmTransaction({
|
|
2221
|
+
minContextSlot: transaction.minNonceContextSlot,
|
|
2222
|
+
nonceAccountPubkey,
|
|
2223
|
+
nonceValue: transaction.nonceInfo.nonce,
|
|
2224
|
+
signature
|
|
2225
|
+
}, options && options.commitment)).value;
|
|
2226
|
+
} else {
|
|
2227
|
+
status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2228
|
+
}
|
|
2192
2229
|
|
|
2193
2230
|
if (status.err) {
|
|
2194
2231
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
@@ -2257,6 +2294,9 @@ const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
|
|
|
2257
2294
|
|
|
2258
2295
|
const NonceAccountLayout = BufferLayout.struct([BufferLayout.u32('version'), BufferLayout.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout.struct([FeeCalculatorLayout], 'feeCalculator')]);
|
|
2259
2296
|
const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
|
|
2297
|
+
/**
|
|
2298
|
+
* A durable nonce is a 32 byte value encoded as a base58 string.
|
|
2299
|
+
*/
|
|
2260
2300
|
|
|
2261
2301
|
/**
|
|
2262
2302
|
* NonceAccount class
|
|
@@ -3671,10 +3711,13 @@ function extractCommitmentFromConfig(commitmentOrConfig) {
|
|
|
3671
3711
|
};
|
|
3672
3712
|
}
|
|
3673
3713
|
/**
|
|
3674
|
-
*
|
|
3714
|
+
* A strategy for confirming durable nonce transactions.
|
|
3675
3715
|
*/
|
|
3676
3716
|
|
|
3677
3717
|
|
|
3718
|
+
/**
|
|
3719
|
+
* @internal
|
|
3720
|
+
*/
|
|
3678
3721
|
function createRpcResult(result) {
|
|
3679
3722
|
return union([type({
|
|
3680
3723
|
jsonrpc: literal('2.0'),
|
|
@@ -5246,25 +5289,45 @@ class Connection {
|
|
|
5246
5289
|
}
|
|
5247
5290
|
|
|
5248
5291
|
assert(decodedSignature.length === 64, 'signature has invalid length');
|
|
5249
|
-
|
|
5250
|
-
|
|
5292
|
+
|
|
5293
|
+
if (typeof strategy === 'string') {
|
|
5294
|
+
return await this.confirmTransactionUsingLegacyTimeoutStrategy({
|
|
5295
|
+
commitment: commitment || this.commitment,
|
|
5296
|
+
signature: rawSignature
|
|
5297
|
+
});
|
|
5298
|
+
} else if ('lastValidBlockHeight' in strategy) {
|
|
5299
|
+
return await this.confirmTransactionUsingBlockHeightExceedanceStrategy({
|
|
5300
|
+
commitment: commitment || this.commitment,
|
|
5301
|
+
strategy
|
|
5302
|
+
});
|
|
5303
|
+
} else {
|
|
5304
|
+
return await this.confirmTransactionUsingDurableNonceStrategy({
|
|
5305
|
+
commitment: commitment || this.commitment,
|
|
5306
|
+
strategy
|
|
5307
|
+
});
|
|
5308
|
+
}
|
|
5309
|
+
}
|
|
5310
|
+
|
|
5311
|
+
getTransactionConfirmationPromise({
|
|
5312
|
+
commitment,
|
|
5313
|
+
signature
|
|
5314
|
+
}) {
|
|
5251
5315
|
let signatureSubscriptionId;
|
|
5252
5316
|
let disposeSignatureSubscriptionStateChangeObserver;
|
|
5253
5317
|
let done = false;
|
|
5254
5318
|
const confirmationPromise = new Promise((resolve, reject) => {
|
|
5255
5319
|
try {
|
|
5256
|
-
signatureSubscriptionId = this.onSignature(
|
|
5320
|
+
signatureSubscriptionId = this.onSignature(signature, (result, context) => {
|
|
5257
5321
|
signatureSubscriptionId = undefined;
|
|
5258
5322
|
const response = {
|
|
5259
5323
|
context,
|
|
5260
5324
|
value: result
|
|
5261
5325
|
};
|
|
5262
|
-
done = true;
|
|
5263
5326
|
resolve({
|
|
5264
5327
|
__type: TransactionStatus.PROCESSED,
|
|
5265
5328
|
response
|
|
5266
5329
|
});
|
|
5267
|
-
},
|
|
5330
|
+
}, commitment);
|
|
5268
5331
|
const subscriptionSetupPromise = new Promise(resolveSubscriptionSetup => {
|
|
5269
5332
|
if (signatureSubscriptionId == null) {
|
|
5270
5333
|
resolveSubscriptionSetup();
|
|
@@ -5280,7 +5343,7 @@ class Connection {
|
|
|
5280
5343
|
(async () => {
|
|
5281
5344
|
await subscriptionSetupPromise;
|
|
5282
5345
|
if (done) return;
|
|
5283
|
-
const response = await this.getSignatureStatus(
|
|
5346
|
+
const response = await this.getSignatureStatus(signature);
|
|
5284
5347
|
if (done) return;
|
|
5285
5348
|
|
|
5286
5349
|
if (response == null) {
|
|
@@ -5299,7 +5362,7 @@ class Connection {
|
|
|
5299
5362
|
if (value !== null && value !== void 0 && value.err) {
|
|
5300
5363
|
reject(value.err);
|
|
5301
5364
|
} else {
|
|
5302
|
-
switch (
|
|
5365
|
+
switch (commitment) {
|
|
5303
5366
|
case 'confirmed':
|
|
5304
5367
|
case 'single':
|
|
5305
5368
|
case 'singleGossip':
|
|
@@ -5341,81 +5404,279 @@ class Connection {
|
|
|
5341
5404
|
reject(err);
|
|
5342
5405
|
}
|
|
5343
5406
|
});
|
|
5407
|
+
|
|
5408
|
+
const abortConfirmation = () => {
|
|
5409
|
+
if (disposeSignatureSubscriptionStateChangeObserver) {
|
|
5410
|
+
disposeSignatureSubscriptionStateChangeObserver();
|
|
5411
|
+
disposeSignatureSubscriptionStateChangeObserver = undefined;
|
|
5412
|
+
}
|
|
5413
|
+
|
|
5414
|
+
if (signatureSubscriptionId) {
|
|
5415
|
+
this.removeSignatureListener(signatureSubscriptionId);
|
|
5416
|
+
signatureSubscriptionId = undefined;
|
|
5417
|
+
}
|
|
5418
|
+
};
|
|
5419
|
+
|
|
5420
|
+
return {
|
|
5421
|
+
abortConfirmation,
|
|
5422
|
+
confirmationPromise
|
|
5423
|
+
};
|
|
5424
|
+
}
|
|
5425
|
+
|
|
5426
|
+
async confirmTransactionUsingBlockHeightExceedanceStrategy({
|
|
5427
|
+
commitment,
|
|
5428
|
+
strategy: {
|
|
5429
|
+
lastValidBlockHeight,
|
|
5430
|
+
signature
|
|
5431
|
+
}
|
|
5432
|
+
}) {
|
|
5433
|
+
let done = false;
|
|
5344
5434
|
const expiryPromise = new Promise(resolve => {
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
case 'single':
|
|
5352
|
-
case 'confirmed':
|
|
5353
|
-
case 'singleGossip':
|
|
5354
|
-
{
|
|
5355
|
-
timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
|
|
5356
|
-
break;
|
|
5357
|
-
}
|
|
5435
|
+
const checkBlockHeight = async () => {
|
|
5436
|
+
try {
|
|
5437
|
+
const blockHeight = await this.getBlockHeight(commitment);
|
|
5438
|
+
return blockHeight;
|
|
5439
|
+
} catch (_e) {
|
|
5440
|
+
return -1;
|
|
5358
5441
|
}
|
|
5442
|
+
};
|
|
5359
5443
|
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5444
|
+
(async () => {
|
|
5445
|
+
let currentBlockHeight = await checkBlockHeight();
|
|
5446
|
+
if (done) return;
|
|
5447
|
+
|
|
5448
|
+
while (currentBlockHeight <= lastValidBlockHeight) {
|
|
5449
|
+
await sleep(1000);
|
|
5450
|
+
if (done) return;
|
|
5451
|
+
currentBlockHeight = await checkBlockHeight();
|
|
5452
|
+
if (done) return;
|
|
5453
|
+
}
|
|
5454
|
+
|
|
5455
|
+
resolve({
|
|
5456
|
+
__type: TransactionStatus.BLOCKHEIGHT_EXCEEDED
|
|
5457
|
+
});
|
|
5458
|
+
})();
|
|
5459
|
+
});
|
|
5460
|
+
const {
|
|
5461
|
+
abortConfirmation,
|
|
5462
|
+
confirmationPromise
|
|
5463
|
+
} = this.getTransactionConfirmationPromise({
|
|
5464
|
+
commitment,
|
|
5465
|
+
signature
|
|
5466
|
+
});
|
|
5467
|
+
let result;
|
|
5468
|
+
|
|
5469
|
+
try {
|
|
5470
|
+
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5471
|
+
|
|
5472
|
+
if (outcome.__type === TransactionStatus.PROCESSED) {
|
|
5473
|
+
result = outcome.response;
|
|
5364
5474
|
} else {
|
|
5365
|
-
|
|
5475
|
+
throw new TransactionExpiredBlockheightExceededError(signature);
|
|
5476
|
+
}
|
|
5477
|
+
} finally {
|
|
5478
|
+
done = true;
|
|
5479
|
+
abortConfirmation();
|
|
5480
|
+
}
|
|
5366
5481
|
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
const blockHeight = await this.getBlockHeight(commitment);
|
|
5370
|
-
return blockHeight;
|
|
5371
|
-
} catch (_e) {
|
|
5372
|
-
return -1;
|
|
5373
|
-
}
|
|
5374
|
-
};
|
|
5482
|
+
return result;
|
|
5483
|
+
}
|
|
5375
5484
|
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5485
|
+
async confirmTransactionUsingDurableNonceStrategy({
|
|
5486
|
+
commitment,
|
|
5487
|
+
strategy: {
|
|
5488
|
+
minContextSlot,
|
|
5489
|
+
nonceAccountPubkey,
|
|
5490
|
+
nonceValue,
|
|
5491
|
+
signature
|
|
5492
|
+
}
|
|
5493
|
+
}) {
|
|
5494
|
+
let done = false;
|
|
5495
|
+
const expiryPromise = new Promise(resolve => {
|
|
5496
|
+
let currentNonceValue = nonceValue;
|
|
5497
|
+
let lastCheckedSlot = null;
|
|
5379
5498
|
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5499
|
+
const getCurrentNonceValue = async () => {
|
|
5500
|
+
try {
|
|
5501
|
+
const {
|
|
5502
|
+
context,
|
|
5503
|
+
value: nonceAccount
|
|
5504
|
+
} = await this.getNonceAndContext(nonceAccountPubkey, {
|
|
5505
|
+
commitment,
|
|
5506
|
+
minContextSlot
|
|
5507
|
+
});
|
|
5508
|
+
lastCheckedSlot = context.slot;
|
|
5509
|
+
return nonceAccount === null || nonceAccount === void 0 ? void 0 : nonceAccount.nonce;
|
|
5510
|
+
} catch (e) {
|
|
5511
|
+
// If for whatever reason we can't reach/read the nonce
|
|
5512
|
+
// account, just keep using the last-known value.
|
|
5513
|
+
return currentNonceValue;
|
|
5514
|
+
}
|
|
5515
|
+
};
|
|
5516
|
+
|
|
5517
|
+
(async () => {
|
|
5518
|
+
currentNonceValue = await getCurrentNonceValue();
|
|
5519
|
+
if (done) return;
|
|
5520
|
+
|
|
5521
|
+
while (true // eslint-disable-line no-constant-condition
|
|
5522
|
+
) {
|
|
5523
|
+
if (nonceValue !== currentNonceValue) {
|
|
5524
|
+
resolve({
|
|
5525
|
+
__type: TransactionStatus.NONCE_INVALID,
|
|
5526
|
+
slotInWhichNonceDidAdvance: lastCheckedSlot
|
|
5527
|
+
});
|
|
5528
|
+
return;
|
|
5385
5529
|
}
|
|
5386
5530
|
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5531
|
+
await sleep(2000);
|
|
5532
|
+
if (done) return;
|
|
5533
|
+
currentNonceValue = await getCurrentNonceValue();
|
|
5534
|
+
if (done) return;
|
|
5535
|
+
}
|
|
5536
|
+
})();
|
|
5537
|
+
});
|
|
5538
|
+
const {
|
|
5539
|
+
abortConfirmation,
|
|
5540
|
+
confirmationPromise
|
|
5541
|
+
} = this.getTransactionConfirmationPromise({
|
|
5542
|
+
commitment,
|
|
5543
|
+
signature
|
|
5392
5544
|
});
|
|
5393
5545
|
let result;
|
|
5394
5546
|
|
|
5395
5547
|
try {
|
|
5396
5548
|
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5397
5549
|
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5550
|
+
if (outcome.__type === TransactionStatus.PROCESSED) {
|
|
5551
|
+
result = outcome.response;
|
|
5552
|
+
} else {
|
|
5553
|
+
var _signatureStatus;
|
|
5554
|
+
|
|
5555
|
+
// Double check that the transaction is indeed unconfirmed.
|
|
5556
|
+
let signatureStatus;
|
|
5557
|
+
|
|
5558
|
+
while (true // eslint-disable-line no-constant-condition
|
|
5559
|
+
) {
|
|
5560
|
+
var _outcome$slotInWhichN;
|
|
5561
|
+
|
|
5562
|
+
const status = await this.getSignatureStatus(signature);
|
|
5563
|
+
|
|
5564
|
+
if (status == null) {
|
|
5565
|
+
break;
|
|
5566
|
+
}
|
|
5567
|
+
|
|
5568
|
+
if (status.context.slot < ((_outcome$slotInWhichN = outcome.slotInWhichNonceDidAdvance) !== null && _outcome$slotInWhichN !== void 0 ? _outcome$slotInWhichN : minContextSlot)) {
|
|
5569
|
+
await sleep(400);
|
|
5570
|
+
continue;
|
|
5571
|
+
}
|
|
5401
5572
|
|
|
5402
|
-
|
|
5403
|
-
result = outcome.response;
|
|
5573
|
+
signatureStatus = status;
|
|
5404
5574
|
break;
|
|
5575
|
+
}
|
|
5576
|
+
|
|
5577
|
+
if ((_signatureStatus = signatureStatus) !== null && _signatureStatus !== void 0 && _signatureStatus.value) {
|
|
5578
|
+
const commitmentForStatus = commitment || 'finalized';
|
|
5579
|
+
const {
|
|
5580
|
+
confirmationStatus
|
|
5581
|
+
} = signatureStatus.value;
|
|
5582
|
+
|
|
5583
|
+
switch (commitmentForStatus) {
|
|
5584
|
+
case 'processed':
|
|
5585
|
+
case 'recent':
|
|
5586
|
+
if (confirmationStatus !== 'processed' && confirmationStatus !== 'confirmed' && confirmationStatus !== 'finalized') {
|
|
5587
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5588
|
+
}
|
|
5589
|
+
|
|
5590
|
+
break;
|
|
5591
|
+
|
|
5592
|
+
case 'confirmed':
|
|
5593
|
+
case 'single':
|
|
5594
|
+
case 'singleGossip':
|
|
5595
|
+
if (confirmationStatus !== 'confirmed' && confirmationStatus !== 'finalized') {
|
|
5596
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5597
|
+
}
|
|
5405
5598
|
|
|
5406
|
-
|
|
5407
|
-
|
|
5599
|
+
break;
|
|
5600
|
+
|
|
5601
|
+
case 'finalized':
|
|
5602
|
+
case 'max':
|
|
5603
|
+
case 'root':
|
|
5604
|
+
if (confirmationStatus !== 'finalized') {
|
|
5605
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5606
|
+
}
|
|
5607
|
+
|
|
5608
|
+
break;
|
|
5609
|
+
|
|
5610
|
+
default:
|
|
5611
|
+
// Exhaustive switch.
|
|
5612
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5613
|
+
(_ => {})(commitmentForStatus);
|
|
5614
|
+
|
|
5615
|
+
}
|
|
5616
|
+
|
|
5617
|
+
result = {
|
|
5618
|
+
context: signatureStatus.context,
|
|
5619
|
+
value: {
|
|
5620
|
+
err: signatureStatus.value.err
|
|
5621
|
+
}
|
|
5622
|
+
};
|
|
5623
|
+
} else {
|
|
5624
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5625
|
+
}
|
|
5408
5626
|
}
|
|
5409
5627
|
} finally {
|
|
5410
|
-
|
|
5628
|
+
done = true;
|
|
5629
|
+
abortConfirmation();
|
|
5630
|
+
}
|
|
5411
5631
|
|
|
5412
|
-
|
|
5413
|
-
|
|
5632
|
+
return result;
|
|
5633
|
+
}
|
|
5634
|
+
|
|
5635
|
+
async confirmTransactionUsingLegacyTimeoutStrategy({
|
|
5636
|
+
commitment,
|
|
5637
|
+
signature
|
|
5638
|
+
}) {
|
|
5639
|
+
let timeoutId;
|
|
5640
|
+
const expiryPromise = new Promise(resolve => {
|
|
5641
|
+
let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
|
|
5642
|
+
|
|
5643
|
+
switch (commitment) {
|
|
5644
|
+
case 'processed':
|
|
5645
|
+
case 'recent':
|
|
5646
|
+
case 'single':
|
|
5647
|
+
case 'confirmed':
|
|
5648
|
+
case 'singleGossip':
|
|
5649
|
+
{
|
|
5650
|
+
timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
|
|
5651
|
+
break;
|
|
5652
|
+
}
|
|
5414
5653
|
}
|
|
5415
5654
|
|
|
5416
|
-
|
|
5417
|
-
|
|
5655
|
+
timeoutId = setTimeout(() => resolve({
|
|
5656
|
+
__type: TransactionStatus.TIMED_OUT,
|
|
5657
|
+
timeoutMs
|
|
5658
|
+
}), timeoutMs);
|
|
5659
|
+
});
|
|
5660
|
+
const {
|
|
5661
|
+
abortConfirmation,
|
|
5662
|
+
confirmationPromise
|
|
5663
|
+
} = this.getTransactionConfirmationPromise({
|
|
5664
|
+
commitment,
|
|
5665
|
+
signature
|
|
5666
|
+
});
|
|
5667
|
+
let result;
|
|
5668
|
+
|
|
5669
|
+
try {
|
|
5670
|
+
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5671
|
+
|
|
5672
|
+
if (outcome.__type === TransactionStatus.PROCESSED) {
|
|
5673
|
+
result = outcome.response;
|
|
5674
|
+
} else {
|
|
5675
|
+
throw new TransactionExpiredTimeoutError(signature, outcome.timeoutMs / 1000);
|
|
5418
5676
|
}
|
|
5677
|
+
} finally {
|
|
5678
|
+
clearTimeout(timeoutId);
|
|
5679
|
+
abortConfirmation();
|
|
5419
5680
|
}
|
|
5420
5681
|
|
|
5421
5682
|
return result;
|
|
@@ -6471,11 +6732,11 @@ class Connection {
|
|
|
6471
6732
|
*/
|
|
6472
6733
|
|
|
6473
6734
|
|
|
6474
|
-
async getNonceAndContext(nonceAccount,
|
|
6735
|
+
async getNonceAndContext(nonceAccount, commitmentOrConfig) {
|
|
6475
6736
|
const {
|
|
6476
6737
|
context,
|
|
6477
6738
|
value: accountInfo
|
|
6478
|
-
} = await this.getAccountInfoAndContext(nonceAccount,
|
|
6739
|
+
} = await this.getAccountInfoAndContext(nonceAccount, commitmentOrConfig);
|
|
6479
6740
|
let value = null;
|
|
6480
6741
|
|
|
6481
6742
|
if (accountInfo !== null) {
|
|
@@ -6492,8 +6753,8 @@ class Connection {
|
|
|
6492
6753
|
*/
|
|
6493
6754
|
|
|
6494
6755
|
|
|
6495
|
-
async getNonce(nonceAccount,
|
|
6496
|
-
return await this.getNonceAndContext(nonceAccount,
|
|
6756
|
+
async getNonce(nonceAccount, commitmentOrConfig) {
|
|
6757
|
+
return await this.getNonceAndContext(nonceAccount, commitmentOrConfig).then(x => x.value).catch(e => {
|
|
6497
6758
|
throw new Error('failed to get nonce for account ' + nonceAccount.toBase58() + ': ' + e);
|
|
6498
6759
|
});
|
|
6499
6760
|
}
|
|
@@ -9908,6 +10169,9 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9908
10169
|
if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'lastValidBlockHeight')) {
|
|
9909
10170
|
confirmationStrategy = confirmationStrategyOrConfirmOptions;
|
|
9910
10171
|
options = maybeConfirmOptions;
|
|
10172
|
+
} else if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'nonceValue')) {
|
|
10173
|
+
confirmationStrategy = confirmationStrategyOrConfirmOptions;
|
|
10174
|
+
options = maybeConfirmOptions;
|
|
9911
10175
|
} else {
|
|
9912
10176
|
options = confirmationStrategyOrConfirmOptions;
|
|
9913
10177
|
}
|
|
@@ -9935,5 +10199,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9935
10199
|
|
|
9936
10200
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9937
10201
|
|
|
9938
|
-
export { Account, AddressLookupTableAccount, AddressLookupTableInstruction, AddressLookupTableProgram, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, LOOKUP_TABLE_INSTRUCTION_LAYOUTS, Loader, Lockup, MAX_SEED_LENGTH, Message, MessageAccountKeys, MessageV0, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PUBLIC_KEY_LENGTH, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionMessage, TransactionStatus, VALIDATOR_INFO_KEY, VERSION_PREFIX_MASK, VOTE_PROGRAM_ID, ValidatorInfo, VersionedMessage, VersionedTransaction, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
10202
|
+
export { Account, AddressLookupTableAccount, AddressLookupTableInstruction, AddressLookupTableProgram, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, LOOKUP_TABLE_INSTRUCTION_LAYOUTS, Loader, Lockup, MAX_SEED_LENGTH, Message, MessageAccountKeys, MessageV0, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PUBLIC_KEY_LENGTH, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredNonceInvalidError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionMessage, TransactionStatus, VALIDATOR_INFO_KEY, VERSION_PREFIX_MASK, VOTE_PROGRAM_ID, ValidatorInfo, VersionedMessage, VersionedTransaction, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9939
10203
|
//# sourceMappingURL=index.esm.js.map
|