aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-05-03 11:16:41 -0700
committerAdam Soltys <[email protected]>2020-05-03 11:16:41 -0700
commit6c9b2db32e4c20fea13031ed74f47086123c7539 (patch)
tree4b147bf435a7ab0ea7f7e0707449f754ac8af9ed
parentc2f6dd746000d561750d1e32c05cc814e39a40ce (diff)
downloadcoinos-server-6c9b2db32e4c20fea13031ed74f47086123c7539.tar.gz
coinos-server-6c9b2db32e4c20fea13031ed74f47086123c7539.zip
take amount param for lightning send
-rw-r--r--routes/lightning/query.js6
-rw-r--r--routes/lightning/send.js11
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 */