aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-09-18 14:42:13 -0700
committerAdam Soltys <[email protected]>2025-09-18 14:42:13 -0700
commit8c7fa95d44aabd38fadc3ef955d835ad3379ec6c (patch)
treec5c3b9f5490acd944656438d31355081835098d3 /routes
parentd2db386e53296babe4e4068ca8d68b3c052e0efb (diff)
downloadcoinos-server-8c7fa95d44aabd38fadc3ef955d835ad3379ec6c.tar.gz
coinos-server-8c7fa95d44aabd38fadc3ef955d835ad3379ec6c.zip
sendinvoice support
Diffstat (limited to 'routes')
-rw-r--r--routes/payments.ts29
1 files changed, 29 insertions, 0 deletions
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);
+ }
+ },
};