From fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 26 Aug 2024 21:17:43 -0700 Subject: typescript --- routes/info.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 routes/info.ts (limited to 'routes/info.ts') diff --git a/routes/info.ts b/routes/info.ts new file mode 100644 index 00000000..f2e262f6 --- /dev/null +++ b/routes/info.ts @@ -0,0 +1,32 @@ +import { archive } from "$lib/db"; +import db from "$lib/db"; +import ln from "$lib/ln"; + +export default { + async balances(req, res) { + let lnchannel; + let lnwallet; + + let total = 0; + + for await (let k of db.scanIterator({ MATCH: "balance:*" })) { + total += parseInt(await db.get(k)); + } + + for await (let k of archive.scanIterator({ MATCH: "balance:*" })) { + total += parseInt(await archive.get(k)); + } + + 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 info = { + lnchannel, + lnwallet, + total, + }; + + res.send(info); + }, +}; -- cgit v1.2.3