@@ -2,55 +2,40 @@ import { getUnixTime } from "date-fns";
22import { Hono } from "hono" ;
33
44import {
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" ;
1515import { logger } from "@/lib/logger" ;
16+ import { publicConfigBuilder } from "@/lib/public-config-builder/singleton" ;
1617
1718const app = new Hono ( ) ;
1819
1920// include ENSIndexer Public Config endpoint
2021app . 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
3328app . 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