2018-09-27 02:02:46 +00:00
|
|
|
var request = require('request');
|
|
|
|
var options = require("../connect");
|
2018-10-10 00:08:05 +00:00
|
|
|
var common = require('../common');
|
2018-09-27 02:02:46 +00:00
|
|
|
|
|
|
|
exports.getNewAddress = (req, res, next) => {
|
2018-10-10 00:08:05 +00:00
|
|
|
options.url = common.lnd_server_url + '/newaddress?type=' + req.query.type;
|
2018-10-01 23:11:28 +00:00
|
|
|
console.log('Request Query Params: ' + JSON.stringify(req.query));
|
|
|
|
console.log('Options URL: ' + JSON.stringify(options.url));
|
2018-09-27 02:02:46 +00:00
|
|
|
request.get(options, (error, response, body) => {
|
2018-10-01 23:11:28 +00:00
|
|
|
const body_str = (undefined === body) ? '' : JSON.stringify(body);
|
|
|
|
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');
|
|
|
|
console.log("New Address Received: " + body_str);
|
|
|
|
if(undefined === body || search_idx > -1 || body.error) {
|
2018-09-27 02:02:46 +00:00
|
|
|
res.status(500).json({
|
|
|
|
message: "Fetching new address failed!",
|
2018-10-12 00:03:54 +00:00
|
|
|
error: (undefined === body || search_idx > -1) ? 'Error From Server!' : body.error
|
2018-09-27 02:02:46 +00:00
|
|
|
});
|
|
|
|
} else {
|
2018-10-01 23:11:28 +00:00
|
|
|
res.status(200).json(body);
|
2018-09-27 02:02:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|