@solana/web3.js 1.41.9 → 1.41.10
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 +136 -42
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +137 -43
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +136 -42
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +44 -10
- package/lib/index.esm.js +137 -43
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +136 -42
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/package.json +1 -1
- package/src/connection.ts +118 -41
- package/src/transaction.ts +54 -6
- package/src/util/send-and-confirm-transaction.ts +19 -6
- package/src/util/tx-expiry-custom-errors.ts +35 -0
package/lib/index.iife.js
CHANGED
|
@@ -14028,9 +14028,17 @@ var solanaWeb3 = (function (exports) {
|
|
|
14028
14028
|
}
|
|
14029
14029
|
}
|
|
14030
14030
|
|
|
14031
|
+
exports.TransactionStatus = void 0;
|
|
14031
14032
|
/**
|
|
14032
14033
|
* Default (empty) signature
|
|
14033
14034
|
*/
|
|
14035
|
+
|
|
14036
|
+
(function (TransactionStatus) {
|
|
14037
|
+
TransactionStatus[TransactionStatus["BLOCKHEIGHT_EXCEEDED"] = 0] = "BLOCKHEIGHT_EXCEEDED";
|
|
14038
|
+
TransactionStatus[TransactionStatus["PROCESSED"] = 1] = "PROCESSED";
|
|
14039
|
+
TransactionStatus[TransactionStatus["TIMED_OUT"] = 2] = "TIMED_OUT";
|
|
14040
|
+
})(exports.TransactionStatus || (exports.TransactionStatus = {}));
|
|
14041
|
+
|
|
14034
14042
|
const DEFAULT_SIGNATURE = buffer.Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
|
14035
14043
|
/**
|
|
14036
14044
|
* Account metadata used to define instructions
|
|
@@ -14121,10 +14129,23 @@ var solanaWeb3 = (function (exports) {
|
|
|
14121
14129
|
this.feePayer = void 0;
|
|
14122
14130
|
this.instructions = [];
|
|
14123
14131
|
this.recentBlockhash = void 0;
|
|
14132
|
+
this.lastValidBlockHeight = void 0;
|
|
14124
14133
|
this.nonceInfo = void 0;
|
|
14125
14134
|
this._message = void 0;
|
|
14126
14135
|
this._json = void 0;
|
|
14127
|
-
|
|
14136
|
+
|
|
14137
|
+
if (!opts) {
|
|
14138
|
+
return;
|
|
14139
|
+
} else if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
|
|
14140
|
+
const newOpts = opts;
|
|
14141
|
+
Object.assign(this, newOpts);
|
|
14142
|
+
this.recentBlockhash = newOpts.blockhash;
|
|
14143
|
+
this.lastValidBlockHeight = newOpts.lastValidBlockHeight;
|
|
14144
|
+
} else {
|
|
14145
|
+
const oldOpts = opts;
|
|
14146
|
+
Object.assign(this, oldOpts);
|
|
14147
|
+
this.recentBlockhash = oldOpts.recentBlockhash;
|
|
14148
|
+
}
|
|
14128
14149
|
}
|
|
14129
14150
|
/**
|
|
14130
14151
|
* @internal
|
|
@@ -14734,7 +14755,11 @@ var solanaWeb3 = (function (exports) {
|
|
|
14734
14755
|
maxRetries: options.maxRetries
|
|
14735
14756
|
};
|
|
14736
14757
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
14737
|
-
const status = (await connection.confirmTransaction(
|
|
14758
|
+
const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
|
|
14759
|
+
signature: signature,
|
|
14760
|
+
blockhash: transaction.recentBlockhash,
|
|
14761
|
+
lastValidBlockHeight: transaction.lastValidBlockHeight
|
|
14762
|
+
}, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
14738
14763
|
|
|
14739
14764
|
if (status.err) {
|
|
14740
14765
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
@@ -24938,16 +24963,28 @@ var solanaWeb3 = (function (exports) {
|
|
|
24938
24963
|
|
|
24939
24964
|
const MS_PER_SLOT = 1000 / NUM_SLOTS_PER_SECOND;
|
|
24940
24965
|
|
|
24941
|
-
|
|
24942
|
-
|
|
24943
|
-
|
|
24944
|
-
|
|
24945
|
-
|
|
24946
|
-
|
|
24947
|
-
|
|
24948
|
-
return result;
|
|
24949
|
-
});
|
|
24966
|
+
class TransactionExpiredBlockheightExceededError extends Error {
|
|
24967
|
+
constructor(signature) {
|
|
24968
|
+
super(`Signature ${signature} has expired: block height exceeded.`);
|
|
24969
|
+
this.signature = void 0;
|
|
24970
|
+
this.signature = signature;
|
|
24971
|
+
}
|
|
24972
|
+
|
|
24950
24973
|
}
|
|
24974
|
+
Object.defineProperty(TransactionExpiredBlockheightExceededError.prototype, 'name', {
|
|
24975
|
+
value: 'TransactionExpiredBlockheightExceededError'
|
|
24976
|
+
});
|
|
24977
|
+
class TransactionExpiredTimeoutError extends Error {
|
|
24978
|
+
constructor(signature, timeoutSeconds) {
|
|
24979
|
+
super(`Transaction was not confirmed in ${timeoutSeconds.toFixed(2)} seconds. It is ` + 'unknown if it succeeded or failed. Check signature ' + `${signature} using the Solana Explorer or CLI tools.`);
|
|
24980
|
+
this.signature = void 0;
|
|
24981
|
+
this.signature = signature;
|
|
24982
|
+
}
|
|
24983
|
+
|
|
24984
|
+
}
|
|
24985
|
+
Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
24986
|
+
value: 'TransactionExpiredTimeoutError'
|
|
24987
|
+
});
|
|
24951
24988
|
|
|
24952
24989
|
function makeWebsocketUrl(endpoint) {
|
|
24953
24990
|
let url = new URL(endpoint);
|
|
@@ -26417,67 +26454,124 @@ var solanaWeb3 = (function (exports) {
|
|
|
26417
26454
|
|
|
26418
26455
|
return res.result;
|
|
26419
26456
|
}
|
|
26420
|
-
/**
|
|
26421
|
-
* Confirm the transaction identified by the specified signature.
|
|
26422
|
-
*/
|
|
26423
26457
|
|
|
26458
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
26459
|
+
async confirmTransaction(strategy, commitment) {
|
|
26460
|
+
let rawSignature;
|
|
26461
|
+
|
|
26462
|
+
if (typeof strategy == 'string') {
|
|
26463
|
+
rawSignature = strategy;
|
|
26464
|
+
} else {
|
|
26465
|
+
const config = strategy;
|
|
26466
|
+
rawSignature = config.signature;
|
|
26467
|
+
}
|
|
26424
26468
|
|
|
26425
|
-
async confirmTransaction(signature, commitment) {
|
|
26426
26469
|
let decodedSignature;
|
|
26427
26470
|
|
|
26428
26471
|
try {
|
|
26429
|
-
decodedSignature = bs58$1.decode(
|
|
26472
|
+
decodedSignature = bs58$1.decode(rawSignature);
|
|
26430
26473
|
} catch (err) {
|
|
26431
|
-
throw new Error('signature must be base58 encoded: ' +
|
|
26474
|
+
throw new Error('signature must be base58 encoded: ' + rawSignature);
|
|
26432
26475
|
}
|
|
26433
26476
|
|
|
26434
26477
|
assert$c(decodedSignature.length === 64, 'signature has invalid length');
|
|
26435
|
-
const start = Date.now();
|
|
26436
26478
|
const subscriptionCommitment = commitment || this.commitment;
|
|
26479
|
+
let timeoutId;
|
|
26437
26480
|
let subscriptionId;
|
|
26438
|
-
let
|
|
26439
|
-
const
|
|
26481
|
+
let done = false;
|
|
26482
|
+
const confirmationPromise = new Promise((resolve, reject) => {
|
|
26440
26483
|
try {
|
|
26441
|
-
subscriptionId = this.onSignature(
|
|
26484
|
+
subscriptionId = this.onSignature(rawSignature, (result, context) => {
|
|
26442
26485
|
subscriptionId = undefined;
|
|
26443
|
-
response = {
|
|
26486
|
+
const response = {
|
|
26444
26487
|
context,
|
|
26445
26488
|
value: result
|
|
26446
26489
|
};
|
|
26447
|
-
|
|
26490
|
+
done = true;
|
|
26491
|
+
resolve({
|
|
26492
|
+
__type: exports.TransactionStatus.PROCESSED,
|
|
26493
|
+
response
|
|
26494
|
+
});
|
|
26448
26495
|
}, subscriptionCommitment);
|
|
26449
26496
|
} catch (err) {
|
|
26450
26497
|
reject(err);
|
|
26451
26498
|
}
|
|
26452
26499
|
});
|
|
26453
|
-
|
|
26454
|
-
|
|
26455
|
-
|
|
26456
|
-
|
|
26457
|
-
|
|
26458
|
-
|
|
26459
|
-
|
|
26460
|
-
|
|
26461
|
-
|
|
26462
|
-
|
|
26463
|
-
|
|
26500
|
+
|
|
26501
|
+
const checkBlockHeight = async () => {
|
|
26502
|
+
try {
|
|
26503
|
+
const blockHeight = await this.getBlockHeight(commitment);
|
|
26504
|
+
return blockHeight;
|
|
26505
|
+
} catch (_e) {
|
|
26506
|
+
return -1;
|
|
26507
|
+
}
|
|
26508
|
+
};
|
|
26509
|
+
|
|
26510
|
+
const expiryPromise = new Promise(resolve => {
|
|
26511
|
+
if (typeof strategy === 'string') {
|
|
26512
|
+
let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
|
|
26513
|
+
|
|
26514
|
+
switch (subscriptionCommitment) {
|
|
26515
|
+
case 'processed':
|
|
26516
|
+
case 'recent':
|
|
26517
|
+
case 'single':
|
|
26518
|
+
case 'confirmed':
|
|
26519
|
+
case 'singleGossip':
|
|
26520
|
+
{
|
|
26521
|
+
timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
|
|
26522
|
+
break;
|
|
26523
|
+
}
|
|
26464
26524
|
}
|
|
26465
|
-
|
|
26525
|
+
|
|
26526
|
+
timeoutId = setTimeout(() => resolve({
|
|
26527
|
+
__type: exports.TransactionStatus.TIMED_OUT,
|
|
26528
|
+
timeoutMs
|
|
26529
|
+
}), timeoutMs);
|
|
26530
|
+
} else {
|
|
26531
|
+
let config = strategy;
|
|
26532
|
+
|
|
26533
|
+
(async () => {
|
|
26534
|
+
let currentBlockHeight = await checkBlockHeight();
|
|
26535
|
+
if (done) return;
|
|
26536
|
+
|
|
26537
|
+
while (currentBlockHeight <= config.lastValidBlockHeight) {
|
|
26538
|
+
await sleep(1000);
|
|
26539
|
+
if (done) return;
|
|
26540
|
+
currentBlockHeight = await checkBlockHeight();
|
|
26541
|
+
if (done) return;
|
|
26542
|
+
}
|
|
26543
|
+
|
|
26544
|
+
resolve({
|
|
26545
|
+
__type: exports.TransactionStatus.BLOCKHEIGHT_EXCEEDED
|
|
26546
|
+
});
|
|
26547
|
+
})();
|
|
26548
|
+
}
|
|
26549
|
+
});
|
|
26550
|
+
let result;
|
|
26466
26551
|
|
|
26467
26552
|
try {
|
|
26468
|
-
await
|
|
26553
|
+
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
26554
|
+
|
|
26555
|
+
switch (outcome.__type) {
|
|
26556
|
+
case exports.TransactionStatus.BLOCKHEIGHT_EXCEEDED:
|
|
26557
|
+
throw new TransactionExpiredBlockheightExceededError(rawSignature);
|
|
26558
|
+
|
|
26559
|
+
case exports.TransactionStatus.PROCESSED:
|
|
26560
|
+
result = outcome.response;
|
|
26561
|
+
break;
|
|
26562
|
+
|
|
26563
|
+
case exports.TransactionStatus.TIMED_OUT:
|
|
26564
|
+
throw new TransactionExpiredTimeoutError(rawSignature, outcome.timeoutMs / 1000);
|
|
26565
|
+
}
|
|
26469
26566
|
} finally {
|
|
26567
|
+
clearTimeout(timeoutId);
|
|
26568
|
+
|
|
26470
26569
|
if (subscriptionId) {
|
|
26471
26570
|
this.removeSignatureListener(subscriptionId);
|
|
26472
26571
|
}
|
|
26473
26572
|
}
|
|
26474
26573
|
|
|
26475
|
-
|
|
26476
|
-
const duration = (Date.now() - start) / 1000;
|
|
26477
|
-
throw new Error(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`);
|
|
26478
|
-
}
|
|
26479
|
-
|
|
26480
|
-
return response;
|
|
26574
|
+
return result;
|
|
26481
26575
|
}
|
|
26482
26576
|
/**
|
|
26483
26577
|
* Return the list of nodes that are currently participating in the cluster
|