diff options
| author | Adam Soltys <[email protected]> | 2024-03-08 04:31:34 +0000 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-03-08 04:31:34 +0000 |
| commit | 972ea530e8139a0357b6b45ccdf9742d19ba6a26 (patch) | |
| tree | eb2774d174c12e7304694d1793811d0ae0abf685 | |
| parent | 2bd73639038bbc9cd4c75758eda685c89011231f (diff) | |
| download | coinos-server-972ea530e8139a0357b6b45ccdf9742d19ba6a26.tar.gz coinos-server-972ea530e8139a0357b6b45ccdf9742d19ba6a26.zip | |
validate tips
| -rw-r--r-- | index.js | 8 | ||||
| -rw-r--r-- | lib/app.js | 4 | ||||
| -rw-r--r-- | lib/db.js | 7 | ||||
| -rw-r--r-- | lib/invoices.js | 1 | ||||
| -rw-r--r-- | lib/migrate.js | 2 | ||||
| -rw-r--r-- | lib/payments.js | 1 | ||||
| -rw-r--r-- | routes/info.js | 6 | ||||
| -rw-r--r-- | routes/invoices.js | 1 |
8 files changed, 24 insertions, 6 deletions
@@ -114,13 +114,17 @@ app.post("/requests/delete", auth, requests.destroy); app.post("/shopify/:id", shopify); app.post("/hidepay", admin, users.hidepay); - app.post("/unlimit", admin, users.unlimit); +app.post("/unlimit", admin, users.unlimit); let host = process.env.HOST || "0.0.0.0"; let port = process.env.PORT || 3119; app.listen({ host, port }); -let logerr = (e) => e.message.startsWith("MASK") || console.log(e); +let logerr = (e) => + e.message.includes("MASK") || + e.message.startsWith("Rate") || + console.log(e); + process.on("unhandledRejection", logerr); process.on("uncaughtException", logerr); @@ -20,8 +20,8 @@ const app = fastify({ }); await app.register(import("@fastify/rate-limit"), { - max: 500, - timeWindow: 5000, + max: 50, + timeWindow: 2000, keyGenerator: (req) => req.headers["cf-connecting-ip"], }); @@ -48,6 +48,13 @@ export let archive = createClient({ }, }); +export let arc2 = createClient({ + url: config.arc2, + socket: { + reconnectStrategy: (retries) => Math.min(retries * 50, 5000), + }, +}); + async function dbReconnect() { try { await db.connect(); diff --git a/lib/invoices.js b/lib/invoices.js index 89c4f3d6..633072f3 100644 --- a/lib/invoices.js +++ b/lib/invoices.js @@ -40,6 +40,7 @@ export let generate = async ({ invoice, user, sender, }) => { if (!rate) rate = store.rates[currency]; if (fiat) amount = Math.round((SATS * fiat) / rate); if (amount < 0) fail("invalid amount"); + if (tip< 0) fail("invalid tip"); if (memo && memo.length > 200) fail("memo too long"); let id = v4(); diff --git a/lib/migrate.js b/lib/migrate.js index 106a6b5f..15ce4a16 100644 --- a/lib/migrate.js +++ b/lib/migrate.js @@ -1,6 +1,6 @@ import { err, warn, l, line } from "$lib/logging"; import { types } from "$lib/payments"; -import { archive, db, g, ga, s } from "$lib/db"; +import { archive, arc2, db, g, ga, s } from "$lib/db"; import { wait } from "$lib/utils"; let queued = {}; diff --git a/lib/payments.js b/lib/payments.js index 76286938..03085280 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -73,6 +73,7 @@ export let debit = async ({ } let tip = parseInt(invoice?.tip) || null; + if (tip < 0) fail("Invalid tip"); if (!amount || amount < 0) fail("Amount must be greater than zero"); diff --git a/routes/info.js b/routes/info.js index 13b1de57..f2e262f6 100644 --- a/routes/info.js +++ b/routes/info.js @@ -1,3 +1,4 @@ +import { archive } from "$lib/db"; import db from "$lib/db"; import ln from "$lib/ln"; @@ -7,10 +8,15 @@ export default { let lnwallet; let total = 0; + for await (let k of db.scanIterator({ MATCH: "balance:*" })) { total += parseInt(await db.get(k)); } + for await (let k of archive.scanIterator({ MATCH: "balance:*" })) { + total += parseInt(await archive.get(k)); + } + const funds = await ln.listfunds(); lnchannel = parseInt(funds.channels.reduce((a, b) => a + b.channel_sat, 0)); lnwallet = parseInt(funds.outputs.reduce((a, b) => a + b.value, 0)); diff --git a/routes/invoices.js b/routes/invoices.js index 7a9a0d1d..5cc60e05 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -32,7 +32,6 @@ export default { try { res.send(await generate({ invoice, user, sender })); } catch (e) { - console.log(e); bail(res, e.message); } }, |
