some cleanup

This commit is contained in:
boufni95 2025-11-17 15:29:03 +00:00
parent 2b18f69873
commit 395f414a79
2 changed files with 11 additions and 12 deletions

View file

@ -7,9 +7,6 @@ import { getLogger } from './services/helpers/logger.js';
import { initMainHandler, initSettings } from './services/main/init.js'; import { initMainHandler, initSettings } from './services/main/init.js';
import { nip19 } from 'nostr-tools' import { nip19 } from 'nostr-tools'
import { LoadStorageSettingsFromEnv } from './services/storage/index.js'; 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 //@ts-ignore
const { nprofileEncode } = nip19 const { nprofileEncode } = nip19

View file

@ -63,7 +63,7 @@ export class SubmarineSwaps {
log: PubLogger log: PubLogger
constructor(settings: SettingsManager) { constructor(settings: SettingsManager) {
this.settings = settings this.settings = settings
this.log = getLogger({ component: 'SwapsService' }) this.log = getLogger({ component: 'SubmarineSwaps' })
} }
SwapInvoice = async (invoice: string, paymentHash: string) => { SwapInvoice = async (invoice: string, paymentHash: string) => {
@ -190,7 +190,7 @@ export class ReverseSwaps {
log: PubLogger log: PubLogger
constructor(settings: SettingsManager) { constructor(settings: SettingsManager) {
this.settings = settings this.settings = settings
this.log = getLogger({ component: 'SwapsService' }) this.log = getLogger({ component: 'ReverseSwaps' })
initEccLib(ecc) initEccLib(ecc)
} }
@ -262,13 +262,17 @@ export class ReverseSwaps {
webSocket.on('open', () => { webSocket.on('open', () => {
webSocket.send(JSON.stringify(subReq)) webSocket.send(JSON.stringify(subReq))
}) })
const done = (txId: string) => { let txId = ""
const done = () => {
webSocket.close() webSocket.close()
swapDone({ ok: true, txId }) swapDone({ ok: true, txId })
} }
webSocket.on('message', async (rawMsg) => { webSocket.on('message', async (rawMsg) => {
try { try {
await this.handleSwapTransactionMessage(rawMsg, data, done) const result = await this.handleSwapTransactionMessage(rawMsg, data, done)
if (result) {
txId = result
}
} catch (err: any) { } catch (err: any) {
this.log(ERROR, 'Error handling transaction WebSocket message', err.message) this.log(ERROR, 'Error handling transaction WebSocket message', err.message)
webSocket.close() 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')); const msg = JSON.parse(rawMsg.toString('utf-8'));
if (msg.event !== 'update') { if (msg.event !== 'update') {
return; return;
@ -286,7 +290,6 @@ export class ReverseSwaps {
this.log('Got WebSocket update'); this.log('Got WebSocket update');
this.log(msg); this.log(msg);
let txId = ""
switch (msg.args[0].status) { switch (msg.args[0].status) {
// "swap.created" means Boltz is waiting for the invoice to be paid // "swap.created" means Boltz is waiting for the invoice to be paid
case 'swap.created': case 'swap.created':
@ -299,11 +302,10 @@ export class ReverseSwaps {
if (!txIdRes.ok) { if (!txIdRes.ok) {
throw new Error(txIdRes.error) throw new Error(txIdRes.error)
} }
txId = txIdRes.txId return txIdRes.txId
return
case 'invoice.settled': case 'invoice.settled':
this.log('Transaction swap successful'); this.log('Transaction swap successful');
done(txId) done()
return; return;
} }
} }