diff options
| author | Adam Soltys <[email protected]> | 2020-04-24 22:46:45 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-04-24 22:46:45 -0700 |
| commit | 83f973224bad381df62774bcc058f76eab635f0c (patch) | |
| tree | ef231f4490b0c9d194b8683be50c05524738903e /routes/lightning/receive.js | |
| parent | 306357c24d3014b55ae1cd25b954a695ea2e5cc6 (diff) | |
| download | coinos-server-assets.tar.gz coinos-server-assets.zip | |
wipassets
Diffstat (limited to 'routes/lightning/receive.js')
| -rw-r--r-- | routes/lightning/receive.js | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js index 6ac4c947..c300d8ea 100644 --- a/routes/lightning/receive.js +++ b/routes/lightning/receive.js @@ -4,19 +4,29 @@ const handlePayment = async msg => { if (!msg.settled) return; const invoice = await db.Invoice.findOne({ - include: { model: db.User, as: "user" }, where: { text: msg.payment_request } }); + if (!invoice) return; - const { text: hash, currency, rate, tip, user } = invoice; + const { text: hash, currency, rate, tip, user_id } = invoice; const amount = parseInt(msg.value) - tip; + let user = await getUserById(user_id); + + const account = await db.Account.findOne({ + where: { + user_id, + asset: config.liquid.btcasset + } + }); + const payment = await db.Payment.create({ - user_id: user.id, + account_id: account.id, + user_id, hash, amount, currency, @@ -24,17 +34,27 @@ const handlePayment = async msg => { received: true, confirmed: true, asset, - tip, + tip }); invoice.received += amount + tip; - user.balance += amount + tip; + account.balance += amount + tip; + await account.save(); await invoice.save(); await payment.save(); await user.save(); + payments.push(msg.payment_request); - l.info("lightning payment received", user.username, payment.amount, payment.tip); + l.info( + "lightning payment received", + user.username, + payment.amount, + payment.tip + ); + + user = await getUser(user.username) + l.info(user.account.balance); emit(user.username, "payment", payment); emit(user.username, "user", user); |
