@atomiqlabs/chain-starknet 7.0.13 → 7.0.15

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.
@@ -66,14 +66,28 @@ class StarknetTransactions extends StarknetModule_1.StarknetModule {
66
66
  const subscription = await this.root.wsChannel.subscribeTransactionStatus({
67
67
  transactionHash: txId
68
68
  });
69
- const status = await new Promise((resolve) => {
69
+ const endSubscription = async () => {
70
+ if (this.root.wsChannel.isConnected() && await subscription.unsubscribe())
71
+ return;
72
+ this.root.wsChannel.removeSubscription(subscription.id);
73
+ };
74
+ if (abortSignal != null && abortSignal.aborted) {
75
+ await endSubscription();
76
+ abortSignal.throwIfAborted();
77
+ }
78
+ const status = await new Promise((resolve, reject) => {
79
+ if (abortSignal != null)
80
+ abortSignal.onabort = () => {
81
+ endSubscription().catch(err => this.logger.error("confirmTransactionWs(): End subscription error: ", err));
82
+ reject(abortSignal.reason);
83
+ };
70
84
  subscription.on((data) => {
71
85
  if (data.status.finality_status !== starknet_1.ETransactionStatus.ACCEPTED_ON_L2 && data.status.finality_status !== starknet_1.ETransactionStatus.ACCEPTED_ON_L1)
72
86
  return; //No pre-confs
73
87
  resolve(data.status.execution_status === starknet_1.ETransactionExecutionStatus.SUCCEEDED ? "success" : "reverted");
74
88
  });
75
89
  });
76
- await subscription.unsubscribe();
90
+ await endSubscription();
77
91
  this.logger.debug(`confirmTransactionWs(): Transaction ${txId} confirmed, transaction status: ${status}`);
78
92
  return {
79
93
  txId,
@@ -145,20 +159,20 @@ class StarknetTransactions extends StarknetModule_1.StarknetModule {
145
159
  txReplaceListener = (oldTx, oldTxId, newTx, newTxId) => {
146
160
  if (checkTxns.has(oldTxId))
147
161
  checkTxns.add(newTxId);
148
- if (this.root.wsChannel != null)
149
- this.confirmTransactionWs(newTxId, abortController.signal)
150
- .then(resolve)
151
- .catch(reject);
162
+ //TODO: Add this when websocket subscriptions get stable
163
+ // if(this.root.wsChannel!=null) this.confirmTransactionWs(newTxId, abortController.signal)
164
+ // .then(resolve)
165
+ // .catch(reject);
152
166
  return Promise.resolve();
153
167
  };
154
168
  this.onBeforeTxReplace(txReplaceListener);
155
169
  this.confirmTransactionPolling(tx.details.walletAddress, BigInt(tx.details.nonce), checkTxns, abortController.signal)
156
170
  .then(resolve)
157
171
  .catch(reject);
158
- if (this.root.wsChannel != null)
159
- this.confirmTransactionWs(tx.txId, abortController.signal)
160
- .then(resolve)
161
- .catch(reject);
172
+ //TODO: Add this when websocket subscriptions get stable
173
+ // if(this.root.wsChannel!=null) this.confirmTransactionWs(tx.txId, abortController.signal)
174
+ // .then(resolve)
175
+ // .catch(reject);
162
176
  });
163
177
  this.offBeforeTxReplace(txReplaceListener);
164
178
  abortController.abort();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/chain-starknet",
3
- "version": "7.0.13",
3
+ "version": "7.0.15",
4
4
  "description": "Starknet specific base implementation",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -99,13 +99,25 @@ export class StarknetTransactions extends StarknetModule {
99
99
  const subscription = await this.root.wsChannel.subscribeTransactionStatus({
100
100
  transactionHash: txId
101
101
  });
102
- const status = await new Promise<"reverted" | "success">((resolve) => {
102
+ const endSubscription = async () => {
103
+ if(this.root.wsChannel.isConnected() && await subscription.unsubscribe()) return;
104
+ this.root.wsChannel.removeSubscription(subscription.id);
105
+ }
106
+ if(abortSignal!=null && abortSignal.aborted) {
107
+ await endSubscription();
108
+ abortSignal.throwIfAborted();
109
+ }
110
+ const status = await new Promise<"reverted" | "success">((resolve, reject) => {
111
+ if(abortSignal!=null) abortSignal.onabort = () => {
112
+ endSubscription().catch(err => this.logger.error("confirmTransactionWs(): End subscription error: ", err));
113
+ reject(abortSignal.reason);
114
+ };
103
115
  subscription.on((data) => {
104
116
  if(data.status.finality_status!==ETransactionStatus.ACCEPTED_ON_L2 && data.status.finality_status!==ETransactionStatus.ACCEPTED_ON_L1) return; //No pre-confs
105
117
  resolve(data.status.execution_status===ETransactionExecutionStatus.SUCCEEDED ? "success" : "reverted");
106
118
  });
107
119
  });
108
- await subscription.unsubscribe();
120
+ await endSubscription();
109
121
  this.logger.debug(`confirmTransactionWs(): Transaction ${txId} confirmed, transaction status: ${status}`);
110
122
  return {
111
123
  txId,
@@ -189,9 +201,10 @@ export class StarknetTransactions extends StarknetModule {
189
201
 
190
202
  txReplaceListener = (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => {
191
203
  if(checkTxns.has(oldTxId)) checkTxns.add(newTxId);
192
- if(this.root.wsChannel!=null) this.confirmTransactionWs(newTxId, abortController.signal)
193
- .then(resolve)
194
- .catch(reject);
204
+ //TODO: Add this when websocket subscriptions get stable
205
+ // if(this.root.wsChannel!=null) this.confirmTransactionWs(newTxId, abortController.signal)
206
+ // .then(resolve)
207
+ // .catch(reject);
195
208
  return Promise.resolve();
196
209
  };
197
210
  this.onBeforeTxReplace(txReplaceListener);
@@ -199,9 +212,10 @@ export class StarknetTransactions extends StarknetModule {
199
212
  this.confirmTransactionPolling(tx.details.walletAddress, BigInt(tx.details.nonce), checkTxns, abortController.signal)
200
213
  .then(resolve)
201
214
  .catch(reject);
202
- if(this.root.wsChannel!=null) this.confirmTransactionWs(tx.txId, abortController.signal)
203
- .then(resolve)
204
- .catch(reject);
215
+ //TODO: Add this when websocket subscriptions get stable
216
+ // if(this.root.wsChannel!=null) this.confirmTransactionWs(tx.txId, abortController.signal)
217
+ // .then(resolve)
218
+ // .catch(reject);
205
219
  });
206
220
  this.offBeforeTxReplace(txReplaceListener);
207
221
  abortController.abort();