@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.
@@ -1925,7 +1925,7 @@ class PublicKey extends Struct {
1925
1925
  /* eslint-disable require-await */
1926
1926
 
1927
1927
 
1928
- static async createProgramAddress(seeds, programId) {
1928
+ static createProgramAddressSync(seeds, programId) {
1929
1929
  let buffer$1 = buffer.Buffer.alloc(0);
1930
1930
  seeds.forEach(function (seed) {
1931
1931
  if (seed.length > MAX_SEED_LENGTH) {
@@ -1944,6 +1944,17 @@ class PublicKey extends Struct {
1944
1944
 
1945
1945
  return new PublicKey(publicKeyBytes);
1946
1946
  }
1947
+ /**
1948
+ * Async version of createProgramAddressSync
1949
+ * For backwards compatibility
1950
+ */
1951
+
1952
+ /* eslint-disable require-await */
1953
+
1954
+
1955
+ static async createProgramAddress(seeds, programId) {
1956
+ return this.createProgramAddressSync(seeds, programId);
1957
+ }
1947
1958
  /**
1948
1959
  * Find a valid program address
1949
1960
  *
@@ -1953,14 +1964,14 @@ class PublicKey extends Struct {
1953
1964
  */
1954
1965
 
1955
1966
 
1956
- static async findProgramAddress(seeds, programId) {
1967
+ static findProgramAddressSync(seeds, programId) {
1957
1968
  let nonce = 255;
1958
1969
  let address;
1959
1970
 
1960
1971
  while (nonce != 0) {
1961
1972
  try {
1962
1973
  const seedsWithNonce = seeds.concat(buffer.Buffer.from([nonce]));
1963
- address = await this.createProgramAddress(seedsWithNonce, programId);
1974
+ address = this.createProgramAddressSync(seedsWithNonce, programId);
1964
1975
  } catch (err) {
1965
1976
  if (err instanceof TypeError) {
1966
1977
  throw err;
@@ -1975,13 +1986,23 @@ class PublicKey extends Struct {
1975
1986
 
1976
1987
  throw new Error(`Unable to find a viable program address nonce`);
1977
1988
  }
1989
+ /**
1990
+ * Async version of findProgramAddressSync
1991
+ * For backwards compatibility
1992
+ */
1993
+
1994
+
1995
+ static async findProgramAddress(seeds, programId) {
1996
+ return this.findProgramAddressSync(seeds, programId);
1997
+ }
1978
1998
  /**
1979
1999
  * Check that a pubkey is on the ed25519 curve.
1980
2000
  */
1981
2001
 
1982
2002
 
1983
- static isOnCurve(pubkey) {
1984
- return is_on_curve(pubkey) == 1;
2003
+ static isOnCurve(pubkeyData) {
2004
+ const pubkey = new PublicKey(pubkeyData);
2005
+ return is_on_curve(pubkey.toBytes()) == 1;
1985
2006
  }
1986
2007
 
1987
2008
  }
@@ -2468,13 +2489,11 @@ class Transaction {
2468
2489
  nonceInstruction: this.nonceInfo.nonceInstruction.toJSON()
2469
2490
  } : null,
2470
2491
  instructions: this.instructions.map(instruction => instruction.toJSON()),
2471
- signatures: this.signatures.map(({
2472
- publicKey,
2473
- signature
2474
- }) => ({
2475
- publicKey: publicKey.toJSON(),
2476
- signature: signature ? [...signature] : null
2477
- }))
2492
+ signers: this.signatures.map(({
2493
+ publicKey
2494
+ }) => {
2495
+ return publicKey.toJSON();
2496
+ })
2478
2497
  };
2479
2498
  }
2480
2499
  /**
@@ -2506,7 +2525,7 @@ class Transaction {
2506
2525
  compileMessage() {
2507
2526
  if (this._message) {
2508
2527
  if (JSON.stringify(this.toJSON()) !== JSON.stringify(this._json)) {
2509
- throw new Error('Transaction mutated after being populated from Message');
2528
+ throw new Error('Transaction message mutated after being populated from Message');
2510
2529
  }
2511
2530
 
2512
2531
  return this._message;
@@ -4085,6 +4104,136 @@ class BpfLoader {
4085
4104
 
4086
4105
  }
4087
4106
 
4107
+ /**
4108
+ * Compute Budget Instruction class
4109
+ */
4110
+
4111
+ class ComputeBudgetInstruction {
4112
+ /**
4113
+ * @internal
4114
+ */
4115
+ constructor() {}
4116
+ /**
4117
+ * Decode a compute budget instruction and retrieve the instruction type.
4118
+ */
4119
+
4120
+
4121
+ static decodeInstructionType(instruction) {
4122
+ this.checkProgramId(instruction.programId);
4123
+ const instructionTypeLayout = BufferLayout__namespace.u8('instruction');
4124
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
4125
+ let type;
4126
+
4127
+ for (const [ixType, layout] of Object.entries(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS)) {
4128
+ if (layout.index == typeIndex) {
4129
+ type = ixType;
4130
+ break;
4131
+ }
4132
+ }
4133
+
4134
+ if (!type) {
4135
+ throw new Error('Instruction type incorrect; not a ComputeBudgetInstruction');
4136
+ }
4137
+
4138
+ return type;
4139
+ }
4140
+ /**
4141
+ * Decode request units compute budget instruction and retrieve the instruction params.
4142
+ */
4143
+
4144
+
4145
+ static decodeRequestUnits(instruction) {
4146
+ this.checkProgramId(instruction.programId);
4147
+ const {
4148
+ units,
4149
+ additionalFee
4150
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestUnits, instruction.data);
4151
+ return {
4152
+ units,
4153
+ additionalFee
4154
+ };
4155
+ }
4156
+ /**
4157
+ * Decode request heap frame compute budget instruction and retrieve the instruction params.
4158
+ */
4159
+
4160
+
4161
+ static decodeRequestHeapFrame(instruction) {
4162
+ this.checkProgramId(instruction.programId);
4163
+ const {
4164
+ bytes
4165
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestHeapFrame, instruction.data);
4166
+ return {
4167
+ bytes
4168
+ };
4169
+ }
4170
+ /**
4171
+ * @internal
4172
+ */
4173
+
4174
+
4175
+ static checkProgramId(programId) {
4176
+ if (!programId.equals(ComputeBudgetProgram.programId)) {
4177
+ throw new Error('invalid instruction; programId is not ComputeBudgetProgram');
4178
+ }
4179
+ }
4180
+
4181
+ }
4182
+ /**
4183
+ * An enumeration of valid ComputeBudgetInstructionType's
4184
+ */
4185
+
4186
+ /**
4187
+ * An enumeration of valid ComputeBudget InstructionType's
4188
+ * @internal
4189
+ */
4190
+ const COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = Object.freeze({
4191
+ RequestUnits: {
4192
+ index: 0,
4193
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u8('instruction'), BufferLayout__namespace.u32('units'), BufferLayout__namespace.u32('additionalFee')])
4194
+ },
4195
+ RequestHeapFrame: {
4196
+ index: 1,
4197
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u8('instruction'), BufferLayout__namespace.u32('bytes')])
4198
+ }
4199
+ });
4200
+ /**
4201
+ * Factory class for transaction instructions to interact with the Compute Budget program
4202
+ */
4203
+
4204
+ class ComputeBudgetProgram {
4205
+ /**
4206
+ * @internal
4207
+ */
4208
+ constructor() {}
4209
+ /**
4210
+ * Public key that identifies the Compute Budget program
4211
+ */
4212
+
4213
+
4214
+ static requestUnits(params) {
4215
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestUnits;
4216
+ const data = encodeData(type, params);
4217
+ return new TransactionInstruction({
4218
+ keys: [],
4219
+ programId: this.programId,
4220
+ data
4221
+ });
4222
+ }
4223
+
4224
+ static requestHeapFrame(params) {
4225
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestHeapFrame;
4226
+ const data = encodeData(type, params);
4227
+ return new TransactionInstruction({
4228
+ keys: [],
4229
+ programId: this.programId,
4230
+ data
4231
+ });
4232
+ }
4233
+
4234
+ }
4235
+ ComputeBudgetProgram.programId = new PublicKey('ComputeBudget111111111111111111111111111111');
4236
+
4088
4237
  var browserPonyfill = {exports: {}};
4089
4238
 
4090
4239
  (function (module, exports) {
@@ -5680,9 +5829,14 @@ const LogsNotificationResult = superstruct.type({
5680
5829
  * Filter for log subscriptions.
5681
5830
  */
5682
5831
 
5832
+ function createSubscriptionWarningMessage(id, label) {
5833
+ return 'Ignored unsubscribe request because an active subscription ' + `with id \`${id}\` for '${label}' events could not be found.`;
5834
+ }
5683
5835
  /**
5684
5836
  * A connection to a fullnode JSON RPC endpoint
5685
5837
  */
5838
+
5839
+
5686
5840
  class Connection {
5687
5841
  /** @internal */
5688
5842
 
@@ -6882,6 +7036,33 @@ class Connection {
6882
7036
  });
6883
7037
  return res;
6884
7038
  }
7039
+ /**
7040
+ * Fetch transaction details for a batch of confirmed transactions.
7041
+ * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
7042
+ */
7043
+
7044
+
7045
+ async getTransactions(signatures, commitment) {
7046
+ const batch = signatures.map(signature => {
7047
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
7048
+
7049
+ return {
7050
+ methodName: 'getTransaction',
7051
+ args
7052
+ };
7053
+ });
7054
+ const unsafeRes = await this._rpcBatchRequest(batch);
7055
+ const res = unsafeRes.map(unsafeRes => {
7056
+ const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
7057
+
7058
+ if ('error' in res) {
7059
+ throw new Error('failed to get transactions: ' + res.error.message);
7060
+ }
7061
+
7062
+ return res.result;
7063
+ });
7064
+ return res;
7065
+ }
6885
7066
  /**
6886
7067
  * Fetch a list of Transactions and transaction statuses from the cluster
6887
7068
  * for a confirmed block.
@@ -7751,7 +7932,7 @@ class Connection {
7751
7932
 
7752
7933
  this._updateSubscriptions();
7753
7934
  } else {
7754
- throw new Error(`Unknown account change id: ${id}`);
7935
+ console.warn(createSubscriptionWarningMessage(id, 'account change'));
7755
7936
  }
7756
7937
  }
7757
7938
  /**
@@ -7817,7 +7998,7 @@ class Connection {
7817
7998
 
7818
7999
  this._updateSubscriptions();
7819
8000
  } else {
7820
- throw new Error(`Unknown program account change id: ${id}`);
8001
+ console.warn(createSubscriptionWarningMessage(id, 'program account change'));
7821
8002
  }
7822
8003
  }
7823
8004
  /**
@@ -7846,15 +8027,15 @@ class Connection {
7846
8027
 
7847
8028
 
7848
8029
  async removeOnLogsListener(id) {
7849
- if (!this._logsSubscriptions[id]) {
7850
- throw new Error(`Unknown logs id: ${id}`);
7851
- }
7852
-
7853
- const subInfo = this._logsSubscriptions[id];
7854
- delete this._logsSubscriptions[id];
7855
- await this._unsubscribe(subInfo, 'logsUnsubscribe');
8030
+ if (this._logsSubscriptions[id]) {
8031
+ const subInfo = this._logsSubscriptions[id];
8032
+ delete this._logsSubscriptions[id];
8033
+ await this._unsubscribe(subInfo, 'logsUnsubscribe');
7856
8034
 
7857
- this._updateSubscriptions();
8035
+ this._updateSubscriptions();
8036
+ } else {
8037
+ console.warn(createSubscriptionWarningMessage(id, 'logs'));
8038
+ }
7858
8039
  }
7859
8040
  /**
7860
8041
  * @internal
@@ -7923,7 +8104,7 @@ class Connection {
7923
8104
 
7924
8105
  this._updateSubscriptions();
7925
8106
  } else {
7926
- throw new Error(`Unknown slot change id: ${id}`);
8107
+ console.warn(createSubscriptionWarningMessage(id, 'slot change'));
7927
8108
  }
7928
8109
  }
7929
8110
  /**
@@ -7976,7 +8157,7 @@ class Connection {
7976
8157
 
7977
8158
  this._updateSubscriptions();
7978
8159
  } else {
7979
- throw new Error(`Unknown slot update id: ${id}`);
8160
+ console.warn(createSubscriptionWarningMessage(id, 'slot update'));
7980
8161
  }
7981
8162
  }
7982
8163
 
@@ -8117,7 +8298,7 @@ class Connection {
8117
8298
 
8118
8299
  this._updateSubscriptions();
8119
8300
  } else {
8120
- throw new Error(`Unknown signature result id: ${id}`);
8301
+ console.warn(createSubscriptionWarningMessage(id, 'signature result'));
8121
8302
  }
8122
8303
  }
8123
8304
  /**
@@ -8169,7 +8350,7 @@ class Connection {
8169
8350
 
8170
8351
  this._updateSubscriptions();
8171
8352
  } else {
8172
- throw new Error(`Unknown root change id: ${id}`);
8353
+ console.warn(createSubscriptionWarningMessage(id, 'root change'));
8173
8354
  }
8174
8355
  }
8175
8356
 
@@ -9856,6 +10037,9 @@ exports.BLOCKHASH_CACHE_TIMEOUT_MS = BLOCKHASH_CACHE_TIMEOUT_MS;
9856
10037
  exports.BPF_LOADER_DEPRECATED_PROGRAM_ID = BPF_LOADER_DEPRECATED_PROGRAM_ID;
9857
10038
  exports.BPF_LOADER_PROGRAM_ID = BPF_LOADER_PROGRAM_ID;
9858
10039
  exports.BpfLoader = BpfLoader;
10040
+ exports.COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS;
10041
+ exports.ComputeBudgetInstruction = ComputeBudgetInstruction;
10042
+ exports.ComputeBudgetProgram = ComputeBudgetProgram;
9859
10043
  exports.Connection = Connection;
9860
10044
  exports.Ed25519Program = Ed25519Program;
9861
10045
  exports.Enum = Enum;