aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-03-11 22:01:35 -0700
committerAdam Soltys <[email protected]>2020-03-11 22:01:35 -0700
commita22b5cd3769ea6d7aac4f34acf142534ee75491c (patch)
tree428fb1a3c36d7ddacf1095c3ab1b47b26042d72b /routes
parentc0888fab024cc9f7c99812bfabf9d7774312dbf7 (diff)
downloadcoinos-server-a22b5cd3769ea6d7aac4f34acf142534ee75491c.tar.gz
coinos-server-a22b5cd3769ea6d7aac4f34acf142534ee75491c.zip
drop lnrpc
Diffstat (limited to 'routes')
-rw-r--r--routes/bitcoin/send.js2
-rw-r--r--routes/lightning/receive.js54
-rw-r--r--routes/lightning/send.js2
-rw-r--r--routes/liquid/send.js2
-rw-r--r--routes/payments.js13
5 files changed, 39 insertions, 34 deletions
diff --git a/routes/bitcoin/send.js b/routes/bitcoin/send.js
index 3c545178..d8a17f98 100644
--- a/routes/bitcoin/send.js
+++ b/routes/bitcoin/send.js
@@ -51,7 +51,7 @@ module.exports = async (req, res) => {
await user.save({ transaction });
});
} catch (e) {
- l.warn("insufficient funds for bitcoin payment", e);
+ l.warn("insufficient funds for bitcoin payment", user.username);
return res.status(500).send("Not enough satoshis");
}
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js
index 6befc7a3..f70867ac 100644
--- a/routes/lightning/receive.js
+++ b/routes/lightning/receive.js
@@ -1,36 +1,34 @@
-module.exports = {
- const handlePayment = async msg => {
- if (!msg.settled) return;
+const handlePayment = async msg => {
+ if (!msg.settled) return;
- let payment = await db.Payment.findOne({
- include: { model: db.User, as: "user" },
- where: {
- hash: msg.payment_request
- }
- });
+ let payment = await db.Payment.findOne({
+ include: { model: db.User, as: "user" },
+ where: {
+ hash: msg.payment_request
+ }
+ });
- if (!payment) return;
+ if (!payment) return;
- const { user } = payment;
+ const { user } = payment;
- payment.received = true;
- user.balance += parseInt(msg.value);
- payment.rate = app.get("rates")[user.currency];
- payment.confirmed = true;
- payment.currency = user.currency;
+ payment.received = true;
+ user.balance += parseInt(msg.value);
+ payment.rate = app.get("rates")[user.currency];
+ payment.confirmed = true;
+ payment.currency = user.currency;
- await payment.save();
- await user.save();
- payments.push(msg.payment_request);
- l.info("lightning payment received", user.username, payment.amount);
+ await payment.save();
+ await user.save();
+ payments.push(msg.payment_request);
+ l.info("lightning payment received", user.username, payment.amount);
- emit(user.username, "payment", payment);
- emit(user.username, "user", user);
- };
+ emit(user.username, "payment", payment);
+ emit(user.username, "user", user);
+};
- const invoices = lna.subscribeInvoices({});
- invoices.on("data", handlePayment);
+const invoices = lna.subscribeInvoices({});
+invoices.on("data", handlePayment);
- const invoicesb = lnb.subscribeInvoices({});
- invoicesb.on("data", handlePayment);
-};
+const invoicesb = lnb.subscribeInvoices({});
+invoicesb.on("data", handlePayment);
diff --git a/routes/lightning/send.js b/routes/lightning/send.js
index 2b661b60..38023a1d 100644
--- a/routes/lightning/send.js
+++ b/routes/lightning/send.js
@@ -30,7 +30,7 @@ module.exports = async (req, res) => {
await user.save({ transaction });
});
} catch (e) {
- l.warn("insufficient funds for lightning payment", e);
+ l.warn("insufficient funds for lightning payment", user.username);
return res.status(500).send("Not enough satoshis");
}
diff --git a/routes/liquid/send.js b/routes/liquid/send.js
index aaced4a9..83c5dc22 100644
--- a/routes/liquid/send.js
+++ b/routes/liquid/send.js
@@ -53,7 +53,7 @@ module.exports = async (req, res) => {
await user.save({ transaction });
});
} catch (e) {
- l.warn("insufficient funds for liquid payment", e);
+ l.warn("insufficient funds for liquid payment", user.username);
return res.status(500).send("Not enough satoshis");
}
diff --git a/routes/payments.js b/routes/payments.js
index d5038b08..7cb51d02 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -1,12 +1,12 @@
const BitcoinCore = require("bitcoin-core");
-const createLnrpc = require("../lib/createLnrpc");
+const lnd = require("../lib/lnd");
(async () => {
bc = new BitcoinCore(config.bitcoin);
lq = new BitcoinCore(config.liquid);
- lna = await createLnrpc(config.lna);
- lnb = await createLnrpc(config.lnb);
+ lna = lnd(config.lna);
+ lnb = lnd(config.lnb);
seen = [];
addresses = {};
@@ -17,16 +17,23 @@ const createLnrpc = require("../lib/createLnrpc");
if (u.liquid) addresses[u.liquid] = u.username;
});
+ payments = (await db.Payment.findAll({
+ attributes: ["hash"]
+ })).map(p => p.hash);
+
app.post("/lightning/invoice", auth, require("./lightning/invoice"));
app.post("/lightning/query", auth, require("./lightning/query"));
app.post("/lightning/send", auth, require("./lightning/send"));
app.post("/lightning/user", auth, require("./lightning/user"));
+ require("./lightning/receive");
app.post("/bitcoin/send", auth, require("./bitcoin/send"));
app.post("/bitcoin/fee", auth, require("./bitcoin/fee"));
+ require("./bitcoin/receive");
app.post("/liquid/send", auth, require("./liquid/send"));
app.post("/liquid/fee", auth, require("./liquid/fee"));
+ require("./liquid/receive");
app.get("/payments", auth, async (req, res) => {
const payments = await db.Payment.findAll({