Skip to content

Commit eea69d0

Browse files
Revert "migrate to new indexer (#36)"
This reverts commit cd9ceda.
1 parent cd9ceda commit eea69d0

File tree

7 files changed

+56
-120
lines changed

7 files changed

+56
-120
lines changed

src/controllers/evaluationController.ts

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,13 @@ export const recreateEvaluationQuestions = async (
108108
return;
109109
}
110110

111-
const [errorReset] = await catchError(
112-
evaluationQuestionService.resetEvaluationQuestions(
113-
chainId,
114-
alloPoolId,
115-
evaluationQuestions
116-
)
111+
await evaluationQuestionService.resetEvaluationQuestions(
112+
chainId,
113+
alloPoolId,
114+
evaluationQuestions
117115
);
118116

119-
if (errorReset !== undefined) {
120-
logger.error('Failed to reset evaluation questions', { errorReset });
121-
res.status(500).json({ message: 'Failed to reset evaluation questions' });
122-
return;
123-
}
124-
125-
const [errorClean] = await catchError(evaluationService.cleanEvaluations());
126-
127-
if (errorClean !== undefined) {
128-
logger.error('Failed to clean evaluations', { errorClean });
129-
res.status(500).json({ message: 'Failed to clean evaluations' });
130-
return;
131-
}
117+
await evaluationService.cleanEvaluations();
132118

133119
res.status(200).json(evaluationQuestions);
134120
};
@@ -164,16 +150,14 @@ export const evaluateApplication = async (
164150
summaryInput,
165151
};
166152

