From 06308bb12edff8e51b189b57d9f5a147959d743a Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 17 Jan 2025 11:28:30 -0800 Subject: send zaps for internal payments --- routes/nostr.ts | 2 +- routes/payments.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'routes') diff --git a/routes/nostr.ts b/routes/nostr.ts index 0ebc879b..9660227e 100644 --- a/routes/nostr.ts +++ b/routes/nostr.ts @@ -255,7 +255,7 @@ export default { const callback = await getZapEndpoint({ content } as Event); const url = new URL(callback); url.searchParams.set("amount", (amount * 1000).toString()); - url.searchParams.set("nostr", encodeURIComponent(JSON.stringify(event))); + url.searchParams.set("nostr", JSON.stringify(event)); const json = await got(url.toString()).json(); res.send(json); diff --git a/routes/payments.ts b/routes/payments.ts index ed533c76..75d667f2 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -55,9 +55,10 @@ export default { let p; + const invoice = await getInvoice(payreq || hash); + const recipient = invoice ? await getUser(invoice.uid) : undefined; if (payreq) { - const invoice = await getInvoice(payreq); - if (invoice && invoice.uid !== (await g("user:mint"))) { + if (invoice && recipient.username !== "mint") { if (invoice.aid === user.id) fail("Cannot send to self"); hash = payreq; if (!amount) ({ amount } = invoice); @@ -68,8 +69,13 @@ export default { if (!p) { if (hash) { - p = await debit({ hash, amount, memo, user }); - await credit({ hash, amount, memo, ref: user.id }); + p = await sendInternal({ + invoice, + amount, + memo, + recipient, + sender: user, + }); } else if (fund) { p = await debit({ hash, amount, memo: fund, user, type: types.fund }); await db.incrBy(`fund:${fund}`, amount); -- cgit v1.2.3