@atomiqlabs/lp-lib 14.0.0-dev.25 → 14.0.0-dev.27
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.
|
@@ -12,6 +12,7 @@ const ServerParamDecoder_1 = require("../../../utils/paramcoders/server/ServerPa
|
|
|
12
12
|
const ToBtcBaseSwapHandler_1 = require("../ToBtcBaseSwapHandler");
|
|
13
13
|
const promise_queue_ts_1 = require("promise-queue-ts");
|
|
14
14
|
const OUTPUT_SCRIPT_MAX_LENGTH = 200;
|
|
15
|
+
const MAX_PARALLEL_TX_PROCESSED = 10;
|
|
15
16
|
/**
|
|
16
17
|
* Handler for to BTC swaps, utilizing PTLCs (proof-time locked contracts) using btc relay (on-chain bitcoin SPV)
|
|
17
18
|
*/
|
|
@@ -170,22 +171,30 @@ class ToBtcAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
170
171
|
*/
|
|
171
172
|
async processBtcTxs() {
|
|
172
173
|
const unsubscribeSwaps = [];
|
|
174
|
+
let promises = [];
|
|
173
175
|
for (let txId in this.activeSubscriptions) {
|
|
174
176
|
const swap = this.activeSubscriptions[txId];
|
|
175
177
|
//TODO: RBF the transaction if it's already taking too long to confirm
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
this.
|
|
182
|
-
|
|
178
|
+
promises.push((async () => {
|
|
179
|
+
try {
|
|
180
|
+
let tx = await this.bitcoin.getWalletTransaction(txId);
|
|
181
|
+
if (tx == null)
|
|
182
|
+
return;
|
|
183
|
+
if (await this.processBtcTx(swap, tx)) {
|
|
184
|
+
this.swapLogger.info(swap, "processBtcTxs(): swap claimed successfully, txId: " + tx.txid + " address: " + swap.address);
|
|
185
|
+
unsubscribeSwaps.push(swap);
|
|
186
|
+
}
|
|
183
187
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
188
|
+
catch (e) {
|
|
189
|
+
this.swapLogger.error(swap, "processBtcTxs(): error processing btc transaction", e);
|
|
190
|
+
}
|
|
191
|
+
})());
|
|
192
|
+
if (promises.length >= MAX_PARALLEL_TX_PROCESSED) {
|
|
193
|
+
await Promise.all(promises);
|
|
194
|
+
promises = [];
|
|
187
195
|
}
|
|
188
196
|
}
|
|
197
|
+
await Promise.all(promises);
|
|
189
198
|
unsubscribeSwaps.forEach(swap => {
|
|
190
199
|
this.unsubscribePayment(swap);
|
|
191
200
|
});
|
|
@@ -404,7 +404,7 @@ class SpvVaultSwapHandler extends SwapHandler_1.SwapHandler {
|
|
|
404
404
|
msg: "One or more PSBT inputs not finalized!"
|
|
405
405
|
};
|
|
406
406
|
const effectiveFeeRate = await this.bitcoinRpc.getEffectiveFeeRate(await this.bitcoin.parsePsbt(signedTx));
|
|
407
|
-
if (effectiveFeeRate.feeRate < swap.btcFeeRate)
|
|
407
|
+
if (Math.round(effectiveFeeRate.feeRate) < swap.btcFeeRate)
|
|
408
408
|
throw {
|
|
409
409
|
code: 20511,
|
|
410
410
|
msg: "Bitcoin transaction fee too low, expected minimum: " + swap.btcFeeRate + " adjusted effective fee rate: " + effectiveFeeRate.feeRate
|
package/package.json
CHANGED
|
@@ -51,6 +51,8 @@ export type ToBtcRequestType = {
|
|
|
51
51
|
exactIn?: boolean
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
+
const MAX_PARALLEL_TX_PROCESSED = 10;
|
|
55
|
+
|
|
54
56
|
/**
|
|
55
57
|
* Handler for to BTC swaps, utilizing PTLCs (proof-time locked contracts) using btc relay (on-chain bitcoin SPV)
|
|
56
58
|
*/
|
|
@@ -248,21 +250,29 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
|
|
|
248
250
|
private async processBtcTxs() {
|
|
249
251
|
const unsubscribeSwaps: ToBtcSwapAbs[] = [];
|
|
250
252
|
|
|
253
|
+
let promises: Promise<void>[] = [];
|
|
251
254
|
for(let txId in this.activeSubscriptions) {
|
|
252
255
|
const swap: ToBtcSwapAbs = this.activeSubscriptions[txId];
|
|
253
256
|
//TODO: RBF the transaction if it's already taking too long to confirm
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
this.
|
|
260
|
-
|
|
257
|
+
promises.push((async () => {
|
|
258
|
+
try {
|
|
259
|
+
let tx: BtcTx = await this.bitcoin.getWalletTransaction(txId);
|
|
260
|
+
if(tx==null) return;
|
|
261
|
+
|
|
262
|
+
if(await this.processBtcTx(swap, tx)) {
|
|
263
|
+
this.swapLogger.info(swap, "processBtcTxs(): swap claimed successfully, txId: "+tx.txid+" address: "+swap.address);
|
|
264
|
+
unsubscribeSwaps.push(swap);
|
|
265
|
+
}
|
|
266
|
+
} catch (e) {
|
|
267
|
+
this.swapLogger.error(swap, "processBtcTxs(): error processing btc transaction", e);
|
|
261
268
|
}
|
|
262
|
-
}
|
|
263
|
-
|
|
269
|
+
})());
|
|
270
|
+
if(promises.length >= MAX_PARALLEL_TX_PROCESSED) {
|
|
271
|
+
await Promise.all(promises);
|
|
272
|
+
promises = [];
|
|
264
273
|
}
|
|
265
274
|
}
|
|
275
|
+
await Promise.all(promises);
|
|
266
276
|
|
|
267
277
|
unsubscribeSwaps.forEach(swap => {
|
|
268
278
|
this.unsubscribePayment(swap);
|
|
@@ -538,7 +538,7 @@ export class SpvVaultSwapHandler extends SwapHandler<SpvVaultSwap, SpvVaultSwapS
|
|
|
538
538
|
};
|
|
539
539
|
|
|
540
540
|
const effectiveFeeRate = await this.bitcoinRpc.getEffectiveFeeRate(await this.bitcoin.parsePsbt(signedTx));
|
|
541
|
-
if(effectiveFeeRate.feeRate < swap.btcFeeRate) throw {
|
|
541
|
+
if(Math.round(effectiveFeeRate.feeRate) < swap.btcFeeRate) throw {
|
|
542
542
|
code: 20511,
|
|
543
543
|
msg: "Bitcoin transaction fee too low, expected minimum: "+swap.btcFeeRate+" adjusted effective fee rate: "+effectiveFeeRate.feeRate
|
|
544
544
|
}
|