@atomiqlabs/lp-lib 14.0.0-dev.30 → 14.0.0-dev.31

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.
@@ -5,7 +5,6 @@ import { ISwapPrice } from "../../../prices/ISwapPrice";
5
5
  import { BtcTx, ChainSwapType, ClaimEvent, InitializeEvent, RefundEvent, SwapData, BitcoinRpc, BtcBlock } from "@atomiqlabs/base";
6
6
  import { IIntermediaryStorage } from "../../../storage/IIntermediaryStorage";
7
7
  import { ToBtcBaseConfig, ToBtcBaseSwapHandler } from "../ToBtcBaseSwapHandler";
8
- import { PromiseQueue } from "promise-queue-ts";
9
8
  import { IBitcoinWallet } from "../../../wallets/IBitcoinWallet";
10
9
  export type ToBtcConfig = ToBtcBaseConfig & {
11
10
  sendSafetyFactor: bigint;
@@ -38,7 +37,6 @@ export declare class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSw
38
37
  };
39
38
  bitcoinRpc: BitcoinRpc<BtcBlock>;
40
39
  bitcoin: IBitcoinWallet;
41
- sendBtcQueue: PromiseQueue;
42
40
  readonly config: ToBtcConfig;
43
41
  constructor(storageDirectory: IIntermediaryStorage<ToBtcSwapAbs>, path: string, chainData: MultichainData, bitcoin: IBitcoinWallet, swapPricing: ISwapPrice, bitcoinRpc: BitcoinRpc<BtcBlock>, config: ToBtcConfig);
44
42
  /**
@@ -10,7 +10,6 @@ const crypto_1 = require("crypto");
10
10
  const SchemaVerifier_1 = require("../../../utils/paramcoders/SchemaVerifier");
11
11
  const ServerParamDecoder_1 = require("../../../utils/paramcoders/server/ServerParamDecoder");
12
12
  const ToBtcBaseSwapHandler_1 = require("../ToBtcBaseSwapHandler");
13
- const promise_queue_ts_1 = require("promise-queue-ts");
14
13
  const BitcoinUtils_1 = require("../../../utils/BitcoinUtils");
15
14
  const OUTPUT_SCRIPT_MAX_LENGTH = 200;
16
15
  const MAX_PARALLEL_TX_PROCESSED = 10;
@@ -23,7 +22,6 @@ class ToBtcAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
23
22
  this.type = SwapHandler_1.SwapHandlerType.TO_BTC;
24
23
  this.swapType = base_1.ChainSwapType.CHAIN_NONCED;
25
24
  this.activeSubscriptions = {};
26
- this.sendBtcQueue = new promise_queue_ts_1.PromiseQueue();
27
25
  this.bitcoinRpc = bitcoinRpc;
28
26
  this.bitcoin = bitcoin;
29
27
  this.config = config;
@@ -269,7 +267,7 @@ class ToBtcAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
269
267
  sendBitcoinPayment(swap) {
270
268
  //Make sure that bitcoin payouts are processed sequentially to avoid race conditions between multiple payouts,
271
269
  // e.g. that 2 payouts share the same input and would effectively double-spend each other
272
- return this.sendBtcQueue.enqueue(async () => {
270
+ return this.bitcoin.execute(async () => {
273
271
  //Run checks
274
272
  this.checkExpiresTooSoon(swap);
275
273
  if (swap.metadata != null)
@@ -64,4 +64,11 @@ export interface IBitcoinWallet {
64
64
  parsePsbt(psbt: Transaction): Promise<BtcTx>;
65
65
  getBlockheight(): Promise<number>;
66
66
  getFeeRate(): Promise<number>;
67
+ /**
68
+ * Post a task to be executed on the sequential thread of the wallet, this makes sure the UTXOs stay consistent during
69
+ * operation, it is recommended to use this approach when spending wallet UTXOs
70
+ *
71
+ * @param executor
72
+ */
73
+ execute(executor: () => Promise<void>): Promise<void>;
67
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/lp-lib",
3
- "version": "14.0.0-dev.30",
3
+ "version": "14.0.0-dev.31",
4
4
  "description": "Main functionality implementation for atomiq LP node",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -21,7 +21,6 @@ import {serverParamDecoder} from "../../../utils/paramcoders/server/ServerParamD
21
21
  import {IParamReader} from "../../../utils/paramcoders/IParamReader";
22
22
  import {ServerParamEncoder} from "../../../utils/paramcoders/server/ServerParamEncoder";
23
23
  import {ToBtcBaseConfig, ToBtcBaseSwapHandler} from "../ToBtcBaseSwapHandler";
24
- import {PromiseQueue} from "promise-queue-ts";
25
24
  import {IBitcoinWallet} from "../../../wallets/IBitcoinWallet";
26
25
  import {checkTransactionReplaced} from "../../../utils/BitcoinUtils";
27
26
 
@@ -64,7 +63,6 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
64
63
  activeSubscriptions: {[txId: string]: ToBtcSwapAbs} = {};
65
64
  bitcoinRpc: BitcoinRpc<BtcBlock>;
66
65
  bitcoin: IBitcoinWallet;
67
- sendBtcQueue: PromiseQueue = new PromiseQueue();
68
66
 
69
67
  readonly config: ToBtcConfig;
70
68
 
@@ -351,7 +349,7 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
351
349
  private sendBitcoinPayment(swap: ToBtcSwapAbs) {
352
350
  //Make sure that bitcoin payouts are processed sequentially to avoid race conditions between multiple payouts,
353
351
  // e.g. that 2 payouts share the same input and would effectively double-spend each other
354
- return this.sendBtcQueue.enqueue<void>(async () => {
352
+ return this.bitcoin.execute(async () => {
355
353
  //Run checks
356
354
  this.checkExpiresTooSoon(swap);
357
355
  if(swap.metadata!=null) swap.metadata.times.payCLTVChecked = Date.now();
@@ -66,4 +66,12 @@ export interface IBitcoinWallet {
66
66
  getBlockheight(): Promise<number>;
67
67
  getFeeRate(): Promise<number>;
68
68
 
69
+ /**
70
+ * Post a task to be executed on the sequential thread of the wallet, this makes sure the UTXOs stay consistent during
71
+ * operation, it is recommended to use this approach when spending wallet UTXOs
72
+ *
73
+ * @param executor
74
+ */
75
+ execute(executor: () => Promise<void>): Promise<void>;
76
+
69
77
  }