@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.
@@ -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
  }
@@ -2391,6 +2412,26 @@ class TransactionInstruction {
2391
2412
  this.data = opts.data;
2392
2413
  }
2393
2414
  }
2415
+ /**
2416
+ * @internal
2417
+ */
2418
+
2419
+
2420
+ toJSON() {
2421
+ return {
2422
+ keys: this.keys.map(({
2423
+ pubkey,
2424
+ isSigner,
2425
+ isWritable
2426
+ }) => ({
2427
+ pubkey: pubkey.toJSON(),
2428
+ isSigner,
2429
+ isWritable
2430
+ })),
2431
+ programId: this.programId.toJSON(),
2432
+ data: [...this.data]
2433
+ };
2434
+ }
2394
2435
 
2395
2436
  }
2396
2437
  /**
@@ -2430,8 +2471,31 @@ class Transaction {
2430
2471
  this.instructions = [];
2431
2472
  this.recentBlockhash = void 0;
2432
2473
  this.nonceInfo = void 0;
2474
+ this._message = void 0;
2475
+ this._json = void 0;
2433
2476
  opts && Object.assign(this, opts);
2434
2477
  }
2478
+ /**
2479
+ * @internal
2480
+ */
2481
+
2482
+
2483
+ toJSON() {
2484
+ return {
2485
+ recentBlockhash: this.recentBlockhash || null,
2486
+ feePayer: this.feePayer ? this.feePayer.toJSON() : null,
2487
+ nonceInfo: this.nonceInfo ? {
2488
+ nonce: this.nonceInfo.nonce,
2489
+ nonceInstruction: this.nonceInfo.nonceInstruction.toJSON()
2490
+ } : null,
2491
+ instructions: this.instructions.map(instruction => instruction.toJSON()),
2492
+ signers: this.signatures.map(({
2493
+ publicKey
2494
+ }) => {
2495
+ return publicKey.toJSON();
2496
+ })
2497
+ };
2498
+ }
2435
2499
  /**
2436
2500
  * Add one or more instructions to this Transaction
2437
2501
  */
@@ -2459,6 +2523,14 @@ class Transaction {
2459
2523
 
2460
2524
 
2461
2525
  compileMessage() {
2526
+ if (this._message) {
2527
+ if (JSON.stringify(this.toJSON()) !== JSON.stringify(this._json)) {
2528
+ throw new Error('Transaction message mutated after being populated from Message');
2529
+ }
2530
+
2531
+ return this._message;
2532
+ }
2533
+
2462
2534
  const {
2463
2535
  nonceInfo
2464
2536
  } = this;
@@ -2980,6 +3052,8 @@ class Transaction {
2980
3052
  data: bs58__default["default"].decode(instruction.data)
2981
3053
  }));
2982
3054
  });
3055
+ transaction._message = message;
3056
+ transaction._json = transaction.toJSON();
2983
3057
  return transaction;
2984
3058
  }
2985
3059
 
