@atomiqlabs/lp-lib 11.0.1 → 11.0.3

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.
@@ -84,7 +84,7 @@ class ToBtcAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
84
84
  return __awaiter(this, void 0, void 0, function* () {
85
85
  const { swapContract, signer } = this.getChain(swap.chainIdentifier);
86
86
  if (swap.state === ToBtcSwapAbs_1.ToBtcSwapState.SAVED) {
87
- const isSignatureExpired = swapContract.isInitAuthorizationExpired(swap.data, swap);
87
+ const isSignatureExpired = yield swapContract.isInitAuthorizationExpired(swap.data, swap);
88
88
  if (isSignatureExpired) {
89
89
  const isCommitted = yield swapContract.isCommited(swap.data);
90
90
  if (!isCommitted) {
@@ -60,9 +60,17 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
60
60
  //Cancel the swaps where signature is expired
61
61
  const isSignatureExpired = yield swapContract.isInitAuthorizationExpired(swap.data, swap);
62
62
  if (isSignatureExpired) {
63
- this.swapLogger.info(swap, "processPastSwap(state=SAVED): signature expired, cancel uncommited swap, invoice: " + swap.pr);
64
- yield this.removeSwapData(swap, ToBtcLnSwapAbs_1.ToBtcLnSwapState.CANCELED);
65
- return;
63
+ const isCommitted = yield swapContract.isCommited(swap.data);
64
+ if (!isCommitted) {
65
+ this.swapLogger.info(swap, "processPastSwap(state=SAVED): authorization expired & swap not committed, cancelling swap, invoice: " + swap.pr);
66
+ yield this.removeSwapData(swap, ToBtcLnSwapAbs_1.ToBtcLnSwapState.CANCELED);
67
+ return;
68
+ }
69
+ else {
70
+ this.swapLogger.info(swap, "processPastSwap(state=SAVED): swap committed (detected from processPastSwap), invoice: " + swap.pr);
71
+ yield swap.setState(ToBtcLnSwapAbs_1.ToBtcLnSwapState.COMMITED);
72
+ yield this.storageManager.saveData(swap.data.getHash(), swap.getSequence(), swap);
73
+ }
66
74
  }
67
75
  //Cancel the swaps where lightning invoice is expired
68
76
  const decodedPR = yield this.lightning.parsePaymentRequest(swap.pr);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/lp-lib",
3
- "version": "11.0.1",
3
+ "version": "11.0.3",
4
4
  "description": "Main functionality implementation for atomiq LP node",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -130,7 +130,7 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
130
130
  const {swapContract, signer} = this.getChain(swap.chainIdentifier);
131
131
 
132
132
  if(swap.state===ToBtcSwapState.SAVED) {
133
- const isSignatureExpired = swapContract.isInitAuthorizationExpired(swap.data, swap);
133
+ const isSignatureExpired = await swapContract.isInitAuthorizationExpired(swap.data, swap);
134
134
  if(isSignatureExpired) {
135
135
  const isCommitted = await swapContract.isCommited(swap.data);
136
136
  if(!isCommitted) {
@@ -142,11 +142,17 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
142
142
  //Cancel the swaps where signature is expired
143
143
  const isSignatureExpired = await swapContract.isInitAuthorizationExpired(swap.data, swap);
144
144
  if(isSignatureExpired) {
145
- this.swapLogger.info(swap, "processPastSwap(state=SAVED): signature expired, cancel uncommited swap, invoice: "+swap.pr);
146
- await this.removeSwapData(swap, ToBtcLnSwapState.CANCELED);
147
- return;
145
+ const isCommitted = await swapContract.isCommited(swap.data);
146
+ if(!isCommitted) {
147
+ this.swapLogger.info(swap, "processPastSwap(state=SAVED): authorization expired & swap not committed, cancelling swap, invoice: "+swap.pr);
148
+ await this.removeSwapData(swap, ToBtcLnSwapState.CANCELED);
149
+ return;
150
+ } else {
151
+ this.swapLogger.info(swap, "processPastSwap(state=SAVED): swap committed (detected from processPastSwap), invoice: "+swap.pr);
152
+ await swap.setState(ToBtcLnSwapState.COMMITED);
153
+ await this.storageManager.saveData(swap.data.getHash(), swap.getSequence(), swap);
154
+ }
148
155
  }
149
-
150
156
  //Cancel the swaps where lightning invoice is expired
151
157
  const decodedPR = await this.lightning.parsePaymentRequest(swap.pr);
152
158
  const isInvoiceExpired = decodedPR.expiryEpochMillis < Date.now();