diff options
| author | Adam Soltys <[email protected]> | 2020-03-27 23:17:38 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-03-27 23:17:38 -0700 |
| commit | 5142c8cfcffd59d04ec18e67183a1866324d9209 (patch) | |
| tree | 265b9bc31176ac88b15bbe7aa54d19a910e56c13 /routes | |
| parent | a4c3ecab30a279db7ed7f7289448c01c73c7b523 (diff) | |
| download | coinos-server-5142c8cfcffd59d04ec18e67183a1866324d9209.tar.gz coinos-server-5142c8cfcffd59d04ec18e67183a1866324d9209.zip | |
create lightning payment
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/lightning/receive.js | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js index f70867ac..c4ce2414 100644 --- a/routes/lightning/receive.js +++ b/routes/lightning/receive.js @@ -1,23 +1,34 @@ const handlePayment = async msg => { if (!msg.settled) return; + l.info("lightning strikes!", msg.payment_request); - let payment = await db.Payment.findOne({ + let invoice = await db.Invoice.findOne({ include: { model: db.User, as: "user" }, where: { - hash: msg.payment_request + text: msg.payment_request } }); - if (!payment) return; + if (!invoice) return; - const { user } = payment; + const { user } = invoice; + const amount = parseInt(msg.value); - payment.received = true; - user.balance += parseInt(msg.value); - payment.rate = app.get("rates")[user.currency]; - payment.confirmed = true; - payment.currency = user.currency; + const payment = await db.Payment.create({ + user_id: user.id, + hash: invoice.text, + amount, + currency: user.currency, + rate: app.get("rates")[user.currency], + received: true, + confirmed: true, + asset: 'LNBTC', + }); + + invoice.received = msg.value; + user.balance += amount; + await invoice.save(); await payment.save(); await user.save(); payments.push(msg.payment_request); |
