@solana/web3.js 1.41.8 → 1.42.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 +182 -64
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +183 -65
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +182 -64
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +65 -22
- package/lib/index.esm.js +183 -65
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +182 -64
- 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 +2 -2
- package/src/connection.ts +157 -65
- package/src/transaction.ts +54 -6
- package/src/util/send-and-confirm-raw-transaction.ts +52 -7
- package/src/util/send-and-confirm-transaction.ts +19 -6
- package/src/util/tx-expiry-custom-errors.ts +35 -0
package/lib/index.d.ts
CHANGED
|
@@ -338,6 +338,11 @@ declare module '@solana/web3.js' {
|
|
|
338
338
|
* Transaction signature as base-58 encoded string
|
|
339
339
|
*/
|
|
340
340
|
export type TransactionSignature = string;
|
|
341
|
+
export const enum TransactionStatus {
|
|
342
|
+
BLOCKHEIGHT_EXCEEDED = 0,
|
|
343
|
+
PROCESSED = 1,
|
|
344
|
+
TIMED_OUT = 2,
|
|
345
|
+
}
|
|
341
346
|
/**
|
|
342
347
|
* Account metadata used to define instructions
|
|
343
348
|
*/
|
|
@@ -394,17 +399,29 @@ declare module '@solana/web3.js' {
|
|
|
394
399
|
};
|
|
395
400
|
/**
|
|
396
401
|
* List of Transaction object fields that may be initialized at construction
|
|
397
|
-
*
|
|
398
402
|
*/
|
|
399
|
-
export type
|
|
400
|
-
/** A recent blockhash */
|
|
401
|
-
recentBlockhash?: Blockhash | null;
|
|
403
|
+
export type TransactionCtorFields_DEPRECATED = {
|
|
402
404
|
/** Optional nonce information used for offline nonce'd transactions */
|
|
403
405
|
nonceInfo?: NonceInformation | null;
|
|
404
406
|
/** The transaction fee payer */
|
|
405
407
|
feePayer?: PublicKey | null;
|
|
406
408
|
/** One or more signatures */
|
|
407
409
|
signatures?: Array<SignaturePubkeyPair>;
|
|
410
|
+
/** A recent blockhash */
|
|
411
|
+
recentBlockhash?: Blockhash;
|
|
412
|
+
};
|
|
413
|
+
/**
|
|
414
|
+
* List of Transaction object fields that may be initialized at construction
|
|
415
|
+
*/
|
|
416
|
+
export type TransactionBlockhashCtor = {
|
|
417
|
+
/** The transaction fee payer */
|
|
418
|
+
feePayer?: PublicKey | null;
|
|
419
|
+
/** One or more signatures */
|
|
420
|
+
signatures?: Array<SignaturePubkeyPair>;
|
|
421
|
+
/** A recent blockhash */
|
|
422
|
+
blockhash: Blockhash;
|
|
423
|
+
/** the last block chain can advance to before tx is exportd expired */
|
|
424
|
+
lastValidBlockHeight: number;
|
|
408
425
|
};
|
|
409
426
|
/**
|
|
410
427
|
* Nonce information to be used to build an offline Transaction.
|
|
@@ -440,15 +457,21 @@ declare module '@solana/web3.js' {
|
|
|
440
457
|
* A recent transaction id. Must be populated by the caller
|
|
441
458
|
*/
|
|
442
459
|
recentBlockhash?: Blockhash;
|
|
460
|
+
/**
|
|
461
|
+
* the last block chain can advance to before tx is exportd expired
|
|
462
|
+
* */
|
|
463
|
+
lastValidBlockHeight?: number;
|
|
443
464
|
/**
|
|
444
465
|
* Optional Nonce information. If populated, transaction will use a durable
|
|
445
466
|
* Nonce hash instead of a recentBlockhash. Must be populated by the caller
|
|
446
467
|
*/
|
|
447
468
|
nonceInfo?: NonceInformation;
|
|
469
|
+
constructor(opts?: TransactionBlockhashCtor);
|
|
448
470
|
/**
|
|
449
|
-
*
|
|
471
|
+
* @deprecated `TransactionCtorFields` has been deprecated and will be removed in a future version.
|
|
472
|
+
* Please supply a `TransactionBlockhashCtor` instead.
|
|
450
473
|
*/
|
|
451
|
-
constructor(opts?:
|
|
474
|
+
constructor(opts?: TransactionCtorFields_DEPRECATED);
|
|
452
475
|
/**
|
|
453
476
|
* Add one or more instructions to this Transaction
|
|
454
477
|
*/
|
|
@@ -602,6 +625,17 @@ declare module '@solana/web3.js' {
|
|
|
602
625
|
/** response value */
|
|
603
626
|
value: T;
|
|
604
627
|
};
|
|
628
|
+
export type BlockhashWithExpiryBlockHeight = Readonly<{
|
|
629
|
+
blockhash: Blockhash;
|
|
630
|
+
lastValidBlockHeight: number;
|
|
631
|
+
}>;
|
|
632
|
+
/**
|
|
633
|
+
* A strategy for confirming transactions that uses the last valid
|
|
634
|
+
* block height for a given blockhash to check for transaction expiration.
|
|
635
|
+
*/
|
|
636
|
+
export type BlockheightBasedTransactionConfimationStrategy = {
|
|
637
|
+
signature: TransactionSignature;
|
|
638
|
+
} & BlockhashWithExpiryBlockHeight;
|
|
605
639
|
/**
|
|
606
640
|
* The level of commitment desired when querying state
|
|
607
641
|
* <pre>
|
|
@@ -1624,11 +1658,13 @@ declare module '@solana/web3.js' {
|
|
|
1624
1658
|
account: AccountInfo<Buffer | ParsedAccountData>;
|
|
1625
1659
|
}>
|
|
1626
1660
|
>;
|
|
1627
|
-
/**
|
|
1628
|
-
* Confirm the transaction identified by the specified signature.
|
|
1629
|
-
*/
|
|
1630
1661
|
confirmTransaction(
|
|
1631
|
-
|
|
1662
|
+
strategy: BlockheightBasedTransactionConfimationStrategy,
|
|
1663
|
+
commitment?: Commitment,
|
|
1664
|
+
): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
1665
|
+
/** @deprecated Instead, call `confirmTransaction` using a `TransactionConfirmationConfig` */
|
|
1666
|
+
confirmTransaction(
|
|
1667
|
+
strategy: TransactionSignature,
|
|
1632
1668
|
commitment?: Commitment,
|
|
1633
1669
|
): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
1634
1670
|
/**
|
|
@@ -1756,22 +1792,18 @@ declare module '@solana/web3.js' {
|
|
|
1756
1792
|
}>;
|
|
1757
1793
|
/**
|
|
1758
1794
|
* Fetch the latest blockhash from the cluster
|
|
1759
|
-
* @return {Promise<
|
|
1795
|
+
* @return {Promise<BlockhashWithExpiryBlockHeight>}
|
|
1760
1796
|
*/
|
|
1761
|
-
getLatestBlockhash(
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
}>;
|
|
1797
|
+
getLatestBlockhash(
|
|
1798
|
+
commitment?: Commitment,
|
|
1799
|
+
): Promise<BlockhashWithExpiryBlockHeight>;
|
|
1765
1800
|
/**
|
|
1766
1801
|
* Fetch the latest blockhash from the cluster
|
|
1767
|
-
* @return {Promise<
|
|
1802
|
+
* @return {Promise<BlockhashWithExpiryBlockHeight>}
|
|
1768
1803
|
*/
|
|
1769
|
-
getLatestBlockhashAndContext(
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
lastValidBlockHeight: number;
|
|
1773
|
-
}>
|
|
1774
|
-
>;
|
|
1804
|
+
getLatestBlockhashAndContext(
|
|
1805
|
+
commitment?: Commitment,
|
|
1806
|
+
): Promise<RpcResponseAndContext<BlockhashWithExpiryBlockHeight>>;
|
|
1775
1807
|
/**
|
|
1776
1808
|
* Fetch the node version
|
|
1777
1809
|
*/
|
|
@@ -3320,9 +3352,20 @@ declare module '@solana/web3.js' {
|
|
|
3320
3352
|
*
|
|
3321
3353
|
* @param {Connection} connection
|
|
3322
3354
|
* @param {Buffer} rawTransaction
|
|
3355
|
+
* @param {BlockheightBasedTransactionConfimationStrategy} confirmationStrategy
|
|
3323
3356
|
* @param {ConfirmOptions} [options]
|
|
3324
3357
|
* @returns {Promise<TransactionSignature>}
|
|
3325
3358
|
*/
|
|
3359
|
+
export function sendAndConfirmRawTransaction(
|
|
3360
|
+
connection: Connection,
|
|
3361
|
+
rawTransaction: Buffer,
|
|
3362
|
+
confirmationStrategy: BlockheightBasedTransactionConfimationStrategy,
|
|
3363
|
+
options?: ConfirmOptions,
|
|
3364
|
+
): Promise<TransactionSignature>;
|
|
3365
|
+
/**
|
|
3366
|
+
* @deprecated Calling `sendAndConfirmRawTransaction()` without a `confirmationStrategy`
|
|
3367
|
+
* is no longer supported and will be removed in a future version.
|
|
3368
|
+
*/
|
|
3326
3369
|
export function sendAndConfirmRawTransaction(
|
|
3327
3370
|
connection: Connection,
|
|
3328
3371
|
rawTransaction: Buffer,
|
package/lib/index.esm.js
CHANGED
|
@@ -2353,9 +2353,17 @@ function assert (condition, message) {
|
|
|
2353
2353
|
}
|
|
2354
2354
|
}
|
|
2355
2355
|
|
|
2356
|
+
let TransactionStatus;
|
|
2356
2357
|
/**
|
|
2357
2358
|
* Default (empty) signature
|
|
2358
2359
|
*/
|
|
2360
|
+
|
|
2361
|
+
(function (TransactionStatus) {
|
|
2362
|
+
TransactionStatus[TransactionStatus["BLOCKHEIGHT_EXCEEDED"] = 0] = "BLOCKHEIGHT_EXCEEDED";
|
|
2363
|
+
TransactionStatus[TransactionStatus["PROCESSED"] = 1] = "PROCESSED";
|
|
2364
|
+
TransactionStatus[TransactionStatus["TIMED_OUT"] = 2] = "TIMED_OUT";
|
|
2365
|
+
})(TransactionStatus || (TransactionStatus = {}));
|
|
2366
|
+
|
|
2359
2367
|
const DEFAULT_SIGNATURE = Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
|
2360
2368
|
/**
|
|
2361
2369
|
* Account metadata used to define instructions
|
|
@@ -2446,10 +2454,23 @@ class Transaction {
|
|
|
2446
2454
|
this.feePayer = void 0;
|
|
2447
2455
|
this.instructions = [];
|
|
2448
2456
|
this.recentBlockhash = void 0;
|
|
2457
|
+
this.lastValidBlockHeight = void 0;
|
|
2449
2458
|
this.nonceInfo = void 0;
|
|
2450
2459
|
this._message = void 0;
|
|
2451
2460
|
this._json = void 0;
|
|
2452
|
-
|
|
2461
|
+
|
|
2462
|
+
if (!opts) {
|
|
2463
|
+
return;
|
|
2464
|
+
} else if (Object.prototype.hasOwnProperty.call(opts, 'lastValidBlockHeight')) {
|
|
2465
|
+
const newOpts = opts;
|
|
2466
|
+
Object.assign(this, newOpts);
|
|
2467
|
+
this.recentBlockhash = newOpts.blockhash;
|
|
2468
|
+
this.lastValidBlockHeight = newOpts.lastValidBlockHeight;
|
|
2469
|
+
} else {
|
|
2470
|
+
const oldOpts = opts;
|
|
2471
|
+
Object.assign(this, oldOpts);
|
|
2472
|
+
this.recentBlockhash = oldOpts.recentBlockhash;
|
|
2473
|
+
}
|
|
2453
2474
|
}
|
|
2454
2475
|
/**
|
|
2455
2476
|
* @internal
|
|
@@ -3059,7 +3080,11 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
3059
3080
|
maxRetries: options.maxRetries
|
|
3060
3081
|
};
|
|
3061
3082
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
3062
|
-
const status = (await connection.confirmTransaction(
|
|
3083
|
+
const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
|
|
3084
|
+
signature: signature,
|
|
3085
|
+
blockhash: transaction.recentBlockhash,
|
|
3086
|
+
lastValidBlockHeight: transaction.lastValidBlockHeight
|
|
3087
|
+
}, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
3063
3088
|
|
|
3064
3089
|
if (status.err) {
|
|
3065
3090
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
@@ -4459,16 +4484,28 @@ const NUM_SLOTS_PER_SECOND = NUM_TICKS_PER_SECOND / DEFAULT_TICKS_PER_SLOT;
|
|
|
4459
4484
|
|
|
4460
4485
|
const MS_PER_SLOT = 1000 / NUM_SLOTS_PER_SECOND;
|
|
4461
4486
|
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4487
|
+
class TransactionExpiredBlockheightExceededError extends Error {
|
|
4488
|
+
constructor(signature) {
|
|
4489
|
+
super(`Signature ${signature} has expired: block height exceeded.`);
|
|
4490
|
+
this.signature = void 0;
|
|
4491
|
+
this.signature = signature;
|
|
4492
|
+
}
|
|
4493
|
+
|
|
4494
|
+
}
|
|
4495
|
+
Object.defineProperty(TransactionExpiredBlockheightExceededError.prototype, 'name', {
|
|
4496
|
+
value: 'TransactionExpiredBlockheightExceededError'
|
|
4497
|
+
});
|
|
4498
|
+
class TransactionExpiredTimeoutError extends Error {
|
|
4499
|
+
constructor(signature, timeoutSeconds) {
|
|
4500
|
+
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.`);
|
|
4501
|
+
this.signature = void 0;
|
|
4502
|
+
this.signature = signature;
|
|
4503
|
+
}
|
|
4504
|
+
|
|
4471
4505
|
}
|
|
4506
|
+
Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
4507
|
+
value: 'TransactionExpiredTimeoutError'
|
|
4508
|
+
});
|
|
4472
4509
|
|
|
4473
4510
|
function makeWebsocketUrl(endpoint) {
|
|
4474
4511
|
let url = new URL(endpoint);
|
|
@@ -5463,7 +5500,7 @@ class Connection {
|
|
|
5463
5500
|
this._disableBlockhashCaching = false;
|
|
5464
5501
|
this._pollingBlockhash = false;
|
|
5465
5502
|
this._blockhashInfo = {
|
|
5466
|
-
|
|
5503
|
+
latestBlockhash: null,
|
|
5467
5504
|
lastFetch: 0,
|
|
5468
5505
|
transactionSignatures: [],
|
|
5469
5506
|
simulatedSignatures: []
|
|
@@ -5944,67 +5981,124 @@ class Connection {
|
|
|
5944
5981
|
|
|
5945
5982
|
return res.result;
|
|
5946
5983
|
}
|
|
5947
|
-
/**
|
|
5948
|
-
* Confirm the transaction identified by the specified signature.
|
|
5949
|
-
*/
|
|
5950
5984
|
|
|
5985
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
5986
|
+
async confirmTransaction(strategy, commitment) {
|
|
5987
|
+
let rawSignature;
|
|
5988
|
+
|
|
5989
|
+
if (typeof strategy == 'string') {
|
|
5990
|
+
rawSignature = strategy;
|
|
5991
|
+
} else {
|
|
5992
|
+
const config = strategy;
|
|
5993
|
+
rawSignature = config.signature;
|
|
5994
|
+
}
|
|
5951
5995
|
|
|
5952
|
-
async confirmTransaction(signature, commitment) {
|
|
5953
5996
|
let decodedSignature;
|
|
5954
5997
|
|
|
5955
5998
|
try {
|
|
5956
|
-
decodedSignature = bs58.decode(
|
|
5999
|
+
decodedSignature = bs58.decode(rawSignature);
|
|
5957
6000
|
} catch (err) {
|
|
5958
|
-
throw new Error('signature must be base58 encoded: ' +
|
|
6001
|
+
throw new Error('signature must be base58 encoded: ' + rawSignature);
|
|
5959
6002
|
}
|
|
5960
6003
|
|
|
5961
6004
|
assert(decodedSignature.length === 64, 'signature has invalid length');
|
|
5962
|
-
const start = Date.now();
|
|
5963
6005
|
const subscriptionCommitment = commitment || this.commitment;
|
|
6006
|
+
let timeoutId;
|
|
5964
6007
|
let subscriptionId;
|
|
5965
|
-
let
|
|
5966
|
-
const
|
|
6008
|
+
let done = false;
|
|
6009
|
+
const confirmationPromise = new Promise((resolve, reject) => {
|
|
5967
6010
|
try {
|
|
5968
|
-
subscriptionId = this.onSignature(
|
|
6011
|
+
subscriptionId = this.onSignature(rawSignature, (result, context) => {
|
|
5969
6012
|
subscriptionId = undefined;
|
|
5970
|
-
response = {
|
|
6013
|
+
const response = {
|
|
5971
6014
|
context,
|
|
5972
6015
|
value: result
|
|
5973
6016
|
};
|
|
5974
|
-
|
|
6017
|
+
done = true;
|
|
6018
|
+
resolve({
|
|
6019
|
+
__type: TransactionStatus.PROCESSED,
|
|
6020
|
+
response
|
|
6021
|
+
});
|
|
5975
6022
|
}, subscriptionCommitment);
|
|
5976
6023
|
} catch (err) {
|
|
5977
6024
|
reject(err);
|
|
5978
6025
|
}
|
|
5979
6026
|
});
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
6027
|
+
|
|
6028
|
+
const checkBlockHeight = async () => {
|
|
6029
|
+
try {
|
|
6030
|
+
const blockHeight = await this.getBlockHeight(commitment);
|
|
6031
|
+
return blockHeight;
|
|
6032
|
+
} catch (_e) {
|
|
6033
|
+
return -1;
|
|
6034
|
+
}
|
|
6035
|
+
};
|
|
6036
|
+
|
|
6037
|
+
const expiryPromise = new Promise(resolve => {
|
|
6038
|
+
if (typeof strategy === 'string') {
|
|
6039
|
+
let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
|
|
6040
|
+
|
|
6041
|
+
switch (subscriptionCommitment) {
|
|
6042
|
+
case 'processed':
|
|
6043
|
+
case 'recent':
|
|
6044
|
+
case 'single':
|
|
6045
|
+
case 'confirmed':
|
|
6046
|
+
case 'singleGossip':
|
|
6047
|
+
{
|
|
6048
|
+
timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
|
|
6049
|
+
break;
|
|
6050
|
+
}
|
|
5991
6051
|
}
|
|
5992
|
-
|
|
6052
|
+
|
|
6053
|
+
timeoutId = setTimeout(() => resolve({
|
|
6054
|
+
__type: TransactionStatus.TIMED_OUT,
|
|
6055
|
+
timeoutMs
|
|
6056
|
+
}), timeoutMs);
|
|
6057
|
+
} else {
|
|
6058
|
+
let config = strategy;
|
|
6059
|
+
|
|
6060
|
+
(async () => {
|
|
6061
|
+
let currentBlockHeight = await checkBlockHeight();
|
|
6062
|
+
if (done) return;
|
|
6063
|
+
|
|
6064
|
+
while (currentBlockHeight <= config.lastValidBlockHeight) {
|
|
6065
|
+
await sleep(1000);
|
|
6066
|
+
if (done) return;
|
|
6067
|
+
currentBlockHeight = await checkBlockHeight();
|
|
6068
|
+
if (done) return;
|
|
6069
|
+
}
|
|
6070
|
+
|
|
6071
|
+
resolve({
|
|
6072
|
+
__type: TransactionStatus.BLOCKHEIGHT_EXCEEDED
|
|
6073
|
+
});
|
|
6074
|
+
})();
|
|
6075
|
+
}
|
|
6076
|
+
});
|
|
6077
|
+
let result;
|
|
5993
6078
|
|
|
5994
6079
|
try {
|
|
5995
|
-
await
|
|
6080
|
+
const outcome = await Promise.race([confirmationPromise, expiryPromise]);
|
|
6081
|
+
|
|
6082
|
+
switch (outcome.__type) {
|
|
6083
|
+
case TransactionStatus.BLOCKHEIGHT_EXCEEDED:
|
|
6084
|
+
throw new TransactionExpiredBlockheightExceededError(rawSignature);
|
|
6085
|
+
|
|
6086
|
+
case TransactionStatus.PROCESSED:
|
|
6087
|
+
result = outcome.response;
|
|
6088
|
+
break;
|
|
6089
|
+
|
|
6090
|
+
case TransactionStatus.TIMED_OUT:
|
|
6091
|
+
throw new TransactionExpiredTimeoutError(rawSignature, outcome.timeoutMs / 1000);
|
|
6092
|
+
}
|
|
5996
6093
|
} finally {
|
|
6094
|
+
clearTimeout(timeoutId);
|
|
6095
|
+
|
|
5997
6096
|
if (subscriptionId) {
|
|
5998
6097
|
this.removeSignatureListener(subscriptionId);
|
|
5999
6098
|
}
|
|
6000
6099
|
}
|
|
6001
6100
|
|
|
6002
|
-
|
|
6003
|
-
const duration = (Date.now() - start) / 1000;
|
|
6004
|
-
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.`);
|
|
6005
|
-
}
|
|
6006
|
-
|
|
6007
|
-
return response;
|
|
6101
|
+
return result;
|
|
6008
6102
|
}
|
|
6009
6103
|
/**
|
|
6010
6104
|
* Return the list of nodes that are currently participating in the cluster
|
|
@@ -6369,7 +6463,7 @@ class Connection {
|
|
|
6369
6463
|
}
|
|
6370
6464
|
/**
|
|
6371
6465
|
* Fetch the latest blockhash from the cluster
|
|
6372
|
-
* @return {Promise<
|
|
6466
|
+
* @return {Promise<BlockhashWithExpiryBlockHeight>}
|
|
6373
6467
|
*/
|
|
6374
6468
|
|
|
6375
6469
|
|
|
@@ -6383,7 +6477,7 @@ class Connection {
|
|
|
6383
6477
|
}
|
|
6384
6478
|
/**
|
|
6385
6479
|
* Fetch the latest blockhash from the cluster
|
|
6386
|
-
* @return {Promise<
|
|
6480
|
+
* @return {Promise<BlockhashWithExpiryBlockHeight>}
|
|
6387
6481
|
*/
|
|
6388
6482
|
|
|
6389
6483
|
|
|
@@ -6966,7 +7060,7 @@ class Connection {
|
|
|
6966
7060
|
*/
|
|
6967
7061
|
|
|
6968
7062
|
|
|
6969
|
-
async
|
|
7063
|
+
async _blockhashWithExpiryBlockHeight(disableCache) {
|
|
6970
7064
|
if (!disableCache) {
|
|
6971
7065
|
// Wait for polling to finish
|
|
6972
7066
|
while (this._pollingBlockhash) {
|
|
@@ -6977,8 +7071,8 @@ class Connection {
|
|
|
6977
7071
|
|
|
6978
7072
|
const expired = timeSinceFetch >= BLOCKHASH_CACHE_TIMEOUT_MS;
|
|
6979
7073
|
|
|
6980
|
-
if (this._blockhashInfo.
|
|
6981
|
-
return this._blockhashInfo.
|
|
7074
|
+
if (this._blockhashInfo.latestBlockhash !== null && !expired) {
|
|
7075
|
+
return this._blockhashInfo.latestBlockhash;
|
|
6982
7076
|
}
|
|
6983
7077
|
}
|
|
6984
7078
|
|
|
@@ -6994,20 +7088,20 @@ class Connection {
|
|
|
6994
7088
|
|
|
6995
7089
|
try {
|
|
6996
7090
|
const startTime = Date.now();
|
|
7091
|
+
const cachedLatestBlockhash = this._blockhashInfo.latestBlockhash;
|
|
7092
|
+
const cachedBlockhash = cachedLatestBlockhash ? cachedLatestBlockhash.blockhash : null;
|
|
6997
7093
|
|
|
6998
7094
|
for (let i = 0; i < 50; i++) {
|
|
6999
|
-
const
|
|
7000
|
-
blockhash
|
|
7001
|
-
} = await this.getRecentBlockhash('finalized');
|
|
7095
|
+
const latestBlockhash = await this.getLatestBlockhash('finalized');
|
|
7002
7096
|
|
|
7003
|
-
if (
|
|
7097
|
+
if (cachedBlockhash !== latestBlockhash.blockhash) {
|
|
7004
7098
|
this._blockhashInfo = {
|
|
7005
|
-
|
|
7099
|
+
latestBlockhash,
|
|
7006
7100
|
lastFetch: Date.now(),
|
|
7007
7101
|
transactionSignatures: [],
|
|
7008
7102
|
simulatedSignatures: []
|
|
7009
7103
|
};
|
|
7010
|
-
return
|
|
7104
|
+
return latestBlockhash;
|
|
7011
7105
|
} // Sleep for approximately half a slot
|
|
7012
7106
|
|
|
7013
7107
|
|
|
@@ -7029,13 +7123,11 @@ class Connection {
|
|
|
7029
7123
|
|
|
7030
7124
|
if (transactionOrMessage instanceof Transaction) {
|
|
7031
7125
|
let originalTx = transactionOrMessage;
|
|
7032
|
-
transaction = new Transaction(
|
|
7033
|
-
|
|
7034
|
-
nonceInfo: originalTx.nonceInfo,
|
|
7035
|
-
feePayer: originalTx.feePayer,
|
|
7036
|
-
signatures: [...originalTx.signatures]
|
|
7037
|
-
});
|
|
7126
|
+
transaction = new Transaction();
|
|
7127
|
+
transaction.feePayer = originalTx.feePayer;
|
|
7038
7128
|
transaction.instructions = transactionOrMessage.instructions;
|
|
7129
|
+
transaction.nonceInfo = originalTx.nonceInfo;
|
|
7130
|
+
transaction.signatures = originalTx.signatures;
|
|
7039
7131
|
} else {
|
|
7040
7132
|
transaction = Transaction.populate(transactionOrMessage); // HACK: this function relies on mutating the populated transaction
|
|
7041
7133
|
|
|
@@ -7048,7 +7140,9 @@ class Connection {
|
|
|
7048
7140
|
let disableCache = this._disableBlockhashCaching;
|
|
7049
7141
|
|
|
7050
7142
|
for (;;) {
|
|
7051
|
-
|
|
7143
|
+
const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
|
|
7144
|
+
transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
|
|
7145
|
+
transaction.recentBlockhash = latestBlockhash.blockhash;
|
|
7052
7146
|
if (!signers) break;
|
|
7053
7147
|
transaction.sign(...signers);
|
|
7054
7148
|
|
|
@@ -7132,7 +7226,9 @@ class Connection {
|
|
|
7132
7226
|
let disableCache = this._disableBlockhashCaching;
|
|
7133
7227
|
|
|
7134
7228
|
for (;;) {
|
|
7135
|
-
|
|
7229
|
+
const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
|
|
7230
|
+
transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
|
|
7231
|
+
transaction.recentBlockhash = latestBlockhash.blockhash;
|
|
7136
7232
|
transaction.sign(...signers);
|
|
7137
7233
|
|
|
7138
7234
|
if (!transaction.signature) {
|
|
@@ -7232,6 +7328,7 @@ class Connection {
|
|
|
7232
7328
|
|
|
7233
7329
|
|
|
7234
7330
|
_wsOnError(err) {
|
|
7331
|
+
this._rpcWebSocketConnected = false;
|
|
7235
7332
|
console.error('ws error:', err.message);
|
|
7236
7333
|
}
|
|
7237
7334
|
/**
|
|
@@ -7240,6 +7337,7 @@ class Connection {
|
|
|
7240
7337
|
|
|
7241
7338
|
|
|
7242
7339
|
_wsOnClose(code) {
|
|
7340
|
+
this._rpcWebSocketConnected = false;
|
|
7243
7341
|
this._rpcWebSocketGeneration++;
|
|
7244
7342
|
|
|
7245
7343
|
if (this._rpcWebSocketHeartbeat) {
|
|
@@ -9571,16 +9669,36 @@ VoteProgram.space = 3731;
|
|
|
9571
9669
|
*
|
|
9572
9670
|
* @param {Connection} connection
|
|
9573
9671
|
* @param {Buffer} rawTransaction
|
|
9672
|
+
* @param {BlockheightBasedTransactionConfimationStrategy} confirmationStrategy
|
|
9574
9673
|
* @param {ConfirmOptions} [options]
|
|
9575
9674
|
* @returns {Promise<TransactionSignature>}
|
|
9576
9675
|
*/
|
|
9577
|
-
|
|
9676
|
+
|
|
9677
|
+
/**
|
|
9678
|
+
* @deprecated Calling `sendAndConfirmRawTransaction()` without a `confirmationStrategy`
|
|
9679
|
+
* is no longer supported and will be removed in a future version.
|
|
9680
|
+
*/
|
|
9681
|
+
// eslint-disable-next-line no-redeclare
|
|
9682
|
+
// eslint-disable-next-line no-redeclare
|
|
9683
|
+
async function sendAndConfirmRawTransaction(connection, rawTransaction, confirmationStrategyOrConfirmOptions, maybeConfirmOptions) {
|
|
9684
|
+
let confirmationStrategy;
|
|
9685
|
+
let options;
|
|
9686
|
+
|
|
9687
|
+
if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'lastValidBlockHeight')) {
|
|
9688
|
+
confirmationStrategy = confirmationStrategyOrConfirmOptions;
|
|
9689
|
+
options = maybeConfirmOptions;
|
|
9690
|
+
} else {
|
|
9691
|
+
options = confirmationStrategyOrConfirmOptions;
|
|
9692
|
+
}
|
|
9693
|
+
|
|
9578
9694
|
const sendOptions = options && {
|
|
9579
9695
|
skipPreflight: options.skipPreflight,
|
|
9580
9696
|
preflightCommitment: options.preflightCommitment || options.commitment
|
|
9581
9697
|
};
|
|
9582
9698
|
const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
|
|
9583
|
-
const
|
|
9699
|
+
const commitment = options && options.commitment;
|
|
9700
|
+
const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
|
|
9701
|
+
const status = (await confirmationPromise).value;
|
|
9584
9702
|
|
|
9585
9703
|
if (status.err) {
|
|
9586
9704
|
throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
@@ -9627,5 +9745,5 @@ function clusterApiUrl(cluster, tls) {
|
|
|
9627
9745
|
|
|
9628
9746
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9629
9747
|
|
|
9630
|
-
export { Account, 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, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, 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, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9748
|
+
export { Account, 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, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, 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, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, TransactionStatus, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9631
9749
|
//# sourceMappingURL=index.esm.js.map
|