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