aboutsummaryrefslogtreecommitdiffstats
path: root/routes/info.js
blob: 13b1de57fdd5d5c8c9803cbd2d169554b74b34c3 (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
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));
    }

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