@atomiqlabs/chain-starknet 4.0.0-dev.35 → 4.0.0-dev.36

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.
@@ -65,7 +65,7 @@ export declare class StarknetTransactions extends StarknetModule {
65
65
  * of a batch of starknet transactions
66
66
  *
67
67
  * @param signer
68
- * @param txs transactions to send
68
+ * @param _txs transactions to send
69
69
  * @param waitForConfirmation whether to wait for transaction confirmations (this also makes sure the transactions
70
70
  * are re-sent at regular intervals)
71
71
  * @param abortSignal abort signal to abort waiting for transaction confirmations
@@ -73,7 +73,7 @@ export declare class StarknetTransactions extends StarknetModule {
73
73
  * are executed in order)
74
74
  * @param onBeforePublish a callback called before every transaction is published
75
75
  */
76
- sendAndConfirm(signer: StarknetSigner, txs: StarknetTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
76
+ sendAndConfirm(signer: StarknetSigner, _txs: StarknetTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
77
77
  /**
78
78
  * Serializes the starknet transaction, saves the transaction, signers & last valid blockheight
79
79
  *
@@ -144,8 +144,11 @@ class StarknetTransactions extends StarknetModule_1.StarknetModule {
144
144
  //Add deploy account tx
145
145
  if (nonce === 0n) {
146
146
  const deployPayload = await signer.getDeployPayload();
147
- if (deployPayload != null)
148
- txs.unshift(await this.root.Accounts.getAccountDeployTransaction(deployPayload));
147
+ if (deployPayload != null) {
148
+ const tx = await this.root.Accounts.getAccountDeployTransaction(deployPayload);
149
+ tx.addedInPrepare = true;
150
+ txs.unshift(tx);
151
+ }
149
152
  }
150
153
  if (!signer.isManagingNoncesInternally) {
151
154
  if (nonce === 0n) {
@@ -160,7 +163,7 @@ class StarknetTransactions extends StarknetModule_1.StarknetModule {
160
163
  nonce = BigInt(await this.root.provider.getNonceForAddress(signer.getAddress())); //Fetch the nonce
161
164
  if (tx.details.nonce == null)
162
165
  tx.details.nonce = nonce;
163
- this.logger.debug("sendAndConfirm(): transaction prepared (" + (i + 1) + "/" + txs.length + "), nonce: " + tx.details.nonce);
166
+ this.logger.debug("prepareTransactions(): transaction prepared (" + (i + 1) + "/" + txs.length + "), nonce: " + tx.details.nonce);
164
167
  nonce += BigInt(1);
165
168
  }
166
169
  }
@@ -192,7 +195,7 @@ class StarknetTransactions extends StarknetModule_1.StarknetModule {
192
195
  * of a batch of starknet transactions
193
196
  *
194
197
  * @param signer
195
- * @param txs transactions to send
198
+ * @param _txs transactions to send
196
199
  * @param waitForConfirmation whether to wait for transaction confirmations (this also makes sure the transactions
197
200
  * are re-sent at regular intervals)
198
201
  * @param abortSignal abort signal to abort waiting for transaction confirmations
@@ -200,7 +203,8 @@ class StarknetTransactions extends StarknetModule_1.StarknetModule {
200
203
  * are executed in order)
201
204
  * @param onBeforePublish a callback called before every transaction is published
202
205
  */
203
- async sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
206
+ async sendAndConfirm(signer, _txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
207
+ const txs = _txs;
204
208
  await this.prepareTransactions(signer, txs);
205
209
  const signedTxs = [];
206
210
  //Don't separate the signing process from the sending when using browser-based wallet
@@ -208,6 +212,7 @@ class StarknetTransactions extends StarknetModule_1.StarknetModule {
208
212
  for (let i = 0; i < txs.length; i++) {
209
213
  const tx = txs[i];
210
214
  const signedTx = await signer.signTransaction(tx);
215
+ signedTx.addedInPrepare = tx.addedInPrepare;
211
216
  signedTxs.push(signedTx);
212
217
  this.logger.debug("sendAndConfirm(): transaction signed (" + (i + 1) + "/" + txs.length + "): " + signedTx.txId);
213
218
  const nextAccountNonce = BigInt(signedTx.details.nonce) + 1n;
@@ -224,13 +229,13 @@ class StarknetTransactions extends StarknetModule_1.StarknetModule {
224
229
  for (let i = 0; i < txs.length; i++) {
225
230
  let tx;
226
231
  if (signer.signTransaction == null) {
227
- const txId = await signer.sendTransaction(txs[i], onBeforePublish);
232
+ const txId = await signer.sendTransaction(txs[i], txs[i].addedInPrepare ? undefined : onBeforePublish);
228
233
  tx = txs[i];
229
234
  tx.txId = txId;
230
235
  }
231
236
  else {
232
237
  const signedTx = signedTxs[i];
233
- await this.sendSignedTransaction(signedTx, onBeforePublish);
238
+ await this.sendSignedTransaction(signedTx, signedTx.addedInPrepare ? undefined : onBeforePublish);
234
239
  tx = signedTx;
235
240
  }
236
241
  if (tx.details.nonce != null) {
@@ -240,9 +245,11 @@ class StarknetTransactions extends StarknetModule_1.StarknetModule {
240
245
  this.latestPendingNonces[(0, Utils_1.toHex)(tx.details.walletAddress)] = nextAccountNonce;
241
246
  }
242
247
  }
243
- promises.push(this.confirmTransaction(tx, abortSignal));
244
- if (!waitForConfirmation)
245
- txIds.push(tx.txId);
248
+ if (!tx.addedInPrepare) {
249
+ promises.push(this.confirmTransaction(tx, abortSignal));
250
+ if (!waitForConfirmation)
251
+ txIds.push(tx.txId);
252
+ }
246
253
  this.logger.debug("sendAndConfirm(): transaction sent (" + (i + 1) + "/" + txs.length + "): " + tx.txId);
247
254
  if (promises.length >= MAX_UNCONFIRMED_TXS) {
248
255
  if (waitForConfirmation)
@@ -258,13 +265,13 @@ class StarknetTransactions extends StarknetModule_1.StarknetModule {
258
265
  for (let i = 0; i < txs.length; i++) {
259
266
  let tx;
260
267
  if (signer.signTransaction == null) {
261
- const txId = await signer.sendTransaction(txs[i], onBeforePublish);
268
+ const txId = await signer.sendTransaction(txs[i], txs[i].addedInPrepare ? undefined : onBeforePublish);
262
269
  tx = txs[i];
263
270
  tx.txId = txId;
264
271
  }
265
272
  else {
266
273
  const signedTx = signedTxs[i];
267
- await this.sendSignedTransaction(signedTx, onBeforePublish);
274
+ await this.sendSignedTransaction(signedTx, signedTx.addedInPrepare ? undefined : onBeforePublish);
268
275
  tx = signedTx;
269
276
  }
270
277
  if (tx.details.nonce != null) {
@@ -280,7 +287,8 @@ class StarknetTransactions extends StarknetModule_1.StarknetModule {
280
287
  let txHash = tx.txId;
281
288
  if (i < txs.length - 1 || waitForConfirmation)
282
289
  txHash = await confirmPromise;
283
- txIds.push(txHash);
290
+ if (!tx.addedInPrepare)
291
+ txIds.push(txHash);
284
292
  }
285
293
  }
286
294
  this.logger.info("sendAndConfirm(): sent transactions, count: " + txs.length +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/chain-starknet",
3
- "version": "4.0.0-dev.35",
3
+ "version": "4.0.0-dev.36",
4
4
  "description": "Starknet specific base implementation",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -167,7 +167,7 @@ export class StarknetTransactions extends StarknetModule {
167
167
  * @param txs
168
168
  * @private
169
169
  */
170
- private async prepareTransactions(signer: StarknetSigner, txs: StarknetTx[]): Promise<void> {
170
+ private async prepareTransactions(signer: StarknetSigner, txs: (StarknetTx & {addedInPrepare?: boolean})[]): Promise<void> {
171
171
  let nonce: bigint = await this.getNonce(signer.getAddress());
172
172
  const latestPendingNonce = this.latestPendingNonces[toHex(signer.getAddress())];
173
173
  if(latestPendingNonce!=null && latestPendingNonce > nonce) {
@@ -178,7 +178,11 @@ export class StarknetTransactions extends StarknetModule {
178
178
  //Add deploy account tx
179
179
  if(nonce===0n) {
180
180
  const deployPayload = await signer.getDeployPayload();
181
- if(deployPayload!=null) txs.unshift(await this.root.Accounts.getAccountDeployTransaction(deployPayload));
181
+ if(deployPayload!=null) {
182
+ const tx: (StarknetTx & {addedInPrepare?: boolean}) = await this.root.Accounts.getAccountDeployTransaction(deployPayload);
183
+ tx.addedInPrepare = true;
184
+ txs.unshift(tx);
185
+ }
182
186
  }
183
187
 
184
188
  if(!signer.isManagingNoncesInternally) {
@@ -193,7 +197,7 @@ export class StarknetTransactions extends StarknetModule {
193
197
  if(nonce==null) nonce = BigInt(await this.root.provider.getNonceForAddress(signer.getAddress())); //Fetch the nonce
194
198
  if(tx.details.nonce==null) tx.details.nonce = nonce;
195
199
 
196
- this.logger.debug("sendAndConfirm(): transaction prepared ("+(i+1)+"/"+txs.length+"), nonce: "+tx.details.nonce);
200
+ this.logger.debug("prepareTransactions(): transaction prepared ("+(i+1)+"/"+txs.length+"), nonce: "+tx.details.nonce);
197
201
 
198
202
  nonce += BigInt(1);
199
203
  }
@@ -231,7 +235,7 @@ export class StarknetTransactions extends StarknetModule {
231
235
  * of a batch of starknet transactions
232
236
  *
233
237
  * @param signer
234
- * @param txs transactions to send
238
+ * @param _txs transactions to send
235
239
  * @param waitForConfirmation whether to wait for transaction confirmations (this also makes sure the transactions
236
240
  * are re-sent at regular intervals)
237
241
  * @param abortSignal abort signal to abort waiting for transaction confirmations
@@ -239,14 +243,16 @@ export class StarknetTransactions extends StarknetModule {
239
243
  * are executed in order)
240
244
  * @param onBeforePublish a callback called before every transaction is published
241
245
  */
242
- public async sendAndConfirm(signer: StarknetSigner, txs: StarknetTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]> {
246
+ public async sendAndConfirm(signer: StarknetSigner, _txs: StarknetTx[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]> {
247
+ const txs: (StarknetTx & {addedInPrepare?: boolean})[] = _txs;
243
248
  await this.prepareTransactions(signer, txs);
244
- const signedTxs: StarknetTx[] = [];
249
+ const signedTxs: (StarknetTx & {addedInPrepare?: boolean})[] = [];
245
250
 
246
251
  //Don't separate the signing process from the sending when using browser-based wallet
247
252
  if(signer.signTransaction!=null) for(let i=0;i<txs.length;i++) {
248
253
  const tx = txs[i];
249
- const signedTx = await signer.signTransaction(tx);
254
+ const signedTx: (StarknetTx & {addedInPrepare?: boolean}) = await signer.signTransaction(tx);
255
+ signedTx.addedInPrepare = tx.addedInPrepare;
250
256
  signedTxs.push(signedTx);
251
257
  this.logger.debug("sendAndConfirm(): transaction signed ("+(i+1)+"/"+txs.length+"): "+signedTx.txId);
252
258
 
@@ -264,14 +270,14 @@ export class StarknetTransactions extends StarknetModule {
264
270
  if(parallel) {
265
271
  let promises: Promise<string>[] = [];
266
272
  for(let i=0;i<txs.length;i++) {
267
- let tx: StarknetTx;
273
+ let tx: (StarknetTx & {addedInPrepare?: boolean});
268
274
  if(signer.signTransaction==null) {
269
- const txId = await signer.sendTransaction(txs[i], onBeforePublish);
275
+ const txId = await signer.sendTransaction(txs[i], txs[i].addedInPrepare ? undefined : onBeforePublish);
270
276
  tx = txs[i];
271
277
  tx.txId = txId;
272
278
  } else {
273
279
  const signedTx = signedTxs[i];
274
- await this.sendSignedTransaction(signedTx, onBeforePublish);
280
+ await this.sendSignedTransaction(signedTx, signedTx.addedInPrepare ? undefined : onBeforePublish);
275
281
  tx = signedTx;
276
282
  }
277
283
 
@@ -283,8 +289,10 @@ export class StarknetTransactions extends StarknetModule {
283
289
  }
284
290
  }
285
291
 
286
- promises.push(this.confirmTransaction(tx, abortSignal));
287
- if(!waitForConfirmation) txIds.push(tx.txId);
292
+ if(!tx.addedInPrepare) {
293
+ promises.push(this.confirmTransaction(tx, abortSignal));
294
+ if(!waitForConfirmation) txIds.push(tx.txId);
295
+ }
288
296
  this.logger.debug("sendAndConfirm(): transaction sent ("+(i+1)+"/"+txs.length+"): "+tx.txId);
289
297
  if(promises.length >= MAX_UNCONFIRMED_TXS) {
290
298
  if(waitForConfirmation) txIds.push(...await Promise.all(promises));
@@ -296,14 +304,14 @@ export class StarknetTransactions extends StarknetModule {
296
304
  }
297
305
  } else {
298
306
  for(let i=0;i<txs.length;i++) {
299
- let tx: StarknetTx;
307
+ let tx: (StarknetTx & {addedInPrepare?: boolean});
300
308
  if(signer.signTransaction==null) {
301
- const txId = await signer.sendTransaction(txs[i], onBeforePublish);
309
+ const txId = await signer.sendTransaction(txs[i], txs[i].addedInPrepare ? undefined : onBeforePublish);
302
310
  tx = txs[i];
303
311
  tx.txId = txId;
304
312
  } else {
305
313
  const signedTx = signedTxs[i];
306
- await this.sendSignedTransaction(signedTx, onBeforePublish);
314
+ await this.sendSignedTransaction(signedTx, signedTx.addedInPrepare ? undefined : onBeforePublish);
307
315
  tx = signedTx;
308
316
  }
309
317
 
@@ -320,7 +328,7 @@ export class StarknetTransactions extends StarknetModule {
320
328
  //Don't await the last promise when !waitForConfirmation
321
329
  let txHash = tx.txId;
322
330
  if(i<txs.length-1 || waitForConfirmation) txHash = await confirmPromise;
323
- txIds.push(txHash);
331
+ if(!tx.addedInPrepare) txIds.push(txHash);
324
332
  }
325
333
  }
326
334