From 8c7fa95d44aabd38fadc3ef955d835ad3379ec6c Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 18 Sep 2025 14:42:13 -0700 Subject: sendinvoice support --- routes/payments.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'routes') diff --git a/routes/payments.ts b/routes/payments.ts index 3d289a1d..9df20c76 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -3,6 +3,7 @@ import api from "$lib/api"; import { requirePin } from "$lib/auth"; import { db, g, s } from "$lib/db"; import { generate } from "$lib/invoices"; +import { replay } from "$lib/lightning"; import ln from "$lib/ln"; import { err, l, warn } from "$lib/logging"; import mqtt from "$lib/mqtt"; @@ -30,6 +31,7 @@ import { } from "$lib/utils"; import rpc from "@coinos/rpc"; import got from "got"; +import { v4 } from "uuid"; export default { async info(_, res) { @@ -704,4 +706,31 @@ export default { console.log(req.body); res.send(req.body); }, + + async sendinvoice(req, res) { + try { + const { user } = req; + const { invreq } = req.body; + + const { amount_msat, bolt12, pay_index } = await ln.sendinvoice({ + invreq, + label: v4(), + }); + + await generate({ + invoice: { + amount: Math.round(amount_msat / 1000), + type: "bolt12", + bolt12, + }, + user, + }); + + const p = await replay(pay_index); + + res.send(p); + } catch (e) { + bail(res, e.message); + } + }, }; -- cgit v1.2.3