aboutsummaryrefslogtreecommitdiffstats
path: root/routes
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
parent98a611d8965d8b896d124c78bdc1f7ceea6593cf (diff)
downloadcoinos-server-33229e38a910e26083175a3e272278745378114c.tar.gz
coinos-server-33229e38a910e26083175a3e272278745378114c.zip
redlock
Diffstat (limited to 'routes')
-rw-r--r--routes/info.js90
-rw-r--r--routes/invoices.js2
-rw-r--r--routes/nostr.js6
-rw-r--r--routes/payments.js2
-rw-r--r--routes/requests.js4
5 files changed, 23 insertions, 81 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);
}
-});
+};
diff --git a/routes/invoices.js b/routes/invoices.js
index acd9457e..3e43c57c 100644
--- a/routes/invoices.js
+++ b/routes/invoices.js
@@ -58,7 +58,7 @@ export default {
);
await s(`invoice:${hash}`, invoice);
- await db.lPush(`${uid}:invoices`, hash);
+ await db.lpush(`${uid}:invoices`, hash);
if (request_id) {
let request = await g(`request:${request_id}`);
diff --git a/routes/nostr.js b/routes/nostr.js
index 005a4be9..bac04810 100644
--- a/routes/nostr.js
+++ b/routes/nostr.js
@@ -41,10 +41,10 @@ export default {
await s(`user:${pubkey}`, user);
- let ids = await db.sMembers(pubkey);
+ let ids = await db.smembers(pubkey);
let events = ids.length
- ? (await db.mGet(ids.map(k => "ev:" + k))).map(JSON.parse)
+ ? (await db.mget(ids.map(k => "ev:" + k))).map(JSON.parse)
: [];
res.send(events.map(e => ({ ...e, user })));
@@ -101,7 +101,7 @@ export default {
async followers({ params: { pubkey } }, res) {
try {
let pubkeys = [
- ...new Set([...(await db.sMembers(`${pubkey}:followers`))])
+ ...new Set([...(await db.smembers(`${pubkey}:followers`))])
];
let followers = [];
diff --git a/routes/payments.js b/routes/payments.js
index 13c0cdb7..22de79c3 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -21,7 +21,7 @@ export default {
// if (start) where.createdAt[Op.gte] = new Date(parseInt(start));
// if (end) where.createdAt[Op.lte] = new Date(parseInt(end));
- let payments = (await db.lRange(`${id}:payments`, 0, -1)) || [];
+ let payments = (await db.lrange(`${id}:payments`, 0, -1)) || [];
payments = await Promise.all(payments.map(hash => g(`payment:${hash}`)));
payments = payments.filter(p => p);
res.send({ payments, total: payments.length });
diff --git a/routes/requests.js b/routes/requests.js
index 79af1fb6..8db373dd 100644
--- a/routes/requests.js
+++ b/routes/requests.js
@@ -15,8 +15,8 @@ export default {
try {
const day = new Date(new Date().setDate(new Date().getDate() - 1));
- let invoices = await db.lRange(`${id}:invoices`, 0, -1);
- let requests = await db.lRange(`${id}:requests`, 0, -1);
+ let invoices = await db.lrange(`${id}:invoices`, 0, -1);
+ let requests = await db.lrange(`${id}:requests`, 0, -1);
res.send({ invoices, requests });
} catch (e) {