diff options
| author | Adam Soltys <[email protected]> | 2024-12-18 22:15:29 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-12-18 22:15:29 -0800 |
| commit | 90d93245ab6682eb59bc700fa00f1328bd7191aa (patch) | |
| tree | 1224f2055540eaed54b0374c23e30ba9fa78e33f /lib | |
| parent | 93d494bc5d149458ea50a8d7017e155b2e1936ab (diff) | |
| download | coinos-server-90d93245ab6682eb59bc700fa00f1328bd7191aa.tar.gz coinos-server-90d93245ab6682eb59bc700fa00f1328bd7191aa.zip | |
handle internal autowithdraws
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/payments.ts | 13 |
1 files changed, 12 insertions, 1 deletions
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; |
