mirror of
https://github.com/Ride-The-Lightning/RTL.git
synced 2024-11-19 18:00:44 +01:00
66 lines
4.1 KiB
TypeScript
66 lines
4.1 KiB
TypeScript
|
import request from 'request-promise';
|
||
|
import { Logger, LoggerService } from '../../utils/logger.js';
|
||
|
import { Common, CommonService } from '../../utils/common.js';
|
||
|
let options = null;
|
||
|
const logger: LoggerService = Logger;
|
||
|
const common: CommonService = Common;
|
||
|
|
||
|
export const getRoute = (req, res, next) => {
|
||
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Getting Network Routes..' });
|
||
|
options = common.getOptions(req);
|
||
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||
|
options.url = req.session.selectedNode.ln_server_url + '/v1/network/getRoute/' + req.params.destPubkey + '/' + req.params.amount;
|
||
|
request(options).then((body) => {
|
||
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Network', msg: 'Query Routes Received', data: body });
|
||
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Network Routes Received' });
|
||
|
res.status(200).json({ routes: body });
|
||
|
}).catch((errRes) => {
|
||
|
const err = common.handleError(errRes, 'Network', 'Query Routes Error', req.session.selectedNode);
|
||
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||
|
});
|
||
|
};
|
||
|
|
||
|
export const listNode = (req, res, next) => {
|
||
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Node Lookup..' });
|
||
|
options = common.getOptions(req);
|
||
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||
|
options.url = req.session.selectedNode.ln_server_url + '/v1/network/listNode/' + req.params.id;
|
||
|
request(options).then((body) => {
|
||
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Network', msg: 'Node Lookup', data: body });
|
||
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Node Lookup Finished' });
|
||
|
res.status(200).json(body);
|
||
|
}).catch((errRes) => {
|
||
|
const err = common.handleError(errRes, 'Network', 'Node Lookup Error', req.session.selectedNode);
|
||
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||
|
});
|
||
|
};
|
||
|
|
||
|
export const listChannel = (req, res, next) => {
|
||
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Channel Lookup..' });
|
||
|
options = common.getOptions(req);
|
||
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||
|
options.url = req.session.selectedNode.ln_server_url + '/v1/network/listChannel/' + req.params.channelShortId;
|
||
|
request(options).then((body) => {
|
||
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Network', msg: 'Channel Lookup', data: body });
|
||
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Channel Lookup Finished' });
|
||
|
res.status(200).json(body);
|
||
|
}).catch((errRes) => {
|
||
|
const err = common.handleError(errRes, 'Network', 'Channel Lookup Error', req.session.selectedNode);
|
||
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||
|
});
|
||
|
};
|
||
|
|
||
|
export const feeRates = (req, res, next) => {
|
||
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Getting Network Fee Rates..' });
|
||
|
options = common.getOptions(req);
|
||
|
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||
|
options.url = req.session.selectedNode.ln_server_url + '/v1/network/feeRates/' + req.params.feeRateStyle;
|
||
|
request(options).then((body) => {
|
||
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Network', msg: 'Network Fee Rates Received for ' + req.params.feeRateStyle, data: body });
|
||
|
res.status(200).json(body);
|
||
|
}).catch((errRes) => {
|
||
|
const err = common.handleError(errRes, 'Network', 'Fee Rates Error', req.session.selectedNode);
|
||
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||
|
});
|
||
|
};
|