aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-02-18 06:47:15 +0000
committerAdam Soltys <[email protected]>2025-02-18 06:47:15 +0000
commitc59d608599d1a47e821f58360701d7dededd1146 (patch)
treecf4c3393b46ca663067b931a81719e2fdb10f087
parent943a1e518165d9a4e1f36af646280b28b4a6f9b4 (diff)
downloadcoinos-server-c59d608599d1a47e821f58360701d7dededd1146.tar.gz
coinos-server-c59d608599d1a47e821f58360701d7dededd1146.zip
fix nwc periods
-rw-r--r--lib/nwc.ts18
-rw-r--r--lib/payments.ts8
2 files changed, 18 insertions, 8 deletions
diff --git a/lib/nwc.ts b/lib/nwc.ts
index 0a41a0e5..1f3e7444 100644
--- a/lib/nwc.ts
+++ b/lib/nwc.ts
@@ -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);