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