@solana/web3.js 1.39.0 → 1.39.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.
package/lib/index.cjs.js CHANGED
@@ -2403,6 +2403,26 @@ class TransactionInstruction {
2403
2403
  this.data = opts.data;
2404
2404
  }
2405
2405
  }
2406
+ /**
2407
+ * @internal
2408
+ */
2409
+
2410
+
2411
+ toJSON() {
2412
+ return {
2413
+ keys: this.keys.map(({
2414
+ pubkey,
2415
+ isSigner,
2416
+ isWritable
2417
+ }) => ({
2418
+ pubkey: pubkey.toJSON(),
2419
+ isSigner,
2420
+ isWritable
2421
+ })),
2422
+ programId: this.programId.toJSON(),
2423
+ data: [...this.data]
2424
+ };
2425
+ }
2406
2426
 
2407
2427
  }
2408
2428
  /**
@@ -2442,8 +2462,33 @@ class Transaction {
2442
2462
  this.instructions = [];
2443
2463
  this.recentBlockhash = void 0;
2444
2464
  this.nonceInfo = void 0;
2465
+ this._message = void 0;
2466
+ this._json = void 0;
2445
2467
  opts && Object.assign(this, opts);
2446
2468
  }
2469
+ /**
2470
+ * @internal
2471
+ */
2472
+
2473
+
2474
+ toJSON() {
2475
+ return {
2476
+ recentBlockhash: this.recentBlockhash || null,
2477
+ feePayer: this.feePayer ? this.feePayer.toJSON() : null,
2478
+ nonceInfo: this.nonceInfo ? {
2479
+ nonce: this.nonceInfo.nonce,
2480
+ nonceInstruction: this.nonceInfo.nonceInstruction.toJSON()
2481
+ } : null,
2482
+ instructions: this.instructions.map(instruction => instruction.toJSON()),
2483
+ signatures: this.signatures.map(({
2484
+ publicKey,
2485
+ signature
2486
+ }) => ({
2487
+ publicKey: publicKey.toJSON(),
2488
+ signature: signature ? [...signature] : null
2489
+ }))
2490
+ };
2491
+ }
2447
2492
  /**
2448
2493
  * Add one or more instructions to this Transaction
2449
2494
  */
@@ -2471,6 +2516,14 @@ class Transaction {
2471
2516
 
2472
2517
 
2473
2518
  compileMessage() {
2519
+ if (this._message) {
2520
+ if (JSON.stringify(this.toJSON()) !== JSON.stringify(this._json)) {
2521
+ throw new Error('Transaction mutated after being populated from Message');
2522
+ }
2523
+
2524
+ return this._message;
2525
+ }
2526
+
2474
2527
  const {
2475
2528
  nonceInfo
2476
2529
  } = this;
@@ -2992,6 +3045,8 @@ class Transaction {
2992
3045
  data: bs58__default["default"].decode(instruction.data)
2993
3046
  }));
2994
3047
  });
3048
+ transaction._message = message;
3049
+ transaction._json = transaction.toJSON();
2995
3050
  return transaction;
2996
3051
  }
2997
3052
 
@@ -6768,7 +6823,9 @@ class Connection {
6768
6823
  });
6769
6824
  transaction.instructions = transactionOrMessage.instructions;
6770
6825
  } else {
6771
- transaction = Transaction.populate(transactionOrMessage);
6826
+ transaction = Transaction.populate(transactionOrMessage); // HACK: this function relies on mutating the populated transaction
6827
+
6828
+ transaction._message = transaction._json = undefined;
6772
6829
  }
6773
6830
 
6774
6831
  if (transaction.nonceInfo && signers) {