diff options
| author | Adam Soltys <[email protected]> | 2024-11-06 08:29:42 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-11-06 08:31:30 -0800 |
| commit | d0de00fab7b474c9b691bef0cd3b2da2dd2d67c1 (patch) | |
| tree | bc35d3323b7f7c466091276a59643711fa5d7101 /routes | |
| parent | 6973aaa259b45ecf038051bda0d3689cac6523b6 (diff) | |
| download | coinos-server-d0de00fab7b474c9b691bef0cd3b2da2dd2d67c1.tar.gz coinos-server-d0de00fab7b474c9b691bef0cd3b2da2dd2d67c1.zip | |
cash balance
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/info.ts | 20 |
1 files changed, 13 insertions, 7 deletions
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, |
