@solana/web3.js 1.41.10 → 1.43.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.
package/lib/index.cjs.js CHANGED
@@ -8,7 +8,7 @@ var BN = require('bn.js');
8
8
  var bs58 = require('bs58');
9
9
  var borsh = require('borsh');
10
10
  var BufferLayout = require('@solana/buffer-layout');
11
- var bufferLayoutUtils = require('@solana/buffer-layout-utils');
11
+ var bigintBuffer = require('bigint-buffer');
12
12
  var crossFetch = require('cross-fetch');
13
13
  var superstruct = require('superstruct');
14
14
  var rpcWebsockets = require('rpc-websockets');
@@ -2840,8 +2840,6 @@ class Transaction {
2840
2840
  const message = this._compile();
2841
2841
 
2842
2842
  this._partialSign(message, ...uniqueSigners);
2843
-
2844
- this._verifySignatures(message.serialize(), true);
2845
2843
  }
2846
2844
  /**
2847
2845
  * Partially sign a transaction with the specified accounts. All accounts must
@@ -3221,6 +3219,38 @@ class NonceAccount {
3221
3219
 
3222
3220
  }
3223
3221
 
3222
+ const encodeDecode = layout => {
3223
+ const decode = layout.decode.bind(layout);
3224
+ const encode = layout.encode.bind(layout);
3225
+ return {
3226
+ decode,
3227
+ encode
3228
+ };
3229
+ };
3230
+
3231
+ const bigInt = length => property => {
3232
+ const layout = BufferLayout.blob(length, property);
3233
+ const {
3234
+ encode,
3235
+ decode
3236
+ } = encodeDecode(layout);
3237
+ const bigIntLayout = layout;
3238
+
3239
+ bigIntLayout.decode = (buffer$1, offset) => {
3240
+ const src = decode(buffer$1, offset);
3241
+ return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
3242
+ };
3243
+
3244
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
3245
+ const src = bigintBuffer.toBufferLE(bigInt, length);
3246
+ return encode(src, buffer, offset);
3247
+ };
3248
+
3249
+ return bigIntLayout;
3250
+ };
3251
+
3252
+ const u64 = bigInt(8);
3253
+
3224
3254
  /**
3225
3255
  * Create account system transaction params
3226
3256
  */
@@ -3522,7 +3552,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
3522
3552
  },
3523
3553
  Transfer: {
3524
3554
  index: 2,
3525
- layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), bufferLayoutUtils.u64('lamports')])
3555
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('lamports')])
3526
3556
  },
3527
3557
  CreateWithSeed: {
3528
3558
  index: 3,
@@ -3558,7 +3588,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
3558
3588
  },
3559
3589
  TransferWithSeed: {
3560
3590
  index: 11,
3561
- layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), bufferLayoutUtils.u64('lamports'), rustString('seed'), publicKey('programId')])
3591
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('lamports'), rustString('seed'), publicKey('programId')])
3562
3592
  }
3563
3593
  });
3564
3594
  /**
@@ -4199,6 +4229,34 @@ class ComputeBudgetInstruction {
4199
4229
  bytes
4200
4230
  };
4201
4231
  }
4232
+ /**
4233
+ * Decode set compute unit limit compute budget instruction and retrieve the instruction params.
4234
+ */
4235
+
4236
+
4237
+ static decodeSetComputeUnitLimit(instruction) {
4238
+ this.checkProgramId(instruction.programId);
4239
+ const {
4240
+ units
4241
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit, instruction.data);
4242
+ return {
4243
+ units
4244
+ };
4245
+ }
4246
+ /**
4247
+ * Decode set compute unit price compute budget instruction and retrieve the instruction params.
4248
+ */
4249
+
4250
+
4251
+ static decodeSetComputeUnitPrice(instruction) {
4252
+ this.checkProgramId(instruction.programId);
4253
+ const {
4254
+ microLamports
4255
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice, instruction.data);
4256
+ return {
4257
+ microLamports
4258
+ };
4259
+ }
4202
4260
  /**
4203
4261
  * @internal
4204
4262
  */
