@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.esm.js
CHANGED
|
@@ -150,13 +150,13 @@ class PublicKey extends Struct {
|
|
|
150
150
|
this._bn = new BN(value);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
if (this._bn.byteLength() >
|
|
153
|
+
if (this._bn.byteLength() > PUBLIC_KEY_LENGTH) {
|
|
154
154
|
throw new Error(`Invalid public key input`);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
/**
|
|
159
|
-
* Returns a unique PublicKey for tests and benchmarks using
|
|
159
|
+
* Returns a unique PublicKey for tests and benchmarks using a counter
|
|
160
160
|
*/
|
|
161
161
|
|
|
162
162
|
|
|
@@ -263,6 +263,8 @@ class PublicKey extends Struct {
|
|
|
263
263
|
/**
|
|
264
264
|
* Async version of createProgramAddressSync
|
|
265
265
|
* For backwards compatibility
|
|
266
|
+
*
|
|
267
|
+
* @deprecated Use {@link createProgramAddressSync} instead
|
|
266
268
|
*/
|
|
267
269
|
|
|
268
270
|
/* eslint-disable require-await */
|
|
@@ -305,6 +307,8 @@ class PublicKey extends Struct {
|
|
|
305
307
|
/**
|
|
306
308
|
* Async version of findProgramAddressSync
|
|
307
309
|
* For backwards compatibility
|
|
310
|
+
*
|
|
311
|
+
* @deprecated Use {@link findProgramAddressSync} instead
|
|
308
312
|
*/
|
|
309
313
|
|
|
310
314
|
|
|
@@ -421,6 +425,17 @@ class TransactionExpiredTimeoutError extends Error {
|
|
|
421
425
|
Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
422
426
|
value: 'TransactionExpiredTimeoutError'
|
|
423
427
|
});
|
|
428
|
+
class TransactionExpiredNonceInvalidError extends Error {
|
|
429
|
+
constructor(signature) {
|
|
430
|
+
super(`Signature ${signature} has expired: the nonce is no longer valid.`);
|
|
431
|
+
this.signature = void 0;
|
|
432
|
+
this.signature = signature;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
}
|
|
436
|
+
Object.defineProperty(TransactionExpiredNonceInvalidError.prototype, 'name', {
|
|
437
|
+
value: 'TransactionExpiredNonceInvalidError'
|
|
438
|
+
});
|
|
424
439
|
|
|
425
440
|
class MessageAccountKeys {
|
|
426
441
|
constructor(staticAccountKeys, accountKeysFromLookups) {
|
|
@@ -1258,6 +1273,7 @@ let TransactionStatus;
|
|
|
1258
1273
|
TransactionStatus[TransactionStatus["BLOCKHEIGHT_EXCEEDED"] = 0] = "BLOCKHEIGHT_EXCEEDED";
|
|
1259
1274
|
TransactionStatus[TransactionStatus["PROCESSED"] = 1] = "PROCESSED";
|
|
1260
1275
|
TransactionStatus[TransactionStatus["TIMED_OUT"] = 2] = "TIMED_OUT";
|
|
1276
|
+
TransactionStatus[TransactionStatus["NONCE_INVALID"] = 3] = "NONCE_INVALID";
|
|
1261
1277
|
})(TransactionStatus || (TransactionStatus = {}));
|
|
1262
1278
|
|
|
1263
1279
|
const DEFAULT_SIGNATURE = Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
|
@@ -1352,6 +1368,7 @@ class Transaction {
|
|
|
1352
1368
|
this.recentBlockhash = void 0;
|
|
1353
1369
|
this.lastValidBlockHeight = void 0;
|
|
1354
1370
|
this.nonceInfo = void 0;
|
|
1371
|
+
this.minNonceContextSlot = void 0;
|
|
1355
1372
|
this._message = void 0;
|
|
1356
1373
|
this._json = void 0;
|
|
1357
1374
|
|
|
@@ -1367,7 +1384,14 @@ class Transaction {
|
|
|
1367
1384
|
this.signatures = opts.signatures;
|
|
1368
1385
|
}
|
|
1369
1386
|
|
|
1370
|
-
if (Object.prototype.hasOwnProperty.call(opts, '
|
|
1387
|
+
if (Object.prototype.hasOwnProperty.call(opts, 'nonceInfo')) {
|
|
1388
|
+
const {
|
|
1389
|
+
minContextSlot,
|
|
1390
|
+
nonceInfo
|
|
1391
|
+
} = opts;
|
|
1392
|
+
this.minNonceContextSlot = minContextSlot;
|
|
1393
|
+
this.nonceInfo = nonceInfo;
|
|
1394
|
+
} else if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
|
|
1371
1395
|
const {
|
|
1372
1396
|
blockhash,
|
|
1373
1397
|
lastValidBlockHeight
|
|
@@ -2000,7 +2024,7 @@ class TransactionMessage {
|
|
|
2000
2024
|
} = header;
|
|
2001
2025
|
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
2002
2026
|
assert(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
2003
|
-
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
2027
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numRequiredSignatures - numReadonlyUnsignedAccounts;
|
|
2004
2028
|
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
2005
2029
|
const accountKeys = message.getAccountKeys(args);
|
|
2006
2030
|
const payerKey = accountKeys.get(0);
|
|
@@ -2184,11 +2208,28 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2184
2208
|
minContextSlot: options.minContextSlot
|
|
2185
2209
|
};
|
|
2186
2210
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2211
|
+
let status;
|
|
2212
|
+
|
|
2213
|
+
if (transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null) {
|
|
2214
|
+
status = (await connection.confirmTransaction({
|
|
2215
|
+
signature: signature,
|
|
2216
|
+
blockhash: transaction.recentBlockhash,
|
|
2217
|
+
lastValidBlockHeight: transaction.lastValidBlockHeight
|
|
2218
|
+
}, options && options.commitment)).value;
|
|
2219
|
+
} else if (transaction.minNonceContextSlot != null && transaction.nonceInfo != null) {
|
|
2220
|
+
const {
|
|
2221
|
+
nonceInstruction
|
|
2222
|
+
} = transaction.nonceInfo;
|
|
2223
|
+
const nonceAccountPubkey = nonceInstruction.keys[0].pubkey;
|
|
2224
|
+
status = (await connection.confirmTransaction({
|
|
2225
|
+
minContextSlot: transaction.minNonceContextSlot,
|
|
2226
|
+
nonceAccountPubkey,
|
|
2227
|
+
nonceValue: transaction.nonceInfo.nonce,
|
|
2228
|
+
signature
|
|
2229
|
+
}, options && options.commitment)).value;
|
|
2230
|
+
} else {
|
|
2231
|
+
status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2232
|
+
}
|
|
2192
2233
|
|
|
2193
2234
|
if (status.err) {
|
|
2194
2235
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
@@ -2257,6 +2298,9 @@ const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
|
|
|
2257
2298
|
|
|
2258
2299
|
const NonceAccountLayout = BufferLayout.struct([BufferLayout.u32('version'), BufferLayout.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout.struct([FeeCalculatorLayout], 'feeCalculator')]);
|
|
2259
2300
|
const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
|
|
2301
|
+
/**
|
|
2302
|
+
* A durable nonce is a 32 byte value encoded as a base58 string.
|
|
2303
|
+
*/
|
|
2260
2304
|
|
|
2261
2305
|
/**
|
|
2262
2306
|
* NonceAccount class
|
|
@@ -3671,10 +3715,13 @@ function extractCommitmentFromConfig(commitmentOrConfig) {
|
|
|
3671
3715
|
};
|
|
3672
3716
|
}
|
|
3673
3717
|
/**
|
|
3674
|
-
*
|
|
3718
|
+
* A strategy for confirming durable nonce transactions.
|
|
3675
3719
|
*/
|
|
3676
3720
|
|
|
3677
3721
|
|
|
3722
|
+
/**
|
|
3723
|
+
* @internal
|
|
3724
|
+
*/
|
|
3678
3725
|
function createRpcResult(result) {
|
|
3679
3726
|
return union([type({
|
|
3680
3727
|
jsonrpc: literal('2.0'),
|
|
@@ -5246,25 +5293,45 @@ class Connection {
|
|
|
5246
5293
|
}
|
|
5247
5294
|
|
|
5248
5295
|
assert(decodedSignature.length === 64, 'signature has invalid length');
|
|
5249
|
-
|
|
5250
|
-
|
|
5296
|
+
|
|
5297
|
+
if (typeof strategy === 'string') {
|
|
5298
|
+
return await this.confirmTransactionUsingLegacyTimeoutStrategy({
|
|
5299
|
+
commitment: commitment || this.commitment,
|
|
5300
|
+
signature: rawSignature
|
|
5301
|
+
});
|
|
5302
|
+
} else if ('lastValidBlockHeight' in strategy) {
|
|
5303
|
+
return await this.confirmTransactionUsingBlockHeightExceedanceStrategy({
|
|
5304
|
+
commitment: commitment || this.commitment,
|
|
5305
|
+
strategy
|
|
5306
|
+
});
|
|
5307
|
+
} else {
|
|
5308
|
+
return await this.confirmTransactionUsingDurableNonceStrategy({
|
|
5309
|
+
commitment: commitment || this.commitment,
|
|
5310
|
+
strategy
|
|
5311
|
+
});
|
|
5312
|
+
}
|
|
5313
|
+
}
|
|
5314
|
+
|
|
5315
|
+
getTransactionConfirmationPromise({
|
|
5316
|
+
commitment,
|
|
5317
|
+
signature
|
|
5318
|
+
}) {
|
|
5251
5319
|
let signatureSubscriptionId;
|
|
5252
5320
|
let disposeSignatureSubscriptionStateChangeObserver;
|
|
5253
5321
|
let done = false;
|
|
5254
5322
|
const confirmationPromise = new Promise((resolve, reject) => {
|
|
5255
5323
|
try {
|
|
5256
|
-
signatureSubscriptionId = this.onSignature(
|
|
5324
|
+
signatureSubscriptionId = this.onSignature(signature, (result, context) => {
|
|
5257
5325
|
signatureSubscriptionId = undefined;
|
|
5258
5326
|
const response = {
|
|
5259
5327
|
context,
|
|
5260
5328
|
value: result
|
|
5261
5329
|
};
|
|
5262
|
-
done = true;
|
|
5263
5330
|
resolve({
|
|
5264
5331
|
__type: TransactionStatus.PROCESSED,
|
|
5265
5332
|
response
|
|
5266
5333
|
});
|
|
5267
|
-
},
|
|
5334
|
+
}, commitment);
|
|
5268
5335
|
const subscriptionSetupPromise = new Promise(resolveSubscriptionSetup => {
|
|
5269
5336
|
if (signatureSubscriptionId == null) {
|
|
5270
5337
|
resolveSubscriptionSetup();
|
|
@@ -5280,7 +5347,7 @@ class Connection {
|
|
|
5280
5347
|
(async () => {
|
|
5281
5348
|
await subscriptionSetupPromise;
|
|
5282
5349
|
if (done) return;
|
|
5283
|
-
const response = await this.getSignatureStatus(
|
|
5350
|
+
const response = await this.getSignatureStatus(signature);
|
|
5284
5351
|
if (done) return;
|
|
5285
5352
|
|
|
5286
5353
|
if (response == null) {
|
|
@@ -5299,7 +5366,7 @@ class Connection {
|
|
|
5299
5366
|
if (value !== null && value !== void 0 && value.err) {
|
|
5300
5367
|
reject(value.err);
|
|
5301
5368
|
} else {
|
|
5302
|
-
switch (
|
|
5369
|
+
switch (commitment) {
|
|
5303
5370
|
case 'confirmed':
|
|
5304
5371
|
case 'single':
|
|
5305
5372
|
case 'singleGossip':
|
|
@@ -5341,81 +5408,279 @@ class Connection {
|
|
|
5341
5408
|
reject(err);
|
|
5342
5409
|
}
|
|
5343
5410
|
});
|
|
5411
|
+
|
|
5412
|
+
const abortConfirmation = () => {
|
|
5413
|
+
if (disposeSignatureSubscriptionStateChangeObserver) {
|
|
5414
|
+
disposeSignatureSubscriptionStateChangeObserver();
|
|
5415
|
+
disposeSignatureSubscriptionStateChangeObserver = undefined;
|
|
5416
|
+
}
|
|
5417
|
+
|
|
5418
|
+
if (signatureSubscriptionId) {
|
|
5419
|
+
this.removeSignatureListener(signatureSubscriptionId);
|
|
5420
|
+
signatureSubscriptionId = undefined;
|
|
5421
|
+
}
|
|
5422
|
+
};
|
|
5423
|
+
|
|
5424
|
+
return {
|
|
5425
|
+
abortConfirmation,
|
|
5426
|
+
confirmationPromise
|
|
5427
|
+
};
|
|
5428
|
+
}
|
|
5429
|
+
|
|
5430
|
+
async confirmTransactionUsingBlockHeightExceedanceStrategy({
|
|
5431
|
+
commitment,
|
|
5432
|
+
strategy: {
|
|
5433
|
+
lastValidBlockHeight,
|
|
5434
|
+
signature
|
|
5435
|
+
}
|
|
5436
|
+
}) {
|
|
5437
|
+
let done = false;
|
|
5344
5438
|
const expiryPromise = new Promise(resolve => {
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5439
|
+
const checkBlockHeight = async () => {
|
|
5440
|
+
try {
|
|
5441
|
+
const blockHeight = await this.getBlockHeight(commitment);
|
|
5442
|
+
return blockHeight;
|
|
5443
|
+
} catch (_e) {
|
|
5444
|
+
return -1;
|
|
5445
|
+
}
|
|
5446
|
+
};
|
|
5447
|
+
|
|
5448
|
+
(async () => {
|
|
5449
|
+
let currentBlockHeight = await checkBlockHeight();
|
|
5450
|
+
if (done) return;
|
|
5451
|
+
|
|
5452
|
+
while (currentBlockHeight <= lastValidBlockHeight) {
|
|
5453
|
+
await sleep(1000);
|
|
5454
|
+
if (done) return;
|
|
5455
|
+
currentBlockHeight = await checkBlockHeight();
|
|
5456
|
+
if (done) return;
|
|
5358
5457
|
}
|
|
5359
5458
|
|
|
5360
|
-
|
|
5361
|
-
__type: TransactionStatus.
|
|
5362
|
-
|
|
5363
|
-
|
|
5459
|
+
resolve({
|
|
5460
|
+
__type: TransactionStatus.BLOCKHEIGHT_EXCEEDED
|
|
5461
|
+
});
|
|
5462
|
+
})();
|
|
5463
|
+
});
|
|
5464
|
+
const {
|
|
5465
|
+
abortConfirmation,
|
|
5466
|
+
confirmationPromise
|
|
5467
|
+
} = this.getTransactionConfirmationPromise({
|
|
5468
|
+
commitment,
|
|
5469
|
+
signature
|
|
5470
|
+
});
|
|
5471
|
+
let result;
|
|
5472
|
+
|
|
5473
|
+
try {
|
|
5474
|
+
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5475
|
+
|
|
5476
|
+
if (outcome.__type === TransactionStatus.PROCESSED) {
|
|
5477
|
+
result = outcome.response;
|
|
5364
5478
|
} else {
|
|
5365
|
-
|
|
5479
|
+
throw new TransactionExpiredBlockheightExceededError(signature);
|
|
5480
|
+
}
|
|
5481
|
+
} finally {
|
|
5482
|
+
done = true;
|
|
5483
|
+
abortConfirmation();
|
|
5484
|
+
}
|
|
5366
5485
|
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
const blockHeight = await this.getBlockHeight(commitment);
|
|
5370
|
-
return blockHeight;
|
|
5371
|
-
} catch (_e) {
|
|
5372
|
-
return -1;
|
|
5373
|
-
}
|
|
5374
|
-
};
|
|
5486
|
+
return result;
|
|
5487
|
+
}
|
|
5375
5488
|
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5489
|
+
async confirmTransactionUsingDurableNonceStrategy({
|
|
5490
|
+
commitment,
|
|
5491
|
+
strategy: {
|
|
5492
|
+
minContextSlot,
|
|
5493
|
+
nonceAccountPubkey,
|
|
5494
|
+
nonceValue,
|
|
5495
|
+
signature
|
|
5496
|
+
}
|
|
5497
|
+
}) {
|
|
5498
|
+
let done = false;
|
|
5499
|
+
const expiryPromise = new Promise(resolve => {
|
|
5500
|
+
let currentNonceValue = nonceValue;
|
|
5501
|
+
let lastCheckedSlot = null;
|
|
5379
5502
|
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5503
|
+
const getCurrentNonceValue = async () => {
|
|
5504
|
+
try {
|
|
5505
|
+
const {
|
|
5506
|
+
context,
|
|
5507
|
+
value: nonceAccount
|
|
5508
|
+
} = await this.getNonceAndContext(nonceAccountPubkey, {
|
|
5509
|
+
commitment,
|
|
5510
|
+
minContextSlot
|
|
5511
|
+
});
|
|
5512
|
+
lastCheckedSlot = context.slot;
|
|
5513
|
+
return nonceAccount === null || nonceAccount === void 0 ? void 0 : nonceAccount.nonce;
|
|
5514
|
+
} catch (e) {
|
|
5515
|
+
// If for whatever reason we can't reach/read the nonce
|
|
5516
|
+
// account, just keep using the last-known value.
|
|
5517
|
+
return currentNonceValue;
|
|
5518
|
+
}
|
|
5519
|
+
};
|
|
5520
|
+
|
|
5521
|
+
(async () => {
|
|
5522
|
+
currentNonceValue = await getCurrentNonceValue();
|
|
5523
|
+
if (done) return;
|
|
5524
|
+
|
|
5525
|
+
while (true // eslint-disable-line no-constant-condition
|
|
5526
|
+
) {
|
|
5527
|
+
if (nonceValue !== currentNonceValue) {
|
|
5528
|
+
resolve({
|
|
5529
|
+
__type: TransactionStatus.NONCE_INVALID,
|
|
5530
|
+
slotInWhichNonceDidAdvance: lastCheckedSlot
|
|
5531
|
+
});
|
|
5532
|
+
return;
|
|
5385
5533
|
}
|
|
5386
5534
|
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5535
|
+
await sleep(2000);
|
|
5536
|
+
if (done) return;
|
|
5537
|
+
currentNonceValue = await getCurrentNonceValue();
|
|
5538
|
+
if (done) return;
|
|
5539
|
+
}
|
|
5540
|
+
})();
|
|
5541
|
+
});
|
|
5542
|
+
const {
|
|
5543
|
+
abortConfirmation,
|
|
5544
|
+
confirmationPromise
|
|
5545
|
+
} = this.getTransactionConfirmationPromise({
|
|
5546
|
+
commitment,
|
|
5547
|
+
signature
|
|
5392
5548
|
});
|
|
5393
5549
|
let result;
|
|
5394
5550
|
|
|
5395
5551
|
try {
|
|
5396
5552
|
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5397
5553
|
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5554
|
+
if (outcome.__type === TransactionStatus.PROCESSED) {
|
|
5555
|
+
result = outcome.response;
|
|
5556
|
+
} else {
|
|
5557
|
+
var _signatureStatus;
|
|
5558
|
+
|
|
5559
|
+
// Double check that the transaction is indeed unconfirmed.
|
|
5560
|
+
let signatureStatus;
|
|
5561
|
+
|
|
5562
|
+
while (true // eslint-disable-line no-constant-condition
|
|
5563
|
+
) {
|
|
5564
|
+
var _outcome$slotInWhichN;
|
|
5565
|
+
|
|
5566
|
+
const status = await this.getSignatureStatus(signature);
|
|
5567
|
+
|
|
5568
|
+
if (status == null) {
|
|
5569
|
+
break;
|
|
5570
|
+
}
|
|
5401
5571
|
|
|
5402
|
-
|
|
5403
|
-
|
|
5572
|
+
if (status.context.slot < ((_outcome$slotInWhichN = outcome.slotInWhichNonceDidAdvance) !== null && _outcome$slotInWhichN !== void 0 ? _outcome$slotInWhichN : minContextSlot)) {
|
|
5573
|
+
await sleep(400);
|
|
5574
|
+
continue;
|
|
5575
|
+
}
|
|
5576
|
+
|
|
5577
|
+
signatureStatus = status;
|
|
5404
5578
|
break;
|
|
5579
|
+
}
|
|
5580
|
+
|
|
5581
|
+
if ((_signatureStatus = signatureStatus) !== null && _signatureStatus !== void 0 && _signatureStatus.value) {
|
|
5582
|
+
const commitmentForStatus = commitment || 'finalized';
|
|
5583
|
+
const {
|
|
5584
|
+
confirmationStatus
|
|
5585
|
+
} = signatureStatus.value;
|
|
5586
|
+
|
|
5587
|
+
switch (commitmentForStatus) {
|
|
5588
|
+
case 'processed':
|
|
5589
|
+
case 'recent':
|
|
5590
|
+
if (confirmationStatus !== 'processed' && confirmationStatus !== 'confirmed' && confirmationStatus !== 'finalized') {
|
|
5591
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5592
|
+
}
|
|
5593
|
+
|
|
5594
|
+
break;
|
|
5595
|
+
|
|
5596
|
+
case 'confirmed':
|
|
5597
|
+
case 'single':
|
|
5598
|
+
case 'singleGossip':
|
|
5599
|
+
if (confirmationStatus !== 'confirmed' && confirmationStatus !== 'finalized') {
|
|
5600
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5601
|
+
}
|
|
5405
5602
|
|
|
5406
|
-
|
|
5407
|
-
|
|
5603
|
+
break;
|
|
5604
|
+
|
|
5605
|
+
case 'finalized':
|
|
5606
|
+
case 'max':
|
|
5607
|
+
case 'root':
|
|
5608
|
+
if (confirmationStatus !== 'finalized') {
|
|
5609
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5610
|
+
}
|
|
5611
|
+
|
|
5612
|
+
break;
|
|
5613
|
+
|
|
5614
|
+
default:
|
|
5615
|
+
// Exhaustive switch.
|
|
5616
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5617
|
+
(_ => {})(commitmentForStatus);
|
|
5618
|
+
|
|
5619
|
+
}
|
|
5620
|
+
|
|
5621
|
+
result = {
|
|
5622
|
+
context: signatureStatus.context,
|
|
5623
|
+
value: {
|
|
5624
|
+
err: signatureStatus.value.err
|
|
5625
|
+
}
|
|
5626
|
+
};
|
|
5627
|
+
} else {
|
|
5628
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5629
|
+
}
|
|
5408
5630
|
}
|
|
5409
5631
|
} finally {
|
|
5410
|
-
|
|
5632
|
+
done = true;
|
|
5633
|
+
abortConfirmation();
|
|
5634
|
+
}
|
|
5411
5635
|
|
|
5412
|
-
|
|
5413
|
-
|
|
5636
|
+
return result;
|
|
5637
|
+
}
|
|
5638
|
+
|
|
5639
|
+
async confirmTransactionUsingLegacyTimeoutStrategy({
|
|
5640
|
+
commitment,
|
|
5641
|
+
signature
|
|
5642
|
+
}) {
|
|
5643
|
+
let timeoutId;
|
|
5644
|
+
const expiryPromise = new Promise(resolve => {
|
|
5645
|
+
let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
|
|
5646
|
+
|
|
5647
|
+
switch (commitment) {
|
|
5648
|
+
case 'processed':
|
|
5649
|
+
case 'recent':
|
|
5650
|
+
case 'single':
|
|
5651
|
+
case 'confirmed':
|
|
5652
|
+
case 'singleGossip':
|
|
5653
|
+
{
|
|
5654
|
+
timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
|
|
5655
|
+
break;
|
|
5656
|
+
}
|
|
5414
5657
|
}
|
|
5415
5658
|
|
|
5416
|
-
|
|
5417
|
-
|
|
5659
|
+
timeoutId = setTimeout(() => resolve({
|
|
5660
|
+
__type: TransactionStatus.TIMED_OUT,
|
|
5661
|
+
timeoutMs
|
|
5662
|
+
}), timeoutMs);
|
|
5663
|
+
});
|
|
5664
|
+
const {
|
|
5665
|
+
abortConfirmation,
|
|
5666
|
+
confirmationPromise
|
|
5667
|
+
} = this.getTransactionConfirmationPromise({
|
|
5668
|
+
commitment,
|
|
5669
|
+
signature
|
|
5670
|
+
});
|
|
5671
|
+
let result;
|
|
5672
|
+
|
|
5673
|
+
try {
|
|
5674
|
+
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5675
|
+
|
|
5676
|
+
if (outcome.__type === TransactionStatus.PROCESSED) {
|
|
5677
|
+
result = outcome.response;
|
|
5678
|
+
} else {
|
|
5679
|
+
throw new TransactionExpiredTimeoutError(signature, outcome.timeoutMs / 1000);
|
|
5418
5680
|
}
|
|
5681
|
+
} finally {
|
|
5682
|
+
clearTimeout(timeoutId);
|
|
5683
|
+
abortConfirmation();
|
|
5419
5684
|
}
|
|
5420
5685
|
|
|
5421
5686
|
return result;
|
|
@@ -6471,11 +6736,11 @@ class Connection {
|
|
|
6471
6736
|
*/
|
|
6472
6737
|
|
|
6473
6738
|
|
|
6474
|
-
async getNonceAndContext(nonceAccount,
|
|
6739
|
+
async getNonceAndContext(nonceAccount, commitmentOrConfig) {
|
|
6475
6740
|
const {
|
|
6476
6741
|
context,
|
|
6477
6742
|
value: accountInfo
|
|
6478
|
-
} = await this.getAccountInfoAndContext(nonceAccount,
|
|
6743
|
+
} = await this.getAccountInfoAndContext(nonceAccount, commitmentOrConfig);
|
|
6479
6744
|
let value = null;
|
|
6480
6745
|
|
|
6481
6746
|
if (accountInfo !== null) {
|
|
@@ -6492,8 +6757,8 @@ class Connection {
|
|
|
6492
6757
|
*/
|
|
6493
6758
|
|
|
6494
6759
|
|
|
6495
|
-
async getNonce(nonceAccount,
|
|
6496
|
-
return await this.getNonceAndContext(nonceAccount,
|
|
6760
|
+
async getNonce(nonceAccount, commitmentOrConfig) {
|
|
6761
|
+
return await this.getNonceAndContext(nonceAccount, commitmentOrConfig).then(x => x.value).catch(e => {
|
|
6497
6762
|
throw new Error('failed to get nonce for account ' + nonceAccount.toBase58() + ': ' + e);
|
|
6498
6763
|
});
|
|
6499
6764
|
}
|
|
@@ -9908,6 +10173,9 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9908
10173
|
if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'lastValidBlockHeight')) {
|
|
9909
10174
|
confirmationStrategy = confirmationStrategyOrConfirmOptions;
|
|
9910
10175
|
options = maybeConfirmOptions;
|
|
10176
|
+
} else if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'nonceValue')) {
|
|
10177
|
+
confirmationStrategy = confirmationStrategyOrConfirmOptions;
|
|
10178
|
+
options = maybeConfirmOptions;
|
|
9911
10179
|
} else {
|
|
9912
10180
|
options = confirmationStrategyOrConfirmOptions;
|
|
9913
10181
|
}
|
|
@@ -9935,5 +10203,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9935
10203
|
|
|
9936
10204
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9937
10205
|
|
|
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 };
|
|
10206
|
+
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
10207
|
//# sourceMappingURL=index.esm.js.map
|