@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.browser.cjs.js
CHANGED
|
@@ -177,13 +177,13 @@ class PublicKey extends Struct {
|
|
|
177
177
|
this._bn = new BN__default["default"](value);
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
if (this._bn.byteLength() >
|
|
180
|
+
if (this._bn.byteLength() > PUBLIC_KEY_LENGTH) {
|
|
181
181
|
throw new Error(`Invalid public key input`);
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
/**
|
|
186
|
-
* Returns a unique PublicKey for tests and benchmarks using
|
|
186
|
+
* Returns a unique PublicKey for tests and benchmarks using a counter
|
|
187
187
|
*/
|
|
188
188
|
|
|
189
189
|
|
|
@@ -290,6 +290,8 @@ class PublicKey extends Struct {
|
|
|
290
290
|
/**
|
|
291
291
|
* Async version of createProgramAddressSync
|
|
292
292
|
* For backwards compatibility
|
|
293
|
+
*
|
|
294
|
+
* @deprecated Use {@link createProgramAddressSync} instead
|
|
293
295
|
*/
|
|
294
296
|
|
|
295
297
|
/* eslint-disable require-await */
|
|
@@ -332,6 +334,8 @@ class PublicKey extends Struct {
|
|
|
332
334
|
/**
|
|
333
335
|
* Async version of findProgramAddressSync
|
|
334
336
|
* For backwards compatibility
|
|
337
|
+
*
|
|
338
|
+
* @deprecated Use {@link findProgramAddressSync} instead
|
|
335
339
|
*/
|
|
336
340
|
|
|
337
341
|
|
|
@@ -448,6 +452,17 @@ class TransactionExpiredTimeoutError extends Error {
|
|
|
448
452
|
Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
449
453
|
value: 'TransactionExpiredTimeoutError'
|
|
450
454
|
});
|
|
455
|
+
class TransactionExpiredNonceInvalidError extends Error {
|
|
456
|
+
constructor(signature) {
|
|
457
|
+
super(`Signature ${signature} has expired: the nonce is no longer valid.`);
|
|
458
|
+
this.signature = void 0;
|
|
459
|
+
this.signature = signature;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
}
|
|
463
|
+
Object.defineProperty(TransactionExpiredNonceInvalidError.prototype, 'name', {
|
|
464
|
+
value: 'TransactionExpiredNonceInvalidError'
|
|
465
|
+
});
|
|
451
466
|
|
|
452
467
|
class MessageAccountKeys {
|
|
453
468
|
constructor(staticAccountKeys, accountKeysFromLookups) {
|
|
@@ -1285,6 +1300,7 @@ exports.TransactionStatus = void 0;
|
|
|
1285
1300
|
TransactionStatus[TransactionStatus["BLOCKHEIGHT_EXCEEDED"] = 0] = "BLOCKHEIGHT_EXCEEDED";
|
|
1286
1301
|
TransactionStatus[TransactionStatus["PROCESSED"] = 1] = "PROCESSED";
|
|
1287
1302
|
TransactionStatus[TransactionStatus["TIMED_OUT"] = 2] = "TIMED_OUT";
|
|
1303
|
+
TransactionStatus[TransactionStatus["NONCE_INVALID"] = 3] = "NONCE_INVALID";
|
|
1288
1304
|
})(exports.TransactionStatus || (exports.TransactionStatus = {}));
|
|
1289
1305
|
|
|
1290
1306
|
const DEFAULT_SIGNATURE = buffer.Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
|
@@ -1379,6 +1395,7 @@ class Transaction {
|
|
|
1379
1395
|
this.recentBlockhash = void 0;
|
|
1380
1396
|
this.lastValidBlockHeight = void 0;
|
|
1381
1397
|
this.nonceInfo = void 0;
|
|
1398
|
+
this.minNonceContextSlot = void 0;
|
|
1382
1399
|
this._message = void 0;
|
|
1383
1400
|
this._json = void 0;
|
|
1384
1401
|
|
|
@@ -1394,7 +1411,14 @@ class Transaction {
|
|
|
1394
1411
|
this.signatures = opts.signatures;
|
|
1395
1412
|
}
|
|
1396
1413
|
|
|
1397
|
-
if (Object.prototype.hasOwnProperty.call(opts, '
|
|
1414
|
+
if (Object.prototype.hasOwnProperty.call(opts, 'nonceInfo')) {
|
|
1415
|
+
const {
|
|
1416
|
+
minContextSlot,
|
|
1417
|
+
nonceInfo
|
|
1418
|
+
} = opts;
|
|
1419
|
+
this.minNonceContextSlot = minContextSlot;
|
|
1420
|
+
this.nonceInfo = nonceInfo;
|
|
1421
|
+
} else if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
|
|
1398
1422
|
const {
|
|
1399
1423
|
blockhash,
|
|
1400
1424
|
lastValidBlockHeight
|
|
@@ -2027,7 +2051,7 @@ class TransactionMessage {
|
|
|
2027
2051
|
} = header;
|
|
2028
2052
|
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
2029
2053
|
assert(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
2030
|
-
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
2054
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numRequiredSignatures - numReadonlyUnsignedAccounts;
|
|
2031
2055
|
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
2032
2056
|
const accountKeys = message.getAccountKeys(args);
|
|
2033
2057
|
const payerKey = accountKeys.get(0);
|
|
@@ -2211,11 +2235,28 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2211
2235
|
minContextSlot: options.minContextSlot
|
|
2212
2236
|
};
|
|
2213
2237
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2238
|
+
let status;
|
|
2239
|
+
|
|
2240
|
+
if (transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null) {
|
|
2241
|
+
status = (await connection.confirmTransaction({
|
|
2242
|
+
signature: signature,
|
|
2243
|
+
blockhash: transaction.recentBlockhash,
|
|
2244
|
+
lastValidBlockHeight: transaction.lastValidBlockHeight
|
|
2245
|
+
}, options && options.commitment)).value;
|
|
2246
|
+
} else if (transaction.minNonceContextSlot != null && transaction.nonceInfo != null) {
|
|
2247
|
+
const {
|
|
2248
|
+
nonceInstruction
|
|
2249
|
+
} = transaction.nonceInfo;
|
|
2250
|
+
const nonceAccountPubkey = nonceInstruction.keys[0].pubkey;
|
|
2251
|
+
status = (await connection.confirmTransaction({
|
|
2252
|
+
minContextSlot: transaction.minNonceContextSlot,
|
|
2253
|
+
nonceAccountPubkey,
|
|
2254
|
+
nonceValue: transaction.nonceInfo.nonce,
|
|
2255
|
+
signature
|
|
2256
|
+
}, options && options.commitment)).value;
|
|
2257
|
+
} else {
|
|
2258
|
+
status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2259
|
+
}
|
|
2219
2260
|
|
|
2220
2261
|
if (status.err) {
|
|
2221
2262
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
@@ -2284,6 +2325,9 @@ const FeeCalculatorLayout = BufferLayout__namespace.nu64('lamportsPerSignature')
|
|
|
2284
2325
|
|
|
2285
2326
|
const NonceAccountLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u32('version'), BufferLayout__namespace.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout__namespace.struct([FeeCalculatorLayout], 'feeCalculator')]);
|
|
2286
2327
|
const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
|
|
2328
|
+
/**
|
|
2329
|
+
* A durable nonce is a 32 byte value encoded as a base58 string.
|
|
2330
|
+
*/
|
|
2287
2331
|
|
|
2288
2332
|
/**
|
|
2289
2333
|
* NonceAccount class
|
|
@@ -3646,10 +3690,13 @@ function extractCommitmentFromConfig(commitmentOrConfig) {
|
|
|
3646
3690
|
};
|
|
3647
3691
|
}
|
|
3648
3692
|
/**
|
|
3649
|
-
*
|
|
3693
|
+
* A strategy for confirming durable nonce transactions.
|
|
3650
3694
|
*/
|
|
3651
3695
|
|
|
3652
3696
|
|
|
3697
|
+
/**
|
|
3698
|
+
* @internal
|
|
3699
|
+
*/
|
|
3653
3700
|
function createRpcResult(result) {
|
|
3654
3701
|
return superstruct.union([superstruct.type({
|
|
3655
3702
|
jsonrpc: superstruct.literal('2.0'),
|
|
@@ -5213,25 +5260,45 @@ class Connection {
|
|
|
5213
5260
|
}
|
|
5214
5261
|
|
|
5215
5262
|
assert(decodedSignature.length === 64, 'signature has invalid length');
|
|
5216
|
-
|
|
5217
|
-
|
|
5263
|
+
|
|
5264
|
+
if (typeof strategy === 'string') {
|
|
5265
|
+
return await this.confirmTransactionUsingLegacyTimeoutStrategy({
|
|
5266
|
+
commitment: commitment || this.commitment,
|
|
5267
|
+
signature: rawSignature
|
|
5268
|
+
});
|
|
5269
|
+
} else if ('lastValidBlockHeight' in strategy) {
|
|
5270
|
+
return await this.confirmTransactionUsingBlockHeightExceedanceStrategy({
|
|
5271
|
+
commitment: commitment || this.commitment,
|
|
5272
|
+
strategy
|
|
5273
|
+
});
|
|
5274
|
+
} else {
|
|
5275
|
+
return await this.confirmTransactionUsingDurableNonceStrategy({
|
|
5276
|
+
commitment: commitment || this.commitment,
|
|
5277
|
+
strategy
|
|
5278
|
+
});
|
|
5279
|
+
}
|
|
5280
|
+
}
|
|
5281
|
+
|
|
5282
|
+
getTransactionConfirmationPromise({
|
|
5283
|
+
commitment,
|
|
5284
|
+
signature
|
|
5285
|
+
}) {
|
|
5218
5286
|
let signatureSubscriptionId;
|
|
5219
5287
|
let disposeSignatureSubscriptionStateChangeObserver;
|
|
5220
5288
|
let done = false;
|
|
5221
5289
|
const confirmationPromise = new Promise((resolve, reject) => {
|
|
5222
5290
|
try {
|
|
5223
|
-
signatureSubscriptionId = this.onSignature(
|
|
5291
|
+
signatureSubscriptionId = this.onSignature(signature, (result, context) => {
|
|
5224
5292
|
signatureSubscriptionId = undefined;
|
|
5225
5293
|
const response = {
|
|
5226
5294
|
context,
|
|
5227
5295
|
value: result
|
|
5228
5296
|
};
|
|
5229
|
-
done = true;
|
|
5230
5297
|
resolve({
|
|
5231
5298
|
__type: exports.TransactionStatus.PROCESSED,
|
|
5232
5299
|
response
|
|
5233
5300
|
});
|
|
5234
|
-
},
|
|
5301
|
+
}, commitment);
|
|
5235
5302
|
const subscriptionSetupPromise = new Promise(resolveSubscriptionSetup => {
|
|
5236
5303
|
if (signatureSubscriptionId == null) {
|
|
5237
5304
|
resolveSubscriptionSetup();
|
|
@@ -5247,7 +5314,7 @@ class Connection {
|
|
|
5247
5314
|
(async () => {
|
|
5248
5315
|
await subscriptionSetupPromise;
|
|
5249
5316
|
if (done) return;
|
|
5250
|
-
const response = await this.getSignatureStatus(
|
|
5317
|
+
const response = await this.getSignatureStatus(signature);
|
|
5251
5318
|
if (done) return;
|
|
5252
5319
|
|
|
5253
5320
|
if (response == null) {
|
|
@@ -5266,7 +5333,7 @@ class Connection {
|
|
|
5266
5333
|
if (value !== null && value !== void 0 && value.err) {
|
|
5267
5334
|
reject(value.err);
|
|
5268
5335
|
} else {
|
|
5269
|
-
switch (
|
|
5336
|
+
switch (commitment) {
|
|
5270
5337
|
case 'confirmed':
|
|
5271
5338
|
case 'single':
|
|
5272
5339
|
case 'singleGossip':
|
|
@@ -5308,81 +5375,279 @@ class Connection {
|
|
|
5308
5375
|
reject(err);
|
|
5309
5376
|
}
|
|
5310
5377
|
});
|
|
5378
|
+
|
|
5379
|
+
const abortConfirmation = () => {
|
|
5380
|
+
if (disposeSignatureSubscriptionStateChangeObserver) {
|
|
5381
|
+
disposeSignatureSubscriptionStateChangeObserver();
|
|
5382
|
+
disposeSignatureSubscriptionStateChangeObserver = undefined;
|
|
5383
|
+
}
|
|
5384
|
+
|
|
5385
|
+
if (signatureSubscriptionId) {
|
|
5386
|
+
this.removeSignatureListener(signatureSubscriptionId);
|
|
5387
|
+
signatureSubscriptionId = undefined;
|
|
5388
|
+
}
|
|
5389
|
+
};
|
|
5390
|
+
|
|
5391
|
+
return {
|
|
5392
|
+
abortConfirmation,
|
|
5393
|
+
confirmationPromise
|
|
5394
|
+
};
|
|
5395
|
+
}
|
|
5396
|
+
|
|
5397
|
+
async confirmTransactionUsingBlockHeightExceedanceStrategy({
|
|
5398
|
+
commitment,
|
|
5399
|
+
strategy: {
|
|
5400
|
+
lastValidBlockHeight,
|
|
5401
|
+
signature
|
|
5402
|
+
}
|
|
5403
|
+
}) {
|
|
5404
|
+
let done = false;
|
|
5311
5405
|
const expiryPromise = new Promise(resolve => {
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5406
|
+
const checkBlockHeight = async () => {
|
|
5407
|
+
try {
|
|
5408
|
+
const blockHeight = await this.getBlockHeight(commitment);
|
|
5409
|
+
return blockHeight;
|
|
5410
|
+
} catch (_e) {
|
|
5411
|
+
return -1;
|
|
5412
|
+
}
|
|
5413
|
+
};
|
|
5414
|
+
|
|
5415
|
+
(async () => {
|
|
5416
|
+
let currentBlockHeight = await checkBlockHeight();
|
|
5417
|
+
if (done) return;
|
|
5418
|
+
|
|
5419
|
+
while (currentBlockHeight <= lastValidBlockHeight) {
|
|
5420
|
+
await sleep(1000);
|
|
5421
|
+
if (done) return;
|
|
5422
|
+
currentBlockHeight = await checkBlockHeight();
|
|
5423
|
+
if (done) return;
|
|
5325
5424
|
}
|
|
5326
5425
|
|
|
5327
|
-
|
|
5328
|
-
__type: exports.TransactionStatus.
|
|
5329
|
-
|
|
5330
|
-
|
|
5426
|
+
resolve({
|
|
5427
|
+
__type: exports.TransactionStatus.BLOCKHEIGHT_EXCEEDED
|
|
5428
|
+
});
|
|
5429
|
+
})();
|
|
5430
|
+
});
|
|
5431
|
+
const {
|
|
5432
|
+
abortConfirmation,
|
|
5433
|
+
confirmationPromise
|
|
5434
|
+
} = this.getTransactionConfirmationPromise({
|
|
5435
|
+
commitment,
|
|
5436
|
+
signature
|
|
5437
|
+
});
|
|
5438
|
+
let result;
|
|
5439
|
+
|
|
5440
|
+
try {
|
|
5441
|
+
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5442
|
+
|
|
5443
|
+
if (outcome.__type === exports.TransactionStatus.PROCESSED) {
|
|
5444
|
+
result = outcome.response;
|
|
5331
5445
|
} else {
|
|
5332
|
-
|
|
5446
|
+
throw new TransactionExpiredBlockheightExceededError(signature);
|
|
5447
|
+
}
|
|
5448
|
+
} finally {
|
|
5449
|
+
done = true;
|
|
5450
|
+
abortConfirmation();
|
|
5451
|
+
}
|
|
5333
5452
|
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
const blockHeight = await this.getBlockHeight(commitment);
|
|
5337
|
-
return blockHeight;
|
|
5338
|
-
} catch (_e) {
|
|
5339
|
-
return -1;
|
|
5340
|
-
}
|
|
5341
|
-
};
|
|
5453
|
+
return result;
|
|
5454
|
+
}
|
|
5342
5455
|
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5456
|
+
async confirmTransactionUsingDurableNonceStrategy({
|
|
5457
|
+
commitment,
|
|
5458
|
+
strategy: {
|
|
5459
|
+
minContextSlot,
|
|
5460
|
+
nonceAccountPubkey,
|
|
5461
|
+
nonceValue,
|
|
5462
|
+
signature
|
|
5463
|
+
}
|
|
5464
|
+
}) {
|
|
5465
|
+
let done = false;
|
|
5466
|
+
const expiryPromise = new Promise(resolve => {
|
|
5467
|
+
let currentNonceValue = nonceValue;
|
|
5468
|
+
let lastCheckedSlot = null;
|
|
5346
5469
|
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5470
|
+
const getCurrentNonceValue = async () => {
|
|
5471
|
+
try {
|
|
5472
|
+
const {
|
|
5473
|
+
context,
|
|
5474
|
+
value: nonceAccount
|
|
5475
|
+
} = await this.getNonceAndContext(nonceAccountPubkey, {
|
|
5476
|
+
commitment,
|
|
5477
|
+
minContextSlot
|
|
5478
|
+
});
|
|
5479
|
+
lastCheckedSlot = context.slot;
|
|
5480
|
+
return nonceAccount === null || nonceAccount === void 0 ? void 0 : nonceAccount.nonce;
|
|
5481
|
+
} catch (e) {
|
|
5482
|
+
// If for whatever reason we can't reach/read the nonce
|
|
5483
|
+
// account, just keep using the last-known value.
|
|
5484
|
+
return currentNonceValue;
|
|
5485
|
+
}
|
|
5486
|
+
};
|
|
5487
|
+
|
|
5488
|
+
(async () => {
|
|
5489
|
+
currentNonceValue = await getCurrentNonceValue();
|
|
5490
|
+
if (done) return;
|
|
5491
|
+
|
|
5492
|
+
while (true // eslint-disable-line no-constant-condition
|
|
5493
|
+
) {
|
|
5494
|
+
if (nonceValue !== currentNonceValue) {
|
|
5495
|
+
resolve({
|
|
5496
|
+
__type: exports.TransactionStatus.NONCE_INVALID,
|
|
5497
|
+
slotInWhichNonceDidAdvance: lastCheckedSlot
|
|
5498
|
+
});
|
|
5499
|
+
return;
|
|
5352
5500
|
}
|
|
5353
5501
|
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5502
|
+
await sleep(2000);
|
|
5503
|
+
if (done) return;
|
|
5504
|
+
currentNonceValue = await getCurrentNonceValue();
|
|
5505
|
+
if (done) return;
|
|
5506
|
+
}
|
|
5507
|
+
})();
|
|
5508
|
+
});
|
|
5509
|
+
const {
|
|
5510
|
+
abortConfirmation,
|
|
5511
|
+
confirmationPromise
|
|
5512
|
+
} = this.getTransactionConfirmationPromise({
|
|
5513
|
+
commitment,
|
|
5514
|
+
signature
|
|
5359
5515
|
});
|
|
5360
5516
|
let result;
|
|
5361
5517
|
|
|
5362
5518
|
try {
|
|
5363
5519
|
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5364
5520
|
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5521
|
+
if (outcome.__type === exports.TransactionStatus.PROCESSED) {
|
|
5522
|
+
result = outcome.response;
|
|
5523
|
+
} else {
|
|
5524
|
+
var _signatureStatus;
|
|
5525
|
+
|
|
5526
|
+
// Double check that the transaction is indeed unconfirmed.
|
|
5527
|
+
let signatureStatus;
|
|
5528
|
+
|
|
5529
|
+
while (true // eslint-disable-line no-constant-condition
|
|
5530
|
+
) {
|
|
5531
|
+
var _outcome$slotInWhichN;
|
|
5532
|
+
|
|
5533
|
+
const status = await this.getSignatureStatus(signature);
|
|
5534
|
+
|
|
5535
|
+
if (status == null) {
|
|
5536
|
+
break;
|
|
5537
|
+
}
|
|
5368
5538
|
|
|
5369
|
-
|
|
5370
|
-
|
|
5539
|
+
if (status.context.slot < ((_outcome$slotInWhichN = outcome.slotInWhichNonceDidAdvance) !== null && _outcome$slotInWhichN !== void 0 ? _outcome$slotInWhichN : minContextSlot)) {
|
|
5540
|
+
await sleep(400);
|
|
5541
|
+
continue;
|
|
5542
|
+
}
|
|
5543
|
+
|
|
5544
|
+
signatureStatus = status;
|
|
5371
5545
|
break;
|
|
5546
|
+
}
|
|
5547
|
+
|
|
5548
|
+
if ((_signatureStatus = signatureStatus) !== null && _signatureStatus !== void 0 && _signatureStatus.value) {
|
|
5549
|
+
const commitmentForStatus = commitment || 'finalized';
|
|
5550
|
+
const {
|
|
5551
|
+
confirmationStatus
|
|
5552
|
+
} = signatureStatus.value;
|
|
5553
|
+
|
|
5554
|
+
switch (commitmentForStatus) {
|
|
5555
|
+
case 'processed':
|
|
5556
|
+
case 'recent':
|
|
5557
|
+
if (confirmationStatus !== 'processed' && confirmationStatus !== 'confirmed' && confirmationStatus !== 'finalized') {
|
|
5558
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5559
|
+
}
|
|
5560
|
+
|
|
5561
|
+
break;
|
|
5562
|
+
|
|
5563
|
+
case 'confirmed':
|
|
5564
|
+
case 'single':
|
|
5565
|
+
case 'singleGossip':
|
|
5566
|
+
if (confirmationStatus !== 'confirmed' && confirmationStatus !== 'finalized') {
|
|
5567
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5568
|
+
}
|
|
5372
5569
|
|
|
5373
|
-
|
|
5374
|
-
|
|
5570
|
+
break;
|
|
5571
|
+
|
|
5572
|
+
case 'finalized':
|
|
5573
|
+
case 'max':
|
|
5574
|
+
case 'root':
|
|
5575
|
+
if (confirmationStatus !== 'finalized') {
|
|
5576
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5577
|
+
}
|
|
5578
|
+
|
|
5579
|
+
break;
|
|
5580
|
+
|
|
5581
|
+
default:
|
|
5582
|
+
// Exhaustive switch.
|
|
5583
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5584
|
+
(_ => {})(commitmentForStatus);
|
|
5585
|
+
|
|
5586
|
+
}
|
|
5587
|
+
|
|
5588
|
+
result = {
|
|
5589
|
+
context: signatureStatus.context,
|
|
5590
|
+
value: {
|
|
5591
|
+
err: signatureStatus.value.err
|
|
5592
|
+
}
|
|
5593
|
+
};
|
|
5594
|
+
} else {
|
|
5595
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5596
|
+
}
|
|
5375
5597
|
}
|
|
5376
5598
|
} finally {
|
|
5377
|
-
|
|
5599
|
+
done = true;
|
|
5600
|
+
abortConfirmation();
|
|
5601
|
+
}
|
|
5378
5602
|
|
|
5379
|
-
|
|
5380
|
-
|
|
5603
|
+
return result;
|
|
5604
|
+
}
|
|
5605
|
+
|
|
5606
|
+
async confirmTransactionUsingLegacyTimeoutStrategy({
|
|
5607
|
+
commitment,
|
|
5608
|
+
signature
|
|
5609
|
+
}) {
|
|
5610
|
+
let timeoutId;
|
|
5611
|
+
const expiryPromise = new Promise(resolve => {
|
|
5612
|
+
let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
|
|
5613
|
+
|
|
5614
|
+
switch (commitment) {
|
|
5615
|
+
case 'processed':
|
|
5616
|
+
case 'recent':
|
|
5617
|
+
case 'single':
|
|
5618
|
+
case 'confirmed':
|
|
5619
|
+
case 'singleGossip':
|
|
5620
|
+
{
|
|
5621
|
+
timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
|
|
5622
|
+
break;
|
|
5623
|
+
}
|
|
5381
5624
|
}
|
|
5382
5625
|
|
|
5383
|
-
|
|
5384
|
-
|
|
5626
|
+
timeoutId = setTimeout(() => resolve({
|
|
5627
|
+
__type: exports.TransactionStatus.TIMED_OUT,
|
|
5628
|
+
timeoutMs
|
|
5629
|
+
}), timeoutMs);
|
|
5630
|
+
});
|
|
5631
|
+
const {
|
|
5632
|
+
abortConfirmation,
|
|
5633
|
+
confirmationPromise
|
|
5634
|
+
} = this.getTransactionConfirmationPromise({
|
|
5635
|
+
commitment,
|
|
5636
|
+
signature
|
|
5637
|
+
});
|
|
5638
|
+
let result;
|
|
5639
|
+
|
|
5640
|
+
try {
|
|
5641
|
+
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5642
|
+
|
|
5643
|
+
if (outcome.__type === exports.TransactionStatus.PROCESSED) {
|
|
5644
|
+
result = outcome.response;
|
|
5645
|
+
} else {
|
|
5646
|
+
throw new TransactionExpiredTimeoutError(signature, outcome.timeoutMs / 1000);
|
|
5385
5647
|
}
|
|
5648
|
+
} finally {
|
|
5649
|
+
clearTimeout(timeoutId);
|
|
5650
|
+
abortConfirmation();
|
|
5386
5651
|
}
|
|
5387
5652
|
|
|
5388
5653
|
return result;
|
|
@@ -6438,11 +6703,11 @@ class Connection {
|
|
|
6438
6703
|
*/
|
|
6439
6704
|
|
|
6440
6705
|
|
|
6441
|
-
async getNonceAndContext(nonceAccount,
|
|
6706
|
+
async getNonceAndContext(nonceAccount, commitmentOrConfig) {
|
|
6442
6707
|
const {
|
|
6443
6708
|
context,
|
|
6444
6709
|
value: accountInfo
|
|
6445
|
-
} = await this.getAccountInfoAndContext(nonceAccount,
|
|
6710
|
+
} = await this.getAccountInfoAndContext(nonceAccount, commitmentOrConfig);
|
|
6446
6711
|
let value = null;
|
|
6447
6712
|
|
|
6448
6713
|
if (accountInfo !== null) {
|
|
@@ -6459,8 +6724,8 @@ class Connection {
|
|
|
6459
6724
|
*/
|
|
6460
6725
|
|
|
6461
6726
|
|
|
6462
|
-
async getNonce(nonceAccount,
|
|
6463
|
-
return await this.getNonceAndContext(nonceAccount,
|
|
6727
|
+
async getNonce(nonceAccount, commitmentOrConfig) {
|
|
6728
|
+
return await this.getNonceAndContext(nonceAccount, commitmentOrConfig).then(x => x.value).catch(e => {
|
|
6464
6729
|
throw new Error('failed to get nonce for account ' + nonceAccount.toBase58() + ': ' + e);
|
|
6465
6730
|
});
|
|
6466
6731
|
}
|
|
@@ -9875,6 +10140,9 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9875
10140
|
if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'lastValidBlockHeight')) {
|
|
9876
10141
|
confirmationStrategy = confirmationStrategyOrConfirmOptions;
|
|
9877
10142
|
options = maybeConfirmOptions;
|
|
10143
|
+
} else if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'nonceValue')) {
|
|
10144
|
+
confirmationStrategy = confirmationStrategyOrConfirmOptions;
|
|
10145
|
+
options = maybeConfirmOptions;
|
|
9878
10146
|
} else {
|
|
9879
10147
|
options = confirmationStrategyOrConfirmOptions;
|
|
9880
10148
|
}
|
|
@@ -9959,6 +10227,7 @@ exports.SystemInstruction = SystemInstruction;
|
|
|
9959
10227
|
exports.SystemProgram = SystemProgram;
|
|
9960
10228
|
exports.Transaction = Transaction;
|
|
9961
10229
|
exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheightExceededError;
|
|
10230
|
+
exports.TransactionExpiredNonceInvalidError = TransactionExpiredNonceInvalidError;
|
|
9962
10231
|
exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
|
|
9963
10232
|
exports.TransactionInstruction = TransactionInstruction;
|
|
9964
10233
|
exports.TransactionMessage = TransactionMessage;
|