This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getNearNetwork } from "../../libraries/config"; | ||
import { ExplorerApi } from "../../libraries/explorer-wamp"; | ||
import BlocksApi from "../../libraries/explorer-wamp/blocks"; | ||
|
||
export default async function (req, res) { | ||
// This endpoint provides the status of Indexer for Explorer | ||
// It checks the latest block height in indexer database | ||
// and the latest block height from JSON RPC | ||
// If the difference in between 30 blocks it is considered as fine | ||
// otherwise not fine | ||
|
||
try { | ||
const rpcFinalBlock = await new ExplorerApi(req).call( | ||
"nearcore-final-block" | ||
); | ||
const indexerFinalBlock = await new BlocksApi(req).getBlocks(1, null); | ||
|
||
const statusResponse = { | ||
rpc_latest_block_height: rpcFinalBlock.header.height, | ||
indexer_latest_block_height: indexerFinalBlock[0].height, | ||
}; | ||
res.status(200).send(statusResponse); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(502).send(error); | ||
} | ||
} |