From 780d357c0b6e3b2d61ec9228a7f7dc92b403aeb6 Mon Sep 17 00:00:00 2001 From: boufni95 Date: Mon, 24 Jun 2024 21:46:25 +0200 Subject: [PATCH] fix event log --- src/services/lnd/liquidityProvider.ts | 16 ++++++++++++++++ src/services/main/sanityChecker.ts | 16 ++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/services/lnd/liquidityProvider.ts b/src/services/lnd/liquidityProvider.ts index fc7bbe61..104c0067 100644 --- a/src/services/lnd/liquidityProvider.ts +++ b/src/services/lnd/liquidityProvider.ts @@ -144,6 +144,22 @@ export class LiquidityProvider { return res } + GetOperations = async () => { + if (this.latestMaxWithdrawable === null) { + throw new Error("liquidity provider is not ready yet") + } + const res = await this.client.GetUserOperations({ + latestIncomingInvoice: 0, latestOutgoingInvoice: 0, + latestIncomingTx: 0, latestOutgoingTx: 0, latestIncomingUserToUserPayment: 0, + latestOutgoingUserToUserPayment: 0, max_size: 200 + }) + if (res.status === 'ERROR') { + this.log("error getting operations", res.reason) + throw new Error(res.reason) + } + return res + } + setNostrInfo = ({ clientId, myPub }: { myPub: string, clientId: string }) => { this.clientId = clientId this.myPub = myPub diff --git a/src/services/main/sanityChecker.ts b/src/services/main/sanityChecker.ts index bdad7154..372dd96c 100644 --- a/src/services/main/sanityChecker.ts +++ b/src/services/main/sanityChecker.ts @@ -3,6 +3,7 @@ import LND from "../lnd/lnd.js" import { LoggedEvent } from '../storage/eventsLog.js' import { Invoice, Payment } from '../../../proto/lnd/lightning'; import { getLogger } from '../helpers/logger.js'; +import * as Types from '../../../proto/autogenerated/ts/types.js' const LN_INVOICE_REGEX = /^(lightning:)?(lnbc|lntb)[0-9a-zA-Z]+$/; const BITCOIN_ADDRESS_REGEX = /^(bitcoin:)?([13][a-km-zA-HJ-NP-Z1-9]{25,34}|bc1[a-zA-HJ-NP-Z0-9]{39,59})$/; type UniqueDecrementReasons = 'ban' @@ -17,6 +18,8 @@ export default class SanityChecker { events: LoggedEvent[] = [] invoices: Invoice[] = [] payments: Payment[] = [] + providerInvoices: Types.UserOperation[] = [] + providerPayments: Types.UserOperation[] = [] incrementSources: Record = {} decrementSources: Record = {} decrementEvents: Record = {} @@ -110,7 +113,10 @@ export default class SanityChecker { if (!entry.internal) { const lndEntry = this.payments.find(i => i.paymentRequest === invoice) if (!lndEntry) { - throw new Error("payment not found in lnd for invoice " + invoice) + const providerEntry = this.providerPayments.find(i => i.identifier === invoice) + if (!providerEntry) { + throw new Error("payment not found in lnd for invoice " + invoice) + } } } } @@ -186,7 +192,10 @@ export default class SanityChecker { if (!entry.internal) { const entry = this.invoices.find(i => i.paymentRequest === invoice) if (!entry) { - throw new Error("invoice not found in lnd " + invoice) + const providerEntry = this.providerInvoices.find(i => i.identifier === invoice) + if (!providerEntry) { + throw new Error("invoice not found in lnd " + invoice) + } } } } @@ -227,6 +236,9 @@ export default class SanityChecker { this.events = await this.storage.eventsLog.GetAllLogs() this.invoices = (await this.lnd.GetAllPaidInvoices(1000)).invoices this.payments = (await this.lnd.GetAllPayments(1000)).payments + const ops = await this.lnd.liquidProvider.GetOperations() + this.providerInvoices = ops.latestIncomingInvoiceOperations.operations + this.providerPayments = ops.latestOutgoingInvoiceOperations.operations this.incrementSources = {} this.decrementSources = {} this.users = {}