Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import { PERMISSIONS } from "@hey/data/constants";
2import { Status } from "@hey/data/enums";
3import type { Context } from "hono";
4import handleApiError from "@/utils/handleApiError";
5import lensPg from "@/utils/lensPg";
6
7const totalSubscribers = async (ctx: Context) => {
8 try {
9 const accounts = (await lensPg.query(
10 `
11 SELECT DISTINCT ksw.owned_by
12 FROM account.known_smart_wallet ksw
13 INNER JOIN "group"."member" AS member ON ksw.address = member.account
14 WHERE member."group" = $1;
15 `,
16 [`\\x${PERMISSIONS.SUBSCRIPTION.replace("0x", "").toLowerCase()}`]
17 )) as Array<{ owned_by: Buffer }>;
18
19 const addresses = accounts.map((account) =>
20 `0x${account.owned_by.toString("hex")}`.toLowerCase()
21 );
22
23 return ctx.json({
24 status: Status.Success,
25 total: addresses.length
26 });
27 } catch (error) {
28 return handleApiError(ctx, error);
29 }
30};
31
32export default totalSubscribers;