fix event log
This commit is contained in:
parent
a8425c3afa
commit
780d357c0b
2 changed files with 30 additions and 2 deletions
|
|
@ -144,6 +144,22 @@ export class LiquidityProvider {
|
||||||
return res
|
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 }) => {
|
setNostrInfo = ({ clientId, myPub }: { myPub: string, clientId: string }) => {
|
||||||
this.clientId = clientId
|
this.clientId = clientId
|
||||||
this.myPub = myPub
|
this.myPub = myPub
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import LND from "../lnd/lnd.js"
|
||||||
import { LoggedEvent } from '../storage/eventsLog.js'
|
import { LoggedEvent } from '../storage/eventsLog.js'
|
||||||
import { Invoice, Payment } from '../../../proto/lnd/lightning';
|
import { Invoice, Payment } from '../../../proto/lnd/lightning';
|
||||||
import { getLogger } from '../helpers/logger.js';
|
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 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})$/;
|
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'
|
type UniqueDecrementReasons = 'ban'
|
||||||
|
|
@ -17,6 +18,8 @@ export default class SanityChecker {
|
||||||
events: LoggedEvent[] = []
|
events: LoggedEvent[] = []
|
||||||
invoices: Invoice[] = []
|
invoices: Invoice[] = []
|
||||||
payments: Payment[] = []
|
payments: Payment[] = []
|
||||||
|
providerInvoices: Types.UserOperation[] = []
|
||||||
|
providerPayments: Types.UserOperation[] = []
|
||||||
incrementSources: Record<string, boolean> = {}
|
incrementSources: Record<string, boolean> = {}
|
||||||
decrementSources: Record<string, boolean> = {}
|
decrementSources: Record<string, boolean> = {}
|
||||||
decrementEvents: Record<string, { userId: string, refund: number, failure: boolean }> = {}
|
decrementEvents: Record<string, { userId: string, refund: number, failure: boolean }> = {}
|
||||||
|
|
@ -110,10 +113,13 @@ export default class SanityChecker {
|
||||||
if (!entry.internal) {
|
if (!entry.internal) {
|
||||||
const lndEntry = this.payments.find(i => i.paymentRequest === invoice)
|
const lndEntry = this.payments.find(i => i.paymentRequest === invoice)
|
||||||
if (!lndEntry) {
|
if (!lndEntry) {
|
||||||
|
const providerEntry = this.providerPayments.find(i => i.identifier === invoice)
|
||||||
|
if (!providerEntry) {
|
||||||
throw new Error("payment not found in lnd for invoice " + invoice)
|
throw new Error("payment not found in lnd for invoice " + invoice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async validateUser2UserPayment({ fromUser, toUser, serialId }: { fromUser: string, toUser: string, serialId?: number }) {
|
async validateUser2UserPayment({ fromUser, toUser, serialId }: { fromUser: string, toUser: string, serialId?: number }) {
|
||||||
if (!serialId) {
|
if (!serialId) {
|
||||||
|
|
@ -186,10 +192,13 @@ export default class SanityChecker {
|
||||||
if (!entry.internal) {
|
if (!entry.internal) {
|
||||||
const entry = this.invoices.find(i => i.paymentRequest === invoice)
|
const entry = this.invoices.find(i => i.paymentRequest === invoice)
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
|
const providerEntry = this.providerInvoices.find(i => i.identifier === invoice)
|
||||||
|
if (!providerEntry) {
|
||||||
throw new Error("invoice not found in lnd " + invoice)
|
throw new Error("invoice not found in lnd " + invoice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async validateRoutingFeeRefund({ amt, invoice, userId }: { userId: string, invoice: string, amt: number }) {
|
async validateRoutingFeeRefund({ amt, invoice, userId }: { userId: string, invoice: string, amt: number }) {
|
||||||
const entry = this.decrementEvents[invoice]
|
const entry = this.decrementEvents[invoice]
|
||||||
|
|
@ -227,6 +236,9 @@ export default class SanityChecker {
|
||||||
this.events = await this.storage.eventsLog.GetAllLogs()
|
this.events = await this.storage.eventsLog.GetAllLogs()
|
||||||
this.invoices = (await this.lnd.GetAllPaidInvoices(1000)).invoices
|
this.invoices = (await this.lnd.GetAllPaidInvoices(1000)).invoices
|
||||||
this.payments = (await this.lnd.GetAllPayments(1000)).payments
|
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.incrementSources = {}
|
||||||
this.decrementSources = {}
|
this.decrementSources = {}
|
||||||
this.users = {}
|
this.users = {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue