From 43c2abbe6958a5de995b3cead5179ea3447ffca5 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 5 Mar 2020 15:26:15 -0800 Subject: additional logging --- bitcoinPayments.js | 2 ++ lightningPayments.js | 3 +++ liquidPayments.js | 2 ++ sendCoins.js | 23 ++++++++++++----------- sendLiquid.js | 3 ++- sendPayment.js | 4 ++-- users.js | 5 +++++ 7 files changed, 28 insertions(+), 14 deletions(-) diff --git a/bitcoinPayments.js b/bitcoinPayments.js index 8b44757a..64a50e58 100644 --- a/bitcoinPayments.js +++ b/bitcoinPayments.js @@ -89,6 +89,7 @@ module.exports = (app, bc, db, addresses, payments, emit) => { asset: 'BTC', }); + l.info("bitcoin detected", user.username, o.value); emit(user.username, "payment", payment); } }) @@ -142,6 +143,7 @@ module.exports = (app, bc, db, addresses, payments, emit) => { limit: 12 }); + l.info("bitcoin confirmed", user.username, p.amount); emit(user.username, "payments", payments); delete queue[hash]; } diff --git a/lightningPayments.js b/lightningPayments.js index 9b3eef78..096655bf 100644 --- a/lightningPayments.js +++ b/lightningPayments.js @@ -1,3 +1,5 @@ +const l = require("pino")(); + module.exports = (app, db, lna, lnb, emit, payments) => { const handlePayment = async msg => { if (!msg.settled) return; @@ -22,6 +24,7 @@ module.exports = (app, db, lna, lnb, emit, payments) => { 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); diff --git a/liquidPayments.js b/liquidPayments.js index 4549ba08..8ed5507a 100644 --- a/liquidPayments.js +++ b/liquidPayments.js @@ -86,6 +86,7 @@ module.exports = (app, db, addresses, payments, emit) => { }); payments.push(blinded.txid); + l.info("liquid detected", user.username, value); emit(user.username, "payment", payment); } }) @@ -126,6 +127,7 @@ module.exports = (app, db, addresses, payments, emit) => { let user = await p.getUser(); user.balance += p.amount; user.pending -= p.amount; + l.info("liquid confirmed", user.username, p.amount); emit(user.username, "user", user); await user.save(); diff --git a/sendCoins.js b/sendCoins.js index 22c22a42..00e2fa99 100644 --- a/sendCoins.js +++ b/sendCoins.js @@ -6,6 +6,7 @@ const l = require("pino")(); const SATS = 100000000; module.exports = (app, bc, db, emit) => async (req, res) => { + let { user } = req; let { address, amount } = req.body; let rawtx, hex, fee, total; @@ -17,7 +18,7 @@ module.exports = (app, bc, db, emit) => async (req, res) => { }); rawtx = await bc.fundRawTransaction(rawtx, { - subtractFeeFromOutputs: amount === req.user.balance ? [0] : [] + subtractFeeFromOutputs: amount === user.balance ? [0] : [] }); ({ hex, fee } = rawtx); @@ -29,11 +30,10 @@ module.exports = (app, bc, db, emit) => async (req, res) => { } try { - l.info("sending coins", req.user.username, amount, fee, address); await db.transaction(async transaction => { let { balance } = await db.User.findOne({ where: { - username: req.user.username + username: user.username }, lock: transaction.LOCK.UPDATE, transaction @@ -44,8 +44,8 @@ module.exports = (app, bc, db, emit) => async (req, res) => { throw new Error("insufficient funds"); } - req.user.balance -= total; - await req.user.save({ transaction }); + user.balance -= total; + await user.save({ transaction }); }); } catch (e) { l.error(e); @@ -62,17 +62,17 @@ module.exports = (app, bc, db, emit) => async (req, res) => { let tx = bitcoin.Transaction.fromHex(rawtx); await db.transaction(async transaction => { - await req.user.save({ transaction }); - emit(req.user.username, "user", req.user); + await user.save({ transaction }); + emit(user.username, "user", user); const payment = await db.Payment.create( { amount: -total, fee, - user_id: req.user.id, + user_id: user.id, hash: txid, - rate: app.get("rates")[req.user.currency], - currency: req.user.currency, + rate: app.get("rates")[user.currency], + currency: user.currency, address, confirmed: true, received: false, @@ -81,7 +81,8 @@ module.exports = (app, bc, db, emit) => async (req, res) => { { transaction } ); - emit(req.user.username, "payment", payment); + l.info("sent bitcoin", user.username, total); + emit(user.username, "payment", payment); res.send(payment); }); } catch (e) { diff --git a/sendLiquid.js b/sendLiquid.js index a4d9413e..855a2617 100644 --- a/sendLiquid.js +++ b/sendLiquid.js @@ -45,7 +45,7 @@ module.exports = (app, db, emit) => async (req, res) => { }); if (amount !== balance && total > balance) { - l.error("amount exceeds balance", amount, fee, balance); + l.warn("amount exceeds balance", { amount, fee, balance }); throw new Error("insufficient funds"); } @@ -84,6 +84,7 @@ module.exports = (app, db, emit) => async (req, res) => { { transaction } ); + l.info("sent liquid", user.username, total); emit(user.username, "payment", payment); res.send(payment); }); diff --git a/sendPayment.js b/sendPayment.js index ad92ef52..31e3f602 100644 --- a/sendPayment.js +++ b/sendPayment.js @@ -9,9 +9,8 @@ module.exports = (app, db, emit, seen, lna, lnb) => async (req, res) => { let { route } = req.body; let { user } = req; - l.info("sending lightning", user.username, payreq.satoshis); - if (seen.includes(hash)) { + l.warn("attempted to pay a paid invoice", user.username); return res.status(500).send("Invoice has been paid, can't pay again"); } @@ -70,6 +69,7 @@ module.exports = (app, db, emit, seen, lna, lnb) => async (req, res) => { { transaction } ); + l.info("sent lightning", user.username, -payment.amount); emit(user.username, "payment", payment); emit(user.username, "user", user); diff --git a/users.js b/users.js index 1d73c12d..2cc43361 100644 --- a/users.js +++ b/users.js @@ -102,6 +102,7 @@ module.exports = (addresses, auth, app, bc, db, emit) => { user = await db.User.create(user); await gift(user); + l.info("new user", user.username); res.send(pick(user, ...whitelist)); }); @@ -161,6 +162,7 @@ module.exports = (addresses, auth, app, bc, db, emit) => { await user.save(); emit(user.username, "user", user); emit(user.username, "otpsecret", user.otpsecret); + l.info("disabled 2fa", user.username); res.end(); }); @@ -184,6 +186,8 @@ module.exports = (addresses, auth, app, bc, db, emit) => { } catch (e) { l.error(e); } + + l.info("enabled 2fa", user.username); res.end(); }); @@ -408,6 +412,7 @@ module.exports = (addresses, auth, app, bc, db, emit) => { addresses[user.address] = user.username; addresses[user.liquid] = user.username; await gift(user); + l.info("new facebook user", user.name); } if (user.twofa && (typeof twofa === "undefined" || !authenticator.check(twofa, user.otpsecret))) -- cgit v1.2.3