2022-04-27 02:52:23 +04:00
|
|
|
import config from '../../config';
|
2022-07-06 11:58:06 +02:00
|
|
|
import { Application, Request, Response } from 'express';
|
2022-04-27 02:52:23 +04:00
|
|
|
import nodesApi from './nodes.api';
|
|
|
|
class NodesRoutes {
|
2022-05-01 03:01:27 +04:00
|
|
|
constructor() { }
|
|
|
|
|
2022-07-06 11:58:06 +02:00
|
|
|
public initRoutes(app: Application) {
|
2022-04-27 02:52:23 +04:00
|
|
|
app
|
2022-07-06 11:58:06 +02:00
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'lightning/nodes/search/:search', this.$searchNode)
|
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'lightning/nodes/top', this.$getTopNodes)
|
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'lightning/nodes/:public_key/statistics', this.$getHistoricalNodeStats)
|
|
|
|
.get(config.MEMPOOL.API_URL_PREFIX + 'lightning/nodes/:public_key', this.$getNode)
|
|
|
|
;
|
2022-04-27 02:52:23 +04:00
|
|
|
}
|
|
|
|
|
2022-05-09 18:21:42 +04:00
|
|
|
private async $searchNode(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const nodes = await nodesApi.$searchNodeByPublicKeyOrAlias(req.params.search);
|
|
|
|
res.json(nodes);
|
|
|
|
} catch (e) {
|
|
|
|
res.status(500).send(e instanceof Error ? e.message : e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-05-05 23:19:24 +04:00
|
|
|
private async $getHistoricalNodeStats(req: Request, res: Response) {
|
|
|
|
try {
|
|
|
|
const statistics = await nodesApi.$getNodeStats(req.params.public_key);
|
|
|
|
res.json(statistics);
|
|
|
|
} catch (e) {
|
|
|
|
res.status(500).send(e instanceof Error ? e.message : e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-27 02:52:23 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-01 03:01:27 +04:00
|
|
|
export default new NodesRoutes();
|