@@ -4227,6 +4285,14 @@ const COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = Object.freeze({
4227
4285
  RequestHeapFrame: {
4228
4286
  index: 1,
4229
4287
  layout: BufferLayout__namespace.struct([BufferLayout__namespace.u8('instruction'), BufferLayout__namespace.u32('bytes')])
4288
+ },
4289
+ SetComputeUnitLimit: {
4290
+ index: 2,
4291
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u8('instruction'), BufferLayout__namespace.u32('units')])
4292
+ },
4293
+ SetComputeUnitPrice: {
4294
+ index: 3,
4295
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u8('instruction'), u64('microLamports')])
4230
4296
  }
4231
4297
  });
4232
4298
  /**
@@ -4263,6 +4329,28 @@ class ComputeBudgetProgram {
4263
4329
  });
4264
4330
  }
4265
4331
 
4332
+ static setComputeUnitLimit(params) {
4333
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit;
4334
+ const data = encodeData(type, params);
4335
+ return new TransactionInstruction({
4336
+ keys: [],
4337
+ programId: this.programId,
4338
+ data
4339
+ });
4340
+ }
4341
+
4342
+ static setComputeUnitPrice(params) {
4343
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice;
4344
+ const data = encodeData(type, {
4345
+ microLamports: BigInt(params.microLamports)
4346
+ });
4347
+ return new TransactionInstruction({
4348
+ keys: [],
4349
+ programId: this.programId,
4350
+ data
4351
+ });
4352
+ }
4353
+
4266
4354
  }
4267
4355
  ComputeBudgetProgram.programId = new PublicKey('ComputeBudget111111111111111111111111111111');
4268
4356
 
@@ -5535,7 +5623,7 @@ class Connection {
5535
5623
  this._disableBlockhashCaching = false;
5536
5624
  this._pollingBlockhash = false;
5537
5625
  this._blockhashInfo = {
5538
- recentBlockhash: null,
5626
+ latestBlockhash: null,
5539
5627
  lastFetch: 0,
5540
5628
  transactionSignatures: [],
5541
5629
  simulatedSignatures: []
@@ -6498,7 +6586,7 @@ class Connection {
6498
6586
  }
6499
6587
  /**
6500
6588
  * Fetch the latest blockhash from the cluster
6501
- * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6589
+ * @return {Promise<BlockhashWithExpiryBlockHeight>}
6502
6590
  */
6503
6591
 
6504
6592
 
@@ -6512,7 +6600,7 @@ class Connection {
6512
6600
  }
6513
6601
  /**
6514
6602
  * Fetch the latest blockhash from the cluster
6515
- * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
6603
+ * @return {Promise<BlockhashWithExpiryBlockHeight>}
6516
6604
  */
6517
6605
 
6518
6606
 
