2
0
mirror of https://github.com/Ride-The-Lightning/RTL synced 2024-11-11 13:10:41 +00:00
RTL/server/controllers/lnd/switch.ts
ShahanaFarooqui 44412d357e
Release 0.12.3 (#1012)
LND Palemoon UX extension panel bug
Cookie file not generated for BTCPayServer #990
ECL Missing fee calculation on Dashboard #975
CLT channel filter on alias bug fix #982
CLightning to Code Lightning #997
Added Infographics for Channel Rebalance
CLN Base fee zero bug fix #987
ECL Query Route bug fix #1007
LND faster initial load
LND Transactions Lookup #1002
LND Bug fix for Routing Fee Calculation
2022-05-01 13:35:20 -04:00

55 lines
3.0 KiB
TypeScript

import request from 'request-promise';
import { Logger, LoggerService } from '../../utils/logger.js';
import { Common, CommonService } from '../../utils/common.js';
let options = null;
const logger: LoggerService = Logger;
const common: CommonService = Common;
const responseData = { switch: { forwarding_events: [], last_offset_index: 0 }, fees: { forwarding_events: [], last_offset_index: 0 } };
const num_max_events = 100;
export const forwardingHistory = (req, res, next) => {
getAllForwardingEvents(req, req.body.start_time, req.body.end_time, 0, 'switch', (eventsResponse) => {
if (eventsResponse.error) {
res.status(eventsResponse.error.statusCode).json(eventsResponse);
} else {
res.status(201).json(eventsResponse);
}
});
};
export const getAllForwardingEvents = (req, start, end, offset, caller, callback) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Switch', msg: 'Getting Forwarding Events..' });
if (offset === 0) { responseData[caller] = { forwarding_events: [], last_offset_index: 0 }; }
if (!req.session.selectedNode) {
const err = common.handleError({ message: 'Session Expired after a day\'s inactivity.', statusCode: 401 }, 'Balance', 'Get Balance Error', req.session.selectedNode);
return callback({ message: err.message, error: err.error, statusCode: err.statusCode });
} options = common.getOptions(req);
options.url = req.session.selectedNode.ln_server_url + '/v1/switch';
options.form = {};
if (start) { options.form.start_time = start; }
if (end) { options.form.end_time = end; }
options.form.num_max_events = num_max_events;
options.form.index_offset = offset;
options.form = JSON.stringify(options.form);
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Switch', msg: 'Forwarding Events Params', data: options.form });
return request.post(options).then((body) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Switch', msg: 'Forwarding Events Received', data: body });
if (body.forwarding_events) {
responseData[caller].forwarding_events.push(...body.forwarding_events);
responseData[caller].last_offset_index = body.last_offset_index ? body.last_offset_index : 0;
}
if (!body.last_offset_index || body.last_offset_index < offset + num_max_events) {
responseData[caller].last_offset_index = body.last_offset_index ? body.last_offset_index : 0;
if (responseData[caller].forwarding_events) {
responseData[caller].forwarding_events = common.sortDescByKey(responseData[caller].forwarding_events, 'timestamp');
}
return callback(responseData[caller]);
} else {
return getAllForwardingEvents(req, start, end, offset + num_max_events, caller, callback);
}
}).catch((errRes) => {
const err = common.handleError(errRes, 'Switch', 'Get All Forwarding Events Error', req.session.selectedNode);
return callback({ message: err.message, error: err.error, statusCode: err.statusCode });
});
};