From d0de00fab7b474c9b691bef0cd3b2da2dd2d67c1 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 6 Nov 2024 08:29:42 -0800 Subject: cash balance --- lib/ecash.ts | 1 + lib/locations.ts | 1 - routes/info.ts | 20 +++++++++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/ecash.ts b/lib/ecash.ts index d9d6728e..9ea4ec38 100644 --- a/lib/ecash.ts +++ b/lib/ecash.ts @@ -90,3 +90,4 @@ export async function init(amount = 10000) { console.log(e); } } + diff --git a/lib/locations.ts b/lib/locations.ts index abf578d8..57658aad 100644 --- a/lib/locations.ts +++ b/lib/locations.ts @@ -45,7 +45,6 @@ export const getLocations = async () => { for await (const l of locations) { const username = l.tags["payment:coinos"]; if (username) { - console.log(username); const uid = await g(`user:${username}`); const user = await g(`user:${uid}`); if (user) l.osm_json.tags.user = pick(user, fields); 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