From 2a60293dd7e1c04df37660e5df2604c43bcad000 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 24 Aug 2024 21:59:18 -0700 Subject: internal send api endpoint --- index.js | 1 + routes/payments.js | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 5d1a4ebd..376bca71 100644 --- a/index.js +++ b/index.js @@ -64,6 +64,7 @@ app.get("/fund/:name/withdraw", payments.withdraw); app.post("/take", auth, payments.take); app.post("/print", auth, payments.print); app.post("/send/:lnaddress/:amount", auth, payments.lnaddress); +app.post("/send", auth, payments.internal); app.post("/gateway", payments.gateway); app.post("/replace", auth, payments.replace); diff --git a/routes/payments.js b/routes/payments.js index e16156b5..1ae87916 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -1,9 +1,10 @@ import config from "$config"; import { emit } from "$lib/sockets"; +import { generate } from "$lib/invoices"; import { v4 } from "uuid"; import { db, g, s, t } from "$lib/db"; import { l, err, warn } from "$lib/logging"; -import { bail, fail, getInvoice, btc, sats, SATS } from "$lib/utils"; +import { bail, fail, getInvoice, btc, sats, SATS, getUser } from "$lib/utils"; import { requirePin } from "$lib/auth"; import { completePayment, @@ -457,4 +458,21 @@ export default { bail(res, e.message); } }, + + async internal({ body: { username, amount }, user: sender }, res) { + let recipient = await getUser(username); + let inv = await generate({ + invoice: { amount, type: "lightning" }, + user: recipient, + sender, + }); + + let { hash } = inv; + let memo; + + let p = await debit({ hash, amount, memo, user: sender }); + await credit(hash, amount, memo, recipient.id); + + res.send(p); + }, }; -- cgit v1.2.3