@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.
@@ -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 superstruct = require('superstruct');
13
13
  var rpcWebsockets = require('rpc-websockets');
14
14
  var RpcClient = require('jayson/lib/client/browser');
@@ -2828,8 +2828,6 @@ class Transaction {
2828
2828
  const message = this._compile();
2829
2829
 
2830
2830
  this._partialSign(message, ...uniqueSigners);
2831
-
2832
- this._verifySignatures(message.serialize(), true);
2833
2831
  }
2834
2832
  /**
2835
2833
  * Partially sign a transaction with the specified accounts. All accounts must
@@ -3209,6 +3207,38 @@ class NonceAccount {
3209
3207
 
3210
3208
  }
3211
3209
 
3210
+ const encodeDecode = layout => {
3211
+ const decode = layout.decode.bind(layout);
3212
+ const encode = layout.encode.bind(layout);
3213
+ return {
3214
+ decode,
3215
+ encode
3216
+ };
3217
+ };
3218
+
3219
+ const bigInt = length => property => {
3220
+ const layout = BufferLayout.blob(length, property);
3221
+ const {
3222
+ encode,
3223
+ decode
3224
+ } = encodeDecode(layout);
3225
+ const bigIntLayout = layout;
3226
+
3227
+ bigIntLayout.decode = (buffer$1, offset) => {
3228
+ const src = decode(buffer$1, offset);
3229
+ return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
3230
+ };
3231
+
3232
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
3233
+ const src = bigintBuffer.toBufferLE(bigInt, length);
3234
+ return encode(src, buffer, offset);
3235
+ };
3236
+
3237
+ return bigIntLayout;
3238
+ };
3239
+
3240
+ const u64 = bigInt(8);
3241
+
3212
3242
  /**
3213
3243
  * Create account system transaction params
3214
3244
  */
@@ -3510,7 +3540,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
3510
3540
  },
3511
3541
  Transfer: {
3512
3542
  index: 2,
3513
- layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), bufferLayoutUtils.u64('lamports')])
3543
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('lamports')])
3514
3544
  },
3515
3545
  CreateWithSeed: {
3516
3546
  index: 3,
@@ -3546,7 +3576,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
3546
3576
  },
3547
3577
  TransferWithSeed: {
3548
3578
  index: 11,
3549
- layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), bufferLayoutUtils.u64('lamports'), rustString('seed'), publicKey('programId')])
3579
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('lamports'), rustString('seed'), publicKey('programId')])
3550
3580
  }
3551
3581
  });
3552
3582
  /**
@@ -4187,6 +4217,34 @@ class ComputeBudgetInstruction {
4187
4217
  bytes
4188
4218
  };
4189
4219
  }
4220
+ /**
4221
+ * Decode set compute unit limit compute budget instruction and retrieve the instruction params.
4222
+ */
4223
+
4224
+
4225
+ static decodeSetComputeUnitLimit(instruction) {
4226
+ this.checkProgramId(instruction.programId);
4227
+ const {
4228
+ units
4229
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit, instruction.data);
4230
+ return {
4231
+ units
4232
+ };
4233
+ }
4234
+ /**
4235
+ * Decode set compute unit price compute budget instruction and retrieve the instruction params.
4236
+ */
4237
+
4238
+
4239
+ static decodeSetComputeUnitPrice(instruction) {
4240
+ this.checkProgramId(instruction.programId);
4241
+ const {
4242
+ microLamports
4243
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice, instruction.data);
4244
+ return {
4245
+ microLamports
4246
+ };
4247
+ }
4190
4248
  /**
4191
4249
  * @internal
4192
4250
  */
@@ -4215,6 +4273,14 @@ const COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = Object.freeze({
4215
4273
  RequestHeapFrame: {
4216
4274
  index: 1,
4217
4275
  layout: BufferLayout__namespace.struct([BufferLayout__namespace.u8('instruction'), BufferLayout__namespace.u32('bytes')])
4276
+ },
4277
+ SetComputeUnitLimit: {
4278
+ index: 2,
4279
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u8('instruction'), BufferLayout__namespace.u32('units')])
4280
+ },
4281
+ SetComputeUnitPrice: {
4282
+ index: 3,
4283
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u8('instruction'), u64('microLamports')])
4218
4284
  }
