From 90d93245ab6682eb59bc700fa00f1328bd7191aa Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 18 Dec 2024 22:15:29 -0800 Subject: handle internal autowithdraws --- lib/payments.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/payments.ts b/lib/payments.ts index 3cc5a501..c9d1c74c 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -27,6 +27,7 @@ import { v4 } from "uuid"; const bc = rpc(config.bitcoin); const lq = rpc(config.liquid); +const { URL } = process.env; const dust = 547; @@ -165,7 +166,7 @@ export const credit = async ({ if (type === types.internal) amount += tip; const user = await getUser(inv.uid); - const { id: uid, currency, username } = user; + const { id: uid, currency } = user; const rates = await g("rates"); let rate = rates[currency]; @@ -257,6 +258,7 @@ export const completePayment = async (inv, p, user) => { }; } } catch (e) { + console.log(e); withdrawal = { failed: true }; warn(username, "autowithdraw failed", e.message); } @@ -275,6 +277,7 @@ const pay = async ({ aid = undefined, amount, to, user }) => { let pr; if (to.includes("@") && to.includes(".")) { const [name, domain] = to.split("@"); + if (URL.includes(domain)) to = name; lnurl = `https://${domain}/.well-known/lnurlp/${name}`; } else if (to.startsWith("lnurl")) { lnurl = Buffer.from( @@ -282,6 +285,14 @@ const pay = async ({ aid = undefined, amount, to, user }) => { ).toString(); } + const recipient = await getUser(to); + if (recipient) + return sendInternal({ + amount, + recipient, + sender: user, + }); + const fee = Math.max(5, Math.round(amount * 0.005)); if (lnurl) { amount -= fee; -- cgit v1.2.3