diff options
| author | Adam Soltys <[email protected]> | 2025-08-10 18:53:31 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-08-10 18:53:34 -0700 |
| commit | 05b18b10c42fe6a21549f05813db6adad59e3362 (patch) | |
| tree | 4c7cfd8973b743c11a34bb646d12938727875b59 | |
| parent | 7d914fe065dbe31f22853db2fa3e2a1c8bc1fbd2 (diff) | |
| download | coinos-server-05b18b10c42fe6a21549f05813db6adad59e3362.tar.gz coinos-server-05b18b10c42fe6a21549f05813db6adad59e3362.zip | |
authorizations
| -rw-r--r-- | index.ts | 3 | ||||
| -rw-r--r-- | routes/payments.ts | 30 |
2 files changed, 27 insertions, 6 deletions
@@ -70,11 +70,12 @@ app.post("/payments", auth, payments.create); app.get("/payments", auth, payments.list); app.get("/payments/:hash", payments.get); app.post("/parse", auth, payments.parse); -app.get("/fund/:name", payments.fund); +app.get("/fund/:id", payments.fund); // app.get("/fund/:name/withdraw", auth, payments.withdraw); app.get("/fund/:name/managers", payments.managers); app.post("/fund/managers", auth, payments.addManager); app.post("/fund/:name/managers/delete", auth, payments.deleteManager); +app.post("/authorize", auth, payments.authorize); app.post("/take", auth, payments.take); app.post("/print", auth, payments.print); app.post("/send/:lnaddress/:amount", auth, payments.lnaddress); diff --git a/routes/payments.ts b/routes/payments.ts index 1aab736f..def8dc69 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -229,12 +229,12 @@ export default { async fund(req, res) { const { - params: { name }, + params: { id }, } = req; - const amount = await g(`fund:${name}`); + const amount = await g(`fund:${id}`); if (typeof amount === "undefined" || amount === null) return bail(res, "fund not found"); - let payments = (await db.lRange(`fund:${name}:payments`, 0, -1)) || []; + let payments = (await db.lRange(`fund:${id}:payments`, 0, -1)) || []; payments = await Promise.all(payments.map((hash) => g(`payment:${hash}`))); await Promise.all( @@ -242,7 +242,9 @@ export default { ); payments = payments.filter((p) => p); - res.send({ amount, payments }); + + const { amount: authorization } = await g(`authorization:${id}`); + res.send({ amount, authorization, payments }); }, // async withdraw(req, res) { @@ -263,6 +265,24 @@ export default { // }); // }, + async authorize(req, res) { + const { id: uid } = req.user; + const { id, fiat, currency, amount } = req.body; + + const managers = await db.sMembers(`fund:${id}:managers`); + if (managers.length && !managers.includes(uid)) fail("Unauthorized"); + + const authorization = { + uid, + currency, + fiat, + amount, + }; + + await s(`authorization:${id}`, authorization); + res.send({}); + }, + async take(req, res) { let { body: { id, amount, invoice: iid }, @@ -285,7 +305,7 @@ export default { const authorization = await g(`authorization:${id}`); if (authorization && !authorization.claimed) { const { currency, fiat } = authorization; - amount = sats(fiat / rates[currency]); + amount = Math.min(amount, sats(fiat / rates[currency])); const sender = await getUser(authorization.uid); authorization.claimed = true; |
