@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.esm.js CHANGED
@@ -2368,6 +2368,26 @@ class TransactionInstruction {
2368
2368
  this.data = opts.data;
2369
2369
  }
2370
2370
  }
2371
+ /**
2372
+ * @internal
2373
+ */
2374
+
2375
+
2376
+ toJSON() {
2377
+ return {
2378
+ keys: this.keys.map(({
2379
+ pubkey,
2380
+ isSigner,
2381
+ isWritable
2382
+ }) => ({
2383
+ pubkey: pubkey.toJSON(),
2384
+ isSigner,
2385
+ isWritable
2386
+ })),
2387
+ programId: this.programId.toJSON(),
2388
+ data: [...this.data]
2389
+ };
2390
+ }
2371
2391
 
2372
2392
  }
2373
2393
  /**
@@ -2407,8 +2427,33 @@ class Transaction {
2407
2427
  this.instructions = [];
2408
2428
  this.recentBlockhash = void 0;
2409
2429
  this.nonceInfo = void 0;
2430
+ this._message = void 0;
2431
+ this._json = void 0;
2410
2432
  opts && Object.assign(this, opts);
2411
2433
  }
2434
+ /**
2435
+ * @internal
2436
+ */
2437
+
2438
+
2439
+ toJSON() {
2440
+ return {
2441
+ recentBlockhash: this.recentBlockhash || null,
2442
+ feePayer: this.feePayer ? this.feePayer.toJSON() : null,
2443
+ nonceInfo: this.nonceInfo ? {
2444
+ nonce: this.nonceInfo.nonce,
2445
+ nonceInstruction: this.nonceInfo.nonceInstruction.toJSON()
2446
+ } : null,
2447
+ instructions: this.instructions.map(instruction => instruction.toJSON()),
2448
+ signatures: this.signatures.map(({
2449
+ publicKey,
2450
+ signature
2451
+ }) => ({
2452
+ publicKey: publicKey.toJSON(),
2453
+ signature: signature ? [...signature] : null
2454
+ }))
2455
+ };
2456
+ }
2412
2457
  /**
2413
2458
  * Add one or more instructions to this Transaction
2414
2459
  */
@@ -2436,6 +2481,14 @@ class Transaction {
2436
2481
 
2437
2482
 
2438
2483
  compileMessage() {
2484
+ if (this._message) {
2485
+ if (JSON.stringify(this.toJSON()) !== JSON.stringify(this._json)) {
2486
+ throw new Error('Transaction mutated after being populated from Message');
2487
+ }
2488
+
2489
+ return this._message;
2490
+ }
2491
+
2439
2492
  const {
2440
2493
  nonceInfo
2441
2494
  } = this;
@@ -2957,6 +3010,8 @@ class Transaction {
2957
3010
  data: bs58.decode(instruction.data)
2958
3011
  }));
2959
3012
  });
3013
+ transaction._message = message;
3014
+ transaction._json = transaction.toJSON();
2960
3015
  return transaction;
2961
3016
  }
2962
3017
 
@@ -6733,7 +6788,9 @@ class Connection {
6733
6788
  });
6734
6789
  transaction.instructions = transactionOrMessage.instructions;
6735
6790
  } else {
6736
- transaction = Transaction.populate(transactionOrMessage);
6791
+ transaction = Transaction.populate(transactionOrMessage); // HACK: this function relies on mutating the populated transaction
6792
+
6793
+ transaction._message = transaction._json = undefined;
6737
6794
  }
6738
6795
 
6739
6796
  if (transaction.nonceInfo && signers) {