aboutsummaryrefslogtreecommitdiffstats
path: root/routes/info.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-01-17 16:05:00 -0800
committerAdam Soltys <[email protected]>2023-01-17 16:05:00 -0800
commit33229e38a910e26083175a3e272278745378114c (patch)
treec63b3fc8c5e9563ae0aa694617ebd3419a3fac8b /routes/info.js
parent98a611d8965d8b896d124c78bdc1f7ceea6593cf (diff)
downloadcoinos-server-33229e38a910e26083175a3e272278745378114c.tar.gz
coinos-server-33229e38a910e26083175a3e272278745378114c.zip
redlock
Diffstat (limited to 'routes/info.js')
-rw-r--r--routes/info.js90
1 files changed, 16 insertions, 74 deletions
diff --git a/routes/info.js b/routes/info.js
index eb42ca35..00a4915e 100644
--- a/routes/info.js
+++ b/routes/info.js
@@ -1,90 +1,32 @@
-import app from "$app";
-import db from "$db";
-import config from "$config";
-import store from "$lib/store";
-
-import bc from "$lib/bitcoin";
-import lq from "$lib/liquid";
+import db from "$lib/db";
import ln from "$lib/ln";
-import sequelize from "@sequelize/core";
-import { SATS } from "$lib/utils";
-
-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", async (req, res, next) => {
- const { clientVersion } = config;
-
- const info = {
- fx: store.fx,
- nodes: store.networks,
- clientVersion
- };
-
- res.send(info);
-});
+export default {
+ async balances(req, res) {
+ let lnchannel;
+ let lnwallet;
-app.get("/balances", async (req, res, next) => {
- try {
- const accounts = await db.Account.findAll({
- where: {
- pubkey: null
- },
- attributes: [
- "asset",
- [sequelize.fn("sum", sequelize.col("balance")), "total"]
- ],
- group: ["asset"]
+ const stream = db.scanStream({
+ match: "balance:*",
+ count: 100
});
- let lnchannel;
- let lnwallet;
+ let b = 0;
+ for await (let keys of stream) {
+ for (let k of keys) b += parseInt(await db.get(k));
+ }
+ console.log(b)
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));
- 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
+ lnwallet,
+ total: lnchannel + lnwallet
};
- info.total =
- parseInt(bitcoin) +
- parseInt(liquid) +
- parseInt(lnchannel) +
- parseInt(lnwallet);
-
res.send(info);
- } catch (e) {
- console.log("problem getting balances", e);
}
-});
+};