@atomiqlabs/lp-lib 12.0.0 → 12.0.2
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.
|
@@ -115,6 +115,24 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
115
115
|
if (swap.secret == null)
|
|
116
116
|
throw new Error("Invalid swap state, needs payment pre-image!");
|
|
117
117
|
const { swapContract, signer } = this.getChain(swap.chainIdentifier);
|
|
118
|
+
//Check if escrow state exists
|
|
119
|
+
const isCommited = await swapContract.isCommited(swap.data);
|
|
120
|
+
if (!isCommited) {
|
|
121
|
+
const status = await swapContract.getCommitStatus(signer.getAddress(), swap.data);
|
|
122
|
+
if (status === base_1.SwapCommitStatus.PAID) {
|
|
123
|
+
//This is alright, we got the money
|
|
124
|
+
await this.removeSwapData(swap, ToBtcLnSwapAbs_1.ToBtcLnSwapState.CLAIMED);
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
else if (status === base_1.SwapCommitStatus.EXPIRED) {
|
|
128
|
+
//This means the user was able to refund before we were able to claim, no good
|
|
129
|
+
await this.removeSwapData(swap, ToBtcLnSwapAbs_1.ToBtcLnSwapState.REFUNDED);
|
|
130
|
+
}
|
|
131
|
+
this.swapLogger.warn(swap, "processPaymentResult(): tried to claim but escrow doesn't exist anymore," +
|
|
132
|
+
" status: " + status +
|
|
133
|
+
" invoice: " + swap.pr);
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
118
136
|
//Set flag that we are sending the transaction already, so we don't end up with race condition
|
|
119
137
|
const unlock = swap.lock(swapContract.claimWithSecretTimeout);
|
|
120
138
|
if (unlock == null)
|
|
@@ -151,30 +169,11 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
151
169
|
await this.saveSwapData(swap);
|
|
152
170
|
return;
|
|
153
171
|
case "confirmed":
|
|
154
|
-
const { swapContract, signer } = this.getChain(swap.chainIdentifier);
|
|
155
172
|
swap.secret = lnPaymentStatus.secret;
|
|
156
173
|
swap.setRealNetworkFee(lnPaymentStatus.feeMtokens / 1000n);
|
|
157
174
|
this.swapLogger.info(swap, "processPaymentResult(): invoice paid, secret: " + swap.secret + " realRoutingFee: " + swap.realNetworkFee.toString(10) + " invoice: " + swap.pr);
|
|
158
175
|
await swap.setState(ToBtcLnSwapAbs_1.ToBtcLnSwapState.PAID);
|
|
159
176
|
await this.saveSwapData(swap);
|
|
160
|
-
//Check if escrow state exists
|
|
161
|
-
const isCommited = await swapContract.isCommited(swap.data);
|
|
162
|
-
if (!isCommited) {
|
|
163
|
-
const status = await swapContract.getCommitStatus(signer.getAddress(), swap.data);
|
|
164
|
-
if (status === base_1.SwapCommitStatus.PAID) {
|
|
165
|
-
//This is alright, we got the money
|
|
166
|
-
await this.removeSwapData(swap, ToBtcLnSwapAbs_1.ToBtcLnSwapState.CLAIMED);
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
else if (status === base_1.SwapCommitStatus.EXPIRED) {
|
|
170
|
-
//This means the user was able to refund before we were able to claim, no good
|
|
171
|
-
await this.removeSwapData(swap, ToBtcLnSwapAbs_1.ToBtcLnSwapState.REFUNDED);
|
|
172
|
-
}
|
|
173
|
-
this.swapLogger.warn(swap, "processPaymentResult(): tried to claim but escrow doesn't exist anymore," +
|
|
174
|
-
" status: " + status +
|
|
175
|
-
" invoice: " + swap.pr);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
177
|
const success = await this.tryClaimSwap(swap);
|
|
179
178
|
if (success)
|
|
180
179
|
this.swapLogger.info(swap, "processPaymentResult(): swap claimed successfully, invoice: " + swap.pr);
|
|
@@ -254,6 +253,12 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
254
253
|
*/
|
|
255
254
|
async processInitialized(swap) {
|
|
256
255
|
//Check if payment was already made
|
|
256
|
+
if (swap.state === ToBtcLnSwapAbs_1.ToBtcLnSwapState.PAID) {
|
|
257
|
+
const success = await this.tryClaimSwap(swap);
|
|
258
|
+
if (success)
|
|
259
|
+
this.swapLogger.info(swap, "processInitialized(): swap claimed successfully, invoice: " + swap.pr);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
257
262
|
if (swap.state === ToBtcLnSwapAbs_1.ToBtcLnSwapState.COMMITED) {
|
|
258
263
|
if (swap.metadata != null)
|
|
259
264
|
swap.metadata.times.payPaymentChecked = Date.now();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/lp-lib",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.2",
|
|
4
4
|
"description": "Main functionality implementation for atomiq LP node",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types:": "./dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"author": "adambor",
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@atomiqlabs/base": "8.0.0",
|
|
25
|
+
"@atomiqlabs/base": "^8.0.0",
|
|
26
26
|
"@atomiqlabs/server-base": "2.0.0",
|
|
27
27
|
"@scure/btc-signer": "1.6.0",
|
|
28
28
|
"express": "4.21.1",
|
|
@@ -216,6 +216,24 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
216
216
|
|
|
217
217
|
const {swapContract, signer} = this.getChain(swap.chainIdentifier);
|
|
218
218
|
|
|
219
|
+
//Check if escrow state exists
|
|
220
|
+
const isCommited = await swapContract.isCommited(swap.data);
|
|
221
|
+
if(!isCommited) {
|
|
222
|
+
const status = await swapContract.getCommitStatus(signer.getAddress(), swap.data);
|
|
223
|
+
if(status===SwapCommitStatus.PAID) {
|
|
224
|
+
//This is alright, we got the money
|
|
225
|
+
await this.removeSwapData(swap, ToBtcLnSwapState.CLAIMED);
|
|
226
|
+
return true;
|
|
227
|
+
} else if(status===SwapCommitStatus.EXPIRED) {
|
|
228
|
+
//This means the user was able to refund before we were able to claim, no good
|
|
229
|
+
await this.removeSwapData(swap, ToBtcLnSwapState.REFUNDED);
|
|
230
|
+
}
|
|
231
|
+
this.swapLogger.warn(swap, "processPaymentResult(): tried to claim but escrow doesn't exist anymore,"+
|
|
232
|
+
" status: "+status+
|
|
233
|
+
" invoice: "+swap.pr);
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
|
|
219
237
|
//Set flag that we are sending the transaction already, so we don't end up with race condition
|
|
220
238
|
const unlock: () => boolean = swap.lock(swapContract.claimWithSecretTimeout);
|
|
221
239
|
if(unlock==null) return false;
|
|
@@ -253,32 +271,12 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
253
271
|
return;
|
|
254
272
|
|
|
255
273
|
case "confirmed":
|
|
256
|
-
const {swapContract, signer} = this.getChain(swap.chainIdentifier);
|
|
257
|
-
|
|
258
274
|
swap.secret = lnPaymentStatus.secret;
|
|
259
275
|
swap.setRealNetworkFee(lnPaymentStatus.feeMtokens / 1000n);
|
|
260
276
|
this.swapLogger.info(swap, "processPaymentResult(): invoice paid, secret: "+swap.secret+" realRoutingFee: "+swap.realNetworkFee.toString(10)+" invoice: "+swap.pr);
|
|
261
277
|
await swap.setState(ToBtcLnSwapState.PAID);
|
|
262
278
|
await this.saveSwapData(swap);
|
|
263
279
|
|
|
264
|
-
//Check if escrow state exists
|
|
265
|
-
const isCommited = await swapContract.isCommited(swap.data);
|
|
266
|
-
if(!isCommited) {
|
|
267
|
-
const status = await swapContract.getCommitStatus(signer.getAddress(), swap.data);
|
|
268
|
-
if(status===SwapCommitStatus.PAID) {
|
|
269
|
-
//This is alright, we got the money
|
|
270
|
-
await this.removeSwapData(swap, ToBtcLnSwapState.CLAIMED);
|
|
271
|
-
return;
|
|
272
|
-
} else if(status===SwapCommitStatus.EXPIRED) {
|
|
273
|
-
//This means the user was able to refund before we were able to claim, no good
|
|
274
|
-
await this.removeSwapData(swap, ToBtcLnSwapState.REFUNDED);
|
|
275
|
-
}
|
|
276
|
-
this.swapLogger.warn(swap, "processPaymentResult(): tried to claim but escrow doesn't exist anymore,"+
|
|
277
|
-
" status: "+status+
|
|
278
|
-
" invoice: "+swap.pr);
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
280
|
const success = await this.tryClaimSwap(swap);
|
|
283
281
|
if(success) this.swapLogger.info(swap, "processPaymentResult(): swap claimed successfully, invoice: "+swap.pr);
|
|
284
282
|
return;
|
|
@@ -364,6 +362,12 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
364
362
|
*/
|
|
365
363
|
private async processInitialized(swap: ToBtcLnSwapAbs) {
|
|
366
364
|
//Check if payment was already made
|
|
365
|
+
if(swap.state===ToBtcLnSwapState.PAID) {
|
|
366
|
+
const success = await this.tryClaimSwap(swap);
|
|
367
|
+
if(success) this.swapLogger.info(swap, "processInitialized(): swap claimed successfully, invoice: "+swap.pr);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
|
|
367
371
|
if(swap.state===ToBtcLnSwapState.COMMITED) {
|
|
368
372
|
if(swap.metadata!=null) swap.metadata.times.payPaymentChecked = Date.now();
|
|
369
373
|
let lnPaymentStatus = await this.lightning.getPayment(swap.lnPaymentHash);
|