167-
const [isAllowedError, isAllowed] = await catchError(
168-
isPoolManager<CreateEvaluationParams>(
169-
createEvaluationParams,
170-
signature,
171-
chainId,
172-
alloPoolId
173-
)
153+
const isAllowed = await isPoolManager<CreateEvaluationParams>(
154+
createEvaluationParams,
155+
signature,
156+
chainId,
157+
alloPoolId
174158
);
175159

176-
if (isAllowedError !== undefined || isAllowed === undefined) {
160+
if (!isAllowed) {
177161
logger.warn(
178162
`User with address: ${evaluator} is not allowed to evaluate application`
179163
);
@@ -317,17 +301,16 @@ export const triggerLLMEvaluation = async (
317301
questions,
318302
};
319303

320-
const [error] = await catchError(createLLMEvaluations([data]));
321-
if (error !== undefined) {
304+
try {
305+
await createLLMEvaluations([data]);
306+
res.status(200).json({ message: 'LLM evaluation triggered successfully' });
307+
} catch (error) {
322308
logger.error('Failed to create evaluations:', error);
323309
res.status(500).json({
324310
message: 'Failed to create evaluations',
325311
error: error.message,
326312
});
327313
}
328-
329-
logger.info('LLM evaluation triggered successfully');
330-
res.status(200).json({ message: 'LLM evaluation triggered successfully' });
331314
};
332315

333316
const batchPromises = <T>(array: T[], batchSize: number): T[][] => {
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import type { Request, Response } from 'express';
2-
import { catchError, validateRequest } from '@/utils';
2+
import { validateRequest } from '@/utils';
33
import type { ProjectApplicationForManager } from '@/ext/passport/types';
44
import { isVerified } from '@/ext/passport/credentialverification';
5-
import { createLogger } from '@/logger';
65

76
interface SocialCredentialBody {
87
application: Partial<ProjectApplicationForManager>;
98
}
109

11-
const logger = createLogger();
12-
1310
export const validateSocialCredential = async (
1411
req: Request,
1512
res: Response
@@ -18,16 +15,13 @@ export const validateSocialCredential = async (
1815

1916
const { application } = req.body as SocialCredentialBody;
2017

21-
const [error, result] = await catchError(isVerified(application));
22-
if (error !== undefined) {
23-
logger.error('Failed to validate social credential:', error);
18+
try {
19+
const result = await isVerified(application);
20+
res.json({
21+
message: 'Social credential validated',
22+
provider: result,
23+
});
24+
} catch (error) {
2425
res.status(400).json({ message: 'Error validating social credential' });
25-
return;
2626
}
27-
28-
logger.info('Social credential validated', { result });
29-
res.json({
30-
message: 'Social credential validated',
31-
provider: result,
32-
});
3327
};

src/controllers/poolController.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,11 @@ const handlePoolEvaluationQuestions = async (
186186
pool: Pool,
187187
poolMetadata: IndexerRoundMetadata
188188
): Promise<PromptEvaluationQuestions> => {
189-
const [error, questions] = await catchError(
190-
evaluationQuestionService.getEvaluationQuestionsByAlloPoolId(
189+
const questions =
190+
await evaluationQuestionService.getEvaluationQuestionsByAlloPoolId(
191191
pool.alloPoolId,
192192
pool.chainId
193-
)
194-
);
195-
196-
if (error !== undefined || questions === undefined) {
197-
logger.error('Failed to get evaluation questions:', error);
198-
throw new Error('Failed to get evaluation questions');
199-
}
193+
);
200194

201195
if (questions.length > 0) {
202196
return questions.map(question => question.question);

src/ext/indexer/indexer.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class IndexerClient {
8787
getRoundManager,
8888
requestVariables
8989
);
90+
9091
if (response.rounds.length === 0) {
9192
this.logger.warn(
9293
`No round found for poolId: ${alloPoolId} on chainId: ${chainId}`
@@ -96,15 +97,15 @@ class IndexerClient {
9697

9798
const round = response.rounds[0];
9899

99-
if (round.roundRoles.length === 0) {
100+
if (round.roles.length === 0) {
100101
this.logger.warn(
101102
`No manager found for poolId: ${alloPoolId} on chainId: ${chainId}`
102103
);
103104
return [];
104105
}
105106

106107
this.logger.info(`Successfully fetched round manager`);
107-
return round.roundRoles.map(role => role.address);
108+
return round.roles.map(role => role.address);
108109
} catch (error) {
109110
this.logger.error(`Failed to fetch round manager: ${error.message}`, {
110111
error,
@@ -156,16 +157,7 @@ class IndexerClient {
156157
return null;
157158
}
158159

159-
const round = {
160-
chainId: response.rounds[0].chainId,
161-
id: response.rounds[0].id,
162-
roundMetadata: response.rounds[0].roundMetadata,
163-
roundMetadataCid: response.rounds[0].roundMetadataCid,
164-
applications: response.rounds[0].applications.map(application => ({
165-
...application,
166-
project: application.projects[0],
167-
})),
168-
};
160+
const round = response.rounds[0];
169161

170162
// Cache the result
171163
this.cache.set(cacheKey, round);
@@ -205,15 +197,15 @@ class IndexerClient {
205197
requestVariables
206198
);
207199

208-
const application = response.applications[0];
200+
const application = response.application;
209201

210202
if (application == null) {
211203
this.logger.warn(
212204
`No application found for applicationId: ${applicationId} in roundId: ${roundId} on chainId: ${chainId}`
213205
);
214206
return null;
215207
}
216-
return application;
208+
return response.application;
217209
} catch (error) {
218210
this.logger.error(
219211
`Failed to fetch round with single application: ${error.message}`,

src/ext/indexer/queries.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { gql } from 'graphql-request';
22

33
export const getRoundManager = gql`
44
query RoundManager($chainId: Int!, $alloPoolId: String!) {
5-
rounds(where: { chainId: { _eq: $chainId }, id: { _eq: $alloPoolId } }) {
6-
roundRoles {
5+
rounds(
6+
filter: { chainId: { equalTo: $chainId }, id: { equalTo: $alloPoolId } }
7+
) {
8+
roles {
79
address
810
}
911
}
@@ -12,7 +14,9 @@ export const getRoundManager = gql`
1214

1315
export const getRoundWithApplications = gql`
1416
query RoundApplications($chainId: Int!, $roundId: String!) {
15-
rounds(where: { chainId: { _eq: $chainId }, id: { _eq: $roundId } }) {
17+
rounds(
18+
filter: { chainId: { equalTo: $chainId }, id: { equalTo: $roundId } }
19+
) {
1620
chainId
1721
id
1822
roundMetadata
@@ -23,7 +27,7 @@ export const getRoundWithApplications = gql`
2327
metadataCid
2428
status
2529
projectId
26-
projects(where: { projectType: { _eq: "canonical" } }) {
30+
project: canonicalProject {
2731
metadata
2832
metadataCid
2933
}
@@ -38,13 +42,7 @@ export const getApplicationWithRound = gql`
3842
$roundId: String!
3943
$applicationId: String!
4044
) {
41-
applications(
42-
where: {
43-
chainId: { _eq: $chainId }
44-
roundId: { _eq: $roundId }
45-
id: { _eq: $applicationId }
46-
}
47-
) {
45+
application(chainId: $chainId, roundId: $roundId, id: $applicationId) {
4846
metadata
4947
metadataCid
5048
round {

src/ext/indexer/types.ts

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// 1. Basic Types & Enums
21
export type Address = `0x${string}`;
32

43
export enum Status {
@@ -7,7 +6,6 @@ export enum Status {
76
REJECTED = 'REJECTED',
87
}
98

10-
// 2. Metadata & Supporting Interfaces
119
export interface ApplicationMetadata {
1210
signature: string;
1311
application: {
@@ -54,48 +52,34 @@ export interface ProjectMetadata {
5452
projectTwitter?: string;
5553
userGithub?: string;
5654
projectGithub?: string;
55+
// credentials: ProjectCredentials;
5756
owners: Array<{ address: string }>;
5857
createdAt: number;
5958
lastUpdated: number;
6059
}
6160

62-
// 3. Base Interfaces (Used in Multiple Places)
63-
export interface BaseProject {
64-
metadata: ProjectMetadata;
65-
metadataCid: string;
66-
}
67-
68-
export interface BaseApplication {
61+
export interface Application {
6962
id: string;
7063
metadata: ApplicationMetadata;
7164
metadataCid: string;
7265
status: Status;
7366
projectId: string;
67+
project: {
68+
metadata: ProjectMetadata;
69+
metadataCid: string;
70+
};
7471
}
7572

76-
// 4. Extended Implementations
77-
export interface Application extends BaseApplication {
78-
project: BaseProject;
79-
}
80-
81-
export interface ApplicationQuery extends BaseApplication {
82-
projects: BaseProject[];
83-
}
84-
85-
export interface BaseRound<T extends BaseApplication> {
73+
export interface RoundWithApplications {
8674
chainId: number;
8775
id: string;
8876
roundMetadata: RoundMetadata;
8977
roundMetadataCid: string;
90-
applications: T[];
78+
applications: Application[];
9179
}
9280

93-
export type RoundWithApplications = BaseRound<Application>;
94-
export type RoundWithApplicationsQuery = BaseRound<ApplicationQuery>;
95-
96-
// 5. API Response Structures
9781
export interface RoundApplicationsQueryResponse {
98-
rounds: RoundWithApplicationsQuery[];
82+
rounds: RoundWithApplications[];
9983
}
10084

10185
export interface ApplicationWithRound {
@@ -110,12 +94,12 @@ export interface ApplicationWithRound {
11094
}
11195

11296
export interface ApplicationRoundQueryResponse {
113-
applications: ApplicationWithRound[];
97+
application: ApplicationWithRound;
11498
}
11599

116100
export interface ManagerRolesResponse {
117101
rounds: Array<{
118-
roundRoles: Array<{
102+
roles: Array<{
119103
address: string;
120104
}>;
121105
}>;

src/utils.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,14 @@ export async function isPoolManager<T>(
5959
chainId: number,
6060
alloPoolId: string
6161
): Promise<boolean> {
62-
const [error, validAddresses] = await catchError(
63-
indexerClient.getRoundManager({
64-
chainId,
65-
alloPoolId,
66-
})
67-
);
68-
69-
if (error !== undefined || validAddresses === undefined) {
70-
logger.error('Failed to fetch pool manager', { error });
71-
return false;
72-
}
73-
62+
const validAddresses = await indexerClient.getRoundManager({
63+
chainId,
64+
alloPoolId,
65+
});
7466
if (env.NODE_ENV === 'development' && signature === '0xdeadbeef') {
7567
logger.info('Skipping signature check in development mode');
7668
return true;
7769
}
78-
7970
try {
8071
const address = await recoverSignerAddress(obj, signature);
8172
logger.info(`Recovered address: ${address}`);

0 commit comments

Comments
 (0)