diff options
| -rw-r--r-- | lib/invoices.js | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/invoices.js b/lib/invoices.js index b07ac1f5..557d0de6 100644 --- a/lib/invoices.js +++ b/lib/invoices.js @@ -13,6 +13,7 @@ import ln from "$lib/ln"; export let generate = async ({ invoice, user, sender }) => { let { + bolt11, currency, expiry, fiat, @@ -48,14 +49,23 @@ export let generate = async ({ invoice, user, sender }) => { let hash, text; if (type === types.lightning) { - let r = await ln.invoice({ - amount_msat: amount ? `${amount + tip}sat` : "any", - label: id, - description: memo || "", - expiry: expiry || 60 * 60 * 24 * 30, - deschashonly: true, - cltv: 19, - }); + let r; + if (bolt11) { + let { id: nodeid } = await ln.getinfo(); + r = await ln.decode(bolt11); + if (r.payee !== nodeid) fail("invalid invoice"); + amount = Math.round(r.amount_msat / 1000); + r.bolt11 = bolt11; + } else { + r = await ln.invoice({ + amount_msat: amount ? `${amount + tip}sat` : "any", + label: id, + description: memo || "", + expiry: expiry || 60 * 60 * 24 * 30, + deschashonly: true, + cltv: 19, + }); + } hash = r.bolt11; text = r.bolt11; |
