@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.39.0",
3
+ "version": "1.39.1",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
package/src/connection.ts CHANGED
@@ -3895,6 +3895,8 @@ export class Connection {
3895
3895
  transaction.instructions = transactionOrMessage.instructions;
3896
3896
  } else {
3897
3897
  transaction = Transaction.populate(transactionOrMessage);
3898
+ // HACK: this function relies on mutating the populated transaction
3899
+ transaction._message = transaction._json = undefined;
3898
3900
  }
3899
3901
 
3900
3902
  if (transaction.nonceInfo && signers) {
@@ -66,6 +66,19 @@ export type SerializeConfig = {
66
66
  verifySignatures?: boolean;
67
67
  };
68
68
 
69
+ /**
70
+ * @internal
71
+ */
72
+ export interface TransactionInstructionJSON {
73
+ keys: {
74
+ pubkey: string;
75
+ isSigner: boolean;
76
+ isWritable: boolean;
77
+ }[];
78
+ programId: string;
79
+ data: number[];
80
+ }
81
+
69
82
  /**
70
83
  * Transaction Instruction class
71
84
  */
@@ -93,6 +106,21 @@ export class TransactionInstruction {
93
106
  this.data = opts.data;
94
107
  }
95
108
  }
109
+
110
+ /**
111
+ * @internal
112
+ */
113
+ toJSON(): TransactionInstructionJSON {
114
+ return {
115
+ keys: this.keys.map(({pubkey, isSigner, isWritable}) => ({
116
+ pubkey: pubkey.toJSON(),
117
+ isSigner,
118
+ isWritable,
119
+ })),
120
+ programId: this.programId.toJSON(),
121
+ data: [...this.data],
122
+ };
123
+ }
96
124
  }
97
125
 
98
126
  /**
@@ -128,6 +156,20 @@ export type NonceInformation = {
128
156
  nonceInstruction: TransactionInstruction;
129
157
  };
130
158
 
159
+ /**
160
+ * @internal
161
+ */
162
+ export interface TransactionJSON {
163
+ recentBlockhash: string | null;
164
+ feePayer: string | null;
165
+ nonceInfo: {
166
+ nonce: string;
167
+ nonceInstruction: TransactionInstructionJSON;
168
+ } | null;
169
+ instructions: TransactionInstructionJSON[];
170
+ signatures: {publicKey: string; signature: number[] | null}[];
171
+ }
172
+
131
173
  /**
132
174
  * Transaction class
133
175
  */
@@ -169,6 +211,16 @@ export class Transaction {
169
211
  */
170
212
  nonceInfo?: NonceInformation;
171
213
 
214
+ /**
215
+ * @internal
216
+ */
217
+ _message?: Message;
218
+
219
+ /**
220
+ * @internal
221
+ */
222
+ _json?: TransactionJSON;
223
+
172
224
  /**
173
225
  * Construct an empty Transaction
174
226
  */
@@ -176,6 +228,27 @@ export class Transaction {
176
228
  opts && Object.assign(this, opts);
177
229
  }
178
230
 
231
+ /**
232
+ * @internal
233
+ */
234
+ toJSON(): TransactionJSON {
235
+ return {
236
+ recentBlockhash: this.recentBlockhash || null,
237
+ feePayer: this.feePayer ? this.feePayer.toJSON() : null,
238
+ nonceInfo: this.nonceInfo
239
+ ? {
240
+ nonce: this.nonceInfo.nonce,
241
+ nonceInstruction: this.nonceInfo.nonceInstruction.toJSON(),
242
+ }
243
+ : null,
244
+ instructions: this.instructions.map(instruction => instruction.toJSON()),
245
+ signatures: this.signatures.map(({publicKey, signature}) => ({
246
+ publicKey: publicKey.toJSON(),
247
+ signature: signature ? [...signature] : null,
248
+ })),
249
+ };
250
+ }
251
+
179
252
  /**
180
253
  * Add one or more instructions to this Transaction
181
254
  */
@@ -204,6 +277,15 @@ export class Transaction {
204
277
  * Compile transaction data
205
278
  */
206
279
  compileMessage(): Message {
280
+ if (this._message) {
281
+ if (JSON.stringify(this.toJSON()) !== JSON.stringify(this._json)) {
282
+ throw new Error(
283
+ 'Transaction mutated after being populated from Message',
284
+ );
285
+ }
286
+ return this._message;
287
+ }
288
+
207
289
  const {nonceInfo} = this;
208
290
  if (nonceInfo && this.instructions[0] != nonceInfo.nonceInstruction) {
209
291
  this.recentBlockhash = nonceInfo.nonce;
@@ -719,6 +801,9 @@ export class Transaction {
719
801
  );
720
802
  });
721
803
 
804
+ transaction._message = message;
805
+ transaction._json = transaction.toJSON();
806
+
722
807
  return transaction;
723
808
  }
724
809
  }