2022-04-27 02:52:23 +04:00
|
|
|
import config from '../../config';
|
|
|
|
import { Express, Request, Response } from 'express';
|
|
|
|
import nodesApi from './nodes.api';
|
2022-04-29 03:57:27 +04:00
|
|
|
import channelsApi from './channels.api';
|
2022-04-27 02:52:23 +04:00
|
|
|
class NodesRoutes {
|
|
|
|
constructor(app: Express) {
|
|
|
|
app
|
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'statistics/latest', this.$getGeneralStats)
|
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'nodes/top', this.$getTopNodes)
|
2022-04-29 03:57:27 +04:00
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'nodes/:public_key', this.$getNode)
|
2022-04-27 02:52:23 +04:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2022-04-29 03:57:27 +04:00
|
|
|
private async $getNode(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const node = await nodesApi.$getNode(req.params.public_key);
|
|
|
|
if (!node) {
|
|
|
|
res.status(404).send('Node not found');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
res.json(node);
|
|
|
|
} catch (e) {
|
|
|
|
res.status(500).send(e instanceof Error ? e.message : e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-27 02:52:23 +04:00
|
|
|
private async $getGeneralStats(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const statistics = await nodesApi.$getLatestStatistics();
|
|
|
|
res.json(statistics);
|
|
|
|
} catch (e) {
|
|
|
|
res.status(500).send(e instanceof Error ? e.message : e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async $getTopNodes(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const topCapacityNodes = await nodesApi.$getTopCapacityNodes();
|
|
|
|
const topChannelsNodes = await nodesApi.$getTopChannelsNodes();
|
|
|
|
res.json({
|
|
|
|
topByCapacity: topCapacityNodes,
|
|
|
|
topByChannels: topChannelsNodes,
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
res.status(500).send(e instanceof Error ? e.message : e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default NodesRoutes;
|