aboutsummaryrefslogtreecommitdiffstats
path: root/lib/nwc.ts
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 /lib/nwc.ts
parent943a1e518165d9a4e1f36af646280b28b4a6f9b4 (diff)
downloadcoinos-server-c59d608599d1a47e821f58360701d7dededd1146.tar.gz
coinos-server-c59d608599d1a47e821f58360701d7dededd1146.zip
fix nwc periods
Diffstat (limited to 'lib/nwc.ts')
-rw-r--r--lib/nwc.ts18
1 files changed, 11 insertions, 7 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);