From 395f414a7993e290e560a41ffe5603683f5c7841 Mon Sep 17 00:00:00 2001 From: boufni95 Date: Mon, 17 Nov 2025 15:29:03 +0000 Subject: [PATCH] some cleanup --- src/index.ts | 3 --- src/services/lnd/swaps.ts | 20 +++++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index 42c02f46..aa4c3c0b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,9 +7,6 @@ import { getLogger } from './services/helpers/logger.js'; import { initMainHandler, initSettings } from './services/main/init.js'; import { nip19 } from 'nostr-tools' import { LoadStorageSettingsFromEnv } from './services/storage/index.js'; -import Main from './services/main/index.js'; -import * as Types from '../proto/autogenerated/ts/types.js'; -import { networks } from 'bitcoinjs-lib'; //@ts-ignore const { nprofileEncode } = nip19 diff --git a/src/services/lnd/swaps.ts b/src/services/lnd/swaps.ts index 7b585f52..33627d2c 100644 --- a/src/services/lnd/swaps.ts +++ b/src/services/lnd/swaps.ts @@ -63,7 +63,7 @@ export class SubmarineSwaps { log: PubLogger constructor(settings: SettingsManager) { this.settings = settings - this.log = getLogger({ component: 'SwapsService' }) + this.log = getLogger({ component: 'SubmarineSwaps' }) } SwapInvoice = async (invoice: string, paymentHash: string) => { @@ -190,7 +190,7 @@ export class ReverseSwaps { log: PubLogger constructor(settings: SettingsManager) { this.settings = settings - this.log = getLogger({ component: 'SwapsService' }) + this.log = getLogger({ component: 'ReverseSwaps' }) initEccLib(ecc) } @@ -262,13 +262,17 @@ export class ReverseSwaps { webSocket.on('open', () => { webSocket.send(JSON.stringify(subReq)) }) - const done = (txId: string) => { + let txId = "" + const done = () => { webSocket.close() swapDone({ ok: true, txId }) } webSocket.on('message', async (rawMsg) => { try { - await this.handleSwapTransactionMessage(rawMsg, data, done) + const result = await this.handleSwapTransactionMessage(rawMsg, data, done) + if (result) { + txId = result + } } catch (err: any) { this.log(ERROR, 'Error handling transaction WebSocket message', err.message) webSocket.close() @@ -278,7 +282,7 @@ export class ReverseSwaps { }) } - handleSwapTransactionMessage = async (rawMsg: ws.RawData, data: TransactionSwapData, done: (txId: string) => void) => { + handleSwapTransactionMessage = async (rawMsg: ws.RawData, data: TransactionSwapData, done: () => void) => { const msg = JSON.parse(rawMsg.toString('utf-8')); if (msg.event !== 'update') { return; @@ -286,7 +290,6 @@ export class ReverseSwaps { this.log('Got WebSocket update'); this.log(msg); - let txId = "" switch (msg.args[0].status) { // "swap.created" means Boltz is waiting for the invoice to be paid case 'swap.created': @@ -299,11 +302,10 @@ export class ReverseSwaps { if (!txIdRes.ok) { throw new Error(txIdRes.error) } - txId = txIdRes.txId - return + return txIdRes.txId case 'invoice.settled': this.log('Transaction swap successful'); - done(txId) + done() return; } }