@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.browser.esm.js
CHANGED
|
@@ -418,6 +418,17 @@ class TransactionExpiredTimeoutError extends Error {
|
|
|
418
418
|
Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
419
419
|
value: 'TransactionExpiredTimeoutError'
|
|
420
420
|
});
|
|
421
|
+
class TransactionExpiredNonceInvalidError extends Error {
|
|
422
|
+
constructor(signature) {
|
|
423
|
+
super(`Signature ${signature} has expired: the nonce is no longer valid.`);
|
|
424
|
+
this.signature = void 0;
|
|
425
|
+
this.signature = signature;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
}
|
|
429
|
+
Object.defineProperty(TransactionExpiredNonceInvalidError.prototype, 'name', {
|
|
430
|
+
value: 'TransactionExpiredNonceInvalidError'
|
|
431
|
+
});
|
|
421
432
|
|
|
422
433
|
class MessageAccountKeys {
|
|
423
434
|
constructor(staticAccountKeys, accountKeysFromLookups) {
|
|
@@ -1255,6 +1266,7 @@ let TransactionStatus;
|
|
|
1255
1266
|
TransactionStatus[TransactionStatus["BLOCKHEIGHT_EXCEEDED"] = 0] = "BLOCKHEIGHT_EXCEEDED";
|
|
1256
1267
|
TransactionStatus[TransactionStatus["PROCESSED"] = 1] = "PROCESSED";
|
|
1257
1268
|
TransactionStatus[TransactionStatus["TIMED_OUT"] = 2] = "TIMED_OUT";
|
|
1269
|
+
TransactionStatus[TransactionStatus["NONCE_INVALID"] = 3] = "NONCE_INVALID";
|
|
1258
1270
|
})(TransactionStatus || (TransactionStatus = {}));
|
|
1259
1271
|
|
|
1260
1272
|
const DEFAULT_SIGNATURE = Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
|
@@ -1349,6 +1361,7 @@ class Transaction {
|
|
|
1349
1361
|
this.recentBlockhash = void 0;
|
|
1350
1362
|
this.lastValidBlockHeight = void 0;
|
|
1351
1363
|
this.nonceInfo = void 0;
|
|
1364
|
+
this.minNonceContextSlot = void 0;
|
|
1352
1365
|
this._message = void 0;
|
|
1353
1366
|
this._json = void 0;
|
|
1354
1367
|
|
|
@@ -1364,7 +1377,14 @@ class Transaction {
|
|
|
1364
1377
|
this.signatures = opts.signatures;
|
|
1365
1378
|
}
|
|
1366
1379
|
|
|
1367
|
-
if (Object.prototype.hasOwnProperty.call(opts, '
|
|
1380
|
+
if (Object.prototype.hasOwnProperty.call(opts, 'nonceInfo')) {
|
|
1381
|
+
const {
|
|
1382
|
+
minContextSlot,
|
|
1383
|
+
nonceInfo
|
|
1384
|
+
} = opts;
|
|
1385
|
+
this.minNonceContextSlot = minContextSlot;
|
|
1386
|
+
this.nonceInfo = nonceInfo;
|
|
1387
|
+
} else if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
|
|
1368
1388
|
const {
|
|
1369
1389
|
blockhash,
|
|
1370
1390
|
lastValidBlockHeight
|
|
@@ -2181,11 +2201,28 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2181
2201
|
minContextSlot: options.minContextSlot
|
|
2182
2202
|
};
|
|
2183
2203
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2204
|
+
let status;
|
|
2205
|
+
|
|
2206
|
+
if (transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null) {
|
|
2207
|
+
status = (await connection.confirmTransaction({
|
|
2208
|
+
signature: signature,
|
|
2209
|
+
blockhash: transaction.recentBlockhash,
|
|
2210
|
+
lastValidBlockHeight: transaction.lastValidBlockHeight
|
|
2211
|
+
}, options && options.commitment)).value;
|
|
2212
|
+
} else if (transaction.minNonceContextSlot != null && transaction.nonceInfo != null) {
|
|
2213
|
+
const {
|
|
2214
|
+
nonceInstruction
|
|
2215
|
+
} = transaction.nonceInfo;
|
|
2216
|
+
const nonceAccountPubkey = nonceInstruction.keys[0].pubkey;
|
|
2217
|
+
status = (await connection.confirmTransaction({
|
|
2218
|
+
minContextSlot: transaction.minNonceContextSlot,
|
|
2219
|
+
nonceAccountPubkey,
|
|
2220
|
+
nonceValue: transaction.nonceInfo.nonce,
|
|
2221
|
+
signature
|
|
2222
|
+
}, options && options.commitment)).value;
|
|
2223
|
+
} else {
|
|
2224
|
+
status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2225
|
+
}
|
|
2189
2226
|
|
|
2190
2227
|
if (status.err) {
|
|
2191
2228
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
@@ -2254,6 +2291,9 @@ const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
|
|
|
2254
2291
|
|
|
2255
2292
|
const NonceAccountLayout = BufferLayout.struct([BufferLayout.u32('version'), BufferLayout.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout.struct([FeeCalculatorLayout], 'feeCalculator')]);
|
|
2256
2293
|
const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
|
|
2294
|
+
/**
|
|
2295
|
+
* A durable nonce is a 32 byte value encoded as a base58 string.
|
|
2296
|
+
*/
|
|
2257
2297
|
|
|
2258
2298
|
/**
|
|
2259
2299
|
* NonceAccount class
|
|
@@ -3616,10 +3656,13 @@ function extractCommitmentFromConfig(commitmentOrConfig) {
|
|
|
3616
3656
|
};
|
|
3617
3657
|
}
|
|
3618
3658
|
/**
|
|
3619
|
-
*
|
|
3659
|
+
* A strategy for confirming durable nonce transactions.
|
|
3620
3660
|
*/
|
|
3621
3661
|
|
|
3622
3662
|
|
|
3663
|
+
/**
|
|
3664
|
+
* @internal
|
|
3665
|
+
*/
|
|
3623
3666
|
function createRpcResult(result) {
|
|
3624
3667
|
return union([type({
|
|
3625
3668
|
jsonrpc: literal('2.0'),
|
|
@@ -5183,25 +5226,45 @@ class Connection {
|
|
|
5183
5226
|
}
|
|
5184
5227
|
|
|
5185
5228
|
assert(decodedSignature.length === 64, 'signature has invalid length');
|
|
5186
|
-
|
|
5187
|
-
|
|
5229
|
+
|
|
5230
|
+
if (typeof strategy === 'string') {
|
|
5231
|
+
return await this.confirmTransactionUsingLegacyTimeoutStrategy({
|
|
5232
|
+
commitment: commitment || this.commitment,
|
|
5233
|
+
signature: rawSignature
|
|
5234
|
+
});
|
|
5235
|
+
} else if ('lastValidBlockHeight' in strategy) {
|
|
5236
|
+
return await this.confirmTransactionUsingBlockHeightExceedanceStrategy({
|
|
5237
|
+
commitment: commitment || this.commitment,
|
|
5238
|
+
strategy
|
|
5239
|
+
});
|
|
5240
|
+
} else {
|
|
5241
|
+
return await this.confirmTransactionUsingDurableNonceStrategy({
|
|
5242
|
+
commitment: commitment || this.commitment,
|
|
5243
|
+
strategy
|
|
5244
|
+
});
|
|
5245
|
+
}
|
|
5246
|
+
}
|
|
5247
|
+
|
|
5248
|
+
getTransactionConfirmationPromise({
|
|
5249
|
+
commitment,
|
|
5250
|
+
signature
|
|
5251
|
+
}) {
|
|
5188
5252
|
let signatureSubscriptionId;
|
|
5189
5253
|
let disposeSignatureSubscriptionStateChangeObserver;
|
|
5190
5254
|
let done = false;
|
|
5191
5255
|
const confirmationPromise = new Promise((resolve, reject) => {
|
|
5192
5256
|
try {
|
|
5193
|
-
signatureSubscriptionId = this.onSignature(
|
|
5257
|
+
signatureSubscriptionId = this.onSignature(signature, (result, context) => {
|
|
5194
5258
|
signatureSubscriptionId = undefined;
|
|
5195
5259
|
const response = {
|
|
5196
5260
|
context,
|
|
5197
5261
|
value: result
|
|
5198
5262
|
};
|
|
5199
|
-
done = true;
|
|
5200
5263
|
resolve({
|
|
5201
5264
|
__type: TransactionStatus.PROCESSED,
|
|
5202
5265
|
response
|
|
5203
5266
|
});
|
|
5204
|
-
},
|
|
5267
|
+
}, commitment);
|
|
5205
5268
|
const subscriptionSetupPromise = new Promise(resolveSubscriptionSetup => {
|
|
5206
5269
|
if (signatureSubscriptionId == null) {
|
|
5207
5270
|
resolveSubscriptionSetup();
|
|
@@ -5217,7 +5280,7 @@ class Connection {
|
|
|
5217
5280
|
(async () => {
|
|
5218
5281
|
await subscriptionSetupPromise;
|
|
5219
5282
|
if (done) return;
|
|
5220
|
-
const response = await this.getSignatureStatus(
|
|
5283
|
+
const response = await this.getSignatureStatus(signature);
|
|
5221
5284
|
if (done) return;
|
|
5222
5285
|
|
|
5223
5286
|
if (response == null) {
|
|
@@ -5236,7 +5299,7 @@ class Connection {
|
|
|
5236
5299
|
if (value !== null && value !== void 0 && value.err) {
|
|
5237
5300
|
reject(value.err);
|
|
5238
5301
|
} else {
|
|
5239
|
-
switch (
|
|
5302
|
+
switch (commitment) {
|
|
5240
5303
|
case 'confirmed':
|
|
5241
5304
|
case 'single':
|
|
5242
5305
|
case 'singleGossip':
|
|
@@ -5278,81 +5341,279 @@ class Connection {
|
|
|
5278
5341
|
reject(err);
|
|
5279
5342
|
}
|
|
5280
5343
|
});
|
|
5344
|
+
|
|
5345
|
+
const abortConfirmation = () => {
|
|
5346
|
+
if (disposeSignatureSubscriptionStateChangeObserver) {
|
|
5347
|
+
disposeSignatureSubscriptionStateChangeObserver();
|
|
5348
|
+
disposeSignatureSubscriptionStateChangeObserver = undefined;
|
|
5349
|
+
}
|
|
5350
|
+
|
|
5351
|
+
if (signatureSubscriptionId) {
|
|
5352
|
+
this.removeSignatureListener(signatureSubscriptionId);
|
|
5353
|
+
signatureSubscriptionId = undefined;
|
|
5354
|
+
}
|
|
5355
|
+
};
|
|
5356
|
+
|
|
5357
|
+
return {
|
|
5358
|
+
abortConfirmation,
|
|
5359
|
+
confirmationPromise
|
|
5360
|
+
};
|
|
5361
|
+
}
|
|
5362
|
+
|
|
5363
|
+
async confirmTransactionUsingBlockHeightExceedanceStrategy({
|
|
5364
|
+
commitment,
|
|
5365
|
+
strategy: {
|
|
5366
|
+
lastValidBlockHeight,
|
|
5367
|
+
signature
|
|
5368
|
+
}
|
|
5369
|
+
}) {
|
|
5370
|
+
let done = false;
|
|
5281
5371
|
const expiryPromise = new Promise(resolve => {
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
case 'single':
|
|
5289
|
-
case 'confirmed':
|
|
5290
|
-
case 'singleGossip':
|
|
5291
|
-
{
|
|
5292
|
-
timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
|
|
5293
|
-
break;
|
|
5294
|
-
}
|
|
5372
|
+
const checkBlockHeight = async () => {
|
|
5373
|
+
try {
|
|
5374
|
+
const blockHeight = await this.getBlockHeight(commitment);
|
|
5375
|
+
return blockHeight;
|
|
5376
|
+
} catch (_e) {
|
|
5377
|
+
return -1;
|
|
5295
5378
|
}
|
|
5379
|
+
};
|
|
5296
5380
|
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5381
|
+
(async () => {
|
|
5382
|
+
let currentBlockHeight = await checkBlockHeight();
|
|
5383
|
+
if (done) return;
|
|
5384
|
+
|
|
5385
|
+
while (currentBlockHeight <= lastValidBlockHeight) {
|
|
5386
|
+
await sleep(1000);
|
|
5387
|
+
if (done) return;
|
|
5388
|
+
currentBlockHeight = await checkBlockHeight();
|
|
5389
|
+
if (done) return;
|
|
5390
|
+
}
|
|
5391
|
+
|
|
5392
|
+
resolve({
|
|
5393
|
+
__type: TransactionStatus.BLOCKHEIGHT_EXCEEDED
|
|
5394
|
+
});
|
|
5395
|
+
})();
|
|
5396
|
+
});
|
|
5397
|
+
const {
|
|
5398
|
+
abortConfirmation,
|
|
5399
|
+
confirmationPromise
|
|
5400
|
+
} = this.getTransactionConfirmationPromise({
|
|
5401
|
+
commitment,
|
|
5402
|
+
signature
|
|
5403
|
+
});
|
|
5404
|
+
let result;
|
|
5405
|
+
|
|
5406
|
+
try {
|
|
5407
|
+
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5408
|
+
|
|
5409
|
+
if (outcome.__type === TransactionStatus.PROCESSED) {
|
|
5410
|
+
result = outcome.response;
|
|
5301
5411
|
} else {
|
|
5302
|
-
|
|
5412
|
+
throw new TransactionExpiredBlockheightExceededError(signature);
|
|
5413
|
+
}
|
|
5414
|
+
} finally {
|
|
5415
|
+
done = true;
|
|
5416
|
+
abortConfirmation();
|
|
5417
|
+
}
|
|
5303
5418
|
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
const blockHeight = await this.getBlockHeight(commitment);
|
|
5307
|
-
return blockHeight;
|
|
5308
|
-
} catch (_e) {
|
|
5309
|
-
return -1;
|
|
5310
|
-
}
|
|
5311
|
-
};
|
|
5419
|
+
return result;
|
|
5420
|
+
}
|
|
5312
5421
|
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5422
|
+
async confirmTransactionUsingDurableNonceStrategy({
|
|
5423
|
+
commitment,
|
|
5424
|
+
strategy: {
|
|
5425
|
+
minContextSlot,
|
|
5426
|
+
nonceAccountPubkey,
|
|
5427
|
+
nonceValue,
|
|
5428
|
+
signature
|
|
5429
|
+
}
|
|
5430
|
+
}) {
|
|
5431
|
+
let done = false;
|
|
5432
|
+
const expiryPromise = new Promise(resolve => {
|
|
5433
|
+
let currentNonceValue = nonceValue;
|
|
5434
|
+
let lastCheckedSlot = null;
|
|
5316
5435
|
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5436
|
+
const getCurrentNonceValue = async () => {
|
|
5437
|
+
try {
|
|
5438
|
+
const {
|
|
5439
|
+
context,
|
|
5440
|
+
value: nonceAccount
|
|
5441
|
+
} = await this.getNonceAndContext(nonceAccountPubkey, {
|
|
5442
|
+
commitment,
|
|
5443
|
+
minContextSlot
|
|
5444
|
+
});
|
|
5445
|
+
lastCheckedSlot = context.slot;
|
|
5446
|
+
return nonceAccount === null || nonceAccount === void 0 ? void 0 : nonceAccount.nonce;
|
|
5447
|
+
} catch (e) {
|
|
5448
|
+
// If for whatever reason we can't reach/read the nonce
|
|
5449
|
+
// account, just keep using the last-known value.
|
|
5450
|
+
return currentNonceValue;
|
|
5451
|
+
}
|
|
5452
|
+
};
|
|
5453
|
+
|
|
5454
|
+
(async () => {
|
|
5455
|
+
currentNonceValue = await getCurrentNonceValue();
|
|
5456
|
+
if (done) return;
|
|
5457
|
+
|
|
5458
|
+
while (true // eslint-disable-line no-constant-condition
|
|
5459
|
+
) {
|
|
5460
|
+
if (nonceValue !== currentNonceValue) {
|
|
5461
|
+
resolve({
|
|
5462
|
+
__type: TransactionStatus.NONCE_INVALID,
|
|
5463
|
+
slotInWhichNonceDidAdvance: lastCheckedSlot
|
|
5464
|
+
});
|
|
5465
|
+
return;
|
|
5322
5466
|
}
|
|
5323
5467
|
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5468
|
+
await sleep(2000);
|
|
5469
|
+
if (done) return;
|
|
5470
|
+
currentNonceValue = await getCurrentNonceValue();
|
|
5471
|
+
if (done) return;
|
|
5472
|
+
}
|
|
5473
|
+
})();
|
|
5474
|
+
});
|
|
5475
|
+
const {
|
|
5476
|
+
abortConfirmation,
|
|
5477
|
+
confirmationPromise
|
|
5478
|
+
} = this.getTransactionConfirmationPromise({
|
|
5479
|
+
commitment,
|
|
5480
|
+
signature
|
|
5329
5481
|
});
|
|
5330
5482
|
let result;
|
|
5331
5483
|
|
|
5332
5484
|
try {
|
|
5333
5485
|
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5334
5486
|
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5487
|
+
if (outcome.__type === TransactionStatus.PROCESSED) {
|
|
5488
|
+
result = outcome.response;
|
|
5489
|
+
} else {
|
|
5490
|
+
var _signatureStatus;
|
|
5491
|
+
|
|
5492
|
+
// Double check that the transaction is indeed unconfirmed.
|
|
5493
|
+
let signatureStatus;
|
|
5494
|
+
|
|
5495
|
+
while (true // eslint-disable-line no-constant-condition
|
|
5496
|
+
) {
|
|
5497
|
+
var _outcome$slotInWhichN;
|
|
5498
|
+
|
|
5499
|
+
const status = await this.getSignatureStatus(signature);
|
|
5500
|
+
|
|
5501
|
+
if (status == null) {
|
|
5502
|
+
break;
|
|
5503
|
+
}
|
|
5504
|
+
|
|
5505
|
+
if (status.context.slot < ((_outcome$slotInWhichN = outcome.slotInWhichNonceDidAdvance) !== null && _outcome$slotInWhichN !== void 0 ? _outcome$slotInWhichN : minContextSlot)) {
|
|
5506
|
+
await sleep(400);
|
|
5507
|
+
continue;
|
|
5508
|
+
}
|
|
5338
5509
|
|
|
5339
|
-
|
|
5340
|
-
result = outcome.response;
|
|
5510
|
+
signatureStatus = status;
|
|
5341
5511
|
break;
|
|
5512
|
+
}
|
|
5513
|
+
|
|
5514
|
+
if ((_signatureStatus = signatureStatus) !== null && _signatureStatus !== void 0 && _signatureStatus.value) {
|
|
5515
|
+
const commitmentForStatus = commitment || 'finalized';
|
|
5516
|
+
const {
|
|
5517
|
+
confirmationStatus
|
|
5518
|
+
} = signatureStatus.value;
|
|
5519
|
+
|
|
5520
|
+
switch (commitmentForStatus) {
|
|
5521
|
+
case 'processed':
|
|
5522
|
+
case 'recent':
|
|
5523
|
+
if (confirmationStatus !== 'processed' && confirmationStatus !== 'confirmed' && confirmationStatus !== 'finalized') {
|
|
5524
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5525
|
+
}
|
|
5526
|
+
|
|
5527
|
+
break;
|
|
5528
|
+
|
|
5529
|
+
case 'confirmed':
|
|
5530
|
+
case 'single':
|
|
5531
|
+
case 'singleGossip':
|
|
5532
|
+
if (confirmationStatus !== 'confirmed' && confirmationStatus !== 'finalized') {
|
|
5533
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5534
|
+
}
|
|
5342
5535
|
|
|
5343
|
-
|
|
5344
|
-
|
|
5536
|
+
break;
|
|
5537
|
+
|
|
5538
|
+
case 'finalized':
|
|
5539
|
+
case 'max':
|
|
5540
|
+
case 'root':
|
|
5541
|
+
if (confirmationStatus !== 'finalized') {
|
|
5542
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5543
|
+
}
|
|
5544
|
+
|
|
5545
|
+
break;
|
|
5546
|
+
|
|
5547
|
+
default:
|
|
5548
|
+
// Exhaustive switch.
|
|
5549
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5550
|
+
(_ => {})(commitmentForStatus);
|
|
5551
|
+
|
|
5552
|
+
}
|
|
5553
|
+
|
|
5554
|
+
result = {
|
|
5555
|
+
context: signatureStatus.context,
|
|
5556
|
+
value: {
|
|
5557
|
+
err: signatureStatus.value.err
|
|
5558
|
+
}
|
|
5559
|
+
};
|
|
5560
|
+
} else {
|
|
5561
|
+
throw new TransactionExpiredNonceInvalidError(signature);
|
|
5562
|
+
}
|
|
5345
5563
|
}
|
|
5346
5564
|
} finally {
|
|
5347
|
-
|
|
5565
|
+
done = true;
|
|
5566
|
+
abortConfirmation();
|
|
5567
|
+
}
|
|
5348
5568
|
|
|
5349
|
-
|
|
5350
|
-
|
|
5569
|
+
return result;
|
|
5570
|
+
}
|
|
5571
|
+
|
|
5572
|
+
async confirmTransactionUsingLegacyTimeoutStrategy({
|
|
5573
|
+
commitment,
|
|
5574
|
+
signature
|
|
5575
|
+
}) {
|
|
5576
|
+
let timeoutId;
|
|
5577
|
+
const expiryPromise = new Promise(resolve => {
|
|
5578
|
+
let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
|
|
5579
|
+
|
|
5580
|
+
switch (commitment) {
|
|
5581
|
+
case 'processed':
|
|
5582
|
+
case 'recent':
|
|
5583
|
+
case 'single':
|
|
5584
|
+
case 'confirmed':
|
|
5585
|
+
case 'singleGossip':
|
|
5586
|
+
{
|
|
5587
|
+
timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
|
|
5588
|
+
break;
|
|
5589
|
+
}
|
|
5351
5590
|
}
|
|
5352
5591
|
|
|
5353
|
-
|
|
5354
|
-
|
|
5592
|
+
timeoutId = setTimeout(() => resolve({
|
|
5593
|
+
__type: TransactionStatus.TIMED_OUT,
|
|
5594
|
+
timeoutMs
|
|
5595
|
+
}), timeoutMs);
|
|
5596
|
+
});
|
|
5597
|
+
const {
|
|
5598
|
+
abortConfirmation,
|
|
5599
|
+
confirmationPromise
|
|
5600
|
+
} = this.getTransactionConfirmationPromise({
|
|
5601
|
+
commitment,
|
|
5602
|
+
signature
|
|
5603
|
+
});
|
|
5604
|
+
let result;
|
|
5605
|
+
|
|
5606
|
+
try {
|
|
5607
|
+
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
5608
|
+
|
|
5609
|
+
if (outcome.__type === TransactionStatus.PROCESSED) {
|
|
5610
|
+
result = outcome.response;
|
|
5611
|
+
} else {
|
|
5612
|
+
throw new TransactionExpiredTimeoutError(signature, outcome.timeoutMs / 1000);
|
|
5355
5613
|
}
|
|
5614
|
+
} finally {
|
|
5615
|
+
clearTimeout(timeoutId);
|
|
5616
|
+
abortConfirmation();
|
|
5356
5617
|
}
|
|
5357
5618
|
|
|
5358
5619
|
return result;
|
|
@@ -6408,11 +6669,11 @@ class Connection {
|
|
|
6408
6669
|
*/
|
|
6409
6670
|
|
|
6410
6671
|
|
|
6411
|
-
async getNonceAndContext(nonceAccount,
|
|
6672
|
+
async getNonceAndContext(nonceAccount, commitmentOrConfig) {
|
|
6412
6673
|
const {
|
|
6413
6674
|
context,
|
|
6414
6675
|
value: accountInfo
|
|
6415
|
-
} = await this.getAccountInfoAndContext(nonceAccount,
|
|
6676
|
+
} = await this.getAccountInfoAndContext(nonceAccount, commitmentOrConfig);
|
|
6416
6677
|
let value = null;
|
|
6417
6678
|
|
|
6418
6679
|
if (accountInfo !== null) {
|
|
@@ -6429,8 +6690,8 @@ class Connection {
|
|
|
6429
6690
|
*/
|
|
6430
6691
|
|
|
6431
6692
|
|
|
6432
|
-
async getNonce(nonceAccount,
|
|
6433
|
-
return await this.getNonceAndContext(nonceAccount,
|
|
6693
|
+
async getNonce(nonceAccount, commitmentOrConfig) {
|
|
6694
|
+
return await this.getNonceAndContext(nonceAccount, commitmentOrConfig).then(x => x.value).catch(e => {
|
|
6434
6695
|
throw new Error('failed to get nonce for account ' + nonceAccount.toBase58() + ': ' + e);
|
|
6435
6696
|
});
|
|
6436
6697
|
}
|
|
@@ -9845,6 +10106,9 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9845
10106
|
if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'lastValidBlockHeight')) {
|
|
9846
10107
|
confirmationStrategy = confirmationStrategyOrConfirmOptions;
|
|
9847
10108
|
options = maybeConfirmOptions;
|
|
10109
|
+
} else if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'nonceValue')) {
|
|
10110
|
+
confirmationStrategy = confirmationStrategyOrConfirmOptions;
|
|
10111
|
+
options = maybeConfirmOptions;
|
|
9848
10112
|
} else {
|
|
9849
10113
|
options = confirmationStrategyOrConfirmOptions;
|
|
9850
10114
|
}
|
|
@@ -9872,5 +10136,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9872
10136
|
|
|
9873
10137
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9874
10138
|
|
|
9875
|
-
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 };
|
|
10139
|
+
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 };
|
|
9876
10140
|
//# sourceMappingURL=index.browser.esm.js.map
|