mempool/lightning-backend/src/api/explorer/channels.routes.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-04-29 03:57:27 +04:00
import config from '../../config';
import { Express, Request, Response } from 'express';
import channelsApi from './channels.api';
class ChannelsRoutes {
2022-05-01 03:01:27 +04:00
constructor() { }
public initRoutes(app: Express) {
2022-04-29 03:57:27 +04:00
app
2022-05-01 03:01:27 +04:00
.get(config.MEMPOOL.API_URL_PREFIX + 'channels/:short_id', this.$getChannel)
.get(config.MEMPOOL.API_URL_PREFIX + 'channels', this.$getChannels)
2022-04-29 03:57:27 +04:00
;
}
2022-05-01 03:01:27 +04:00
private async $getChannel(req: Request, res: Response) {
try {
const channel = await channelsApi.$getChannel(req.params.short_id);
if (!channel) {
res.status(404).send('Channel not found');
return;
}
res.json(channel);
} catch (e) {
res.status(500).send(e instanceof Error ? e.message : e);
}
}
2022-04-29 03:57:27 +04:00
private async $getChannels(req: Request, res: Response) {
try {
2022-05-01 03:01:27 +04:00
if (typeof req.query.public_key !== 'string') {
res.status(501).send('Missing parameter: public_key');
return;
}
const channels = await channelsApi.$getChannelsForNode(req.query.public_key);
res.json(channels);
2022-04-29 03:57:27 +04:00
} catch (e) {
res.status(500).send(e instanceof Error ? e.message : e);
}
}
}
2022-05-01 03:01:27 +04:00
export default new ChannelsRoutes();