@solana/web3.js 1.41.10 → 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.
@@ -5997,7 +5997,7 @@ class Connection {
5997
5997
  this._disableBlockhashCaching = false;
5998
5998
  this._pollingBlockhash = false;
5999
5999
  this._blockhashInfo = {
6000
- recentBlockhash: null,
6000
+ latestBlockhash: null,
6001
6001
  lastFetch: 0,
6002
6002
  transactionSignatures: [],
6003
6003
  simulatedSignatures: []
@@ -6960,7 +6960,7 @@ class Connection {
6960
6960
  }
6961
6961
  /**
6962
6962
  * Fetch the latest blockhash from the cluster
6963
- * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6963
+ * @return {Promise<BlockhashWithExpiryBlockHeight>}
6964
6964
  */
6965
6965
 
6966
6966
 
@@ -6974,7 +6974,7 @@ class Connection {
6974
6974
  }
6975
6975
  /**
6976
6976
  * Fetch the latest blockhash from the cluster
6977
- * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6977
+ * @return {Promise<BlockhashWithExpiryBlockHeight>}
6978
6978
  */
6979
6979
 
6980
6980
 
@@ -7557,7 +7557,7 @@ class Connection {
7557
7557
  */
7558
7558
 
7559
7559
 
7560
- async _recentBlockhash(disableCache) {
7560
+ async _blockhashWithExpiryBlockHeight(disableCache) {
7561
7561
  if (!disableCache) {
7562
7562
  // Wait for polling to finish
7563
7563
  while (this._pollingBlockhash) {
@@ -7568,8 +7568,8 @@ class Connection {
7568
7568
 
7569
7569
  const expired = timeSinceFetch >= BLOCKHASH_CACHE_TIMEOUT_MS;
7570
7570
 
7571
- if (this._blockhashInfo.recentBlockhash !== null && !expired) {
7572
- return this._blockhashInfo.recentBlockhash;
7571
+ if (this._blockhashInfo.latestBlockhash !== null && !expired) {
7572
+ return this._blockhashInfo.latestBlockhash;
7573
7573
  }
7574
7574
  }
7575
7575
 
@@ -7585,20 +7585,20 @@ class Connection {
7585
7585
 
7586
7586
  try {
7587
7587
  const startTime = Date.now();
7588
+ const cachedLatestBlockhash = this._blockhashInfo.latestBlockhash;
7589
+ const cachedBlockhash = cachedLatestBlockhash ? cachedLatestBlockhash.blockhash : null;
7588
7590
 
7589
7591
  for (let i = 0; i < 50; i++) {
7590
- const {
7591
- blockhash
7592
- } = await this.getRecentBlockhash('finalized');
7592
+ const latestBlockhash = await this.getLatestBlockhash('finalized');
7593
7593
 
7594
- if (this._blockhashInfo.recentBlockhash != blockhash) {
7594
+ if (cachedBlockhash !== latestBlockhash.blockhash) {
7595
7595
  this._blockhashInfo = {
7596
- recentBlockhash: blockhash,
7596
+ latestBlockhash,
7597
7597
  lastFetch: Date.now(),
7598
7598
  transactionSignatures: [],
7599
7599
  simulatedSignatures: []
7600
7600
  };
7601
- return blockhash;
7601
+ return latestBlockhash;
7602
7602
  } // Sleep for approximately half a slot
7603
7603
 
7604
7604
 
@@ -7620,13 +7620,11 @@ class Connection {
7620
7620
 
7621
7621
  if (transactionOrMessage instanceof Transaction) {
7622
7622
  let originalTx = transactionOrMessage;
7623
- transaction = new Transaction({
7624
- recentBlockhash: originalTx.recentBlockhash,
7625
- nonceInfo: originalTx.nonceInfo,
7626
- feePayer: originalTx.feePayer,
7627
- signatures: [...originalTx.signatures]
7628
- });
7623
+ transaction = new Transaction();
7624
+ transaction.feePayer = originalTx.feePayer;
7629
7625
  transaction.instructions = transactionOrMessage.instructions;
7626
+ transaction.nonceInfo = originalTx.nonceInfo;
7627
+ transaction.signatures = originalTx.signatures;
7630
7628
  } else {
7631
7629
  transaction = Transaction.populate(transactionOrMessage); // HACK: this function relies on mutating the populated transaction
7632
7630
 
@@ -7639,7 +7637,9 @@ class Connection {
7639
7637
  let disableCache = this._disableBlockhashCaching;
7640
7638
 
7641
7639
  for (;;) {
7642
- transaction.recentBlockhash = await this._recentBlockhash(disableCache);
7640
+ const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
7641
+ transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
7642
+ transaction.recentBlockhash = latestBlockhash.blockhash;
7643
7643
  if (!signers) break;
7644
7644
  transaction.sign(...signers);
7645
7645
 
@@ -7723,7 +7723,9 @@ class Connection {
7723
7723
  let disableCache = this._disableBlockhashCaching;
7724
7724
 
7725
7725
  for (;;) {
7726
- transaction.recentBlockhash = await this._recentBlockhash(disableCache);
7726
+ const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
7727
+ transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
7728
+ transaction.recentBlockhash = latestBlockhash.blockhash;
7727
7729
  transaction.sign(...signers);
7728
7730
 
7729
7731
  if (!transaction.signature) {
@@ -10164,16 +10166,36 @@ VoteProgram.space = 3731;
10164
10166
  *
10165
10167
  * @param {Connection} connection
10166
10168
  * @param {Buffer} rawTransaction
10169
+ * @param {BlockheightBasedTransactionConfimationStrategy} confirmationStrategy
10167
10170
  * @param {ConfirmOptions} [options]
10168
10171
  * @returns {Promise<TransactionSignature>}
10169
10172
  */
10170
- async function sendAndConfirmRawTransaction(connection, rawTransaction, options) {
10173
+
10174
+ /**
10175
+ * @deprecated Calling `sendAndConfirmRawTransaction()` without a `confirmationStrategy`
10176
+ * is no longer supported and will be removed in a future version.
10177
+ */
10178
+ // eslint-disable-next-line no-redeclare
10179
+ // eslint-disable-next-line no-redeclare
10180
+ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirmationStrategyOrConfirmOptions, maybeConfirmOptions) {
10181
+ let confirmationStrategy;
10182
+ let options;
10183
+
10184
+ if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'lastValidBlockHeight')) {
10185
+ confirmationStrategy = confirmationStrategyOrConfirmOptions;
10186
+ options = maybeConfirmOptions;
10187
+ } else {
10188
+ options = confirmationStrategyOrConfirmOptions;
10189
+ }
10190
+
10171
10191
  const sendOptions = options && {
10172
10192
  skipPreflight: options.skipPreflight,
10173
10193
  preflightCommitment: options.preflightCommitment || options.commitment
10174
10194
  };
10175
10195
  const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
10176
- const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
10196
+ const commitment = options && options.commitment;
10197
+ const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
10198
+ const status = (await confirmationPromise).value;
10177
10199
 
10178
10200
  if (status.err) {
10179
10201
  throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);