@@ -5625,9 +5699,14 @@ const LogsNotificationResult = superstruct.type({
5625
5699
  * Filter for log subscriptions.
5626
5700
  */
5627
5701
 
5702
+ function createSubscriptionWarningMessage(id, label) {
5703
+ return 'Ignored unsubscribe request because an active subscription ' + `with id \`${id}\` for '${label}' events could not be found.`;
5704
+ }
5628
5705
  /**
5629
5706
  * A connection to a fullnode JSON RPC endpoint
5630
5707
  */
5708
+
5709
+
5631
5710
  class Connection {
5632
5711
  /** @internal */
5633
5712
 
@@ -6827,6 +6906,33 @@ class Connection {
6827
6906
  });
6828
6907
  return res;
6829
6908
  }
6909
+ /**
6910
+ * Fetch transaction details for a batch of confirmed transactions.
6911
+ * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
6912
+ */
6913
+
6914
+
6915
+ async getTransactions(signatures, commitment) {
6916
+ const batch = signatures.map(signature => {
6917
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
6918
+
6919
+ return {
6920
+ methodName: 'getTransaction',
6921
+ args
6922
+ };
6923
+ });
6924
+ const unsafeRes = await this._rpcBatchRequest(batch);
6925
+ const res = unsafeRes.map(unsafeRes => {
6926
+ const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
6927
+
6928
+ if ('error' in res) {
6929
+ throw new Error('failed to get transactions: ' + res.error.message);
6930
+ }
6931
+
6932
+ return res.result;
6933
+ });
6934
+ return res;
6935
+ }
6830
6936
  /**
6831
6937
  * Fetch a list of Transactions and transaction statuses from the cluster
6832
6938
  * for a confirmed block.
@@ -7262,7 +7368,9 @@ class Connection {
7262
7368
  });
7263
7369
  transaction.instructions = transactionOrMessage.instructions;
7264
7370
  } else {
7265
- transaction = Transaction.populate(transactionOrMessage);
7371
+ transaction = Transaction.populate(transactionOrMessage); // HACK: this function relies on mutating the populated transaction
7372
+
7373
+ transaction._message = transaction._json = undefined;
7266
7374
  }
7267
7375
 
7268
7376
  if (transaction.nonceInfo && signers) {
@@ -7694,7 +7802,7 @@ class Connection {
7694
7802
 
7695
7803
  this._updateSubscriptions();
7696
7804
  } else {
7697
- throw new Error(`Unknown account change id: ${id}`);
7805
+ console.warn(createSubscriptionWarningMessage(id, 'account change'));
7698
7806
  }
7699
7807
  }
7700
7808
  /**
@@ -7760,7 +7868,7 @@ class Connection {
7760
7868
 
7761
7869
  this._updateSubscriptions();
7762
7870
  } else {
7763
- throw new Error(`Unknown program account change id: ${id}`);
7871
+ console.warn(createSubscriptionWarningMessage(id, 'program account change'));
7764
7872
  }
7765
7873
  }
7766
7874
  /**
@@ -7789,15 +7897,15 @@ class Connection {
7789
7897
 
7790
7898
 
7791
7899
  async removeOnLogsListener(id) {
7792
- if (!this._logsSubscriptions[id]) {
7793
- throw new Error(`Unknown logs id: ${id}`);
7794
- }
7795
-
7796
- const subInfo = this._logsSubscriptions[id];
7797
- delete this._logsSubscriptions[id];
7798
- await this._unsubscribe(subInfo, 'logsUnsubscribe');
7900
+ if (this._logsSubscriptions[id]) {
7901
+ const subInfo = this._logsSubscriptions[id];
7902
+ delete this._logsSubscriptions[id];
7903
+ await this._unsubscribe(subInfo, 'logsUnsubscribe');
7799
7904
 
7800
- this._updateSubscriptions();
7905
+ this._updateSubscriptions();
7906
+ } else {
7907
+ console.warn(createSubscriptionWarningMessage(id, 'logs'));
7908
+ }
7801
7909
  }
7802
7910
  /**
7803
7911
  * @internal
@@ -7866,7 +7974,7 @@ class Connection {
7866
7974
 
7867
7975
  this._updateSubscriptions();
7868
7976
  } else {
7869
- throw new Error(`Unknown slot change id: ${id}`);
7977
+ console.warn(createSubscriptionWarningMessage(id, 'slot change'));
7870
7978
  }
7871
7979
  }
7872
7980
  /**
@@ -7919,7 +8027,7 @@ class Connection {
7919
8027
 
7920
8028
  this._updateSubscriptions();
7921
8029
  } else {
7922
- throw new Error(`Unknown slot update id: ${id}`);
8030
+ console.warn(createSubscriptionWarningMessage(id, 'slot update'));
7923
8031
  }
7924
8032
  }
7925
8033
 
@@ -8060,7 +8168,7 @@ class Connection {
8060
8168
 
8061
8169
  this._updateSubscriptions();
8062
8170
  } else {
8063
- throw new Error(`Unknown signature result id: ${id}`);
8171
+ console.warn(createSubscriptionWarningMessage(id, 'signature result'));
8064
8172
  }
8065
8173
  }
8066
8174
  /**
@@ -8112,7 +8220,7 @@ class Connection {
8112
8220
 
8113
8221
  this._updateSubscriptions();
8114
8222
  } else {
8115
- throw new Error(`Unknown root change id: ${id}`);
8223
+ console.warn(createSubscriptionWarningMessage(id, 'root change'));
8116
8224
  }
8117
8225
  }
8118
8226