From c16f433b816d2239e61b6e325ce9996d01ea3619 Mon Sep 17 00:00:00 2001 From: hatim boufnichel Date: Thu, 14 Mar 2024 21:59:19 +0100 Subject: [PATCH] only check non internal --- src/services/main/index.ts | 57 ++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/src/services/main/index.ts b/src/services/main/index.ts index 1bc04c1b..7d0fb71d 100644 --- a/src/services/main/index.ts +++ b/src/services/main/index.ts @@ -241,22 +241,8 @@ export default class { async VerifyEventsLog() { const events = await this.storage.eventsLog.GetAllLogs() - const invoices = await this.lnd.GetAllPaidInvoices(300) - const payments = await this.lnd.GetAllPayments(300) - const verifyWithLnd = (type: "balance_decrement" | "balance_increment", invoice: string) => { - if (type === 'balance_decrement') { - const entry = payments.payments.find(p => p.paymentRequest === invoice) - if (!entry) { - throw new Error("payment not found in lnd " + invoice) - } - return Number(entry.valueSat) - } - const entry = invoices.invoices.find(i => i.paymentRequest === invoice) - if (!entry) { - throw new Error("invoice not found in lnd " + invoice) - } - return Number(entry.amtPaidSat) - } + const invoices = await this.lnd.GetAllPaidInvoices(1000) + const payments = await this.lnd.GetAllPayments(1000) const users: Record = {} for (let i = 0; i < events.length; i++) { @@ -264,19 +250,21 @@ export default class { if (e.type === 'balance_decrement') { users[e.userId] = this.checkUserEntry(e, users[e.userId]) if (LN_INVOICE_REGEX.test(e.data)) { - const invoiceEntry = await this.storage.paymentStorage.GetPaymentOwner(e.data) - if (!invoiceEntry) { - throw new Error("invoice entry not found for " + e.data) + const paymentEntry = await this.storage.paymentStorage.GetPaymentOwner(e.data) + if (!paymentEntry) { + throw new Error("payment entry not found for " + e.data) } - if (invoiceEntry.paid_at_unix === 0) { - throw new Error("invoice was never paid " + e.data) + if (paymentEntry.paid_at_unix === 0) { + throw new Error("payment was never paid " + e.data) } - const entry = payments.payments.find(i => i.paymentRequest === e.data) - if (!entry) { - throw new Error("invoice not found in lnd " + e.data) - } - if (Number(entry.valueSat) !== e.amount) { - throw new Error(`invalid amounts got: ${Number(entry.valueSat)} expected: ${e.amount}`) + if (!paymentEntry.internal) { + const entry = payments.payments.find(i => i.paymentRequest === e.data) + if (!entry) { + throw new Error("payment not found in lnd " + e.data) + } + if (Number(entry.valueSat) !== e.amount) { + throw new Error(`invalid payment amounts got: ${Number(entry.valueSat)} expected: ${e.amount}`) + } } } } else if (e.type === 'balance_increment') { @@ -289,13 +277,16 @@ export default class { if (invoiceEntry.paid_at_unix === 0) { throw new Error("invoice was never paid " + e.data) } - const entry = invoices.invoices.find(i => i.paymentRequest === e.data) - if (!entry) { - throw new Error("invoice not found in lnd " + e.data) - } - if (Number(entry.amtPaidSat) !== e.amount) { - throw new Error(`invalid amounts got: ${Number(entry.amtPaidSat)} expected: ${e.amount}`) + if (!invoiceEntry.internal) { + const entry = invoices.invoices.find(i => i.paymentRequest === e.data) + if (!entry) { + throw new Error("invoice not found in lnd " + e.data) + } + if (Number(entry.amtPaidSat) !== e.amount) { + throw new Error(`invalid invoice amounts got: ${Number(entry.amtPaidSat)} expected: ${e.amount}`) + } } + } } else { await this.storage.paymentStorage.VerifyDbEvent(e)