@solana/web3.js 1.39.0 → 1.40.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.
@@ -1893,7 +1893,7 @@ class PublicKey extends Struct {
1893
1893
  /* eslint-disable require-await */
1894
1894
 
1895
1895
 
1896
- static async createProgramAddress(seeds, programId) {
1896
+ static createProgramAddressSync(seeds, programId) {
1897
1897
  let buffer = Buffer.alloc(0);
1898
1898
  seeds.forEach(function (seed) {
1899
1899
  if (seed.length > MAX_SEED_LENGTH) {
@@ -1912,6 +1912,17 @@ class PublicKey extends Struct {
1912
1912
 
1913
1913
  return new PublicKey(publicKeyBytes);
1914
1914
  }
1915
+ /**
1916
+ * Async version of createProgramAddressSync
1917
+ * For backwards compatibility
1918
+ */
1919
+
1920
+ /* eslint-disable require-await */
1921
+
1922
+
1923
+ static async createProgramAddress(seeds, programId) {
1924
+ return this.createProgramAddressSync(seeds, programId);
1925
+ }
1915
1926
  /**
1916
1927
  * Find a valid program address
1917
1928
  *
@@ -1921,14 +1932,14 @@ class PublicKey extends Struct {
1921
1932
  */
1922
1933
 
1923
1934
 
1924
- static async findProgramAddress(seeds, programId) {
1935
+ static findProgramAddressSync(seeds, programId) {
1925
1936
  let nonce = 255;
1926
1937
  let address;
1927
1938
 
1928
1939
  while (nonce != 0) {
1929
1940
  try {
1930
1941
  const seedsWithNonce = seeds.concat(Buffer.from([nonce]));
1931
- address = await this.createProgramAddress(seedsWithNonce, programId);
1942
+ address = this.createProgramAddressSync(seedsWithNonce, programId);
1932
1943
  } catch (err) {
1933
1944
  if (err instanceof TypeError) {
1934
1945
  throw err;
@@ -1943,13 +1954,23 @@ class PublicKey extends Struct {
1943
1954
 
1944
1955
  throw new Error(`Unable to find a viable program address nonce`);
1945
1956
  }
1957
+ /**
1958
+ * Async version of findProgramAddressSync
1959
+ * For backwards compatibility
1960
+ */
1961
+
1962
+
1963
+ static async findProgramAddress(seeds, programId) {
1964
+ return this.findProgramAddressSync(seeds, programId);
1965
+ }
1946
1966
  /**
1947
1967
  * Check that a pubkey is on the ed25519 curve.
1948
1968
  */
1949
1969
 
1950
1970
 
1951
- static isOnCurve(pubkey) {
1952
- return is_on_curve(pubkey) == 1;
1971
+ static isOnCurve(pubkeyData) {
1972
+ const pubkey = new PublicKey(pubkeyData);
1973
+ return is_on_curve(pubkey.toBytes()) == 1;
1953
1974
  }
1954
1975
 
1955
1976
  }
@@ -2359,6 +2380,26 @@ class TransactionInstruction {
2359
2380
  this.data = opts.data;
2360
2381
  }
2361
2382
  }
2383
+ /**
2384
+ * @internal
2385
+ */
2386
+
2387
+
2388
+ toJSON() {
2389
+ return {
2390
+ keys: this.keys.map(({
2391
+ pubkey,
2392
+ isSigner,
2393
+ isWritable
2394
+ }) => ({
2395
+ pubkey: pubkey.toJSON(),
2396
+ isSigner,
2397
+ isWritable
2398
+ })),
2399
+ programId: this.programId.toJSON(),
2400
+ data: [...this.data]
2401
+ };
2402
+ }
2362
2403
 
2363
2404
  }
2364
2405
  /**
@@ -2398,8 +2439,31 @@ class Transaction {
2398
2439
  this.instructions = [];
2399
2440
  this.recentBlockhash = void 0;
2400
2441
  this.nonceInfo = void 0;
2442
+ this._message = void 0;
2443
+ this._json = void 0;
2401
2444
  opts && Object.assign(this, opts);
2402
2445
  }
2446
+ /**
2447
+ * @internal
2448
+ */
2449
+
2450
+
2451
+ toJSON() {
2452
+ return {
2453
+ recentBlockhash: this.recentBlockhash || null,
2454
+ feePayer: this.feePayer ? this.feePayer.toJSON() : null,
2455
+ nonceInfo: this.nonceInfo ? {
2456
+ nonce: this.nonceInfo.nonce,
2457
+ nonceInstruction: this.nonceInfo.nonceInstruction.toJSON()
2458
+ } : null,
2459
+ instructions: this.instructions.map(instruction => instruction.toJSON()),
2460
+ signers: this.signatures.map(({
2461
+ publicKey
2462
+ }) => {
2463
+ return publicKey.toJSON();
2464
+ })
2465
+ };
2466
+ }
2403
2467
  /**
2404
2468
  * Add one or more instructions to this Transaction
2405
2469
  */
@@ -2427,6 +2491,14 @@ class Transaction {
2427
2491
 
2428
2492
 
2429
2493
  compileMessage() {
2494
+ if (this._message) {
2495
+ if (JSON.stringify(this.toJSON()) !== JSON.stringify(this._json)) {
2496
+ throw new Error('Transaction message mutated after being populated from Message');
2497
+ }
2498
+
2499
+ return this._message;
2500
+ }
2501
+
2430
2502
  const {
2431
2503
  nonceInfo
2432
2504
  } = this;
@@ -2948,6 +3020,8 @@ class Transaction {
2948
3020
  data: bs58.decode(instruction.data)
2949
3021
  }));
2950
3022
  });
3023
+ transaction._message = message;
3024
+ transaction._json = transaction.toJSON();
2951
3025
  return transaction;
2952
3026
  }
2953
3027
 
@@ -5593,9 +5667,14 @@ const LogsNotificationResult = type({
5593
5667
  * Filter for log subscriptions.
5594
5668
  */
5595
5669
 
5670
+ function createSubscriptionWarningMessage(id, label) {
5671
+ return 'Ignored unsubscribe request because an active subscription ' + `with id \`${id}\` for '${label}' events could not be found.`;
5672
+ }
5596
5673
  /**
5597
5674
  * A connection to a fullnode JSON RPC endpoint
5598
5675
  */
5676
+
5677
+
5599
5678
  class Connection {
5600
5679
  /** @internal */
5601
5680
 
@@ -6795,6 +6874,33 @@ class Connection {
6795
6874
  });
6796
6875
  return res;
6797
6876
  }
6877
+ /**
6878
+ * Fetch transaction details for a batch of confirmed transactions.
6879
+ * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
6880
+ */
6881
+
6882
+
6883
+ async getTransactions(signatures, commitment) {
6884
+ const batch = signatures.map(signature => {
6885
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
6886
+
6887
+ return {
6888
+ methodName: 'getTransaction',
6889
+ args
6890
+ };
6891
+ });
6892
+ const unsafeRes = await this._rpcBatchRequest(batch);
6893
+ const res = unsafeRes.map(unsafeRes => {
6894
+ const res = create(unsafeRes, GetTransactionRpcResult);
6895
+
6896
+ if ('error' in res) {
6897
+ throw new Error('failed to get transactions: ' + res.error.message);
6898
+ }
6899
+
6900
+ return res.result;
6901
+ });
6902
+ return res;
6903
+ }
6798
6904
  /**
6799
6905
  * Fetch a list of Transactions and transaction statuses from the cluster
6800
6906
  * for a confirmed block.
@@ -7230,7 +7336,9 @@ class Connection {
7230
7336
  });
7231
7337
  transaction.instructions = transactionOrMessage.instructions;
7232
7338
  } else {
7233
- transaction = Transaction.populate(transactionOrMessage);
7339
+ transaction = Transaction.populate(transactionOrMessage); // HACK: this function relies on mutating the populated transaction
7340
+
7341
+ transaction._message = transaction._json = undefined;
7234
7342
  }
7235
7343
 
7236
7344
  if (transaction.nonceInfo && signers) {
@@ -7662,7 +7770,7 @@ class Connection {
7662
7770
 
7663
7771
  this._updateSubscriptions();
7664
7772
  } else {
7665
- throw new Error(`Unknown account change id: ${id}`);
7773
+ console.warn(createSubscriptionWarningMessage(id, 'account change'));
7666
7774
  }
7667
7775
  }
7668
7776
  /**
@@ -7728,7 +7836,7 @@ class Connection {
7728
7836
 
7729
7837
  this._updateSubscriptions();
7730
7838
  } else {
7731
- throw new Error(`Unknown program account change id: ${id}`);
7839
+ console.warn(createSubscriptionWarningMessage(id, 'program account change'));
7732
7840
  }
7733
7841
  }
7734
7842
  /**
@@ -7757,15 +7865,15 @@ class Connection {
7757
7865
 
7758
7866
 
7759
7867
  async removeOnLogsListener(id) {
7760
- if (!this._logsSubscriptions[id]) {
7761
- throw new Error(`Unknown logs id: ${id}`);
7762
- }
7763
-
7764
- const subInfo = this._logsSubscriptions[id];
7765
- delete this._logsSubscriptions[id];
7766
- await this._unsubscribe(subInfo, 'logsUnsubscribe');
7868
+ if (this._logsSubscriptions[id]) {
7869
+ const subInfo = this._logsSubscriptions[id];
7870
+ delete this._logsSubscriptions[id];
7871
+ await this._unsubscribe(subInfo, 'logsUnsubscribe');
7767
7872
 
7768
- this._updateSubscriptions();
7873
+ this._updateSubscriptions();
7874
+ } else {
7875
+ console.warn(createSubscriptionWarningMessage(id, 'logs'));
7876
+ }
7769
7877
  }
7770
7878
  /**
7771
7879
  * @internal
@@ -7834,7 +7942,7 @@ class Connection {
7834
7942
 
7835
7943
  this._updateSubscriptions();
7836
7944
  } else {
7837
- throw new Error(`Unknown slot change id: ${id}`);
7945
+ console.warn(createSubscriptionWarningMessage(id, 'slot change'));
7838
7946
  }
7839
7947
  }
7840
7948
  /**
@@ -7887,7 +7995,7 @@ class Connection {
7887
7995
 
7888
7996
  this._updateSubscriptions();
7889
7997
  } else {
7890
- throw new Error(`Unknown slot update id: ${id}`);
7998
+ console.warn(createSubscriptionWarningMessage(id, 'slot update'));
7891
7999
  }
7892
8000
  }
7893
8001
 
@@ -8028,7 +8136,7 @@ class Connection {
8028
8136
 
8029
8137
  this._updateSubscriptions();
8030
8138
  } else {
8031
- throw new Error(`Unknown signature result id: ${id}`);
8139
+ console.warn(createSubscriptionWarningMessage(id, 'signature result'));
8032
8140
  }
8033
8141
  }
8034
8142
  /**
@@ -8080,7 +8188,7 @@ class Connection {
8080
8188
 
8081
8189
  this._updateSubscriptions();
8082
8190
  } else {
8083
- throw new Error(`Unknown root change id: ${id}`);
8191
+ console.warn(createSubscriptionWarningMessage(id, 'root change'));
8084
8192
  }
8085
8193
  }
8086
8194