From 95e543d1060ba7f0cd5b249b4dacceb977e23df8 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 18 Aug 2024 23:37:56 -0700 Subject: allow specifying bolt11 invoice --- lib/invoices.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'lib') 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; -- cgit v1.2.3