@atomiqlabs/lp-lib 14.0.0-dev.35 → 14.0.0-dev.37
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.
- package/dist/swaps/escrow/frombtc_abstract/FromBtcAbs.js +1 -1
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.js +2 -2
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.js +2 -2
- package/dist/swaps/escrow/tobtc_abstract/ToBtcAbs.js +13 -5
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.js +1 -1
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.js +1 -1
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrusted.js +1 -1
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.js +2 -2
- package/package.json +2 -2
- package/src/swaps/escrow/frombtc_abstract/FromBtcAbs.ts +1 -1
- package/src/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.ts +2 -2
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.ts +2 -2
- package/src/swaps/escrow/tobtc_abstract/ToBtcAbs.ts +17 -10
- package/src/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.ts +1 -1
- package/src/swaps/spv_vault_swap/SpvVaultSwapHandler.ts +1 -1
- package/src/swaps/trusted/frombtc_trusted/FromBtcTrusted.ts +1 -1
- package/src/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.ts +2 -2
|
@@ -202,7 +202,7 @@ class FromBtcAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
202
202
|
const parsedBody = await req.paramReader.getParams({
|
|
203
203
|
address: (val) => val != null &&
|
|
204
204
|
typeof (val) === "string" &&
|
|
205
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
205
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
206
206
|
amount: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
207
207
|
token: (val) => val != null &&
|
|
208
208
|
typeof (val) === "string" &&
|
|
@@ -423,7 +423,7 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
423
423
|
address = invoice.description;
|
|
424
424
|
}
|
|
425
425
|
const { chainInterface } = this.getChain(chainIdentifier);
|
|
426
|
-
if (!chainInterface.isValidAddress(address))
|
|
426
|
+
if (!chainInterface.isValidAddress(address, true))
|
|
427
427
|
throw {
|
|
428
428
|
_httpStatus: 200,
|
|
429
429
|
code: 10001,
|
|
@@ -475,7 +475,7 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
475
475
|
const parsedBody = await req.paramReader.getParams({
|
|
476
476
|
address: (val) => val != null &&
|
|
477
477
|
typeof (val) === "string" &&
|
|
478
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
478
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
479
479
|
paymentHash: (val) => val != null &&
|
|
480
480
|
typeof (val) === "string" &&
|
|
481
481
|
val.length === 64 &&
|
|
@@ -444,7 +444,7 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
444
444
|
address = invoice.description;
|
|
445
445
|
}
|
|
446
446
|
const { chainInterface } = this.getChain(chainIdentifier);
|
|
447
|
-
if (!chainInterface.isValidAddress(address))
|
|
447
|
+
if (!chainInterface.isValidAddress(address, true))
|
|
448
448
|
throw {
|
|
449
449
|
_httpStatus: 200,
|
|
450
450
|
code: 10001,
|
|
@@ -499,7 +499,7 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
499
499
|
const parsedBody = await req.paramReader.getParams({
|
|
500
500
|
address: (val) => val != null &&
|
|
501
501
|
typeof (val) === "string" &&
|
|
502
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
502
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
503
503
|
paymentHash: (val) => val != null &&
|
|
504
504
|
typeof (val) === "string" &&
|
|
505
505
|
val.length === 64 &&
|
|
@@ -48,17 +48,25 @@ class ToBtcAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
48
48
|
* @param vout
|
|
49
49
|
*/
|
|
50
50
|
async tryClaimSwap(tx, swap, vout) {
|
|
51
|
-
const { swapContract, signer } = this.getChain(swap.chainIdentifier);
|
|
51
|
+
const { chainInterface, swapContract, signer } = this.getChain(swap.chainIdentifier);
|
|
52
52
|
const blockHeader = await this.bitcoinRpc.getBlockHeader(tx.blockhash);
|
|
53
53
|
//Set flag that we are sending the transaction already, so we don't end up with race condition
|
|
54
|
+
if (swap.isLocked())
|
|
55
|
+
return false;
|
|
56
|
+
let txns;
|
|
57
|
+
try {
|
|
58
|
+
txns = await swapContract.txsClaimWithTxData(signer, swap.data, { ...tx, height: blockHeader.getHeight() }, swap.requiredConfirmations, vout, null, null, false);
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
this.swapLogger.error(swap, "tryClaimSwap(): error occurred creating swap claim transactions, height: " + blockHeader.getHeight() + " utxo: " + tx.txid + ":" + vout + " address: " + swap.address, e);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
54
64
|
const unlock = swap.lock(swapContract.claimWithTxDataTimeout);
|
|
55
65
|
if (unlock == null)
|
|
56
66
|
return false;
|
|
57
67
|
try {
|
|
58
68
|
this.swapLogger.debug(swap, "tryClaimSwap(): initiate claim of swap, height: " + blockHeader.getHeight() + " utxo: " + tx.txid + ":" + vout);
|
|
59
|
-
|
|
60
|
-
waitForConfirmation: true
|
|
61
|
-
});
|
|
69
|
+
await chainInterface.sendAndConfirm(signer, txns, true);
|
|
62
70
|
this.swapLogger.info(swap, "tryClaimSwap(): swap claimed successfully, height: " + blockHeader.getHeight() + " utxo: " + tx.txid + ":" + vout + " address: " + swap.address);
|
|
63
71
|
if (swap.metadata != null)
|
|
64
72
|
swap.metadata.times.txClaimed = Date.now();
|
|
@@ -537,7 +545,7 @@ class ToBtcAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
537
545
|
this.isTokenSupported(chainIdentifier, val) ? val : null,
|
|
538
546
|
offerer: (val) => val != null &&
|
|
539
547
|
typeof (val) === "string" &&
|
|
540
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
548
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
541
549
|
exactIn: SchemaVerifier_1.FieldTypeEnum.BooleanOptional
|
|
542
550
|
});
|
|
543
551
|
if (parsedBody == null)
|
|
@@ -629,7 +629,7 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
629
629
|
this.isTokenSupported(chainIdentifier, val) ? val : null,
|
|
630
630
|
offerer: (val) => val != null &&
|
|
631
631
|
typeof (val) === "string" &&
|
|
632
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
632
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
633
633
|
exactIn: SchemaVerifier_1.FieldTypeEnum.BooleanOptional,
|
|
634
634
|
amount: SchemaVerifier_1.FieldTypeEnum.BigIntOptional
|
|
635
635
|
});
|
|
@@ -192,7 +192,7 @@ class SpvVaultSwapHandler extends SwapHandler_1.SwapHandler {
|
|
|
192
192
|
const parsedBody = await req.paramReader.getParams({
|
|
193
193
|
address: (val) => val != null &&
|
|
194
194
|
typeof (val) === "string" &&
|
|
195
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
195
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
196
196
|
amount: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
197
197
|
token: (val) => val != null &&
|
|
198
198
|
typeof (val) === "string" &&
|
|
@@ -347,7 +347,7 @@ class FromBtcTrusted extends SwapHandler_1.SwapHandler {
|
|
|
347
347
|
const parsedBody = (0, SchemaVerifier_1.verifySchema)(req.query, {
|
|
348
348
|
address: (val) => val != null &&
|
|
349
349
|
typeof (val) === "string" &&
|
|
350
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
350
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
351
351
|
refundAddress: (val) => val == null ? "" :
|
|
352
352
|
typeof (val) === "string" &&
|
|
353
353
|
this.isValidBitcoinAddress(val) ? val : null,
|
|
@@ -275,7 +275,7 @@ class FromBtcLnTrusted extends SwapHandler_1.SwapHandler {
|
|
|
275
275
|
address = invoice.description;
|
|
276
276
|
}
|
|
277
277
|
const { chainInterface } = this.getChain(chainIdentifier);
|
|
278
|
-
if (!chainInterface.isValidAddress(address))
|
|
278
|
+
if (!chainInterface.isValidAddress(address, true))
|
|
279
279
|
throw {
|
|
280
280
|
_httpStatus: 200,
|
|
281
281
|
code: 10001,
|
|
@@ -324,7 +324,7 @@ class FromBtcLnTrusted extends SwapHandler_1.SwapHandler {
|
|
|
324
324
|
const parsedBody = (0, SchemaVerifier_1.verifySchema)(req.query, {
|
|
325
325
|
address: (val) => val != null &&
|
|
326
326
|
typeof (val) === "string" &&
|
|
327
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
327
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
328
328
|
token: (val) => val != null &&
|
|
329
329
|
typeof (val) === "string" &&
|
|
330
330
|
this.isTokenSupported(chainIdentifier, val) ? val : null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/lp-lib",
|
|
3
|
-
"version": "14.0.0-dev.
|
|
3
|
+
"version": "14.0.0-dev.37",
|
|
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": "^10.0.0-dev.
|
|
25
|
+
"@atomiqlabs/base": "^10.0.0-dev.17",
|
|
26
26
|
"@atomiqlabs/server-base": "^3.0.0",
|
|
27
27
|
"@scure/btc-signer": "1.6.0",
|
|
28
28
|
"express": "4.21.1",
|
|
@@ -279,7 +279,7 @@ export class FromBtcAbs extends FromBtcBaseSwapHandler<FromBtcSwapAbs, FromBtcSw
|
|
|
279
279
|
const parsedBody: FromBtcRequestType = await req.paramReader.getParams({
|
|
280
280
|
address: (val: string) => val!=null &&
|
|
281
281
|
typeof(val)==="string" &&
|
|
282
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
282
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
283
283
|
amount: FieldTypeEnum.BigInt,
|
|
284
284
|
token: (val: string) => val!=null &&
|
|
285
285
|
typeof(val)==="string" &&
|
|
@@ -532,7 +532,7 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
|
|
|
532
532
|
address = invoice.description;
|
|
533
533
|
}
|
|
534
534
|
const {chainInterface} = this.getChain(chainIdentifier);
|
|
535
|
-
if(!chainInterface.isValidAddress(address)) throw {
|
|
535
|
+
if(!chainInterface.isValidAddress(address, true)) throw {
|
|
536
536
|
_httpStatus: 200,
|
|
537
537
|
code: 10001,
|
|
538
538
|
msg: "Invoice expired/canceled"
|
|
@@ -595,7 +595,7 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
|
|
|
595
595
|
const parsedBody: FromBtcLnRequestType = await req.paramReader.getParams({
|
|
596
596
|
address: (val: string) => val!=null &&
|
|
597
597
|
typeof(val)==="string" &&
|
|
598
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
598
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
599
599
|
paymentHash: (val: string) => val!=null &&
|
|
600
600
|
typeof(val)==="string" &&
|
|
601
601
|
val.length===64 &&
|
|
@@ -538,7 +538,7 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
|
|
|
538
538
|
address = invoice.description;
|
|
539
539
|
}
|
|
540
540
|
const {chainInterface} = this.getChain(chainIdentifier);
|
|
541
|
-
if(!chainInterface.isValidAddress(address)) throw {
|
|
541
|
+
if(!chainInterface.isValidAddress(address, true)) throw {
|
|
542
542
|
_httpStatus: 200,
|
|
543
543
|
code: 10001,
|
|
544
544
|
msg: "Invoice expired/canceled"
|
|
@@ -602,7 +602,7 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
|
|
|
602
602
|
const parsedBody: FromBtcLnAutoRequestType = await req.paramReader.getParams({
|
|
603
603
|
address: (val: string) => val!=null &&
|
|
604
604
|
typeof(val)==="string" &&
|
|
605
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
605
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
606
606
|
paymentHash: (val: string) => val!=null &&
|
|
607
607
|
typeof(val)==="string" &&
|
|
608
608
|
val.length===64 &&
|
|
@@ -104,17 +104,16 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
|
|
|
104
104
|
* @param vout
|
|
105
105
|
*/
|
|
106
106
|
private async tryClaimSwap(tx: {blockhash: string, confirmations: number, txid: string, hex: string}, swap: ToBtcSwapAbs, vout: number): Promise<boolean> {
|
|
107
|
-
const {swapContract, signer} = this.getChain(swap.chainIdentifier);
|
|
107
|
+
const {chainInterface, swapContract, signer} = this.getChain(swap.chainIdentifier);
|
|
108
108
|
|
|
109
109
|
const blockHeader = await this.bitcoinRpc.getBlockHeader(tx.blockhash);
|
|
110
110
|
|
|
111
111
|
//Set flag that we are sending the transaction already, so we don't end up with race condition
|
|
112
|
-
|
|
113
|
-
if(unlock==null) return false;
|
|
112
|
+
if(swap.isLocked()) return false;
|
|
114
113
|
|
|
114
|
+
let txns: any[];
|
|
115
115
|
try {
|
|
116
|
-
|
|
117
|
-
const result = await swapContract.claimWithTxData(
|
|
116
|
+
txns = await swapContract.txsClaimWithTxData(
|
|
118
117
|
signer,
|
|
119
118
|
swap.data,
|
|
120
119
|
{...tx, height: blockHeader.getHeight()},
|
|
@@ -122,11 +121,19 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
|
|
|
122
121
|
vout,
|
|
123
122
|
null,
|
|
124
123
|
null,
|
|
125
|
-
false
|
|
126
|
-
{
|
|
127
|
-
waitForConfirmation: true
|
|
128
|
-
}
|
|
124
|
+
false
|
|
129
125
|
);
|
|
126
|
+
} catch (e) {
|
|
127
|
+
this.swapLogger.error(swap, "tryClaimSwap(): error occurred creating swap claim transactions, height: "+blockHeader.getHeight()+" utxo: "+tx.txid+":"+vout+" address: "+swap.address, e);
|
|
128
|
+
return false
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const unlock: () => boolean = swap.lock(swapContract.claimWithTxDataTimeout);
|
|
132
|
+
if(unlock==null) return false;
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
this.swapLogger.debug(swap, "tryClaimSwap(): initiate claim of swap, height: "+blockHeader.getHeight()+" utxo: "+tx.txid+":"+vout);
|
|
136
|
+
await chainInterface.sendAndConfirm(signer, txns, true);
|
|
130
137
|
this.swapLogger.info(swap, "tryClaimSwap(): swap claimed successfully, height: "+blockHeader.getHeight()+" utxo: "+tx.txid+":"+vout+" address: "+swap.address);
|
|
131
138
|
if(swap.metadata!=null) swap.metadata.times.txClaimed = Date.now();
|
|
132
139
|
unlock();
|
|
@@ -645,7 +652,7 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
|
|
|
645
652
|
this.isTokenSupported(chainIdentifier, val) ? val : null,
|
|
646
653
|
offerer: (val: string) => val!=null &&
|
|
647
654
|
typeof(val)==="string" &&
|
|
648
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
655
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
649
656
|
exactIn: FieldTypeEnum.BooleanOptional
|
|
650
657
|
});
|
|
651
658
|
if (parsedBody==null) throw {
|
|
@@ -811,7 +811,7 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
811
811
|
this.isTokenSupported(chainIdentifier, val) ? val : null,
|
|
812
812
|
offerer: (val: string) => val!=null &&
|
|
813
813
|
typeof(val)==="string" &&
|
|
814
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
814
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
815
815
|
exactIn: FieldTypeEnum.BooleanOptional,
|
|
816
816
|
amount: FieldTypeEnum.BigIntOptional
|
|
817
817
|
});
|
|
@@ -264,7 +264,7 @@ export class SpvVaultSwapHandler extends SwapHandler<SpvVaultSwap, SpvVaultSwapS
|
|
|
264
264
|
const parsedBody: SpvVaultSwapRequestType = await req.paramReader.getParams({
|
|
265
265
|
address: (val: string) => val!=null &&
|
|
266
266
|
typeof(val)==="string" &&
|
|
267
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
267
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
268
268
|
amount: FieldTypeEnum.BigInt,
|
|
269
269
|
token: (val: string) => val!=null &&
|
|
270
270
|
typeof(val)==="string" &&
|
|
@@ -407,7 +407,7 @@ export class FromBtcTrusted extends SwapHandler<FromBtcTrustedSwap, FromBtcTrust
|
|
|
407
407
|
const parsedBody: FromBtcTrustedRequestType = verifySchema(req.query,{
|
|
408
408
|
address: (val: string) => val!=null &&
|
|
409
409
|
typeof(val)==="string" &&
|
|
410
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
410
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
411
411
|
refundAddress: (val: string) => val==null ? "" :
|
|
412
412
|
typeof(val)==="string" &&
|
|
413
413
|
this.isValidBitcoinAddress(val) ? val : null,
|
|
@@ -325,7 +325,7 @@ export class FromBtcLnTrusted extends SwapHandler<FromBtcLnTrustedSwap, FromBtcL
|
|
|
325
325
|
address = invoice.description;
|
|
326
326
|
}
|
|
327
327
|
const { chainInterface} = this.getChain(chainIdentifier);
|
|
328
|
-
if(!chainInterface.isValidAddress(address)) throw {
|
|
328
|
+
if(!chainInterface.isValidAddress(address, true)) throw {
|
|
329
329
|
_httpStatus: 200,
|
|
330
330
|
code: 10001,
|
|
331
331
|
msg: "Invoice expired/canceled"
|
|
@@ -384,7 +384,7 @@ export class FromBtcLnTrusted extends SwapHandler<FromBtcLnTrustedSwap, FromBtcL
|
|
|
384
384
|
const parsedBody: FromBtcLnTrustedRequestType = verifySchema(req.query,{
|
|
385
385
|
address: (val: string) => val!=null &&
|
|
386
386
|
typeof(val)==="string" &&
|
|
387
|
-
chainInterface.isValidAddress(val) ? val : null,
|
|
387
|
+
chainInterface.isValidAddress(val, true) ? val : null,
|
|
388
388
|
token: (val: string) => val!=null &&
|
|
389
389
|
typeof(val)==="string" &&
|
|
390
390
|
this.isTokenSupported(chainIdentifier, val) ? val : null,
|