4219
4285
  });
4220
4286
  /**
@@ -4251,6 +4317,28 @@ class ComputeBudgetProgram {
4251
4317
  });
4252
4318
  }
4253
4319
 
4320
+ static setComputeUnitLimit(params) {
4321
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit;
4322
+ const data = encodeData(type, params);
4323
+ return new TransactionInstruction({
4324
+ keys: [],
4325
+ programId: this.programId,
4326
+ data
4327
+ });
4328
+ }
4329
+
4330
+ static setComputeUnitPrice(params) {
4331
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice;
4332
+ const data = encodeData(type, {
4333
+ microLamports: BigInt(params.microLamports)
4334
+ });
4335
+ return new TransactionInstruction({
4336
+ keys: [],
4337
+ programId: this.programId,
4338
+ data
4339
+ });
4340
+ }
4341
+
4254
4342
  }
4255
4343
  ComputeBudgetProgram.programId = new PublicKey('ComputeBudget111111111111111111111111111111');
4256
4344
 
@@ -6029,7 +6117,7 @@ class Connection {
6029
6117
  this._disableBlockhashCaching = false;
6030
6118
  this._pollingBlockhash = false;
6031
6119
  this._blockhashInfo = {
6032
- recentBlockhash: null,
6120
+ latestBlockhash: null,
6033
6121
  lastFetch: 0,
6034
6122
  transactionSignatures: [],
6035
6123
  simulatedSignatures: []
@@ -6992,7 +7080,7 @@ class Connection {
6992
7080
  }
6993
7081
  /**
6994
7082
  * Fetch the latest blockhash from the cluster
6995
- * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
7083
+ * @return {Promise<BlockhashWithExpiryBlockHeight>}
6996
7084
  */
6997
7085
 
6998
7086
 
@@ -7006,7 +7094,7 @@ class Connection {
7006
7094
  }
7007
7095
  /**
7008
7096
  * Fetch the latest blockhash from the cluster
7009
- * @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
7097
+ * @return {Promise<BlockhashWithExpiryBlockHeight>}
7010
7098
  */
7011
7099
 
7012
7100
 
