@solana/web3.js 1.41.11 → 1.42.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.
@@ -6058,7 +6058,7 @@ class Connection {
6058
6058
  this._disableBlockhashCaching = false;
6059
6059
  this._pollingBlockhash = false;
6060
6060
  this._blockhashInfo = {
6061
- recentBlockhash: null,
6061
+ latestBlockhash: null,
6062
6062
  lastFetch: 0,
6063
6063
  transactionSignatures: [],
6064
6064
  simulatedSignatures: []
@@ -7021,7 +7021,7 @@ class Connection {
7021
7021
  }
7022
7022
  /**
7023
7023
  * Fetch the latest blockhash from the cluster
7024
- * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
7024
+ * @return {Promise<BlockhashWithExpiryBlockHeight>}
7025
7025
  */
7026
7026
 
7027
7027
 
@@ -7035,7 +7035,7 @@ class Connection {
7035
7035
  }
7036
7036
  /**
7037
7037
  * Fetch the latest blockhash from the cluster
7038
- * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
7038
+ * @return {Promise<BlockhashWithExpiryBlockHeight>}
7039
7039
  */
7040
7040
 
7041
7041
 
@@ -7618,7 +7618,7 @@ class Connection {
7618
7618
  */
7619
7619
 
7620
7620
 
7621
- async _recentBlockhash(disableCache) {
7621
+ async _blockhashWithExpiryBlockHeight(disableCache) {
7622
7622
  if (!disableCache) {
7623
7623
  // Wait for polling to finish
7624
7624
  while (this._pollingBlockhash) {
@@ -7629,8 +7629,8 @@ class Connection {
7629
7629
 
7630
7630
  const expired = timeSinceFetch >= BLOCKHASH_CACHE_TIMEOUT_MS;
7631
7631
 
7632
- if (this._blockhashInfo.recentBlockhash !== null && !expired) {
7633
- return this._blockhashInfo.recentBlockhash;
7632
+ if (this._blockhashInfo.latestBlockhash !== null && !expired) {
7633
+ return this._blockhashInfo.latestBlockhash;
7634
7634
  }
7635
7635
  }
7636
7636
 
@@ -7646,20 +7646,20 @@ class Connection {
7646
7646
 
7647
7647
  try {
7648
7648
  const startTime = Date.now();
7649
+ const cachedLatestBlockhash = this._blockhashInfo.latestBlockhash;
7650
+ const cachedBlockhash = cachedLatestBlockhash ? cachedLatestBlockhash.blockhash : null;
7649
7651
 
7650
7652
  for (let i = 0; i < 50; i++) {
7651
- const {
7652
- blockhash
7653
- } = await this.getRecentBlockhash('finalized');
7653
+ const latestBlockhash = await this.getLatestBlockhash('finalized');
7654
7654
 
7655
- if (this._blockhashInfo.recentBlockhash != blockhash) {
7655
+ if (cachedBlockhash !== latestBlockhash.blockhash) {
7656
7656
  this._blockhashInfo = {
7657
- recentBlockhash: blockhash,
7657
+ latestBlockhash,
7658
7658
  lastFetch: Date.now(),
7659
7659
  transactionSignatures: [],
7660
7660
  simulatedSignatures: []
7661
7661
  };
7662
- return blockhash;
7662
+ return latestBlockhash;
7663
7663
  } // Sleep for approximately half a slot
7664
7664
 
7665
7665
 
@@ -7681,13 +7681,11 @@ class Connection {
7681
7681
 
7682
7682
  if (transactionOrMessage instanceof Transaction) {
7683
7683
  let originalTx = transactionOrMessage;
7684
- transaction = new Transaction({
7685
- recentBlockhash: originalTx.recentBlockhash,
7686
- nonceInfo: originalTx.nonceInfo,
7687
- feePayer: originalTx.feePayer,
7688
- signatures: [...originalTx.signatures]
7689
- });
7684
+ transaction = new Transaction();
7685
+ transaction.feePayer = originalTx.feePayer;
7690
7686
  transaction.instructions = transactionOrMessage.instructions;
7687
+ transaction.nonceInfo = originalTx.nonceInfo;
7688
+ transaction.signatures = originalTx.signatures;
7691
7689
  } else {
7692
7690
  transaction = Transaction.populate(transactionOrMessage); // HACK: this function relies on mutating the populated transaction
7693
7691
 
@@ -7700,7 +7698,9 @@ class Connection {
7700
7698
  let disableCache = this._disableBlockhashCaching;
7701
7699
 
7702
7700
  for (;;) {
7703
- transaction.recentBlockhash = await this._recentBlockhash(disableCache);
7701
+ const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
7702
+ transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
7703
+ transaction.recentBlockhash = latestBlockhash.blockhash;
7704
7704
  if (!signers) break;
7705
7705
  transaction.sign(...signers);
7706
7706
 
@@ -7784,7 +7784,9 @@ class Connection {
7784
7784
  let disableCache = this._disableBlockhashCaching;
7785
7785
 
7786
7786
  for (;;) {
7787
- transaction.recentBlockhash = await this._recentBlockhash(disableCache);
7787
+ const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
7788
+ transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
7789
+ transaction.recentBlockhash = latestBlockhash.blockhash;
7788
7790
  transaction.sign(...signers);
7789
7791
 
7790
7792
  if (!transaction.signature) {
@@ -10223,16 +10225,36 @@ VoteProgram.space = 3731;
10223
10225
  *
10224
10226
  * @param {Connection} connection
10225
10227
  * @param {Buffer} rawTransaction
10228
+ * @param {BlockheightBasedTransactionConfimationStrategy} confirmationStrategy
10226
10229
  * @param {ConfirmOptions} [options]
10227
10230
  * @returns {Promise<TransactionSignature>}
10228
10231
  */
10229
- async function sendAndConfirmRawTransaction(connection, rawTransaction, options) {
10232
+
10233
+ /**
10234
+ * @deprecated Calling `sendAndConfirmRawTransaction()` without a `confirmationStrategy`
10235
+ * is no longer supported and will be removed in a future version.
10236
+ */
10237
+ // eslint-disable-next-line no-redeclare
10238
+ // eslint-disable-next-line no-redeclare
10239
+ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirmationStrategyOrConfirmOptions, maybeConfirmOptions) {
10240
+ let confirmationStrategy;
10241
+ let options;
10242
+
10243
+ if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'lastValidBlockHeight')) {
10244
+ confirmationStrategy = confirmationStrategyOrConfirmOptions;
10245
+ options = maybeConfirmOptions;
10246
+ } else {
10247
+ options = confirmationStrategyOrConfirmOptions;
10248
+ }
10249
+
10230
10250
  const sendOptions = options && {
10231
10251
  skipPreflight: options.skipPreflight,
10232
10252
  preflightCommitment: options.preflightCommitment || options.commitment
10233
10253
  };
10234
10254
  const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
10235
- const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
10255
+ const commitment = options && options.commitment;
10256
+ const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
10257
+ const status = (await confirmationPromise).value;
10236
10258
 
10237
10259
  if (status.err) {
10238
10260
  throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);