From 765eeed9c926ff83221d22af664c9a79f762a24d Mon Sep 17 00:00:00 2001 From: Overtorment Date: Sat, 5 Jan 2019 14:52:27 +0000 Subject: [PATCH] ADD: pay for zero-amount (tip) invoices --- controllers/api.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/controllers/api.js b/controllers/api.js index 06725c8..32fbffa 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -106,12 +106,19 @@ router.post('/payinvoice', async function(req, res) { } if (!req.body.invoice) return errorBadArguments(res); + let freeAmount = false; + if (req.body.amount) freeAmount = parseInt(req.body.amount); let userBalance = await u.getBalance(); lightning.decodePayReq({ pay_req: req.body.invoice }, async function(err, info) { if (err) return errorNotAValidInvoice(res); + if (+info.num_satoshis === 0) { + // 'tip' invoices + info.num_satoshis = freeAmount; + } + if (userBalance >= info.num_satoshis) { // got enough balance @@ -158,7 +165,7 @@ router.post('/payinvoice', async function(req, res) { return errorLnd(res); } }); - let inv = { payment_request: req.body.invoice }; + let inv = { payment_request: req.body.invoice, amt: info.num_satoshis }; // amt is used only for 'tip' invoices call.write(inv); } else { return errorNotEnougBalance(res);