@solana/web3.js 1.41.9 → 1.41.11
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 +181 -60
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +182 -61
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +181 -60
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +44 -10
- package/lib/index.esm.js +182 -61
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +181 -60
- 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 +22 -22
- package/src/connection.ts +118 -41
- package/src/message.ts +9 -12
- package/src/transaction.ts +56 -8
- package/src/util/guarded-array-utils.ts +34 -0
- package/src/util/send-and-confirm-transaction.ts +19 -6
- package/src/util/tx-expiry-custom-errors.ts +35 -0
- package/src/validator-info.ts +5 -4
package/lib/index.iife.js
CHANGED
|
@@ -13876,6 +13876,36 @@ var solanaWeb3 = (function (exports) {
|
|
|
13876
13876
|
}
|
|
13877
13877
|
}
|
|
13878
13878
|
|
|
13879
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
13880
|
+
/**
|
|
13881
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
13882
|
+
*/
|
|
13883
|
+
|
|
13884
|
+
function guardedShift(byteArray) {
|
|
13885
|
+
if (byteArray.length === 0) {
|
|
13886
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
13887
|
+
}
|
|
13888
|
+
|
|
13889
|
+
return byteArray.shift();
|
|
13890
|
+
}
|
|
13891
|
+
/**
|
|
13892
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
13893
|
+
* the array.
|
|
13894
|
+
*/
|
|
13895
|
+
|
|
13896
|
+
function guardedSplice(byteArray, ...args) {
|
|
13897
|
+
var _args$;
|
|
13898
|
+
|
|
13899
|
+
const [start] = args;
|
|
13900
|
+
|
|
13901
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
13902
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
13903
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
13904
|
+
}
|
|
13905
|
+
|
|
13906
|
+
return byteArray.splice(...args);
|
|
13907
|
+
}
|
|
13908
|
+
|
|
13879
13909
|
/**
|
|
13880
13910
|
* The message header, identifying signed and read-only account
|
|
13881
13911
|
*/
|
|
@@ -13974,32 +14004,28 @@ var solanaWeb3 = (function (exports) {
|
|
|
13974
14004
|
static from(buffer$1) {
|
|
13975
14005
|
// Slice up wire data
|
|
13976
14006
|
let byteArray = [...buffer$1];
|
|
13977
|
-
const numRequiredSignatures = byteArray
|
|
13978
|
-
const numReadonlySignedAccounts = byteArray
|
|
13979
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
14007
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
14008
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
14009
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
13980
14010
|
const accountCount = decodeLength(byteArray);
|
|
13981
14011
|
let accountKeys = [];
|
|
13982
14012
|
|
|
13983
14013
|
for (let i = 0; i < accountCount; i++) {
|
|
13984
|
-
const account = byteArray
|
|
13985
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
14014
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
13986
14015
|
accountKeys.push(bs58$1.encode(buffer.Buffer.from(account)));
|
|
13987
14016
|
}
|
|
13988
14017
|
|
|
13989
|
-
const recentBlockhash = byteArray
|
|
13990
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
14018
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
13991
14019
|
const instructionCount = decodeLength(byteArray);
|
|
13992
14020
|
let instructions = [];
|
|
13993
14021
|
|
|
13994
14022
|
for (let i = 0; i < instructionCount; i++) {
|
|
13995
|
-
const programIdIndex = byteArray
|
|
14023
|
+
const programIdIndex = guardedShift(byteArray);
|
|
13996
14024
|
const accountCount = decodeLength(byteArray);
|
|
13997
|
-
const accounts = byteArray
|
|
13998
|
-
byteArray = byteArray.slice(accountCount);
|
|
14025
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
13999
14026
|
const dataLength = decodeLength(byteArray);
|
|
14000
|
-
const dataSlice = byteArray
|
|
14027
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
14001
14028
|
const data = bs58$1.encode(buffer.Buffer.from(dataSlice));
|
|
14002
|
-
byteArray = byteArray.slice(dataLength);
|
|
14003
14029
|
instructions.push({
|
|
14004
14030
|
programIdIndex,
|
|
14005
14031
|
accounts,
|
|
@@ -14028,9 +14054,21 @@ var solanaWeb3 = (function (exports) {
|
|
|
14028
14054
|
}
|
|
14029
14055
|
}
|
|
14030
14056
|
|
|
14057
|
+
/**
|
|
14058
|
+
* Transaction signature as base-58 encoded string
|
|
14059
|
+
*/
|
|
14060
|
+
|
|
14061
|
+
exports.TransactionStatus = void 0;
|
|
14031
14062
|
/**
|
|
14032
14063
|
* Default (empty) signature
|
|
14033
14064
|
*/
|
|
14065
|
+
|
|
14066
|
+
(function (TransactionStatus) {
|
|
14067
|
+
TransactionStatus[TransactionStatus["BLOCKHEIGHT_EXCEEDED"] = 0] = "BLOCKHEIGHT_EXCEEDED";
|
|
14068
|
+
TransactionStatus[TransactionStatus["PROCESSED"] = 1] = "PROCESSED";
|
|
14069
|
+
TransactionStatus[TransactionStatus["TIMED_OUT"] = 2] = "TIMED_OUT";
|
|
14070
|
+
})(exports.TransactionStatus || (exports.TransactionStatus = {}));
|
|
14071
|
+
|
|
14034
14072
|
const DEFAULT_SIGNATURE = buffer.Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
|
14035
14073
|
/**
|
|
14036
14074
|
* Account metadata used to define instructions
|
|
@@ -14121,10 +14159,23 @@ var solanaWeb3 = (function (exports) {
|
|
|
14121
14159
|
this.feePayer = void 0;
|
|
14122
14160
|
this.instructions = [];
|
|
14123
14161
|
this.recentBlockhash = void 0;
|
|
14162
|
+
this.lastValidBlockHeight = void 0;
|
|
14124
14163
|
this.nonceInfo = void 0;
|
|
14125
14164
|
this._message = void 0;
|
|
14126
14165
|
this._json = void 0;
|
|
14127
|
-
|
|
14166
|
+
|
|
14167
|
+
if (!opts) {
|
|
14168
|
+
return;
|
|
14169
|
+
} else if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
|
|
14170
|
+
const newOpts = opts;
|
|
14171
|
+
Object.assign(this, newOpts);
|
|
14172
|
+
this.recentBlockhash = newOpts.blockhash;
|
|
14173
|
+
this.lastValidBlockHeight = newOpts.lastValidBlockHeight;
|
|
14174
|
+
} else {
|
|
14175
|
+
const oldOpts = opts;
|
|
14176
|
+
Object.assign(this, oldOpts);
|
|
14177
|
+
this.recentBlockhash = oldOpts.recentBlockhash;
|
|
14178
|
+
}
|
|
14128
14179
|
}
|
|
14129
14180
|
/**
|
|
14130
14181
|
* @internal
|
|
@@ -14657,8 +14708,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
14657
14708
|
let signatures = [];
|
|
14658
14709
|
|
|
14659
14710
|
for (let i = 0; i < signatureCount; i++) {
|
|
14660
|
-
const signature = byteArray
|
|
14661
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
14711
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
14662
14712
|
signatures.push(bs58$1.encode(buffer.Buffer.from(signature)));
|
|
14663
14713
|
}
|
|
14664
14714
|
|
|
@@ -14734,7 +14784,11 @@ var solanaWeb3 = (function (exports) {
|
|
|
14734
14784
|
maxRetries: options.maxRetries
|
|
14735
14785
|
};
|
|
14736
14786
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
14737
|
-
const status = (await connection.confirmTransaction(
|
|
14787
|
+
const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
|
|
14788
|
+
signature: signature,
|
|
14789
|
+
blockhash: transaction.recentBlockhash,
|
|
14790
|
+
lastValidBlockHeight: transaction.lastValidBlockHeight
|
|
14791
|
+
}, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
14738
14792
|
|
|
14739
14793
|
if (status.err) {
|
|
14740
14794
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
@@ -24938,16 +24992,28 @@ var solanaWeb3 = (function (exports) {
|
|
|
24938
24992
|
|
|
24939
24993
|
const MS_PER_SLOT = 1000 / NUM_SLOTS_PER_SECOND;
|
|
24940
24994
|
|
|
24941
|
-
|
|
24942
|
-
|
|
24943
|
-
|
|
24944
|
-
|
|
24945
|
-
|
|
24946
|
-
|
|
24947
|
-
|
|
24948
|
-
return result;
|
|
24949
|
-
});
|
|
24995
|
+
class TransactionExpiredBlockheightExceededError extends Error {
|
|
24996
|
+
constructor(signature) {
|
|
24997
|
+
super(`Signature ${signature} has expired: block height exceeded.`);
|
|
24998
|
+
this.signature = void 0;
|
|
24999
|
+
this.signature = signature;
|
|
25000
|
+
}
|
|
25001
|
+
|
|
24950
25002
|
}
|
|
25003
|
+
Object.defineProperty(TransactionExpiredBlockheightExceededError.prototype, 'name', {
|
|
25004
|
+
value: 'TransactionExpiredBlockheightExceededError'
|
|
25005
|
+
});
|
|
25006
|
+
class TransactionExpiredTimeoutError extends Error {
|
|
25007
|
+
constructor(signature, timeoutSeconds) {
|
|
25008
|
+
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.`);
|
|
25009
|
+
this.signature = void 0;
|
|
25010
|
+
this.signature = signature;
|
|
25011
|
+
}
|
|
25012
|
+
|
|
25013
|
+
}
|
|
25014
|
+
Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
25015
|
+
value: 'TransactionExpiredTimeoutError'
|
|
25016
|
+
});
|
|
24951
25017
|
|
|
24952
25018
|
function makeWebsocketUrl(endpoint) {
|
|
24953
25019
|
let url = new URL(endpoint);
|
|
@@ -26417,67 +26483,124 @@ var solanaWeb3 = (function (exports) {
|
|
|
26417
26483
|
|
|
26418
26484
|
return res.result;
|
|
26419
26485
|
}
|
|
26420
|
-
/**
|
|
26421
|
-
* Confirm the transaction identified by the specified signature.
|
|
26422
|
-
*/
|
|
26423
26486
|
|
|
26487
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
26488
|
+
async confirmTransaction(strategy, commitment) {
|
|
26489
|
+
let rawSignature;
|
|
26490
|
+
|
|
26491
|
+
if (typeof strategy == 'string') {
|
|
26492
|
+
rawSignature = strategy;
|
|
26493
|
+
} else {
|
|
26494
|
+
const config = strategy;
|
|
26495
|
+
rawSignature = config.signature;
|
|
26496
|
+
}
|
|
26424
26497
|
|
|
26425
|
-
async confirmTransaction(signature, commitment) {
|
|
26426
26498
|
let decodedSignature;
|
|
26427
26499
|
|
|
26428
26500
|
try {
|
|
26429
|
-
decodedSignature = bs58$1.decode(
|
|
26501
|
+
decodedSignature = bs58$1.decode(rawSignature);
|
|
26430
26502
|
} catch (err) {
|
|
26431
|
-
throw new Error('signature must be base58 encoded: ' +
|
|
26503
|
+
throw new Error('signature must be base58 encoded: ' + rawSignature);
|
|
26432
26504
|
}
|
|
26433
26505
|
|
|
26434
26506
|
assert$c(decodedSignature.length === 64, 'signature has invalid length');
|
|
26435
|
-
const start = Date.now();
|
|
26436
26507
|
const subscriptionCommitment = commitment || this.commitment;
|
|
26508
|
+
let timeoutId;
|
|
26437
26509
|
let subscriptionId;
|
|
26438
|
-
let
|
|
26439
|
-
const
|
|
26510
|
+
let done = false;
|
|
26511
|
+
const confirmationPromise = new Promise((resolve, reject) => {
|
|
26440
26512
|
try {
|
|
26441
|
-
subscriptionId = this.onSignature(
|
|
26513
|
+
subscriptionId = this.onSignature(rawSignature, (result, context) => {
|
|
26442
26514
|
subscriptionId = undefined;
|
|
26443
|
-
response = {
|
|
26515
|
+
const response = {
|
|
26444
26516
|
context,
|
|
26445
26517
|
value: result
|
|
26446
26518
|
};
|
|
26447
|
-
|
|
26519
|
+
done = true;
|
|
26520
|
+
resolve({
|
|
26521
|
+
__type: exports.TransactionStatus.PROCESSED,
|
|
26522
|
+
response
|
|
26523
|
+
});
|
|
26448
26524
|
}, subscriptionCommitment);
|
|
26449
26525
|
} catch (err) {
|
|
26450
26526
|
reject(err);
|
|
26451
26527
|
}
|
|
26452
26528
|
});
|
|
26453
|
-
|
|
26454
|
-
|
|
26455
|
-
|
|
26456
|
-
|
|
26457
|
-
|
|
26458
|
-
|
|
26459
|
-
|
|
26460
|
-
|
|
26461
|
-
|
|
26462
|
-
|
|
26463
|
-
|
|
26529
|
+
|
|
26530
|
+
const checkBlockHeight = async () => {
|
|
26531
|
+
try {
|
|
26532
|
+
const blockHeight = await this.getBlockHeight(commitment);
|
|
26533
|
+
return blockHeight;
|
|
26534
|
+
} catch (_e) {
|
|
26535
|
+
return -1;
|
|
26536
|
+
}
|
|
26537
|
+
};
|
|
26538
|
+
|
|
26539
|
+
const expiryPromise = new Promise(resolve => {
|
|
26540
|
+
if (typeof strategy === 'string') {
|
|
26541
|
+
let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
|
|
26542
|
+
|
|
26543
|
+
switch (subscriptionCommitment) {
|
|
26544
|
+
case 'processed':
|
|
26545
|
+
case 'recent':
|
|
26546
|
+
case 'single':
|
|
26547
|
+
case 'confirmed':
|
|
26548
|
+
case 'singleGossip':
|
|
26549
|
+
{
|
|
26550
|
+
timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
|
|
26551
|
+
break;
|
|
26552
|
+
}
|
|
26464
26553
|
}
|
|
26465
|
-
|
|
26554
|
+
|
|
26555
|
+
timeoutId = setTimeout(() => resolve({
|
|
26556
|
+
__type: exports.TransactionStatus.TIMED_OUT,
|
|
26557
|
+
timeoutMs
|
|
26558
|
+
}), timeoutMs);
|
|
26559
|
+
} else {
|
|
26560
|
+
let config = strategy;
|
|
26561
|
+
|
|
26562
|
+
(async () => {
|
|
26563
|
+
let currentBlockHeight = await checkBlockHeight();
|
|
26564
|
+
if (done) return;
|
|
26565
|
+
|
|
26566
|
+
while (currentBlockHeight <= config.lastValidBlockHeight) {
|
|
26567
|
+
await sleep(1000);
|
|
26568
|
+
if (done) return;
|
|
26569
|
+
currentBlockHeight = await checkBlockHeight();
|
|
26570
|
+
if (done) return;
|
|
26571
|
+
}
|
|
26572
|
+
|
|
26573
|
+
resolve({
|
|
26574
|
+
__type: exports.TransactionStatus.BLOCKHEIGHT_EXCEEDED
|
|
26575
|
+
});
|
|
26576
|
+
})();
|
|
26577
|
+
}
|
|
26578
|
+
});
|
|
26579
|
+
let result;
|
|
26466
26580
|
|
|
26467
26581
|
try {
|
|
26468
|
-
await
|
|
26582
|
+
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
26583
|
+
|
|
26584
|
+
switch (outcome.__type) {
|
|
26585
|
+
case exports.TransactionStatus.BLOCKHEIGHT_EXCEEDED:
|
|
26586
|
+
throw new TransactionExpiredBlockheightExceededError(rawSignature);
|
|
26587
|
+
|
|
26588
|
+
case exports.TransactionStatus.PROCESSED:
|
|
26589
|
+
result = outcome.response;
|
|
26590
|
+
break;
|
|
26591
|
+
|
|
26592
|
+
case exports.TransactionStatus.TIMED_OUT:
|
|
26593
|
+
throw new TransactionExpiredTimeoutError(rawSignature, outcome.timeoutMs / 1000);
|
|
26594
|
+
}
|
|
26469
26595
|
} finally {
|
|
26596
|
+
clearTimeout(timeoutId);
|
|
26597
|
+
|
|
26470
26598
|
if (subscriptionId) {
|
|
26471
26599
|
this.removeSignatureListener(subscriptionId);
|
|
26472
26600
|
}
|
|
26473
26601
|
}
|
|
26474
26602
|
|
|
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;
|
|
26603
|
+
return result;
|
|
26481
26604
|
}
|
|
26482
26605
|
/**
|
|
26483
26606
|
* Return the list of nodes that are currently participating in the cluster
|
|
@@ -29594,10 +29717,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
29594
29717
|
const configKeys = [];
|
|
29595
29718
|
|
|
29596
29719
|
for (let i = 0; i < 2; i++) {
|
|
29597
|
-
const publicKey = new PublicKey(byteArray
|
|
29598
|
-
|
|
29599
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
29600
|
-
byteArray = byteArray.slice(1);
|
|
29720
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
29721
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
29601
29722
|
configKeys.push({
|
|
29602
29723
|
publicKey,
|
|
29603
29724
|
isSigner
|