@atomiqlabs/chain-evm 1.0.0-dev.69 → 1.0.0-dev.70

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.
@@ -31,12 +31,15 @@ class EVMTransactions extends EVMModule_1.EVMModule {
31
31
  };
32
32
  this.onBeforeTxReplace(txReplaceListener);
33
33
  let state = "pending";
34
+ let confirmedTxId = null;
34
35
  while (state === "pending" || state === "not_found") {
35
36
  await (0, Utils_1.timeoutPromise)(3000, abortSignal);
36
37
  for (let txId of checkTxns) {
37
38
  state = await this.getTxIdStatus(txId);
38
- if (state === "reverted" || state === "success")
39
+ if (state === "reverted" || state === "success") {
40
+ confirmedTxId = txId;
39
41
  break;
42
+ }
40
43
  }
41
44
  }
42
45
  this.offBeforeTxReplace(txReplaceListener);
@@ -47,6 +50,7 @@ class EVMTransactions extends EVMModule_1.EVMModule {
47
50
  }
48
51
  if (state === "reverted")
49
52
  throw new Error("Transaction reverted!");
53
+ return confirmedTxId;
50
54
  }
51
55
  /**
52
56
  * Prepares starknet transactions, checks if the account is deployed, assigns nonces if needed & calls beforeTxSigned callback
@@ -138,7 +142,7 @@ class EVMTransactions extends EVMModule_1.EVMModule {
138
142
  }
139
143
  this.logger.debug("sendAndConfirm(): sending transactions, count: " + txs.length +
140
144
  " waitForConfirmation: " + waitForConfirmation + " parallel: " + parallel);
141
- const txIds = [];
145
+ let txIds = [];
142
146
  if (parallel) {
143
147
  let promises = [];
144
148
  for (let i = 0; i < txs.length; i++) {
@@ -166,7 +170,7 @@ class EVMTransactions extends EVMModule_1.EVMModule {
166
170
  }
167
171
  }
168
172
  if (promises.length > 0)
169
- await Promise.all(promises);
173
+ txIds = await Promise.all(promises);
170
174
  }
171
175
  else {
172
176
  for (let i = 0; i < txs.length; i++) {
@@ -187,9 +191,10 @@ class EVMTransactions extends EVMModule_1.EVMModule {
187
191
  const confirmPromise = this.confirmTransaction(tx, abortSignal);
188
192
  this.logger.debug("sendAndConfirm(): transaction sent (" + (i + 1) + "/" + txs.length + "): " + tx.hash);
189
193
  //Don't await the last promise when !waitForConfirmation
194
+ let txHash = tx.hash;
190
195
  if (i < txs.length - 1 || waitForConfirmation)
191
- await confirmPromise;
192
- txIds.push(tx.hash);
196
+ txHash = await confirmPromise;
197
+ txIds.push(txHash);
193
198
  }
194
199
  }
195
200
  this.logger.info("sendAndConfirm(): sent transactions, count: " + txs.length +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/chain-evm",
3
- "version": "1.0.0-dev.69",
3
+ "version": "1.0.0-dev.70",
4
4
  "description": "EVM specific base implementation",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -39,7 +39,7 @@ export class EVMTransactions extends EVMModule<any> {
39
39
  * @param abortSignal signal to abort waiting for tx confirmation
40
40
  * @private
41
41
  */
42
- private async confirmTransaction(tx: TransactionResponse | Transaction, abortSignal?: AbortSignal) {
42
+ private async confirmTransaction(tx: TransactionResponse | Transaction, abortSignal?: AbortSignal): Promise<string> {
43
43
  const checkTxns: Set<string> = new Set([tx.hash]);
44
44
 
45
45
  const txReplaceListener = (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => {
@@ -49,11 +49,15 @@ export class EVMTransactions extends EVMModule<any> {
49
49
  this.onBeforeTxReplace(txReplaceListener);
50
50
 
51
51
  let state = "pending";
52
+ let confirmedTxId: string = null;
52
53
  while(state==="pending" || state==="not_found") {
53
54
  await timeoutPromise(3000, abortSignal);
54
55
  for(let txId of checkTxns) {
55
56
  state = await this.getTxIdStatus(txId);
56
- if(state==="reverted" || state==="success") break;
57
+ if(state==="reverted" || state==="success") {
58
+ confirmedTxId = txId;
59
+ break;
60
+ }
57
61
  }
58
62
  }
59
63
 
@@ -65,6 +69,8 @@ export class EVMTransactions extends EVMModule<any> {
65
69
  this.latestConfirmedNonces[tx.from] = nextAccountNonce;
66
70
  }
67
71
  if(state==="reverted") throw new Error("Transaction reverted!");
72
+
73
+ return confirmedTxId;
68
74
  }
69
75
 
70
76
  /**
@@ -168,9 +174,9 @@ export class EVMTransactions extends EVMModule<any> {
168
174
  this.logger.debug("sendAndConfirm(): sending transactions, count: "+txs.length+
169
175
  " waitForConfirmation: "+waitForConfirmation+" parallel: "+parallel);
170
176
 
171
- const txIds: string[] = [];
177
+ let txIds: string[] = [];
172
178
  if(parallel) {
173
- let promises: Promise<void>[] = [];
179
+ let promises: Promise<string>[] = [];
174
180
  for(let i=0;i<txs.length;i++) {
175
181
  let tx: TransactionResponse | Transaction;
176
182
  if(signer.signTransaction==null) {
@@ -195,7 +201,7 @@ export class EVMTransactions extends EVMModule<any> {
195
201
  promises = [];
196
202
  }
197
203
  }
198
- if(promises.length>0) await Promise.all(promises);
204
+ if(promises.length>0) txIds = await Promise.all(promises);
199
205
  } else {
200
206
  for(let i=0;i<txs.length;i++) {
201
207
  let tx: TransactionResponse | Transaction;
@@ -216,8 +222,9 @@ export class EVMTransactions extends EVMModule<any> {
216
222
  const confirmPromise = this.confirmTransaction(tx, abortSignal);
217
223
  this.logger.debug("sendAndConfirm(): transaction sent ("+(i+1)+"/"+txs.length+"): "+tx.hash);
218
224
  //Don't await the last promise when !waitForConfirmation
219
- if(i<txs.length-1 || waitForConfirmation) await confirmPromise;
220
- txIds.push(tx.hash);
225
+ let txHash = tx.hash;
226
+ if(i<txs.length-1 || waitForConfirmation) txHash = await confirmPromise;
227
+ txIds.push(txHash);
221
228
  }
222
229
  }
223
230