@atomiqlabs/lp-lib 11.0.3 → 11.0.5
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.
|
@@ -239,8 +239,6 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
239
239
|
//Compute max cltv delta
|
|
240
240
|
const maxFee = swap.quotedNetworkFee;
|
|
241
241
|
const maxUsableCLTVdelta = expiryTimestamp.sub(currentTimestamp).sub(this.config.gracePeriod).div(this.config.bitcoinBlocktime.mul(this.config.safetyFactor));
|
|
242
|
-
yield swap.setState(ToBtcLnSwapAbs_1.ToBtcLnSwapState.COMMITED);
|
|
243
|
-
yield this.storageManager.saveData(decodedPR.id, swap.data.getSequence(), swap);
|
|
244
242
|
//Initiate payment
|
|
245
243
|
this.swapLogger.info(swap, "sendLightningPayment(): paying lightning network invoice," +
|
|
246
244
|
" cltvDelta: " + maxUsableCLTVdelta.toString(10) +
|
|
@@ -275,11 +273,28 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
275
273
|
processInitialized(swap) {
|
|
276
274
|
return __awaiter(this, void 0, void 0, function* () {
|
|
277
275
|
//Check if payment was already made
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
276
|
+
if (swap.state === ToBtcLnSwapAbs_1.ToBtcLnSwapState.COMMITED) {
|
|
277
|
+
let lnPaymentStatus = yield this.lightning.getPayment(swap.getHash());
|
|
278
|
+
if (lnPaymentStatus != null) {
|
|
279
|
+
if (lnPaymentStatus.status === "pending") {
|
|
280
|
+
//Payment still ongoing, process the result
|
|
281
|
+
this.subscribeToPayment(swap);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
//Payment has already concluded, process the result
|
|
286
|
+
yield this.processPaymentResult(swap, lnPaymentStatus);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
//Payment not founds, try to process again
|
|
292
|
+
yield swap.setState(ToBtcLnSwapAbs_1.ToBtcLnSwapState.SAVED);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (swap.state === ToBtcLnSwapAbs_1.ToBtcLnSwapState.SAVED) {
|
|
296
|
+
yield swap.setState(ToBtcLnSwapAbs_1.ToBtcLnSwapState.COMMITED);
|
|
297
|
+
yield this.storageManager.saveData(swap.data.getHash(), swap.data.getSequence(), swap);
|
|
283
298
|
try {
|
|
284
299
|
yield this.sendLightningPayment(swap);
|
|
285
300
|
}
|
|
@@ -298,12 +313,6 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
298
313
|
this.subscribeToPayment(swap);
|
|
299
314
|
return;
|
|
300
315
|
}
|
|
301
|
-
if (lnPaymentStatus.status === "pending") {
|
|
302
|
-
this.subscribeToPayment(swap);
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
//Payment has already concluded, process the result
|
|
306
|
-
yield this.processPaymentResult(swap, lnPaymentStatus);
|
|
307
316
|
});
|
|
308
317
|
}
|
|
309
318
|
processInitializeEvent(chainIdentifier, event) {
|
|
@@ -646,6 +655,10 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
646
655
|
const createdSwap = new ToBtcLnSwapAbs_1.ToBtcLnSwapAbs(parsedAuth.chainIdentifier, parsedBody.pr, parsedPR.mtokens, parsedAuth.swapFee, parsedAuth.swapFeeInToken, parsedAuth.quotedNetworkFee, parsedAuth.quotedNetworkFeeInToken);
|
|
647
656
|
createdSwap.data = payObject;
|
|
648
657
|
createdSwap.metadata = metadata;
|
|
658
|
+
createdSwap.prefix = sigData.prefix;
|
|
659
|
+
createdSwap.timeout = sigData.timeout;
|
|
660
|
+
createdSwap.signature = sigData.signature;
|
|
661
|
+
createdSwap.feeRate = sigData.feeRate;
|
|
649
662
|
yield PluginManager_1.PluginManager.swapCreate(createdSwap);
|
|
650
663
|
yield this.storageManager.saveData(parsedPR.id, sequence, createdSwap);
|
|
651
664
|
this.swapLogger.info(createdSwap, "REST: /payInvoiceExactIn: created exact in swap," +
|
package/package.json
CHANGED
|
@@ -3,14 +3,7 @@ import {Express, Request, Response} from "express";
|
|
|
3
3
|
import {ToBtcLnSwapAbs, ToBtcLnSwapState} from "./ToBtcLnSwapAbs";
|
|
4
4
|
import {MultichainData, SwapHandlerType} from "../SwapHandler";
|
|
5
5
|
import {ISwapPrice} from "../ISwapPrice";
|
|
6
|
-
import {
|
|
7
|
-
ChainSwapType,
|
|
8
|
-
ClaimEvent,
|
|
9
|
-
InitializeEvent,
|
|
10
|
-
RefundEvent,
|
|
11
|
-
SwapCommitStatus,
|
|
12
|
-
SwapData
|
|
13
|
-
} from "@atomiqlabs/base";
|
|
6
|
+
import {ChainSwapType, ClaimEvent, InitializeEvent, RefundEvent, SwapCommitStatus, SwapData} from "@atomiqlabs/base";
|
|
14
7
|
import {expressHandlerWrapper, HEX_REGEX, isDefinedRuntimeError} from "../../utils/Utils";
|
|
15
8
|
import {PluginManager} from "../../plugins/PluginManager";
|
|
16
9
|
import {IIntermediaryStorage} from "../../storage/IIntermediaryStorage";
|
|
@@ -23,8 +16,10 @@ import {ToBtcBaseConfig, ToBtcBaseSwapHandler} from "../ToBtcBaseSwapHandler";
|
|
|
23
16
|
import {
|
|
24
17
|
ILightningWallet,
|
|
25
18
|
OutgoingLightningNetworkPayment,
|
|
26
|
-
ParsedPaymentRequest,
|
|
27
|
-
|
|
19
|
+
ParsedPaymentRequest,
|
|
20
|
+
ProbeAndRouteInit,
|
|
21
|
+
ProbeAndRouteResponse,
|
|
22
|
+
routesMatch
|
|
28
23
|
} from "../../wallets/ILightningWallet";
|
|
29
24
|
|
|
30
25
|
export type ToBtcLnConfig = ToBtcBaseConfig & {
|
|
@@ -327,9 +322,6 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
327
322
|
const maxFee = swap.quotedNetworkFee;
|
|
328
323
|
const maxUsableCLTVdelta = expiryTimestamp.sub(currentTimestamp).sub(this.config.gracePeriod).div(this.config.bitcoinBlocktime.mul(this.config.safetyFactor));
|
|
329
324
|
|
|
330
|
-
await swap.setState(ToBtcLnSwapState.COMMITED);
|
|
331
|
-
await this.storageManager.saveData(decodedPR.id, swap.data.getSequence(), swap);
|
|
332
|
-
|
|
333
325
|
//Initiate payment
|
|
334
326
|
this.swapLogger.info(swap, "sendLightningPayment(): paying lightning network invoice,"+
|
|
335
327
|
" cltvDelta: "+maxUsableCLTVdelta.toString(10)+
|
|
@@ -363,11 +355,27 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
363
355
|
*/
|
|
364
356
|
private async processInitialized(swap: ToBtcLnSwapAbs) {
|
|
365
357
|
//Check if payment was already made
|
|
366
|
-
|
|
367
|
-
|
|
358
|
+
if(swap.state===ToBtcLnSwapState.COMMITED) {
|
|
359
|
+
let lnPaymentStatus = await this.lightning.getPayment(swap.getHash());
|
|
360
|
+
if(lnPaymentStatus!=null) {
|
|
361
|
+
if(lnPaymentStatus.status==="pending") {
|
|
362
|
+
//Payment still ongoing, process the result
|
|
363
|
+
this.subscribeToPayment(swap);
|
|
364
|
+
return;
|
|
365
|
+
} else {
|
|
366
|
+
//Payment has already concluded, process the result
|
|
367
|
+
await this.processPaymentResult(swap, lnPaymentStatus);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
} else {
|
|
371
|
+
//Payment not founds, try to process again
|
|
372
|
+
await swap.setState(ToBtcLnSwapState.SAVED);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
368
375
|
|
|
369
|
-
|
|
370
|
-
|
|
376
|
+
if(swap.state===ToBtcLnSwapState.SAVED) {
|
|
377
|
+
await swap.setState(ToBtcLnSwapState.COMMITED);
|
|
378
|
+
await this.storageManager.saveData(swap.data.getHash(), swap.data.getSequence(), swap);
|
|
371
379
|
try {
|
|
372
380
|
await this.sendLightningPayment(swap);
|
|
373
381
|
} catch (e) {
|
|
@@ -382,14 +390,6 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
382
390
|
this.subscribeToPayment(swap);
|
|
383
391
|
return;
|
|
384
392
|
}
|
|
385
|
-
|
|
386
|
-
if(lnPaymentStatus.status==="pending") {
|
|
387
|
-
this.subscribeToPayment(swap);
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
//Payment has already concluded, process the result
|
|
392
|
-
await this.processPaymentResult(swap, lnPaymentStatus);
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
protected async processInitializeEvent(chainIdentifier: string, event: InitializeEvent<SwapData>): Promise<void> {
|
|
@@ -785,6 +785,10 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
785
785
|
);
|
|
786
786
|
createdSwap.data = payObject;
|
|
787
787
|
createdSwap.metadata = metadata;
|
|
788
|
+
createdSwap.prefix = sigData.prefix;
|
|
789
|
+
createdSwap.timeout = sigData.timeout;
|
|
790
|
+
createdSwap.signature = sigData.signature
|
|
791
|
+
createdSwap.feeRate = sigData.feeRate;
|
|
788
792
|
|
|
789
793
|
await PluginManager.swapCreate(createdSwap);
|
|
790
794
|
await this.storageManager.saveData(parsedPR.id, sequence, createdSwap);
|