@solana/web3.js 1.66.5 → 1.67.1
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 +341 -72
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +341 -73
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +341 -72
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +87 -7
- package/lib/index.esm.js +341 -73
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +341 -72
- 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 +341 -72
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -3
- package/src/account.ts +1 -1
- package/src/connection.ts +320 -76
- package/src/message/legacy.ts +4 -4
- package/src/nonce-account.ts +7 -3
- package/src/publickey.ts +6 -2
- package/src/transaction/expiry-custom-errors.ts +13 -0
- package/src/transaction/legacy.ts +39 -3
- package/src/transaction/message.ts +3 -1
- package/src/utils/send-and-confirm-raw-transaction.ts +13 -0
- package/src/utils/send-and-confirm-transaction.ts +39 -18
package/lib/index.cjs.js
CHANGED
|
@@ -183,13 +183,13 @@ class PublicKey extends Struct {
|
|
|
183
183
|
this._bn = new BN__default["default"](value);
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
if (this._bn.byteLength() >
|
|
186
|
+
if (this._bn.byteLength() > PUBLIC_KEY_LENGTH) {
|
|
187
187
|
throw new Error(`Invalid public key input`);
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
/**
|
|
192
|
-
* Returns a unique PublicKey for tests and benchmarks using
|
|
192
|
+
* Returns a unique PublicKey for tests and benchmarks using a counter
|
|
193
193
|
*/
|
|
194
194
|
|
|
195
195
|
|
|
@@ -296,6 +296,8 @@ class PublicKey extends Struct {
|
|
|
296
296
|
/**
|
|
297
297
|
* Async version of createProgramAddressSync
|
|
298
298
|
* For backwards compatibility
|
|
299
|
+
*
|
|
300
|
+
* @deprecated Use {@link createProgramAddressSync} instead
|
|
299
301
|
*/
|
|
300
302
|
|
|
301
303
|
/* eslint-disable require-await */
|
|
@@ -338,6 +340,8 @@ class PublicKey extends Struct {
|
|
|
338
340
|
/**
|
|
339
341
|
* Async version of findProgramAddressSync
|
|
340
342
|
* For backwards compatibility
|
|
343
|
+
*
|
|
344
|
+
* @deprecated Use {@link findProgramAddressSync} instead
|
|
341
345
|
*/
|
|
342
346
|
|
|
343
347
|
|
|
@@ -454,6 +458,17 @@ class TransactionExpiredTimeoutError extends Error {
|
|
|
454
458
|
Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
455
459
|
value: 'TransactionExpiredTimeoutError'
|
|
456
460
|
});
|
|
461
|
+
class TransactionExpiredNonceInvalidError extends Error {
|
|
462
|
+
constructor(signature) {
|
|
463
|
+
super(`Signature ${signature} has expired: the nonce is no longer valid.`);
|
|
464
|
+
this.signature = void 0;
|
|
465
|
+
this.signature = signature;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
}
|
|
469
|
+
Object.defineProperty(TransactionExpiredNonceInvalidError.prototype, 'name', {
|
|
470
|
+
value: 'TransactionExpiredNonceInvalidError'
|
|
471
|
+
});
|
|
457
472
|
|
|
458
473
|
class MessageAccountKeys {
|
|
459
474
|
constructor(staticAccountKeys, accountKeysFromLookups) {
|
|
@@ -1291,6 +1306,7 @@ exports.TransactionStatus = void 0;
|
|
|
1291
1306
|
TransactionStatus[TransactionStatus["BLOCKHEIGHT_EXCEEDED"] = 0] = "BLOCKHEIGHT_EXCEEDED";
|
|
1292
1307
|
TransactionStatus[TransactionStatus["PROCESSED"] = 1] = "PROCESSED";
|
|
1293
1308
|
TransactionStatus[TransactionStatus["TIMED_OUT"] = 2] = "TIMED_OUT";
|
|
1309
|
+
TransactionStatus[TransactionStatus["NONCE_INVALID"] = 3] = "NONCE_INVALID";
|
|
1294
1310
|
})(exports.TransactionStatus || (exports.TransactionStatus = {}));
|
|
1295
1311
|
|
|
1296
1312
|
const DEFAULT_SIGNATURE = buffer.Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
|
@@ -1385,6 +1401,7 @@ class Transaction {
|
|
|
1385
1401
|
this.recentBlockhash = void 0;
|
|
1386
1402
|
this.lastValidBlockHeight = void 0;
|
|
1387
1403
|
this.nonceInfo = void 0;
|
|
1404
|
+
this.minNonceContextSlot = void 0;
|
|
1388
1405
|
this._message = void 0;
|
|
1389
1406
|
this._json = void 0;
|
|
1390
1407
|
|
|
@@ -1400,7 +1417,14 @@ class Transaction {
|
|
|
1400
1417
|
this.signatures = opts.signatures;
|
|
1401
1418
|
}
|
|
1402
1419
|
|
|
1403
|
-
if (Object.prototype.hasOwnProperty.call(opts, '
|
|
1420
|
+
if (Object.prototype.hasOwnProperty.call(opts, 'nonceInfo')) {
|
|
1421
|
+
const {
|
|
1422
|
+
minContextSlot,
|
|
1423
|
+
nonceInfo
|
|
1424
|
+
} = opts;
|
|
1425
|
+
this.minNonceContextSlot = minContextSlot;
|
|
1426
|
+
this.nonceInfo = nonceInfo;
|
|
1427
|
+
} else if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
|
|
1404
1428
|
const {
|
|
1405
1429
|
blockhash,
|
|
1406
1430
|
lastValidBlockHeight
|
|
@@ -2033,7 +2057,7 @@ class TransactionMessage {
|
|
|
2033
2057
|
} = header;
|
|
2034
2058
|
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
2035
2059
|
assert(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
2036
|
-
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
2060
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numRequiredSignatures - numReadonlyUnsignedAccounts;
|
|
2037
2061
|
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
2038
2062
|
const accountKeys = message.getAccountKeys(args);
|
|
2039
2063
|
const payerKey = accountKeys.get(0);
|
|
@@ -2217,11 +2241,28 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2217
2241
|
minContextSlot: options.minContextSlot
|
|
2218
2242
|
};
|
|
2219
2243
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2244
|
+
let status;
|
|
2245
|
+
|
|
2246
|
+
if (transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null) {
|
|
2247
|
+
status = (await connection.confirmTransaction({
|
|
2248
|
+
signature: signature,
|
|
2249
|
+
blockhash: transaction.recentBlockhash,
|
|
2250
|
+
lastValidBlockHeight: transaction.lastValidBlockHeight
|
|
2251
|
+
}, options && options.commitment)).value;
|
|
2252
|
+
} else if (transaction.minNonceContextSlot != null && transaction.nonceInfo != null) {
|
|
2253
|
+
const {
|
|
2254
|
+
nonceInstruction
|
|
2255
|
+
} = transaction.nonceInfo;
|
|
2256
|
+
const nonceAccountPubkey = nonceInstruction.keys[0].pubkey;
|
|
2257
|
+
status = (await connection.confirmTransaction({
|
|
2258
|
+
minContextSlot: transaction.minNonceContextSlot,
|
|
2259
|
+
nonceAccountPubkey,
|
|
2260
|
+
nonceValue: transaction.nonceInfo.nonce,
|
|
2261
|
+
signature
|
|
2262
|
+
}, options && options.commitment)).value;
|
|
2263
|
+
} else {
|
|
2264
|
+
status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2265
|
+
}
|
|
2225
2266
|
|
|
2226
2267
|
if (status.err) {
|
|
2227
2268
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
@@ -2290,6 +2331,9 @@ const FeeCalculatorLayout = BufferLayout__namespace.nu64('lamportsPerSignature')
|
|
|
2290
2331
|
|
|
2291
2332
|
const NonceAccountLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u32('version'), BufferLayout__namespace.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout__namespace.struct([FeeCalculatorLayout], 'feeCalculator')]);
|
|
2292
2333
|
const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
|
|
2334
|
+
/**
|
|
2335
|
+
* A durable nonce is a 32 byte value encoded as a base58 string.
|
|
2336
|
+
*/
|
|
2293
2337
|
|
|
2294
2338
|
/**
|
|
2295
2339
|
* NonceAccount class
|
|
@@ -3704,10 +3748,13 @@ function extractCommitmentFromConfig(commitmentOrConfig) {
|
|
|
3704
3748
|
};
|
|
3705
3749
|
}
|
|
3706
3750
|
/**
|
|
3707
|
-
*
|
|
3751
|
+
* A strategy for confirming durable nonce transactions.
|
|
3708
3752
|
*/
|
|
3709
3753
|
|
|
3710
3754
|
|
|
3755
|
+
/**
|
|
3756
|
+
* @internal
|
|
3757
|
+
*/
|
|
3711
3758
|
function createRpcResult(result) {
|
|
3712
3759
|
return superstruct.union([superstruct.type({
|
|
3713
3760
|
jsonrpc: superstruct.literal('2.0'),
|
|
@@ -5279,25 +5326,45 @@ class Connection {
|
|
|
5279
5326
|
}
|
|
5280
5327
|
|
|
5281
5328
|
assert(decodedSignature.length === 64, 'signature has invalid length');
|
|
5282
|
-
|
|
5283
|
-
|
|
5329
|
+
|
|
5330
|
+
if (typeof strategy === 'string') {
|
|
5331
|
+
return await this.confirmTransactionUsingLegacyTimeoutStrategy({
|
|
5332
|
+
commitment: commitment || this.commitment,
|
|
5333
|
+
signature: rawSignature
|
|
5334
|
+
});
|
|
5335
|
+
} else if ('lastValidBlockHeight' in strategy) {
|
|
5336
|
+
return await this.confirmTransactionUsingBlockHeightExceedanceStrategy({
|
|
5337
|
+
commitment: commitment || this.commitment,
|
|
5338
|
+
strategy
|
|
5339
|
+
});
|
|
5340
|
+
} else {
|
|
5341
|
+
return await this.confirmTransactionUsingDurableNonceStrategy({
|
|
5342
|
+
commitment: commitment || this.commitment,
|
|
5343
|
+
strategy
|
|
5344
|
+
});
|
|
5345
|
+
}
|
|
5346
|
+
}
|
|
5347
|
+
|
|
5348
|
+
getTransactionConfirmationPromise({
|
|
5349
|
+
commitment,
|
|
5350
|
+
signature
|
|
5351
|
+
}) {
|
|
5284
5352
|
let signatureSubscriptionId;
|
|
5285
5353
|
let disposeSignatureSubscriptionStateChangeObserver;
|
|
5286
5354
|
let done = false;
|
|
5287
5355
|
const confirmationPromise = new Promise((resolve, reject) => {
|
|
5288
5356
|
try {
|
|
5289
|
-
signatureSubscriptionId = this.onSignature(
|
|
5357
|
+
signatureSubscriptionId = this.onSignature(signature, (result, context) => {
|
|
5290
5358
|
signatureSubscriptionId = undefined;
|
|
5291
5359
|
const response = {
|
|
5292
5360
|
context,
|
|
5293
5361
|
value: result
|
|
5294
5362
|
};
|
|
5295
|
-
done = true;
|
|
5296
5363
|
resolve({
|
|
5297
5364
|
__type: exports.TransactionStatus.PROCESSED,
|
|
5298
5365
|
response
|
|
5299
5366
|
});
|
|
5300
|
-
},
|
|
5367
|
+
}, commitment);
|
|
5301
5368
|
const subscriptionSetupPromise = new Promise(resolveSubscriptionSetup => {
|
|
5302
5369
|
if (signatureSubscriptionId == null) {
|
|
5303
5370
|
resolveSubscriptionSetup();
|
|
@@ -5313,7 +5380,7 @@ class Connection {
|
|
|
5313
5380
|
(async () => {
|
|
5314
5381
|
await subscriptionSetupPromise;
|
|
5315
5382
|
if (done) return;
|
|
5316
|
-
const response = await this.getSignatureStatus(
|
|
5383
|
+
const response = await this.getSignatureStatus(signature);
|
|
5317
5384
|
if (done) return;
|
|
5318
5385
|
|
|
5319
5386
|
if (response == null) {
|
|
@@ -5332,7 +5399,7 @@ class Connection {
|
|
|
5332
5399
|
if (value !== null && value !== void 0 && value.err) {
|
|
5333
5400
|
reject(value.err);
|
|
5334
5401
|
} else {
|
|
5335
|
-
switch (
|
|
5402
|
+
switch (commitment) {
|
|
5336
5403
|
case 'confirmed':
|
|
5337
5404
|
case 'single':
|
|
5338
5405
|
case 'singleGossip':
|
|
@@ -5374,81 +5441,279 @@ class Connection {
|
|
|
5374
5441
|
reject(err);
|
|
5375
5442
|
}
|
|
5376
5443
|
});
|
|
5444
|
+
|
|
5445
|
+
const abortConfirmation = () => {
|
|
5446
|
+
if (disposeSignatureSubscriptionStateChangeObserver) {
|
|
5447
|
+
disposeSignatureSubscriptionStateChangeObserver();
|
|
5448
|
+
disposeSignatureSubscriptionStateChangeObserver = undefined;
|
|
5449
|
+
}
|
|
5450
|
+
|
|
5451
|
+
if (signatureSubscriptionId) {
|
|
5452
|
+
this.removeSignatureListener(signatureSubscriptionId);
|
|
5453
|
+
signatureSubscriptionId = undefined;
|
|
5454
|
+
}
|
|
5455
|
+
};
|
|
5456
|
+
|
|
5457
|
+
return {
|
|
5458
|
+
abortConfirmation,
|
|
5459
|
+
confirmationPromise
|
|
5460
|
+
};
|
|
5461
|
+
}
|
|
5462
|
+
|
|
5463
|
+
async confirmTransactionUsingBlockHeightExceedanceStrategy({
|
|
5464
|
+
commitment,
|
|
5465
|
+
strategy: {
|
|
5466
|
+
lastValidBlockHeight,
|
|
5467
|
+
signature
|
|
5468
|
+
}
|
|
5469
|
+
}) {
|
|
5470
|
+
let done = false;
|
|
5377
5471
|
const expiryPromise = new Promise(resolve => {
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5472
|
+
const checkBlockHeight = async () => {
|
|
5473
|
+
try {
|
|
5474
|
+
const blockHeight = await this.getBlockHeight(commitment);
|
|
5475
|
+
return blockHeight;
|
|
5476
|
+
} catch (_e) {
|
|
5477
|
+
return -1;
|
|
5478
|
+
}
|
|
5479
|
+
};
|
|
5480
|
+
|
|
5481
|
+
(async () => {
|
|
5482
|
+
let currentBlockHeight = await checkBlockHeight();
|
|
5483
|
+
if (done) return;
|
|
5484
|
+
|
|
5485
|
+
while (currentBlockHeight <= lastValidBlockHeight) {
|
|
5486
|
+
await sleep(1000);
|
|
5487
|
+
if (done) return;
|
|
5488
|
+
currentBlockHeight = await checkBlockHeight();
|
|
5489
|
+
if (done) return;
|
|
5391
5490
|
}
|
|
5392
5491
|
|
|
5393
|
-
|
|
5394
|
-
__type: exports.TransactionStatus.
|
|
5395
|
-
|
|
5396
|
-
|
|
5492
|
+
resolve({
|
|
5493
|
+
__type: exports.TransactionStatus.BLOCKHEIGHT_EXCEEDED
|
|
5494
|
+
});
|
|
5495
|
+
})();
|
|
5496
|
+
});
|
|
5497
|
+
const {
|
|
5498
|
+
abortConfirmation,
|
|
5499
|
+
confirmationPromise
|
|
5500
|
+
} = this.getTransactionConfirmationPromise({
|
|
5501
|
+
commitment,
|
|
5502
|
+
signature
|
|
5503
|
+
});
|
|
5504
|
+
let result;
|
|
5505
|
+
|
|
5506
|
+
try {
|
|
5507
|
+
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5508
|
+
|
|
5509
|
+
if (outcome.__type === exports.TransactionStatus.PROCESSED) {
|
|
5510
|
+
result = outcome.response;
|
|
5397
5511
|
} else {
|
|
5398
|
-
|
|
5512
|
+
throw new TransactionExpiredBlockheightExceededError(signature);
|
|
5513
|
+
}
|
|
5514
|
+
} finally {
|
|
5515
|
+
done = true;
|
|
5516
|
+
abortConfirmation();
|
|
5517
|
+
}
|
|
5399
5518
|
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
const blockHeight = await this.getBlockHeight(commitment);
|
|
5403
|
-
return blockHeight;
|
|
5404
|
-
} catch (_e) {
|
|
5405
|
-
return -1;
|
|
5406
|
-
}
|
|
5407
|
-
};
|
|
5519
|
+
return result;
|
|
5520
|
+
}
|
|
5408
5521
|
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5522
|
+
async confirmTransactionUsingDurableNonceStrategy({
|
|
5523
|
+
commitment,
|
|
5524
|
+
strategy: {
|
|
5525
|
+
minContextSlot,
|
|
5526
|
+
nonceAccountPubkey,
|
|
5527
|
+
nonceValue,
|
|
5528
|
+
signature
|
|
5529
|
+
}
|
|
5530
|
+
}) {
|
|
5531
|
+
let done = false;
|
|
5532
|
+
const expiryPromise = new Promise(resolve => {
|
|
5533
|
+
let currentNonceValue = nonceValue;
|
|
5534
|
+
let lastCheckedSlot = null;
|
|
5412
5535
|
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5417
|
-
|
|
5536
|
+
const getCurrentNonceValue = async () => {
|
|
5537
|
+
try {
|
|
5538
|
+
const {
|
|
5539
|
+
context,
|
|
5540
|
+
value: nonceAccount
|
|
5541
|
+
} = await this.getNonceAndContext(nonceAccountPubkey, {
|
|
5542
|
+
commitment,
|
|
5543
|
+
minContextSlot
|
|
5544
|
+
});
|
|
5545
|
+
lastCheckedSlot = context.slot;
|
|
5546
|
+
return nonceAccount === null || nonceAccount === void 0 ? void 0 : nonceAccount.nonce;
|
|
5547
|
+
} catch (e) {
|
|
5548
|
+
// If for whatever reason we can't reach/read the nonce
|
|
5549
|
+
// account, just keep using the last-known value.
|
|
5550
|
+
return currentNonceValue;
|
|
5551
|
+
}
|
|
5552
|
+
};
|
|
5553
|
+
|
|
5554
|
+
(async () => {
|
|
5555
|
+
currentNonceValue = await getCurrentNonceValue();
|
|
5556
|
+
if (done) return;
|
|
5557
|
+
|
|
5558
|
+
while (true // eslint-disable-line no-constant-condition
|
|
5559
|
+
) {
|
|
5560
|
+
if (nonceValue !== currentNonceValue) {
|
|
5561
|
+
resolve({
|
|
5562
|
+
__type: exports.TransactionStatus.NONCE_INVALID,
|
|
5563
|
+
slotInWhichNonceDidAdvance: lastCheckedSlot
|
|
5564
|
+
});
|
|
5565
|
+
return;
|
|
5418
5566
|
}
|
|
5419
5567
|
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
|
|
5568
|
+
await sleep(2000);
|
|
5569
|
+
if (done) return;
|
|
5570
|
+
currentNonceValue = await getCurrentNonceValue();
|
|
5571
|
+
if (done) return;
|
|
5572
|
+
}
|
|
5573
|
+
})();
|
|
5574
|
+
});
|
|
5575
|
+
const {
|
|
5576
|
+
abortConfirmation,
|
|
5577
|
+
confirmationPromise
|
|
5578
|
+
} = this.getTransactionConfirmationPromise({
|
|
5579
|
+
commitment,
|
|
5580
|
+
signature
|
|
5425
5581
|
});
|
|
5426
5582
|
let result;
|
|
5427
5583
|
|
|
5428
5584
|
try {
|
|
5429
5585
|
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5430
5586
|
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5587
|
+
if (outcome.__type === exports.TransactionStatus.PROCESSED) {
|
|
5588
|
+
result = outcome.response;
|
|
5589
|
+
} else {
|
|
5590
|
+
var _signatureStatus;
|
|
5591
|
+
|
|
5592
|
+
// Double check that the transaction is indeed unconfirmed.
|
|
5593
|
+
let signatureStatus;
|
|
5594
|
+
|
|
5595
|
+
while (true // eslint-disable-line no-constant-condition
|
|
5596
|
+
) {
|
|
5597
|
+
var _outcome$slotInWhichN;
|
|
5598
|
+
|
|
5599
|
+
const status = await this.getSignatureStatus(signature);
|
|
5600
|
+
|
|
5601
|
+
if (status == null) {
|
|
5602
|
+
break;
|
|
5603
|
+
}
|
|
5434
5604
|
|
|
5435
|
-
|
|
5436
|
-
|
|
5605
|
+
if (status.context.slot < ((_outcome$slotInWhichN = outcome.slotInWhichNonceDidAdvance) !== null && _outcome$slotInWhichN !== void 0 ? _outcome$slotInWhichN : minContextSlot)) {
|
|
5606
|
+
await sleep(400);
|
|
5607
|
+
continue;
|
|
5608
|
+
}
|
|
5609
|
+
|
|
5610
|
+
signatureStatus = status;
|
|
5437
5611
|
break;
|
|
5612
|
+
}
|
|
5613
|
+
|
|
5614
|
+
if ((_signatureStatus = signatureStatus) !== null && _signatureStatus !== void 0 && _signatureStatus.value) {
|
|
5615
|
+
const commitmentForStatus = commitment || 'finalized';
|
|
5616
|
+
const {
|
|
5617
|
+
confirmationStatus
|
|
5618
|
+
} = signatureStatus.value;
|
|
5619
|
+
|
|
5620
|
+
switch (commitmentForStatus) {
|
|
5621
|
+
case 'processed':
|
|
5622
|
+
case 'recent':
|
|
5623
|
+
if (confirmationStatus !== 'processed' && confirmationStatus !== 'confirmed' && confirmationStatus !== 'finalized') {
|
|
5624
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5625
|
+
}
|
|
5626
|
+
|
|
5627
|
+
break;
|
|
5628
|
+
|
|
5629
|
+
case 'confirmed':
|
|
5630
|
+
case 'single':
|
|
5631
|
+
case 'singleGossip':
|
|
5632
|
+
if (confirmationStatus !== 'confirmed' && confirmationStatus !== 'finalized') {
|
|
5633
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5634
|
+
}
|
|
5438
5635
|
|
|
5439
|
-
|
|
5440
|
-
|
|
5636
|
+
break;
|
|
5637
|
+
|
|
5638
|
+
case 'finalized':
|
|
5639
|
+
case 'max':
|
|
5640
|
+
case 'root':
|
|
5641
|
+
if (confirmationStatus !== 'finalized') {
|
|
5642
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5643
|
+
}
|
|
5644
|
+
|
|
5645
|
+
break;
|
|
5646
|
+
|
|
5647
|
+
default:
|
|
5648
|
+
// Exhaustive switch.
|
|
5649
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5650
|
+
(_ => {})(commitmentForStatus);
|
|
5651
|
+
|
|
5652
|
+
}
|
|
5653
|
+
|
|
5654
|
+
result = {
|
|
5655
|
+
context: signatureStatus.context,
|
|
5656
|
+
value: {
|
|
5657
|
+
err: signatureStatus.value.err
|
|
5658
|
+
}
|
|
5659
|
+
};
|
|
5660
|
+
} else {
|
|
5661
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5662
|
+
}
|
|
5441
5663
|
}
|
|
5442
5664
|
} finally {
|
|
5443
|
-
|
|
5665
|
+
done = true;
|
|
5666
|
+
abortConfirmation();
|
|
5667
|
+
}
|
|
5444
5668
|
|
|
5445
|
-
|
|
5446
|
-
|
|
5669
|
+
return result;
|
|
5670
|
+
}
|
|
5671
|
+
|
|
5672
|
+
async confirmTransactionUsingLegacyTimeoutStrategy({
|
|
5673
|
+
commitment,
|
|
5674
|
+
signature
|
|
5675
|
+
}) {
|
|
5676
|
+
let timeoutId;
|
|
5677
|
+
const expiryPromise = new Promise(resolve => {
|
|
5678
|
+
let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
|
|
5679
|
+
|
|
5680
|
+
switch (commitment) {
|
|
5681
|
+
case 'processed':
|
|
5682
|
+
case 'recent':
|
|
5683
|
+
case 'single':
|
|
5684
|
+
case 'confirmed':
|
|
5685
|
+
case 'singleGossip':
|
|
5686
|
+
{
|
|
5687
|
+
timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
|
|
5688
|
+
break;
|
|
5689
|
+
}
|
|
5447
5690
|
}
|
|
5448
5691
|
|
|
5449
|
-
|
|
5450
|
-
|
|
5692
|
+
timeoutId = setTimeout(() => resolve({
|
|
5693
|
+
__type: exports.TransactionStatus.TIMED_OUT,
|
|
5694
|
+
timeoutMs
|
|
5695
|
+
}), timeoutMs);
|
|
5696
|
+
});
|
|
5697
|
+
const {
|
|
5698
|
+
abortConfirmation,
|
|
5699
|
+
confirmationPromise
|
|
5700
|
+
} = this.getTransactionConfirmationPromise({
|
|
5701
|
+
commitment,
|
|
5702
|
+
signature
|
|
5703
|
+
});
|
|
5704
|
+
let result;
|
|
5705
|
+
|
|
5706
|
+
try {
|
|
5707
|
+
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5708
|
+
|
|
5709
|
+
if (outcome.__type === exports.TransactionStatus.PROCESSED) {
|
|
5710
|
+
result = outcome.response;
|
|
5711
|
+
} else {
|
|
5712
|
+
throw new TransactionExpiredTimeoutError(signature, outcome.timeoutMs / 1000);
|
|
5451
5713
|
}
|
|
5714
|
+
} finally {
|
|
5715
|
+
clearTimeout(timeoutId);
|
|
5716
|
+
abortConfirmation();
|
|
5452
5717
|
}
|
|
5453
5718
|
|
|
5454
5719
|
return result;
|
|
@@ -6504,11 +6769,11 @@ class Connection {
|
|
|
6504
6769
|
*/
|
|
6505
6770
|
|
|
6506
6771
|
|
|
6507
|
-
async getNonceAndContext(nonceAccount,
|
|
6772
|
+
async getNonceAndContext(nonceAccount, commitmentOrConfig) {
|
|
6508
6773
|
const {
|
|
6509
6774
|
context,
|
|
6510
6775
|
value: accountInfo
|
|
6511
|
-
} = await this.getAccountInfoAndContext(nonceAccount,
|
|
6776
|
+
} = await this.getAccountInfoAndContext(nonceAccount, commitmentOrConfig);
|
|
6512
6777
|
let value = null;
|
|
6513
6778
|
|
|
6514
6779
|
if (accountInfo !== null) {
|
|
@@ -6525,8 +6790,8 @@ class Connection {
|
|
|
6525
6790
|
*/
|
|
6526
6791
|
|
|
6527
6792
|
|
|
6528
|
-
async getNonce(nonceAccount,
|
|
6529
|
-
return await this.getNonceAndContext(nonceAccount,
|
|
6793
|
+
async getNonce(nonceAccount, commitmentOrConfig) {
|
|
6794
|
+
return await this.getNonceAndContext(nonceAccount, commitmentOrConfig).then(x => x.value).catch(e => {
|
|
6530
6795
|
throw new Error('failed to get nonce for account ' + nonceAccount.toBase58() + ': ' + e);
|
|
6531
6796
|
});
|
|
6532
6797
|
}
|
|
@@ -9941,6 +10206,9 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9941
10206
|
if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'lastValidBlockHeight')) {
|
|
9942
10207
|
confirmationStrategy = confirmationStrategyOrConfirmOptions;
|
|
9943
10208
|
options = maybeConfirmOptions;
|
|
10209
|
+
} else if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'nonceValue')) {
|
|
10210
|
+
confirmationStrategy = confirmationStrategyOrConfirmOptions;
|
|
10211
|
+
options = maybeConfirmOptions;
|
|
9944
10212
|
} else {
|
|
9945
10213
|
options = confirmationStrategyOrConfirmOptions;
|
|
9946
10214
|
}
|
|
@@ -10025,6 +10293,7 @@ exports.SystemInstruction = SystemInstruction;
|
|
|
10025
10293
|
exports.SystemProgram = SystemProgram;
|
|
10026
10294
|
exports.Transaction = Transaction;
|
|
10027
10295
|
exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheightExceededError;
|
|
10296
|
+
exports.TransactionExpiredNonceInvalidError = TransactionExpiredNonceInvalidError;
|
|
10028
10297
|
exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
|
|
10029
10298
|
exports.TransactionInstruction = TransactionInstruction;
|
|
10030
10299
|
exports.TransactionMessage = TransactionMessage;
|