diff options
| author | Adam Soltys <[email protected]> | 2020-06-13 21:39:22 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-06-13 21:39:22 -0700 |
| commit | 74b7d2a0d614f170ba5aea3a1a172a7a68356d80 (patch) | |
| tree | be2a73a9917616c0b49c24dc99642378e5a47549 /routes/info.js | |
| parent | dcb21adb40a44c8108f1d652cc6ddd59ae7c4024 (diff) | |
| download | coinos-server-74b7d2a0d614f170ba5aea3a1a172a7a68356d80.tar.gz coinos-server-74b7d2a0d614f170ba5aea3a1a172a7a68356d80.zip | |
push notifications
Diffstat (limited to 'routes/info.js')
| -rw-r--r-- | routes/info.js | 72 |
1 files changed, 72 insertions, 0 deletions
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); +}); |
