diff options
Diffstat (limited to 'routes/lightning/receive.js')
| -rw-r--r-- | routes/lightning/receive.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js new file mode 100644 index 00000000..6befc7a3 --- /dev/null +++ b/routes/lightning/receive.js @@ -0,0 +1,36 @@ +module.exports = { + 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 + } + }); + + if (!payment) return; + + 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; + + 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); + }; + + const invoices = lna.subscribeInvoices({}); + invoices.on("data", handlePayment); + + const invoicesb = lnb.subscribeInvoices({}); + invoicesb.on("data", handlePayment); +}; |