@@ -7589,7 +7677,7 @@ class Connection {
7589
7677
  */
7590
7678
 
7591
7679
 
7592
- async _recentBlockhash(disableCache) {
7680
+ async _blockhashWithExpiryBlockHeight(disableCache) {
7593
7681
  if (!disableCache) {
7594
7682
  // Wait for polling to finish
7595
7683
  while (this._pollingBlockhash) {
@@ -7600,8 +7688,8 @@ class Connection {
7600
7688
 
7601
7689
  const expired = timeSinceFetch >= BLOCKHASH_CACHE_TIMEOUT_MS;
7602
7690
 
7603
- if (this._blockhashInfo.recentBlockhash !== null && !expired) {
7604
- return this._blockhashInfo.recentBlockhash;
7691
+ if (this._blockhashInfo.latestBlockhash !== null && !expired) {
7692
+ return this._blockhashInfo.latestBlockhash;
7605
7693
  }
7606
7694
  }
7607
7695
 
@@ -7617,20 +7705,20 @@ class Connection {
7617
7705
 
7618
7706
  try {
7619
7707
  const startTime = Date.now();
7708
+ const cachedLatestBlockhash = this._blockhashInfo.latestBlockhash;
7709
+ const cachedBlockhash = cachedLatestBlockhash ? cachedLatestBlockhash.blockhash : null;
7620
7710
 
7621
7711
  for (let i = 0; i < 50; i++) {
7622
- const {
7623
- blockhash
7624
- } = await this.getRecentBlockhash('finalized');
7712
+ const latestBlockhash = await this.getLatestBlockhash('finalized');
7625
7713
 
7626
- if (this._blockhashInfo.recentBlockhash != blockhash) {
7714
+ if (cachedBlockhash !== latestBlockhash.blockhash) {
7627
7715
  this._blockhashInfo = {
7628
- recentBlockhash: blockhash,
7716
+ latestBlockhash,
7629
7717
  lastFetch: Date.now(),
7630
7718
  transactionSignatures: [],
7631
7719
  simulatedSignatures: []
7632
7720
  };
7633
- return blockhash;
7721
+ return latestBlockhash;
7634
7722
  } // Sleep for approximately half a slot
7635
7723
 
7636
7724
 
@@ -7652,13 +7740,11 @@ class Connection {
7652
7740
 
7653
7741
  if (transactionOrMessage instanceof Transaction) {
7654
7742
  let originalTx = transactionOrMessage;
7655
- transaction = new Transaction({
7656
- recentBlockhash: originalTx.recentBlockhash,
7657
- nonceInfo: originalTx.nonceInfo,
7658
- feePayer: originalTx.feePayer,
7659
- signatures: [...originalTx.signatures]
7660
- });
7743
+ transaction = new Transaction();
7744
+ transaction.feePayer = originalTx.feePayer;
7661
7745
  transaction.instructions = transactionOrMessage.instructions;
7746
+ transaction.nonceInfo = originalTx.nonceInfo;
7747
+ transaction.signatures = originalTx.signatures;
7662
7748
  } else {
7663
7749
  transaction = Transaction.populate(transactionOrMessage); // HACK: this function relies on mutating the populated transaction
7664
7750
 
@@ -7671,7 +7757,9 @@ class Connection {
7671
7757
  let disableCache = this._disableBlockhashCaching;
7672
7758
 
7673
7759
  for (;;) {
7674
- transaction.recentBlockhash = await this._recentBlockhash(disableCache);
7760
+ const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
7761
+ transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
7762
+ transaction.recentBlockhash = latestBlockhash.blockhash;
7675
7763
  if (!signers) break;
7676
7764
  transaction.sign(...signers);
7677
7765
 
@@ -7755,7 +7843,9 @@ class Connection {
7755
7843
  let disableCache = this._disableBlockhashCaching;
7756
7844
 
7757
7845
  for (;;) {
7758
- transaction.recentBlockhash = await this._recentBlockhash(disableCache);
7846
+ const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
7847
+ transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
7848
+ transaction.recentBlockhash = latestBlockhash.blockhash;
7759
7849
  transaction.sign(...signers);
7760
7850
 
7761
7851
  if (!transaction.signature) {
@@ -10196,16 +10286,36 @@ VoteProgram.space = 3731;
10196
10286
  *
10197
10287
  * @param {Connection} connection
10198
10288
  * @param {Buffer} rawTransaction
10289
+ * @param {BlockheightBasedTransactionConfirmationStrategy} confirmationStrategy
10199
10290
  * @param {ConfirmOptions} [options]
10200
10291
  * @returns {Promise<TransactionSignature>}
10201
10292
  */
10202
- async function sendAndConfirmRawTransaction(connection, rawTransaction, options) {
10293
+
10294
+ /**
10295
+ * @deprecated Calling `sendAndConfirmRawTransaction()` without a `confirmationStrategy`
10296
+ * is no longer supported and will be removed in a future version.
10297
+ */
10298
+ // eslint-disable-next-line no-redeclare
10299
+ // eslint-disable-next-line no-redeclare
10300
+ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirmationStrategyOrConfirmOptions, maybeConfirmOptions) {
10301
+ let confirmationStrategy;
10302
+ let options;
10303
+
10304
+ if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'lastValidBlockHeight')) {
10305
+ confirmationStrategy = confirmationStrategyOrConfirmOptions;
10306
+ options = maybeConfirmOptions;
10307
+ } else {
10308
+ options = confirmationStrategyOrConfirmOptions;
10309
+ }
10310
+
10203
10311
  const sendOptions = options && {
10204
10312
  skipPreflight: options.skipPreflight,
10205
10313
  preflightCommitment: options.preflightCommitment || options.commitment
10206
10314
  };
10207
10315
  const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
10208
- const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
10316
+ const commitment = options && options.commitment;
10317
+ const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
10318
+ const status = (await confirmationPromise).value;
10209
10319
 
10210
10320
  if (status.err) {
10211
10321
  throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);