aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-10-01 16:40:24 -0700
committerAdam Soltys <[email protected]>2022-10-01 16:40:24 -0700
commit4e58ebca11ca68bfe08e3187e6cf13c01982bd4f (patch)
tree73509444ae0aa6b94b2119bd0df0b3f910227d8f /routes
parent721f96b11d25eeb58342c5847b0a4bd3f5159dbb (diff)
downloadcoinos-server-4e58ebca11ca68bfe08e3187e6cf13c01982bd4f.tar.gz
coinos-server-4e58ebca11ca68bfe08e3187e6cf13c01982bd4f.zip
increment invoice received
Diffstat (limited to 'routes')
-rw-r--r--routes/bitcoin/receive.js3
-rw-r--r--routes/lightning/index.js4
-rw-r--r--routes/lightning/parse.js20
-rw-r--r--routes/lightning/receive.js2
-rw-r--r--routes/liquid/receive.js1
-rw-r--r--routes/payments.js1
6 files changed, 28 insertions, 3 deletions
diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js
index 7451e868..3bc1750d 100644
--- a/routes/bitcoin/receive.js
+++ b/routes/bitcoin/receive.js
@@ -213,12 +213,13 @@ setInterval(async () => {
if (p && p.user) user = p.user;
if (p && p.account) {
- ({ account } = p);
+ ({ account, invoice } = p);
total = p.amount + p.tip;
p.confirmed = 1;
await account.save({ transaction });
+ await invoice.increment({ received: total }, { transaction });
await account.increment({ balance: total }, { transaction });
await account.decrement(
{ pending: Math.min(account.pending, total) },
diff --git a/routes/lightning/index.js b/routes/lightning/index.js
index 52a94398..b4611ef5 100644
--- a/routes/lightning/index.js
+++ b/routes/lightning/index.js
@@ -2,10 +2,12 @@ import channel from "./channel";
import invoice from "./invoice";
import query from "./query";
import send from "./send";
+import parse from "./parse";
export default {
channel,
invoice,
query,
- send
+ send,
+ parse
};
diff --git a/routes/lightning/parse.js b/routes/lightning/parse.js
new file mode 100644
index 00000000..1d960689
--- /dev/null
+++ b/routes/lightning/parse.js
@@ -0,0 +1,20 @@
+import ln from "$lib/ln";
+import store from "$lib/store";
+
+export default async (req, res) => {
+ let { payreq } = req.body;
+ let hour = 1000 * 60 * 60;
+ let { last } = store.nodes;
+ let { nodes } = store;
+
+ if (!last || last > Date.now() - hour) ({ nodes } = await ln.listnodes());
+ store.nodes = nodes;
+
+
+ let twoWeeksAgo = new Date(new Date().setDate(new Date().getDate() - 14));
+ let { msatoshi, payee } = await ln.decodepay(payreq);
+ let { alias } = nodes.find((n) => n.nodeid === payee);
+ let route = await ln.getroute(payee, msatoshi, 5);
+
+ res.send({ alias, route });
+};
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js
index 084161b5..898152fe 100644
--- a/routes/lightning/receive.js
+++ b/routes/lightning/receive.js
@@ -70,11 +70,11 @@ const handlePayment = async msg => {
);
total = amount + tip;
- invoice.received += total;
invoice.status = "paid";
await invoice.save({ transaction });
+ await invoice.increment({ received: total }, { transaction });
await account.increment({ balance: total }, { transaction });
// get the # of fee credits you would need to pay off this amount of bitcoin
await account.increment(
diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js
index 480677de..4ad4c7dc 100644
--- a/routes/liquid/receive.js
+++ b/routes/liquid/receive.js
@@ -344,6 +344,7 @@ setInterval(async () => {
p.confirmed = 1;
await p.account.save({ transaction });
+ await p.invoice.increment({ received: total }, { transaction });
await p.account.increment({ balance: total }, { transaction });
await p.account.decrement(
{ pending: Math.min(p.account.pending, total) },
diff --git a/routes/payments.js b/routes/payments.js
index 8b91d9fb..6c489372 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -57,6 +57,7 @@ app.get("/except", adminAuth, (req, res) => {
res.send("updated exceptions");
});
+app.post("/lightning/parse", lnRoutes.parse);
app.post("/lightning/channel", lnRoutes.channel);
app.post("/lightning/query", auth, lnRoutes.query);
app.post("/lightning/send", auth, lnRoutes.send);