aboutsummaryrefslogtreecommitdiffstats
path: root/routes/info.ts
blob: a0ac7693ccd9576e1732e2a1a5c13939a2e7df62 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { archive } from "$lib/db";
import { db, g } from "$lib/db";
import { getHealthStatus } from "$lib/health";
import ln from "$lib/ln";
import { getDecodedToken } from "@cashu/cashu-ts";

export default {
  async health(_, res) {
    const status = getHealthStatus();
    const httpStatus = status.healthy ? 200 : 503;
    res.status(httpStatus).send(status);
  },

  async balances(_, res) {
    let total = 0;

    // for await (const k of db.scanIterator({ MATCH: "balance:*" })) {
    //   total += parseInt(await db.get(k));
    // }
    //
    // for await (const k of archive.scanIterator({ MATCH: "balance:*" })) {
    //   total += parseInt(await archive.get(k));
    // }

    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,
    };

    res.send(info);
  },
};