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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
const sequelize = require("sequelize");
const { Op } = sequelize;
/**
* @api {get} /info Request server information
* @apiName GetInfo
* @apiGroup Info
*
* @apiSuccess {Object} fx Exchange rates relative to USD - fx.CUR is the value of one CUR in USD.
* @apiSuccess {String[]} networks Array of supported networks; possible values are "bitcoin", "liquid" and "lightning".
* @apiSuccess {String} clientVersion the current git commit of the ui
*/
app.get("/info", ah(async (req, res, next) => {
const { clientVersion } = config;
const info = {
fx: app.get("fx"),
nodes: networks,
clientVersion,
};
res.send(info);
}));
app.get("/balances", ah(async (req, res, next) => {
const accounts = await db.Account.findAll({
attributes: [
"asset",
"pubkey",
[sequelize.fn("sum", sequelize.col("balance")), "total"]
],
group: ["asset", "pubkey"],
});
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 lnp.getInfo({});
lnchannel = parseInt((await lnp.channelBalance({})).balance);
lnwallet = parseInt((await lnp.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,
};
info.total =
parseInt(bitcoin) +
parseInt(liquid) +
parseInt(lnchannel) +
parseInt(lnwallet);
res.send(info);
}));
|