2019-01-01 16:26:51 +00:00
|
|
|
var request = require('request-promise');
|
2018-10-10 00:08:05 +00:00
|
|
|
var common = require('../common');
|
2019-01-13 22:55:25 +00:00
|
|
|
var logger = require('./logger');
|
2019-03-02 17:55:19 +00:00
|
|
|
var options = {};
|
2018-10-10 00:08:05 +00:00
|
|
|
|
|
|
|
exports.getPayments = (req, res, next) => {
|
2019-03-02 17:55:19 +00:00
|
|
|
options = common.options;
|
2018-10-10 00:08:05 +00:00
|
|
|
options.url = common.lnd_server_url + '/payments';
|
2019-01-01 16:26:51 +00:00
|
|
|
request(options).then((body) => {
|
2018-10-10 00:08:05 +00:00
|
|
|
const body_str = (undefined === body) ? '' : JSON.stringify(body);
|
|
|
|
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');
|
2019-01-13 22:55:25 +00:00
|
|
|
logger.info('\r\nPayments: 10: ' + JSON.stringify(Date.now()) + ': INFO: Payment Decoded Received: ' + body_str);
|
2018-10-10 00:08:05 +00:00
|
|
|
if(undefined === body || search_idx > -1 || body.error) {
|
|
|
|
res.status(500).json({
|
|
|
|
message: "Payments List Failed!",
|
2018-10-12 00:03:54 +00:00
|
|
|
error: (undefined === body || search_idx > -1) ? 'Error From Server!' : body.error
|
2018-10-10 00:08:05 +00:00
|
|
|
});
|
|
|
|
} else {
|
2018-12-12 00:06:57 +00:00
|
|
|
if (undefined !== body.payments) {
|
|
|
|
body.payments.forEach(payment => {
|
|
|
|
payment.creation_date_str = (undefined === payment.creation_date) ? '' : common.convertTimestampToDate(payment.creation_date);
|
|
|
|
});
|
2019-01-19 23:47:56 +00:00
|
|
|
body.payments = common.sortDescByKey(body.payments, 'creation_date');
|
2018-12-12 00:06:57 +00:00
|
|
|
}
|
2018-10-10 00:08:05 +00:00
|
|
|
res.status(200).json(body.payments);
|
|
|
|
}
|
2019-01-01 16:26:51 +00:00
|
|
|
})
|
|
|
|
.catch(function (err) {
|
|
|
|
return res.status(500).json({
|
|
|
|
message: "Payments List Failed!",
|
|
|
|
error: err.error
|
|
|
|
});
|
2018-10-10 00:08:05 +00:00
|
|
|
});
|
|
|
|
};
|