@solana/web3.js 1.39.1 → 1.41.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.iife.js CHANGED
@@ -11295,7 +11295,7 @@ var solanaWeb3 = (function (exports) {
11295
11295
  /* eslint-disable require-await */
11296
11296
 
11297
11297
 
11298
- static async createProgramAddress(seeds, programId) {
11298
+ static createProgramAddressSync(seeds, programId) {
11299
11299
  let buffer$1 = buffer.Buffer.alloc(0);
11300
11300
  seeds.forEach(function (seed) {
11301
11301
  if (seed.length > MAX_SEED_LENGTH) {
@@ -11314,6 +11314,17 @@ var solanaWeb3 = (function (exports) {
11314
11314
 
11315
11315
  return new PublicKey(publicKeyBytes);
11316
11316
  }
11317
+ /**
11318
+ * Async version of createProgramAddressSync
11319
+ * For backwards compatibility
11320
+ */
11321
+
11322
+ /* eslint-disable require-await */
11323
+
11324
+
11325
+ static async createProgramAddress(seeds, programId) {
11326
+ return this.createProgramAddressSync(seeds, programId);
11327
+ }
11317
11328
  /**
11318
11329
  * Find a valid program address
11319
11330
  *
@@ -11323,14 +11334,14 @@ var solanaWeb3 = (function (exports) {
11323
11334
  */
11324
11335
 
11325
11336
 
11326
- static async findProgramAddress(seeds, programId) {
11337
+ static findProgramAddressSync(seeds, programId) {
11327
11338
  let nonce = 255;
11328
11339
  let address;
11329
11340
 
11330
11341
  while (nonce != 0) {
11331
11342
  try {
11332
11343
  const seedsWithNonce = seeds.concat(buffer.Buffer.from([nonce]));
11333
- address = await this.createProgramAddress(seedsWithNonce, programId);
11344
+ address = this.createProgramAddressSync(seedsWithNonce, programId);
11334
11345
  } catch (err) {
11335
11346
  if (err instanceof TypeError) {
11336
11347
  throw err;
@@ -11345,13 +11356,23 @@ var solanaWeb3 = (function (exports) {
11345
11356
 
11346
11357
  throw new Error(`Unable to find a viable program address nonce`);
11347
11358
  }
11359
+ /**
11360
+ * Async version of findProgramAddressSync
11361
+ * For backwards compatibility
11362
+ */
11363
+
11364
+
11365
+ static async findProgramAddress(seeds, programId) {
11366
+ return this.findProgramAddressSync(seeds, programId);
11367
+ }
11348
11368
  /**
11349
11369
  * Check that a pubkey is on the ed25519 curve.
11350
11370
  */
11351
11371
 
11352
11372
 
11353
- static isOnCurve(pubkey) {
11354
- return is_on_curve(pubkey) == 1;
11373
+ static isOnCurve(pubkeyData) {
11374
+ const pubkey = new PublicKey(pubkeyData);
11375
+ return is_on_curve(pubkey.toBytes()) == 1;
11355
11376
  }
11356
11377
 
11357
11378
  }
@@ -14121,13 +14142,11 @@ var solanaWeb3 = (function (exports) {
14121
14142
  nonceInstruction: this.nonceInfo.nonceInstruction.toJSON()
14122
14143
  } : null,
14123
14144
  instructions: this.instructions.map(instruction => instruction.toJSON()),
14124
- signatures: this.signatures.map(({
14125
- publicKey,
14126
- signature
14127
- }) => ({
14128
- publicKey: publicKey.toJSON(),
14129
- signature: signature ? [...signature] : null
14130
- }))
14145
+ signers: this.signatures.map(({
14146
+ publicKey
14147
+ }) => {
14148
+ return publicKey.toJSON();
14149
+ })
14131
14150
  };
14132
14151
  }
14133
14152
  /**
@@ -14159,7 +14178,7 @@ var solanaWeb3 = (function (exports) {
14159
14178
  compileMessage() {
14160
14179
  if (this._message) {
14161
14180
  if (JSON.stringify(this.toJSON()) !== JSON.stringify(this._json)) {
14162
- throw new Error('Transaction mutated after being populated from Message');
14181
+ throw new Error('Transaction message mutated after being populated from Message');
14163
14182
  }
14164
14183
 
14165
14184
  return this._message;
@@ -15738,6 +15757,136 @@ var solanaWeb3 = (function (exports) {
15738
15757
 
15739
15758
  }
15740
15759
 
15760
+ /**
15761
+ * Compute Budget Instruction class
15762
+ */
15763
+
15764
+ class ComputeBudgetInstruction {
15765
+ /**
15766
+ * @internal
15767
+ */
15768
+ constructor() {}
15769
+ /**
15770
+ * Decode a compute budget instruction and retrieve the instruction type.
15771
+ */
15772
+
15773
+
15774
+ static decodeInstructionType(instruction) {
15775
+ this.checkProgramId(instruction.programId);
15776
+ const instructionTypeLayout = u8('instruction');
15777
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
15778
+ let type;
15779
+
15780
+ for (const [ixType, layout] of Object.entries(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS)) {
15781
+ if (layout.index == typeIndex) {
15782
+ type = ixType;
15783
+ break;
15784
+ }
15785
+ }
15786
+
15787
+ if (!type) {
15788
+ throw new Error('Instruction type incorrect; not a ComputeBudgetInstruction');
15789
+ }
15790
+
15791
+ return type;
15792
+ }
15793
+ /**
15794
+ * Decode request units compute budget instruction and retrieve the instruction params.
15795
+ */
15796
+
15797
+
15798
+ static decodeRequestUnits(instruction) {
15799
+ this.checkProgramId(instruction.programId);
15800
+ const {
15801
+ units,
15802
+ additionalFee
15803
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestUnits, instruction.data);
15804
+ return {
15805
+ units,
15806
+ additionalFee
15807
+ };
15808
+ }
15809
+ /**
15810
+ * Decode request heap frame compute budget instruction and retrieve the instruction params.
15811
+ */
15812
+
15813
+
15814
+ static decodeRequestHeapFrame(instruction) {
15815
+ this.checkProgramId(instruction.programId);
15816
+ const {
15817
+ bytes
15818
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestHeapFrame, instruction.data);
15819
+ return {
15820
+ bytes
15821
+ };
15822
+ }
15823
+ /**
15824
+ * @internal
15825
+ */
15826
+
15827
+
15828
+ static checkProgramId(programId) {
15829
+ if (!programId.equals(ComputeBudgetProgram.programId)) {
15830
+ throw new Error('invalid instruction; programId is not ComputeBudgetProgram');
15831
+ }
15832
+ }
15833
+
15834
+ }
15835
+ /**
15836
+ * An enumeration of valid ComputeBudgetInstructionType's
15837
+ */
15838
+
15839
+ /**
15840
+ * An enumeration of valid ComputeBudget InstructionType's
15841
+ * @internal
15842
+ */
15843
+ const COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = Object.freeze({
15844
+ RequestUnits: {
15845
+ index: 0,
15846
+ layout: struct([u8('instruction'), u32('units'), u32('additionalFee')])
15847
+ },
15848
+ RequestHeapFrame: {
15849
+ index: 1,
15850
+ layout: struct([u8('instruction'), u32('bytes')])
15851
+ }
15852
+ });
15853
+ /**
15854
+ * Factory class for transaction instructions to interact with the Compute Budget program
15855
+ */
15856
+
15857
+ class ComputeBudgetProgram {
15858
+ /**
15859
+ * @internal
15860
+ */
15861
+ constructor() {}
15862
+ /**
15863
+ * Public key that identifies the Compute Budget program
15864
+ */
15865
+
15866
+
15867
+ static requestUnits(params) {
15868
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestUnits;
15869
+ const data = encodeData(type, params);
15870
+ return new TransactionInstruction({
15871
+ keys: [],
15872
+ programId: this.programId,
15873
+ data
15874
+ });
15875
+ }
15876
+
15877
+ static requestHeapFrame(params) {
15878
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestHeapFrame;
15879
+ const data = encodeData(type, params);
15880
+ return new TransactionInstruction({
15881
+ keys: [],
15882
+ programId: this.programId,
15883
+ data
15884
+ });
15885
+ }
15886
+
15887
+ }
15888
+ ComputeBudgetProgram.programId = new PublicKey('ComputeBudget111111111111111111111111111111');
15889
+
15741
15890
  var browserPonyfill = {exports: {}};
15742
15891
 
15743
15892
  (function (module, exports) {
@@ -20944,9 +21093,14 @@ var solanaWeb3 = (function (exports) {
20944
21093
  * Filter for log subscriptions.
20945
21094
  */
20946
21095
 
21096
+ function createSubscriptionWarningMessage(id, label) {
21097
+ return 'Ignored unsubscribe request because an active subscription ' + `with id \`${id}\` for '${label}' events could not be found.`;
21098
+ }
20947
21099
  /**
20948
21100
  * A connection to a fullnode JSON RPC endpoint
20949
21101
  */
21102
+
21103
+
20950
21104
  class Connection {
20951
21105
  /** @internal */
20952
21106
 
@@ -22146,6 +22300,33 @@ var solanaWeb3 = (function (exports) {
22146
22300
  });
22147
22301
  return res;
22148
22302
  }
22303
+ /**
22304
+ * Fetch transaction details for a batch of confirmed transactions.
22305
+ * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
22306
+ */
22307
+
22308
+
22309
+ async getTransactions(signatures, commitment) {
22310
+ const batch = signatures.map(signature => {
22311
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
22312
+
22313
+ return {
22314
+ methodName: 'getTransaction',
22315
+ args
22316
+ };
22317
+ });
22318
+ const unsafeRes = await this._rpcBatchRequest(batch);
22319
+ const res = unsafeRes.map(unsafeRes => {
22320
+ const res = create(unsafeRes, GetTransactionRpcResult);
22321
+
22322
+ if ('error' in res) {
22323
+ throw new Error('failed to get transactions: ' + res.error.message);
22324
+ }
22325
+
22326
+ return res.result;
22327
+ });
22328
+ return res;
22329
+ }
22149
22330
  /**
22150
22331
  * Fetch a list of Transactions and transaction statuses from the cluster
22151
22332
  * for a confirmed block.
@@ -23015,7 +23196,7 @@ var solanaWeb3 = (function (exports) {
23015
23196
 
23016
23197
  this._updateSubscriptions();
23017
23198
  } else {
23018
- throw new Error(`Unknown account change id: ${id}`);
23199
+ console.warn(createSubscriptionWarningMessage(id, 'account change'));
23019
23200
  }
23020
23201
  }
23021
23202
  /**
@@ -23081,7 +23262,7 @@ var solanaWeb3 = (function (exports) {
23081
23262
 
23082
23263
  this._updateSubscriptions();
23083
23264
  } else {
23084
- throw new Error(`Unknown program account change id: ${id}`);
23265
+ console.warn(createSubscriptionWarningMessage(id, 'program account change'));
23085
23266
  }
23086
23267
  }
23087
23268
  /**
@@ -23110,15 +23291,15 @@ var solanaWeb3 = (function (exports) {
23110
23291
 
23111
23292
 
23112
23293
  async removeOnLogsListener(id) {
23113
- if (!this._logsSubscriptions[id]) {
23114
- throw new Error(`Unknown logs id: ${id}`);
23115
- }
23116
-
23117
- const subInfo = this._logsSubscriptions[id];
23118
- delete this._logsSubscriptions[id];
23119
- await this._unsubscribe(subInfo, 'logsUnsubscribe');
23294
+ if (this._logsSubscriptions[id]) {
23295
+ const subInfo = this._logsSubscriptions[id];
23296
+ delete this._logsSubscriptions[id];
23297
+ await this._unsubscribe(subInfo, 'logsUnsubscribe');
23120
23298
 
23121
- this._updateSubscriptions();
23299
+ this._updateSubscriptions();
23300
+ } else {
23301
+ console.warn(createSubscriptionWarningMessage(id, 'logs'));
23302
+ }
23122
23303
  }
23123
23304
  /**
23124
23305
  * @internal
@@ -23187,7 +23368,7 @@ var solanaWeb3 = (function (exports) {
23187
23368
 
23188
23369
  this._updateSubscriptions();
23189
23370
  } else {
23190
- throw new Error(`Unknown slot change id: ${id}`);
23371
+ console.warn(createSubscriptionWarningMessage(id, 'slot change'));
23191
23372
  }
23192
23373
  }
23193
23374
  /**
@@ -23240,7 +23421,7 @@ var solanaWeb3 = (function (exports) {
23240
23421
 
23241
23422
  this._updateSubscriptions();
23242
23423
  } else {
23243
- throw new Error(`Unknown slot update id: ${id}`);
23424
+ console.warn(createSubscriptionWarningMessage(id, 'slot update'));
23244
23425
  }
23245
23426
  }
23246
23427
 
@@ -23381,7 +23562,7 @@ var solanaWeb3 = (function (exports) {
23381
23562
 
23382
23563
  this._updateSubscriptions();
23383
23564
  } else {
23384
- throw new Error(`Unknown signature result id: ${id}`);
23565
+ console.warn(createSubscriptionWarningMessage(id, 'signature result'));
23385
23566
  }
23386
23567
  }
23387
23568
  /**
@@ -23433,7 +23614,7 @@ var solanaWeb3 = (function (exports) {
23433
23614
 
23434
23615
  this._updateSubscriptions();
23435
23616
  } else {
23436
- throw new Error(`Unknown root change id: ${id}`);
23617
+ console.warn(createSubscriptionWarningMessage(id, 'root change'));
23437
23618
  }
23438
23619
  }
23439
23620
 
@@ -29924,6 +30105,9 @@ var solanaWeb3 = (function (exports) {
29924
30105
  exports.BPF_LOADER_DEPRECATED_PROGRAM_ID = BPF_LOADER_DEPRECATED_PROGRAM_ID;
29925
30106
  exports.BPF_LOADER_PROGRAM_ID = BPF_LOADER_PROGRAM_ID;
29926
30107
  exports.BpfLoader = BpfLoader;
30108
+ exports.COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS;
30109
+ exports.ComputeBudgetInstruction = ComputeBudgetInstruction;
30110
+ exports.ComputeBudgetProgram = ComputeBudgetProgram;
29927
30111
  exports.Connection = Connection;
29928
30112
  exports.Ed25519Program = Ed25519Program;
29929
30113
  exports.Enum = Enum;