aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-08-18 23:37:56 -0700
committerAdam Soltys <[email protected]>2024-08-18 23:37:56 -0700
commit95e543d1060ba7f0cd5b249b4dacceb977e23df8 (patch)
treee723bca71ab44e3bd566efe0b810810a8a3cee9e /lib
parent0c55be9b7ac1067314826944655f0b4f08a6afa4 (diff)
downloadcoinos-server-95e543d1060ba7f0cd5b249b4dacceb977e23df8.tar.gz
coinos-server-95e543d1060ba7f0cd5b249b4dacceb977e23df8.zip
allow specifying bolt11 invoice
Diffstat (limited to 'lib')
-rw-r--r--lib/invoices.js26
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;