From 6c9b2db32e4c20fea13031ed74f47086123c7539 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 3 May 2020 11:16:41 -0700 Subject: take amount param for lightning send --- routes/lightning/query.js | 6 +++--- routes/lightning/send.js | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/routes/lightning/query.js b/routes/lightning/query.js index c980b0c0..6f0dccbf 100644 --- a/routes/lightning/query.js +++ b/routes/lightning/query.js @@ -1,11 +1,11 @@ const bolt11 = require("bolt11"); module.exports = async (req, res) => { - let hash = req.body.payreq; - let payreq = bolt11.decode(hash); + let { amount, payreq } = req.body; + payreq = bolt11.decode(payreq); try { - res.send(await lna.queryRoutes({ pub_key: payreq.payeeNodeKey, amt: payreq.satoshis })); + res.send(await lna.queryRoutes({ pub_key: payreq.payeeNodeKey, amt: amount || payreq.satoshis })); } catch (e) { res.status(500).send(e.message); } diff --git a/routes/lightning/send.js b/routes/lightning/send.js index d273471a..9141bc1d 100644 --- a/routes/lightning/send.js +++ b/routes/lightning/send.js @@ -3,10 +3,12 @@ const bolt11 = require("bolt11"); module.exports = async (req, res) => { let hash = req.body.payreq; let payreq = bolt11.decode(hash); - let { route } = req.body; + let { amount, route } = req.body; let { user } = req; - l.info("attempting lightning payment", user.username, payreq.satoshis); + if (!amount) amount = payreq.satoshis; + + l.info("attempting lightning payment", user.username, amount); if (seen.includes(hash)) { l.warn("attempted to pay a paid invoice", user.username); @@ -24,11 +26,12 @@ module.exports = async (req, res) => { transaction }); - if (account.balance < payreq.satoshis) { + if (account.balance < amount) { throw new Error("Insufficient funds"); } let m = await lna.sendPaymentSync({ + amt: amount, payment_request: hash }); @@ -67,7 +70,7 @@ module.exports = async (req, res) => { emit(user.username, "user", user); if (payreq.payeeNodeKey === config.lnb.id) { - lna.addInvoice({ value: payreq.satoshis }, (err, invoice) => { + lna.addInvoice({ value: amount }, (err, invoice) => { let payback = lnb.sendPayment(lnb.meta, {}); /* eslint-disable-next-line */ -- cgit v1.2.3