aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-07-16 00:04:56 -0700
committerAdam Soltys <[email protected]>2025-07-16 00:04:56 -0700
commit428fb7d17e393304641a9438500faecd8775672a (patch)
treeaf33aa88276ece6333bee975354aa1a3fb200243
parent53a4d40f6861312a6fc6e6d99c317a0d82eda32f (diff)
downloadcoinos-server-428fb7d17e393304641a9438500faecd8775672a.tar.gz
coinos-server-428fb7d17e393304641a9438500faecd8775672a.zip
record lnurl invoice
-rw-r--r--lib/auth.ts4
-rw-r--r--routes/lnurl.ts31
2 files changed, 21 insertions, 14 deletions
diff --git a/lib/auth.ts b/lib/auth.ts
index 29edcf61..0dfff4ec 100644
--- a/lib/auth.ts
+++ b/lib/auth.ts
@@ -1,7 +1,7 @@
-import fastifyPassport from "@fastify/passport";
+import config from "$config";
import { g } from "$lib/db";
import { fail, getUser } from "$lib/utils";
-import config from "$config";
+import fastifyPassport from "@fastify/passport";
import jwt from "passport-jwt";
export const admin = {
diff --git a/routes/lnurl.ts b/routes/lnurl.ts
index 0f17a52d..b1b7b8f0 100644
--- a/routes/lnurl.ts
+++ b/routes/lnurl.ts
@@ -1,9 +1,7 @@
import { db, g, s } from "$lib/db";
import { generate } from "$lib/invoices";
-import ln from "$lib/ln";
import { err, warn } from "$lib/logging";
import { serverPubkey } from "$lib/nostr";
-import { credit } from "$lib/payments";
import { bail, fail, getInvoice, getUser } from "$lib/utils";
import { bech32 } from "bech32";
import got from "got";
@@ -102,6 +100,7 @@ export default {
query: { amount, comment, nostr },
} = req;
try {
+ const iid = await g(`lnurl:${id}:invoice`);
const uid = await g(`lnurl:${id}`);
const user = await getUser(uid);
if (!user) fail("user not found");
@@ -125,16 +124,22 @@ export default {
}
}
- const { id: iid, text: pr } = await generate({
- invoice: {
- amount: Math.round(amount / 1000),
- memo: metadata,
- type: PaymentType.lightning,
- },
- user,
- });
+ const invoice = iid
+ ? await g(`invoice:${iid}`)
+ : await generate({
+ invoice: {
+ amount: Math.round(amount / 1000),
+ memo: metadata,
+ type: PaymentType.lightning,
+ },
+ user,
+ });
- res.send({ pr, routes: [], verify: `${URL}/api/lnurl/verify/${iid}` });
+ res.send({
+ pr: invoice.text,
+ routes: [],
+ verify: `${URL}/api/lnurl/verify/${invoice.id}`,
+ });
} catch (e) {
bail(res, e.message);
}
@@ -188,7 +193,9 @@ export default {
const id = v4();
await s(`lnurl:${id}`, uid);
- const total = (parseInt(invoice.amount || 0) + parseInt(invoice.tip || 0)) * 1000;
+ await s(`lnurl:${id}:invoice`, invoice.id);
+ const total =
+ (parseInt(invoice.amount || 0) + parseInt(invoice.tip || 0)) * 1000;
res.send({
allowsNostr: true,