aboutsummaryrefslogtreecommitdiffstats
path: root/routes/info.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-08-26 21:17:43 -0700
committerAdam Soltys <[email protected]>2024-08-26 21:17:43 -0700
commitfe62cadd6fb4a7e49f7d59401fc74ae0411e32a7 (patch)
treeaa8f34e1692bd2d638a2c996eeadb58671d07aea /routes/info.ts
parent00e43ddc0bf3d6dd719fc9295d156567fa2fecfb (diff)
downloadcoinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.tar.gz
coinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.zip
typescript
Diffstat (limited to 'routes/info.ts')
-rw-r--r--routes/info.ts32
1 files changed, 32 insertions, 0 deletions
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);
+ },
+};