log channel state
This commit is contained in:
parent
c708027529
commit
1df733fb8e
5 changed files with 15 additions and 22 deletions
|
|
@ -14,7 +14,7 @@ export default (serverMethods: Types.ServerMethods, mainHandler: Main, nostrSett
|
|||
return { user_id: nostrUser.user.user_id, app_user_id: nostrUser.identifier, app_id: appId || "" }
|
||||
},
|
||||
metricsCallback: metrics => mainHandler.settings.recordPerformance ? mainHandler.metricsManager.AddMetrics(metrics) : null,
|
||||
logger: { log, error: err => log("ERROR", err) }
|
||||
logger: { log: console.log, error: err => log("ERROR", err) }
|
||||
})
|
||||
const nostr = new Nostr(nostrSettings, event => {
|
||||
let j: NostrRequest
|
||||
|
|
|
|||
|
|
@ -16,16 +16,17 @@ type TxOutput = {
|
|||
hash: string
|
||||
index: number
|
||||
}
|
||||
export type ChannelBalance = {
|
||||
channelId: string;
|
||||
localBalanceSats: number;
|
||||
remoteBalanceSats: number;
|
||||
htlcs: { incoming: boolean, amount: number }[]
|
||||
}
|
||||
export type BalanceInfo = {
|
||||
confirmedBalance: number;
|
||||
unconfirmedBalance: number;
|
||||
totalBalance: number;
|
||||
channelsBalance: {
|
||||
channelId: string;
|
||||
localBalanceSats: number;
|
||||
remoteBalanceSats: number;
|
||||
htlcs: { incoming: boolean, amount: number }[]
|
||||
}[];
|
||||
channelsBalance: ChannelBalance[];
|
||||
}
|
||||
|
||||
export type AddressPaidCb = (txOutput: TxOutput, address: string, amount: number, internal: boolean) => void
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { EnvCanBeInteger } from "../helpers/envParser.js";
|
||||
import { getLogger } from "../helpers/logger.js";
|
||||
import { LightningHandler } from "../lnd/index.js";
|
||||
import { ChannelBalance } from "../lnd/settings.js";
|
||||
import Storage from '../storage/index.js'
|
||||
export type WatchdogSettings = {
|
||||
maxDiffSats: number
|
||||
|
|
@ -48,20 +49,13 @@ export class Watchdog {
|
|||
}
|
||||
|
||||
getTotalLndBalance = async () => {
|
||||
const localLog = getLogger({ appName: "debugLndBalance" })
|
||||
const { confirmedBalance, channelsBalance } = await this.lnd.GetBalance()
|
||||
this.log(confirmedBalance, "sats in chain wallet")
|
||||
let total = confirmedBalance
|
||||
channelsBalance.forEach(c => {
|
||||
let outgoingSats = 0
|
||||
c.htlcs.forEach(htlc => {
|
||||
if (!htlc.incoming) {
|
||||
outgoingSats += Number(htlc.amount)
|
||||
}
|
||||
})
|
||||
total += Number(c.localBalanceSats) - outgoingSats
|
||||
this.log(c.localBalanceSats, "sats in channel", c.channelId, "with", outgoingSats, "sats in pending outgoing htlcs")
|
||||
})
|
||||
return total
|
||||
localLog(channelsBalance)
|
||||
return channelsBalance.reduce((acc, c) => {
|
||||
return acc + c.localBalanceSats + c.htlcs.reduce((acc2, htlc) => acc2 + (htlc.incoming ? htlc.amount : -htlc.amount), 0)
|
||||
}, 0)
|
||||
}
|
||||
|
||||
checkBalanceUpdate = (deltaLnd: number, deltaUsers: number) => {
|
||||
|
|
|
|||
|
|
@ -193,8 +193,6 @@ export default class Handler {
|
|||
}))
|
||||
if (!sent) {
|
||||
log("failed to send event")
|
||||
} else {
|
||||
log("event sent ok")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ export default (mainHandler: Main): Types.ServerMethods => {
|
|||
if (err != null) throw new Error(err.message)
|
||||
await mainHandler.paymentManager.SetMockInvoiceAsPaid(req)
|
||||
},
|
||||
UserHealth: async () => { getLogger({})("got health request") },
|
||||
UserHealth: async () => { },
|
||||
GetUserInfo: ({ ctx }) => mainHandler.appUserManager.GetUserInfo(ctx),
|
||||
GetUserOperations: async ({ ctx, req }) => {
|
||||
return mainHandler.paymentManager.GetUserOperations(ctx.user_id, req)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue