@atomiqlabs/lp-lib 15.0.9 → 15.0.10

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.
@@ -309,7 +309,7 @@ class ToBtcAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
309
309
  if (swap.sending)
310
310
  return;
311
311
  //Bitcoin transaction was signed (maybe also sent)
312
- const tx = await (0, BitcoinUtils_1.checkTransactionReplaced)(swap.txId, swap.btcRawTx, this.bitcoin);
312
+ const tx = await (0, BitcoinUtils_1.checkTransactionReplaced)(swap.txId, swap.btcRawTx, this.bitcoinRpc);
313
313
  const isTxSent = tx != null;
314
314
  if (!isTxSent) {
315
315
  //Reset the state to COMMITED
@@ -105,7 +105,7 @@ class SpvVaultSwapHandler extends SwapHandler_1.SwapHandler {
105
105
  const foundWithdrawal = vault.pendingWithdrawals.find(val => val.btcTx.txid === swap.btcTxId);
106
106
  let tx = foundWithdrawal?.btcTx;
107
107
  if (tx == null)
108
- tx = await this.bitcoin.getWalletTransaction(swap.btcTxId);
108
+ tx = await this.bitcoinRpc.getTransaction(swap.btcTxId);
109
109
  if (tx == null) {
110
110
  await this.removeSwapData(swap, SpvVaultSwap_1.SpvVaultSwapState.FAILED);
111
111
  return;
@@ -128,7 +128,7 @@ class SpvVaultSwapHandler extends SwapHandler_1.SwapHandler {
128
128
  const foundWithdrawal = vault.pendingWithdrawals.find(val => val.btcTx.txid === swap.btcTxId);
129
129
  let tx = foundWithdrawal?.btcTx;
130
130
  if (tx == null)
131
- tx = await this.bitcoin.getWalletTransaction(swap.btcTxId);
131
+ tx = await this.bitcoinRpc.getTransaction(swap.btcTxId);
132
132
  if (tx == null) {
133
133
  await this.removeSwapData(swap, SpvVaultSwap_1.SpvVaultSwapState.DOUBLE_SPENT);
134
134
  return;
@@ -330,7 +330,7 @@ class SpvVaults {
330
330
  if (pendingWithdrawal.sending)
331
331
  continue;
332
332
  //Check all the pending withdrawals that were not finalized yet
333
- const btcTx = await (0, BitcoinUtils_1.checkTransactionReplacedRpc)(pendingWithdrawal.btcTx.txid, pendingWithdrawal.btcTx.raw, this.bitcoinRpc);
333
+ const btcTx = await (0, BitcoinUtils_1.checkTransactionReplaced)(pendingWithdrawal.btcTx.txid, pendingWithdrawal.btcTx.raw, this.bitcoinRpc);
334
334
  if (btcTx == null) {
335
335
  //Probable double-spend, remove from pending withdrawals
336
336
  if (!vault.doubleSpendPendingWithdrawal(pendingWithdrawal)) {
@@ -608,7 +608,7 @@ class FromBtcTrusted extends SwapHandler_1.SwapHandler {
608
608
  }
609
609
  async checkDoubleSpends() {
610
610
  for (let swap of this.doubleSpendWatchdogSwaps.keys()) {
611
- const tx = await this.bitcoin.getWalletTransaction(swap.txId);
611
+ const tx = await this.bitcoinRpc.getTransaction(swap.txId);
612
612
  if (tx == null) {
613
613
  this.swapLogger.debug(swap, "checkDoubleSpends(): Swap was double spent, burning... - original txId: " + swap.txId);
614
614
  this.processPastSwap(swap, null, null);
@@ -1,6 +1,4 @@
1
1
  import { TransactionInput } from "@scure/btc-signer/psbt";
2
2
  import { BitcoinRpc, BtcTx } from "@atomiqlabs/base";
3
- import { IBitcoinWallet } from "../wallets/IBitcoinWallet";
4
3
  export declare function isLegacyInput(input: TransactionInput): boolean;
5
- export declare function checkTransactionReplaced(txId: string, txRaw: string, bitcoin: IBitcoinWallet): Promise<BtcTx>;
6
- export declare function checkTransactionReplacedRpc(txId: string, txRaw: string, bitcoin: BitcoinRpc<any>): Promise<BtcTx>;
4
+ export declare function checkTransactionReplaced(txId: string, txRaw: string, bitcoin: BitcoinRpc<any>): Promise<BtcTx>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkTransactionReplacedRpc = exports.checkTransactionReplaced = exports.isLegacyInput = void 0;
3
+ exports.checkTransactionReplaced = exports.isLegacyInput = void 0;
4
4
  const utxo_1 = require("@scure/btc-signer/utxo");
5
5
  const btc_signer_1 = require("@scure/btc-signer");
6
6
  const Utils_1 = require("./Utils");
@@ -46,20 +46,6 @@ function isLegacyInput(input) {
46
46
  }
47
47
  exports.isLegacyInput = isLegacyInput;
48
48
  async function checkTransactionReplaced(txId, txRaw, bitcoin) {
49
- const existingTx = await bitcoin.getWalletTransaction(txId);
50
- if (existingTx != null)
51
- return existingTx;
52
- //Try to re-broadcast
53
- try {
54
- await bitcoin.sendRawTransaction(txRaw);
55
- }
56
- catch (e) {
57
- logger.error("checkTransactionReplaced(" + txId + "): Error when trying to re-broadcast raw transaction: ", e);
58
- }
59
- return await bitcoin.getWalletTransaction(txId);
60
- }
61
- exports.checkTransactionReplaced = checkTransactionReplaced;
62
- async function checkTransactionReplacedRpc(txId, txRaw, bitcoin) {
63
49
  const existingTx = await bitcoin.getTransaction(txId);
64
50
  if (existingTx != null)
65
51
  return existingTx;
@@ -72,4 +58,4 @@ async function checkTransactionReplacedRpc(txId, txRaw, bitcoin) {
72
58
  }
73
59
  return await bitcoin.getTransaction(txId);
74
60
  }
75
- exports.checkTransactionReplacedRpc = checkTransactionReplacedRpc;
61
+ exports.checkTransactionReplaced = checkTransactionReplaced;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/lp-lib",
3
- "version": "15.0.9",
3
+ "version": "15.0.10",
4
4
  "description": "Main functionality implementation for atomiq LP node",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -396,7 +396,7 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
396
396
  if(swap.state===ToBtcSwapState.BTC_SENDING) {
397
397
  if(swap.sending) return;
398
398
  //Bitcoin transaction was signed (maybe also sent)
399
- const tx = await checkTransactionReplaced(swap.txId, swap.btcRawTx, this.bitcoin);
399
+ const tx = await checkTransactionReplaced(swap.txId, swap.btcRawTx, this.bitcoinRpc);
400
400
 
401
401
  const isTxSent = tx!=null;
402
402
  if(!isTxSent) {
@@ -27,9 +27,9 @@ import {ServerParamEncoder} from "../../utils/paramcoders/server/ServerParamEnco
27
27
  import {FieldTypeEnum} from "../../utils/paramcoders/SchemaVerifier";
28
28
  import {FromBtcAmountAssertions} from "../assertions/FromBtcAmountAssertions";
29
29
  import {randomBytes} from "crypto";
30
- import {getInputType, OutScript, Transaction} from "@scure/btc-signer";
30
+ import {Transaction} from "@scure/btc-signer";
31
31
  import {SpvVaults, VAULT_DUST_AMOUNT} from "./SpvVaults";
32
- import {checkTransactionReplaced, isLegacyInput} from "../../utils/BitcoinUtils";
32
+ import {isLegacyInput} from "../../utils/BitcoinUtils";
33
33
 
34
34
  export type SpvVaultSwapHandlerConfig = SwapBaseConfig & {
35
35
  vaultsCheckInterval: number,
@@ -170,7 +170,7 @@ export class SpvVaultSwapHandler extends SwapHandler<SpvVaultSwap, SpvVaultSwapS
170
170
  const vault = await this.Vaults.getVault(swap.chainIdentifier, swap.vaultOwner, swap.vaultId);
171
171
  const foundWithdrawal = vault.pendingWithdrawals.find(val => val.btcTx.txid === swap.btcTxId);
172
172
  let tx = foundWithdrawal?.btcTx;
173
- if(tx==null) tx = await this.bitcoin.getWalletTransaction(swap.btcTxId);
173
+ if(tx==null) tx = await this.bitcoinRpc.getTransaction(swap.btcTxId);
174
174
 
175
175
  if(tx==null) {
176
176
  await this.removeSwapData(swap, SpvVaultSwapState.FAILED);
@@ -191,7 +191,7 @@ export class SpvVaultSwapHandler extends SwapHandler<SpvVaultSwap, SpvVaultSwapS
191
191
  const vault = await this.Vaults.getVault(swap.chainIdentifier, swap.vaultOwner, swap.vaultId);
192
192
  const foundWithdrawal = vault.pendingWithdrawals.find(val => val.btcTx.txid === swap.btcTxId);
193
193
  let tx = foundWithdrawal?.btcTx;
194
- if(tx==null) tx = await this.bitcoin.getWalletTransaction(swap.btcTxId);
194
+ if(tx==null) tx = await this.bitcoinRpc.getTransaction(swap.btcTxId);
195
195
 
196
196
  if(tx==null) {
197
197
  await this.removeSwapData(swap, SpvVaultSwapState.DOUBLE_SPENT);
@@ -15,7 +15,7 @@ import {ISpvVaultSigner} from "../../wallets/ISpvVaultSigner";
15
15
  import {AmountAssertions} from "../assertions/AmountAssertions";
16
16
  import {ChainData} from "../SwapHandler";
17
17
  import {Transaction} from "@scure/btc-signer";
18
- import {checkTransactionReplacedRpc} from "../../utils/BitcoinUtils";
18
+ import {checkTransactionReplaced} from "../../utils/BitcoinUtils";
19
19
 
20
20
  export const VAULT_DUST_AMOUNT = 600;
21
21
  const VAULT_INIT_CONFIRMATIONS = 2;
@@ -389,7 +389,7 @@ export class SpvVaults {
389
389
  if(pendingWithdrawal.sending) continue;
390
390
 
391
391
  //Check all the pending withdrawals that were not finalized yet
392
- const btcTx = await checkTransactionReplacedRpc(pendingWithdrawal.btcTx.txid, pendingWithdrawal.btcTx.raw, this.bitcoinRpc);
392
+ const btcTx = await checkTransactionReplaced(pendingWithdrawal.btcTx.txid, pendingWithdrawal.btcTx.raw, this.bitcoinRpc);
393
393
  if(btcTx==null) {
394
394
  //Probable double-spend, remove from pending withdrawals
395
395
  if(!vault.doubleSpendPendingWithdrawal(pendingWithdrawal)) {
@@ -702,7 +702,7 @@ export class FromBtcTrusted extends SwapHandler<FromBtcTrustedSwap, FromBtcTrust
702
702
 
703
703
  private async checkDoubleSpends(): Promise<void> {
704
704
  for(let swap of this.doubleSpendWatchdogSwaps.keys()) {
705
- const tx = await this.bitcoin.getWalletTransaction(swap.txId);
705
+ const tx = await this.bitcoinRpc.getTransaction(swap.txId);
706
706
  if(tx==null) {
707
707
  this.swapLogger.debug(swap, "checkDoubleSpends(): Swap was double spent, burning... - original txId: "+swap.txId);
708
708
  this.processPastSwap(swap, null, null);
@@ -46,19 +46,7 @@ export function isLegacyInput(input: TransactionInput): boolean {
46
46
  return true;
47
47
  }
48
48
 
49
- export async function checkTransactionReplaced(txId: string, txRaw: string, bitcoin: IBitcoinWallet): Promise<BtcTx> {
50
- const existingTx = await bitcoin.getWalletTransaction(txId);
51
- if(existingTx!=null) return existingTx;
52
- //Try to re-broadcast
53
- try {
54
- await bitcoin.sendRawTransaction(txRaw);
55
- } catch (e) {
56
- logger.error("checkTransactionReplaced("+txId+"): Error when trying to re-broadcast raw transaction: ", e);
57
- }
58
- return await bitcoin.getWalletTransaction(txId);
59
- }
60
-
61
- export async function checkTransactionReplacedRpc(txId: string, txRaw: string, bitcoin: BitcoinRpc<any>): Promise<BtcTx> {
49
+ export async function checkTransactionReplaced(txId: string, txRaw: string, bitcoin: BitcoinRpc<any>): Promise<BtcTx> {
62
50
  const existingTx = await bitcoin.getTransaction(txId);
63
51
  if(existingTx!=null) return existingTx;
64
52
  //Try to re-broadcast