From 74b7d2a0d614f170ba5aea3a1a172a7a68356d80 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 13 Jun 2020 21:39:22 -0700 Subject: push notifications --- routes/info.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 routes/info.js (limited to 'routes/info.js') diff --git a/routes/info.js b/routes/info.js new file mode 100644 index 00000000..81cb2095 --- /dev/null +++ b/routes/info.js @@ -0,0 +1,72 @@ +const sequelize = require("sequelize"); +const { Op } = sequelize; + +const fs = require("fs"); +try { + clientVersion = fs.readFileSync('config/clientversion').toString(); + l.info("client version", clientVersion); +} catch(e) { + l.warn("no client version found"); +} + +app.get("/info", async (req, res) => { + const accounts = await db.Account.findAll({ + attributes: [ + "asset", + [sequelize.fn("sum", sequelize.col("balance")), "total"] + ], + group: ["asset"], + }); + + let lnchannel; + let lnwallet; + let lninfo; + + if (config.lna) { + if (config.lna.clightning) { + const funds = await lna.listfunds(); + lninfo = await lna.getinfo(); + lnchannel = parseInt(funds.channels.reduce((a, b) => a + b.channel_sat, 0)); + lnwallet = parseInt(funds.outputs.reduce((a, b) => a + b.value, 0)); + } else { + lninfo = await lna.getInfo({}); + lnchannel = parseInt((await lna.channelBalance({})).balance); + lnwallet = parseInt((await lna.walletBalance({})).total_balance); + } + } + + let bitcoin, bitcoind; + if (config.bitcoin) { + bitcoin = parseInt((await bc.getBalance()) * SATS); + bitcoind = await bc.getNetworkInfo(); + } + + let assets, liquid, elementsd; + if (config.liquid) { + assets = await lq.getBalance(); + liquid = parseInt(assets.bitcoin * SATS); + elementsd = await lq.getNetworkInfo(); + } + + const info = { + bitcoind, + elementsd, + accounts, + assets, + bitcoin, + liquid, + lnchannel, + lnwallet, + rates: app.get("rates"), + nodes: networks, + clientVersion, + }; + + info.total = + parseInt(bitcoin) + + parseInt(liquid) + + parseInt(lnchannel) + + parseInt(lnwallet); + + res.send(info); +}); -- cgit v1.2.3