aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lightning
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/lightning
parentc0888fab024cc9f7c99812bfabf9d7774312dbf7 (diff)
downloadcoinos-server-a22b5cd3769ea6d7aac4f34acf142534ee75491c.tar.gz
coinos-server-a22b5cd3769ea6d7aac4f34acf142534ee75491c.zip
drop lnrpc
Diffstat (limited to 'routes/lightning')
-rw-r--r--routes/lightning/receive.js54
-rw-r--r--routes/lightning/send.js2
2 files changed, 27 insertions, 29 deletions
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");
}