diff options
| author | Adam Soltys <[email protected]> | 2025-02-18 06:47:15 +0000 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-02-18 06:47:15 +0000 |
| commit | c59d608599d1a47e821f58360701d7dededd1146 (patch) | |
| tree | cf4c3393b46ca663067b931a81719e2fdb10f087 /lib | |
| parent | 943a1e518165d9a4e1f36af646280b28b4a6f9b4 (diff) | |
| download | coinos-server-c59d608599d1a47e821f58360701d7dededd1146.tar.gz coinos-server-c59d608599d1a47e821f58360701d7dededd1146.zip | |
fix nwc periods
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/nwc.ts | 18 | ||||
| -rw-r--r-- | lib/payments.ts | 8 |
2 files changed, 18 insertions, 8 deletions
@@ -1,7 +1,7 @@ import { db, g } from "$lib/db"; import { generate } from "$lib/invoices"; import ln from "$lib/ln"; -import { err, l } from "$lib/logging"; +import { err, warn, l } from "$lib/logging"; import { handleZap, serverPubkey, serverSecret } from "$lib/nostr"; import { sendInternal, sendKeysend, sendLightning } from "$lib/payments"; import { fail, getInvoice, sleep } from "$lib/utils"; @@ -56,6 +56,8 @@ export default () => { await nip04.decrypt(serverSecret, pubkey, content), ); + db.sAdd("activeNwc", pubkey); + if (!methods.includes(method)) return; try { @@ -106,11 +108,11 @@ const handle = (method, params, ev, app, user) => const { max_amount, budget_renewal, pubkey } = app; const periods = { - daily: 60 * 60 * 24, - weekly: 60 * 60 * 24 * 7, - monthly: 60 * 60 * 24 * 7 * 30, - yearly: 60 * 60 * 24 * 7 * 30 * 365, - never: 60 * 60 * 24 * 7 * 30 * 365 * 10, + daily: 60 * 60 * 24 * 1000, + weekly: 60 * 60 * 24 * 7 * 1000, + monthly: 60 * 60 * 24 * 30 * 1000, + yearly: 60 * 60 * 24 * 365 * 1000, + never: 60 * 60 * 24 * 365 * 10 * 1000, }; const pids = await db.lRange(`${pubkey}:payments`, 0, -1); @@ -129,11 +131,13 @@ const handle = (method, params, ev, app, user) => 0, ); - if (spent + amount > max_amount) + if (spent + amount > max_amount) { + warn("budget exceeded", pubkey, user?.username, spent, amount, max_amount); return error({ code: "INTERNAL", message: `Budget exceeded: ${spent + amount} of ${max_amount}`, }); + } if (payee === id) { const invoice = await getInvoice(pr); diff --git a/lib/payments.ts b/lib/payments.ts index 7a862668..9c819866 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -54,14 +54,20 @@ export const debit = async ({ rate = undefined, }) => { amount = parseInt(amount); + const whitelisted = await db.sIsMember( "whitelist", user?.username?.toLowerCase().trim(), ); + const blacklisted = await db.sIsMember( + "blacklist", + user?.username?.toLowerCase().trim(), + ); + let serverLimit = await g(`${type}:limit`); let userLimit = await g("limit"); - let frozen = (await g("hardfreeze")) || ((await g("freeze")) && type !== types.internal); + let frozen = (await g("hardfreeze")) || ((await g("freeze")) && type !== types.internal) || blacklisted; if (frozen || (amount > userLimit && !whitelisted) || amount > serverLimit) { warn("Blocking", user.username, amount, hash, user.id, type, frozen, userLimit, serverLimit); |
