2019-01-01 17:26:51 +01:00
|
|
|
var request = require('request-promise');
|
2019-09-01 19:01:38 +02:00
|
|
|
var common = require('../../common');
|
|
|
|
var logger = require('../logger');
|
|
|
|
var connect = require('../../connect');
|
2019-03-02 18:55:19 +01:00
|
|
|
var options = {};
|
2018-09-15 03:31:01 +02:00
|
|
|
|
|
|
|
exports.getInfo = (req, res, next) => {
|
2019-04-07 00:42:09 +02:00
|
|
|
common.setOptions();
|
2019-04-07 02:20:40 +02:00
|
|
|
options = common.getOptions();
|
|
|
|
options.url = common.getSelLNDServerUrl() + '/getinfo';
|
2019-05-07 03:56:11 +02:00
|
|
|
if(common.multi_node_setup) {
|
2019-07-27 20:20:17 +02:00
|
|
|
logger.info({fileName:'GetInfo', msg: 'Selected Node: ' + JSON.stringify(common.selectedNode.ln_node)});
|
2019-05-07 03:56:11 +02:00
|
|
|
} else {
|
2019-07-27 20:20:17 +02:00
|
|
|
logger.info({fileName:'GetInfo', msg: 'Single Node Setup!'});
|
2019-05-07 03:56:11 +02:00
|
|
|
}
|
2019-07-28 02:23:23 +02:00
|
|
|
common.nodes.map(node => { if (node.lnImplementation === 'LND') { connect.getAllNodeAllChannelBackup(node); }});
|
2019-07-27 20:20:17 +02:00
|
|
|
logger.info({fileName: 'GetInfo', msg: 'Calling getinfo from lnd server url: ' + options.url});
|
2019-01-01 17:26:51 +01:00
|
|
|
request(options).then((body) => {
|
2019-07-27 20:20:17 +02:00
|
|
|
logger.info({fileName: 'GetInfo', msg: JSON.stringify(body)});
|
2018-09-16 08:29:21 +02:00
|
|
|
const body_str = (undefined === body) ? '' : JSON.stringify(body);
|
|
|
|
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');
|
|
|
|
if(undefined === body || search_idx > -1 || body.error) {
|
2018-09-15 03:31:01 +02:00
|
|
|
res.status(500).json({
|
|
|
|
message: "Fetching Info failed!",
|
2018-10-12 02:03:54 +02:00
|
|
|
error: (undefined === body || search_idx > -1) ? 'Error From Server!' : body.error
|
2018-09-15 03:31:01 +02:00
|
|
|
});
|
|
|
|
} else {
|
2018-09-16 08:29:21 +02:00
|
|
|
res.status(200).json(body);
|
2018-09-15 03:31:01 +02:00
|
|
|
}
|
2019-01-01 17:26:51 +01:00
|
|
|
})
|
|
|
|
.catch(function (err) {
|
|
|
|
return res.status(500).json({
|
|
|
|
message: "Fetching Info failed!",
|
|
|
|
error: err.error
|
|
|
|
});
|
2018-09-15 03:31:01 +02:00
|
|
|
});
|
|
|
|
};
|