aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-08-24 21:59:18 -0700
committerAdam Soltys <[email protected]>2024-08-24 21:59:18 -0700
commit2a60293dd7e1c04df37660e5df2604c43bcad000 (patch)
tree8dddbc522fb04ffaa7c769a4e730b4dd15218839
parent9f02f34ab83fc7e11ca0bcc6e13e9f76f07dfc38 (diff)
downloadcoinos-server-2a60293dd7e1c04df37660e5df2604c43bcad000.tar.gz
coinos-server-2a60293dd7e1c04df37660e5df2604c43bcad000.zip
internal send api endpoint
-rw-r--r--index.js1
-rw-r--r--routes/payments.js20
2 files changed, 20 insertions, 1 deletions
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);
+ },
};