From d0de00fab7b474c9b691bef0cd3b2da2dd2d67c1 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 6 Nov 2024 08:29:42 -0800 Subject: cash balance --- routes/info.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'routes') diff --git a/routes/info.ts b/routes/info.ts index 09361a01..8892b7f7 100644 --- a/routes/info.ts +++ b/routes/info.ts @@ -1,12 +1,10 @@ import { archive } from "$lib/db"; -import db from "$lib/db"; +import { db, g } from "$lib/db"; import ln from "$lib/ln"; +import { getDecodedToken } from "@cashu/cashu-ts"; export default { - async balances(req, res) { - let lnchannel; - let lnwallet; - + async balances(_, res) { let total = 0; for await (const k of db.scanIterator({ MATCH: "balance:*" })) { @@ -18,10 +16,18 @@ export default { } const funds = await ln.listfunds(); - lnchannel = parseInt(funds.channels.reduce((a, b) => a + b.channel_sat, 0)); - lnwallet = parseInt(funds.outputs.reduce((a, b) => a + b.value, 0)); + const lnchannel = parseInt( + funds.channels.reduce((a, b) => a + b.channel_sat, 0), + ); + const lnwallet = parseInt(funds.outputs.reduce((a, b) => a + b.value, 0)); + + const cash = getDecodedToken(await g("cash")).token[0].proofs.reduce( + (a, b) => a + b.amount, + 0, + ); const info = { + cash, lnchannel, lnwallet, total, -- cgit v1.2.3