Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
feat: API indexer-status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
khorolets committed Sep 13, 2021
1 parent e43ea1e commit 1eac779
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions frontend/src/pages/api/status-indexer.js
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);
}
}

0 comments on commit 1eac779

Please sign in to comment.