@@ -7095,7 +7183,7 @@ class Connection {
7095
7183
  */
7096
7184
 
7097
7185
 
7098
- async _recentBlockhash(disableCache) {
7186
+ async _blockhashWithExpiryBlockHeight(disableCache) {
7099
7187
  if (!disableCache) {
7100
7188
  // Wait for polling to finish
7101
7189
  while (this._pollingBlockhash) {
@@ -7106,8 +7194,8 @@ class Connection {
7106
7194
 
7107
7195
  const expired = timeSinceFetch >= BLOCKHASH_CACHE_TIMEOUT_MS;
7108
7196
 
7109
- if (this._blockhashInfo.recentBlockhash !== null && !expired) {
7110
- return this._blockhashInfo.recentBlockhash;
7197
+ if (this._blockhashInfo.latestBlockhash !== null && !expired) {
7198
+ return this._blockhashInfo.latestBlockhash;
7111
7199
  }
7112
7200
  }
7113
7201
 
@@ -7123,20 +7211,20 @@ class Connection {
7123
7211
 
7124
7212
  try {
7125
7213
  const startTime = Date.now();
7214
+ const cachedLatestBlockhash = this._blockhashInfo.latestBlockhash;
7215
+ const cachedBlockhash = cachedLatestBlockhash ? cachedLatestBlockhash.blockhash : null;
7126
7216
 
7127
7217
  for (let i = 0; i < 50; i++) {
7128
- const {
7129
- blockhash
7130
- } = await this.getRecentBlockhash('finalized');
7218
+ const latestBlockhash = await this.getLatestBlockhash('finalized');
7131
7219
 
7132
- if (this._blockhashInfo.recentBlockhash != blockhash) {
7220
+ if (cachedBlockhash !== latestBlockhash.blockhash) {
7133
7221
  this._blockhashInfo = {
7134
- recentBlockhash: blockhash,
7222
+ latestBlockhash,
7135
7223
  lastFetch: Date.now(),
7136
7224
  transactionSignatures: [],
7137
7225
  simulatedSignatures: []
7138
7226
  };
7139
- return blockhash;
7227
+ return latestBlockhash;
7140
7228
  } // Sleep for approximately half a slot
7141
7229
 
7142
7230
 
@@ -7158,13 +7246,11 @@ class Connection {
7158
7246
 
7159
7247
  if (transactionOrMessage instanceof Transaction) {
7160
7248
  let originalTx = transactionOrMessage;
7161
- transaction = new Transaction({
7162
- recentBlockhash: originalTx.recentBlockhash,
7163
- nonceInfo: originalTx.nonceInfo,
7164
- feePayer: originalTx.feePayer,
7165
- signatures: [...originalTx.signatures]
7166
- });
7249
+ transaction = new Transaction();
7250
+ transaction.feePayer = originalTx.feePayer;
7167
7251
  transaction.instructions = transactionOrMessage.instructions;
7252
+ transaction.nonceInfo = originalTx.nonceInfo;
7253
+ transaction.signatures = originalTx.signatures;
7168
7254
  } else {
7169
7255
  transaction = Transaction.populate(transactionOrMessage); // HACK: this function relies on mutating the populated transaction
7170
7256
 
@@ -7177,7 +7263,9 @@ class Connection {
7177
7263
  let disableCache = this._disableBlockhashCaching;
7178
7264
 
7179
7265
  for (;;) {
7180
- transaction.recentBlockhash = await this._recentBlockhash(disableCache);
7266
+ const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
7267
+ transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
7268
+ transaction.recentBlockhash = latestBlockhash.blockhash;
7181
7269
  if (!signers) break;
7182
7270
  transaction.sign(...signers);
7183
7271
 
@@ -7261,7 +7349,9 @@ class Connection {
7261
7349
  let disableCache = this._disableBlockhashCaching;
7262
7350
 
7263
7351
  for (;;) {
7264
- transaction.recentBlockhash = await this._recentBlockhash(disableCache);
7352
+ const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
7353
+ transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
7354
+ transaction.recentBlockhash = latestBlockhash.blockhash;
7265
7355
  transaction.sign(...signers);
7266
7356
 
7267
7357
  if (!transaction.signature) {
@@ -9702,16 +9792,36 @@ VoteProgram.space = 3731;
9702
9792
  *
9703
9793
  * @param {Connection} connection
9704
9794
  * @param {Buffer} rawTransaction
9795
+ * @param {BlockheightBasedTransactionConfirmationStrategy} confirmationStrategy
9705
9796
  * @param {ConfirmOptions} [options]
9706
9797
  * @returns {Promise<TransactionSignature>}
9707
9798
  */
9708
- async function sendAndConfirmRawTransaction(connection, rawTransaction, options) {
9799
+
9800
+ /**
9801
+ * @deprecated Calling `sendAndConfirmRawTransaction()` without a `confirmationStrategy`
9802
+ * is no longer supported and will be removed in a future version.
9803
+ */
9804
+ // eslint-disable-next-line no-redeclare
9805
+ // eslint-disable-next-line no-redeclare
9806
+ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirmationStrategyOrConfirmOptions, maybeConfirmOptions) {
9807
+ let confirmationStrategy;
9808
+ let options;
9809
+
9810
+ if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'lastValidBlockHeight')) {
9811
+ confirmationStrategy = confirmationStrategyOrConfirmOptions;
9812
+ options = maybeConfirmOptions;
9813
+ } else {
9814
+ options = confirmationStrategyOrConfirmOptions;
9815
+ }
9816
+
9709
9817
  const sendOptions = options && {
9710
9818
  skipPreflight: options.skipPreflight,
9711
9819
  preflightCommitment: options.preflightCommitment || options.commitment
9712
9820
  };
9713
9821
  const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
9714
- const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
9822
+ const commitment = options && options.commitment;
9823
+ const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
9824
+ const status = (await confirmationPromise).value;
9715
9825
 
9716
9826
  if (status.err) {
9717
9827
  throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);