ADD: pay for zero-amount (tip) invoices
This commit is contained in:
parent
bc5841d07d
commit
765eeed9c9
@ -106,12 +106,19 @@ router.post('/payinvoice', async function(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!req.body.invoice) return errorBadArguments(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();
|
let userBalance = await u.getBalance();
|
||||||
|
|
||||||
lightning.decodePayReq({ pay_req: req.body.invoice }, async function(err, info) {
|
lightning.decodePayReq({ pay_req: req.body.invoice }, async function(err, info) {
|
||||||
if (err) return errorNotAValidInvoice(res);
|
if (err) return errorNotAValidInvoice(res);
|
||||||
|
|
||||||
|
if (+info.num_satoshis === 0) {
|
||||||
|
// 'tip' invoices
|
||||||
|
info.num_satoshis = freeAmount;
|
||||||
|
}
|
||||||
|
|
||||||
if (userBalance >= info.num_satoshis) {
|
if (userBalance >= info.num_satoshis) {
|
||||||
// got enough balance
|
// got enough balance
|
||||||
|
|
||||||
@ -158,7 +165,7 @@ router.post('/payinvoice', async function(req, res) {
|
|||||||
return errorLnd(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);
|
call.write(inv);
|
||||||
} else {
|
} else {
|
||||||
return errorNotEnougBalance(res);
|
return errorNotEnougBalance(res);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user