aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-03-04 11:10:49 -0800
committerAdam Soltys <[email protected]>2026-03-04 11:10:49 -0800
commit6781fd2935ebc3abdeed182b4cee62c25c5482e7 (patch)
tree45a815255b9d04bbfc50f992770e053256433ac2
parent1f10995adc4dca6831f1c128c7bbbded74c641f0 (diff)
downloadcoinos-server-6781fd2935ebc3abdeed182b4cee62c25c5482e7.tar.gz
coinos-server-6781fd2935ebc3abdeed182b4cee62c25c5482e7.zip
funds route
-rw-r--r--index.ts1
-rw-r--r--routes/payments.ts19
-rw-r--r--routes/users.ts2
3 files changed, 22 insertions, 0 deletions
diff --git a/index.ts b/index.ts
index f879b65f..ef6d9778 100644
--- a/index.ts
+++ b/index.ts
@@ -102,6 +102,7 @@ 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("/funds", auth, payments.funds);
app.get("/fund/:id", payments.fund);
app.get("/fund/:name/managers", payments.managers);
app.post("/fund/managers", auth, payments.addManager);
diff --git a/routes/payments.ts b/routes/payments.ts
index f58304cd..dd679816 100644
--- a/routes/payments.ts
+++ b/routes/payments.ts
@@ -153,6 +153,7 @@ export default {
});
await tbFundCredit(fund, amount);
await db.lPush(`fund:${fund}:payments`, p.id);
+ await db.sAdd(`user:${user.id}:funds`, fund);
l("funded fund", fund);
}
}
@@ -332,6 +333,22 @@ export default {
}
},
+ async funds(c) {
+ const user = c.get("user");
+ const fundIds = [...await db.sMembers(`user:${user.id}:funds`)];
+
+ const funds = await Promise.all(
+ fundIds.map(async (id) => {
+ const amount = await getFundBalance(id);
+ if (amount === null) return null;
+ const managers = [...await db.sMembers(`fund:${id}:managers`)];
+ return { id, amount, managed: managers.includes(user.id), managers: managers.length };
+ }),
+ );
+
+ return c.json(funds.filter(Boolean));
+ },
+
async fund(c) {
const id = c.req.param("id");
const amount = await getFundBalance(id);
@@ -409,6 +426,7 @@ export default {
await tbFundCredit(id, amount);
await db.lPush(`fund:${id}:payments`, pid);
+ await db.sAdd(`user:${sender.id}:funds`, id);
l("funded fund", id);
}
@@ -428,6 +446,7 @@ export default {
});
await db.lPush(`fund:${id}:payments`, payment.id);
+ await db.sAdd(`user:${user.id}:funds`, id);
return c.json(payment);
} catch (e) {
diff --git a/routes/users.ts b/routes/users.ts
index 78fddbc9..88c77846 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -418,6 +418,8 @@ export default {
}
}
+ if (!user) return c.json({}, 401);
+
if (body.authPubkey && !user.authPubkey) {
user.authPubkey = body.authPubkey;
await s(`user:${user.id}`, user);