aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-06-23 08:48:52 -0700
committerAdam Soltys <[email protected]>2025-06-23 08:50:12 -0700
commit6aa385b4bcfe5a97bbf21263126f61adcd3bc606 (patch)
tree68a65dc4c92e8df1823dcba7047d9680546f9678
parente92f232d7194626d9182a5eaeff3d42d67fbb53f (diff)
downloadcoinos-server-6aa385b4bcfe5a97bbf21263126f61adcd3bc606.tar.gz
coinos-server-6aa385b4bcfe5a97bbf21263126f61adcd3bc606.zip
mark self-generated invoices
-rw-r--r--lib/invoices.ts3
-rw-r--r--routes/invoices.ts7
-rw-r--r--routes/lnurl.ts16
3 files changed, 20 insertions, 6 deletions
diff --git a/lib/invoices.ts b/lib/invoices.ts
index f6ad65e8..d624ac6b 100644
--- a/lib/invoices.ts
+++ b/lib/invoices.ts
@@ -23,6 +23,7 @@ export const generate = async ({ invoice, user }) => {
tip,
amount,
items = [],
+ own,
rate,
request_id,
memo,
@@ -38,6 +39,7 @@ export const generate = async ({ invoice, user }) => {
if (user) user = await getUser(user.username);
if (!user) fail("user not provided");
+ if (typeof prompt === "undefined") prompt = user.prompt;
let account = await g(`account:${aid}`);
if (!account) account = await g(`account:${user.id}`);
@@ -134,6 +136,7 @@ export const generate = async ({ invoice, user }) => {
received: 0,
request_id,
memoPrompt,
+ own,
path,
prompt,
secret,
diff --git a/routes/invoices.ts b/routes/invoices.ts
index 0881c69f..ecac713c 100644
--- a/routes/invoices.ts
+++ b/routes/invoices.ts
@@ -24,11 +24,14 @@ export default {
async create(req, res) {
let { body, user } = req;
- if (body.user) user = body.user;
const { invoice } = body;
+ if (body.user) user = body.user;
+ if (req.user.username === user.username) invoice.own = true;
+
try {
- res.send(await generate({ invoice, user }));
+ const result = await generate({ invoice, user });
+ res.send(result);
} catch (e) {
err(
"problem generating invoice",
diff --git a/routes/lnurl.ts b/routes/lnurl.ts
index e5b3e60c..18785164 100644
--- a/routes/lnurl.ts
+++ b/routes/lnurl.ts
@@ -46,7 +46,8 @@ export default {
bech32.fromWords(bech32.decode(text, 20000).words),
).toString();
- res.send(await got(url).json());
+ const r = await got(url).json();
+ res.send(r);
} catch (e) {
bail(res, e.message);
}
@@ -156,11 +157,18 @@ export default {
try {
const user = await getUser(username);
const iid = await db.lIndex(`${user.id}:invoices`, 0);
- const invoice = await getInvoice(iid);
+ let invoice = await getInvoice(iid);
const fiveMinutes = 1000 * 60 * 5;
const paid = invoice.received >= invoice.amount;
const expired = Date.now() - invoice.created > fiveMinutes;
- if (paid || expired) fail("No active invoice");
+ if (paid || expired || !invoice.own) {
+ invoice = await generate({
+ invoice: {
+ type: PaymentType.lightning,
+ },
+ user,
+ });
+ }
const { id: uid } = user;
@@ -175,7 +183,7 @@ export default {
res.send({
allowsNostr: true,
minSendable: invoice.amount * 1000,
- maxSendable: invoice.amount * 1000,
+ maxSendable: invoice.amount ? invoice.amount * 1000 : undefined,
metadata,
nostrPubkey: serverPubkey,
commentAllowed: 512,