aboutsummaryrefslogtreecommitdiffstats
path: root/routes/info.ts
blob: f2bcda1a933367dd2ae46c462b88e5f297ac27c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { g } from "$lib/db";
import { getHealthStatus } from "$lib/health";
import ln from "$lib/ln";
import { getDecodedToken } from "@cashu/cashu-ts";

export default {
  async health(c) {
    const status = getHealthStatus();
    const httpStatus = status.healthy ? 200 : 503;
    return c.json(status, httpStatus);
  },

  async balances(c) {
    const funds = await ln.listfunds();
    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")).proofs.reduce((a, b) => a + b.amount, 0);

    const info = {
      cash,
      lnchannel,
      lnwallet,
    };

    return c.json(info);
  },
};