2
0
mirror of https://github.com/Ride-The-Lightning/RTL synced 2024-11-09 13:10:44 +00:00
RTL/controllers/c-lightning/network.js

74 lines
2.4 KiB
JavaScript
Raw Normal View History

2019-09-08 19:09:00 +00:00
var request = require('request-promise');
var common = require('../../common');
var logger = require('../logger');
var options = {};
exports.getRoute = (req, res, next) => {
options = common.getOptions();
options.url = common.getSelLNServerUrl() + '/network/getRoute/' + req.params.destPubkey + '/' + req.params.amount;
request(options).then((body) => {
logger.info({fileName: 'Network', msg: 'Query Routes Received: ' + JSON.stringify(body)});
if(undefined === body || body.error) {
res.status(500).json({
message: "Fetching Query Routes Failed!",
error: (undefined === body) ? 'Error From Server!' : body.error
});
}
res.status(200).json({routes: body});
})
.catch((err) => {
return res.status(500).json({
message: "Fetching Query Routes Failed!",
error: err.error
});
});
};
exports.listNode = (req, res, next) => {
options = common.getOptions();
options.url = common.getSelLNServerUrl() + '/peer/listPeers';
request(options).then(function (body) {
let peers = (undefined !== body) ? common.sortDescByKey(body, 'alias') : [];
logger.info({fileName: 'Peers', msg: 'Peers with Alias: ' + JSON.stringify(peers)});
res.status(200).json(peers);
})
.catch((err) => {
return res.status(500).json({
message: "Peers Fetch Failed!",
error: err.error
});
});
};
exports.listChannel = (req, res, next) => {
options = common.getOptions();
options.url = common.getSelLNServerUrl() + '/peer/listPeers';
request(options).then(function (body) {
let peers = (undefined !== body) ? common.sortDescByKey(body, 'alias') : [];
logger.info({fileName: 'Peers', msg: 'Peers with Alias: ' + JSON.stringify(peers)});
res.status(200).json(peers);
})
.catch((err) => {
return res.status(500).json({
message: "Peers Fetch Failed!",
error: err.error
});
});
};
exports.feeRates = (req, res, next) => {
options = common.getOptions();
options.url = common.getSelLNServerUrl() + '/peer/listPeers';
request(options).then(function (body) {
let peers = (undefined !== body) ? common.sortDescByKey(body, 'alias') : [];
logger.info({fileName: 'Peers', msg: 'Peers with Alias: ' + JSON.stringify(peers)});
res.status(200).json(peers);
})
.catch((err) => {
return res.status(500).json({
message: "Peers Fetch Failed!",
error: err.error
});
});
};