Skip to content

Commit 1608765

Browse files
committed
Simplify logic in ENSIndexer HTTP endpoints
1 parent 98e6c45 commit 1608765

1 file changed

Lines changed: 12 additions & 27 deletions

File tree

apps/ensindexer/ponder/src/api/handlers/ensnode-api.ts

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,40 @@ import { getUnixTime } from "date-fns";
22
import { Hono } from "hono";
33

44
import {
5+
buildCrossChainIndexingStatusSnapshotOmnichain,
56
createRealtimeIndexingStatusProjection,
67
EnsIndexerIndexingStatusResponseCodes,
78
type EnsIndexerIndexingStatusResponseError,
89
type EnsIndexerIndexingStatusResponseOk,
9-
IndexingMetadataContextStatusCodes,
1010
serializeEnsIndexerIndexingStatusResponse,
1111
serializeEnsIndexerPublicConfig,
1212
} from "@ensnode/ensnode-sdk";
1313

14-
import { ensDbClient } from "@/lib/ensdb/singleton";
14+
import { indexingStatusBuilder } from "@/lib/indexing-status-builder/singleton";
1515
import { logger } from "@/lib/logger";
16+
import { publicConfigBuilder } from "@/lib/public-config-builder/singleton";
1617

1718
const app = new Hono();
1819

1920
// include ENSIndexer Public Config endpoint
2021
app.get("/config", async (c) => {
21-
const indexingMetadataContext = await ensDbClient.getIndexingMetadataContext();
22-
23-
// Invariant: the public config is guaranteed to be available in ENSDb after
24-
// application startup.
25-
if (indexingMetadataContext.statusCode !== IndexingMetadataContextStatusCodes.Initialized) {
26-
throw new Error("Unreachable: ENSIndexer Public Config is not available in ENSDb");
27-
}
22+
const ensIndexerPublicConfig = await publicConfigBuilder.getPublicConfig();
2823

2924
// respond with the serialized public config object
30-
return c.json(serializeEnsIndexerPublicConfig(indexingMetadataContext.stackInfo.ensIndexer));
25+
return c.json(serializeEnsIndexerPublicConfig(ensIndexerPublicConfig));
3126
});
3227

3328
app.get("/indexing-status", async (c) => {
3429
try {
35-
const indexingMetadataContext = await ensDbClient.getIndexingMetadataContext();
36-
37-
// Invariant: the Indexing Status Snapshot is expected to be available in
38-
// ENSDb shortly after application startup. There is a possibility that
39-
// the snapshot is not yet available at the time of the request,
40-
// i.e. when ENSDb has not yet been populated with the first snapshot.
41-
// In this case, we treat the snapshot as unavailable and respond with
42-
// an error response.
43-
if (indexingMetadataContext.statusCode !== IndexingMetadataContextStatusCodes.Initialized) {
44-
throw new Error("ENSDb does not contain an Indexing Status Snapshot");
45-
}
46-
47-
const crossChainSnapshot = indexingMetadataContext.indexingStatus;
48-
const projectedAt = getUnixTime(new Date());
49-
const realtimeProjection = createRealtimeIndexingStatusProjection(
50-
crossChainSnapshot,
51-
projectedAt,
30+
const now = getUnixTime(new Date());
31+
const omnichainSnapshot = await indexingStatusBuilder.getOmnichainIndexingStatusSnapshot();
32+
const crossChainSnapshot = buildCrossChainIndexingStatusSnapshotOmnichain(
33+
omnichainSnapshot,
34+
now,
5235
);
5336

37+
const realtimeProjection = createRealtimeIndexingStatusProjection(crossChainSnapshot, now);
38+
5439
return c.json(
5540
serializeEnsIndexerIndexingStatusResponse({
5641
responseCode: EnsIndexerIndexingStatusResponseCodes.Ok,

0 commit comments

Comments
 (0)