mirror of
https://github.com/Ride-The-Lightning/RTL.git
synced 2025-03-12 18:48:09 +01:00
* rm .DS_Store * Add watchfrontenddev command for npm * Fix toggle issues in sidenav (pinning and on page refresh) * Add copy-to-clipboard fallback if navigator.clipboard is not available (#1336) * add copy-to-clipboard fallback if navigator.clipboard is not available * amend copy fallback * clipboard copy lint fixes and frontend build * fix: add missing boltz state `transaction.lockupFailed` (#1349) * fix: boltzd docs link (#1354) * exit gracefully (#1356) * allow for eclair updated relayed audit format (#1363) * feat: add boltz service to cln (#1352) * lint fix * Request Params Cleanup * cln: Boltz auto-send (#1366) * Bug-fix (CLN Boltz): Hide claim tx id and routing fee for non-zero conf reverse swap * cln: Boltz auto-send - Added auto send option for Swap In - Checking compatiblity with v2.0.0 and above * Test import fixes * Update help.component.ts (#1379) Fixed broken link under "Help" -> "Node Settings" * Backend config fix (#1382) * Updating Common Application Configuration * Fixed get RTL Conf * Update Application Settings * application and settings case change * Unified config models * Default node update * 2FA and Password reset * Final application settings update * Config Settings and Authentication case fixed * Node Setting Fix * Fiat currency Symbol fix * CLN: Fiat symbol fix * All: Fiat symbol fix * Update node settings * Services UI fix * CLN: Removed child node settings * All: Removed child node settings * Test fixes * mempool links for onchain information (#1383) * Tests fix Tests fix * UI for Block Explorer Configuration (#1385) * Bump fee with mempool information (#1386) * Mempool openchannel minfee (#1388) Open channel model block if min fee is higher * Show error on login screen if rune is incorrect and getinfo throws error (#1391) * cln: Removed channel lookup call for update policy (#1392) * ECL: On-chain Transactions, Invoice and Payments pagination (#1393) Done most of the UI changes to accommodate pagination on transactions, payments and invoices tables but true pagination cannot be implemented till total number of records are missing from the API response. Once the issue https://github.com/ACINQ/eclair/issues/2855 is fixed, I will uncomment pagination changes in the frontend. * lnd: Onchain CPFP (#1394) - UTXO label bug fix - Warning on utxo label for "sweep" in text. * Bug fixes after testing * Testing bug fixes (#1401) * Bug fix 2: lnd: Link channel point to explorer and show fee on close channel too * lnd: explorer link on pending channels * Node lookup link on view channel peer pubkey * Testing bug fixes (#1402) * Bug fix 2: lnd: Link channel point to explorer and show fee on close channel too * lnd: explorer link on pending channels * Node lookup link on view channel peer pubkey * test fixes * ng update to v18.0.x * Updating install with --legacy-peer-deps --------- Co-authored-by: Grzegorz Kućmierz <gkucmierz@gmail.com> Co-authored-by: lacksfish <lacksfish@gmail.com> Co-authored-by: jackstar12 <62219658+jackstar12@users.noreply.github.com> Co-authored-by: Kilian <19181985+kilrau@users.noreply.github.com> Co-authored-by: Taylor King <taylorbradleyking@gmail.com> Co-authored-by: Fishcake <128653975+fishcakeday@users.noreply.github.com> Co-authored-by: Ant <72945059+2140data@users.noreply.github.com>
266 lines
14 KiB
TypeScript
266 lines
14 KiB
TypeScript
import jwt from 'jsonwebtoken';
|
|
import * as fs from 'fs';
|
|
import { sep } from 'path';
|
|
import ini from 'ini';
|
|
import parseHocon from 'hocon-parser';
|
|
import request from 'request-promise';
|
|
import { Database, DatabaseService } from '../../utils/database.js';
|
|
import { Logger, LoggerService } from '../../utils/logger.js';
|
|
import { Common, CommonService } from '../../utils/common.js';
|
|
import { WSServer } from '../../utils/webSocketServer.js';
|
|
import { Authentication, SSO } from '../../models/config.model.js';
|
|
|
|
const options = { url: '' };
|
|
const logger: LoggerService = Logger;
|
|
const common: CommonService = Common;
|
|
const wsServer = WSServer;
|
|
const databaseService: DatabaseService = Database;
|
|
// Set local block explorer URL after first API call
|
|
// if the selected node block explorer has working REST API suite
|
|
// otherwise set it to mempool.space
|
|
let blockExplorerUrl = '';
|
|
|
|
export const getExplorerFeesRecommended = (req, res, next) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Getting Recommended Fee Rates..' });
|
|
options.url = (blockExplorerUrl === '') ?
|
|
req.session.selectedNode.settings.blockExplorerUrl + '/api/v1/fees/recommended' :
|
|
blockExplorerUrl + '/api/v1/fees/recommended';
|
|
request(options).then((body) => {
|
|
blockExplorerUrl = req.session.selectedNode.settings.blockExplorerUrl;
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Recommended Fee Rates Received', data: body });
|
|
res.status(200).json(JSON.parse(body));
|
|
}).catch((errRes) => {
|
|
blockExplorerUrl = 'https://mempool.space';
|
|
options.url = blockExplorerUrl + '/api/v1/fees/recommended';
|
|
return request(options).then((body) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Recommended Fee Rates Received', data: body });
|
|
res.status(200).json(JSON.parse(body));
|
|
}).catch((errRes) => {
|
|
const errMsg = 'Get Recommended Fee Rates Error';
|
|
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.error, error: err.error });
|
|
});
|
|
});
|
|
};
|
|
|
|
export const getExplorerTransaction = (req, res, next) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Getting Transaction From Block Explorer..' });
|
|
options.url = (blockExplorerUrl === '') ?
|
|
req.session.selectedNode.settings.blockExplorerUrl + '/api/tx/' + req.params.txid :
|
|
blockExplorerUrl + '/api/tx/' + req.params.txid;
|
|
request(options).then((body) => {
|
|
blockExplorerUrl = req.session.selectedNode.settings.blockExplorerUrl;
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Transaction From Block Explorer Received', data: body });
|
|
res.status(200).json(JSON.parse(body));
|
|
}).catch((errRes) => {
|
|
blockExplorerUrl = 'https://mempool.space';
|
|
options.url = blockExplorerUrl + '/api/tx/' + req.params.txid;
|
|
return request(options).then((body) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Transaction From Block Explorer Received', data: body });
|
|
res.status(200).json(JSON.parse(body));
|
|
}).catch((errRes) => {
|
|
const errMsg = 'Get Transaction From Block Explorer Error';
|
|
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.error, error: err.error });
|
|
});
|
|
});
|
|
};
|
|
|
|
export const getCurrencyRates = (req, res, next) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Getting Currency Rates..' });
|
|
options.url = 'https://blockchain.info/ticker';
|
|
request(options).then((body) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Currency Rates Received', data: body });
|
|
res.status(200).json(JSON.parse(body));
|
|
}).catch((errRes) => {
|
|
const errMsg = 'Get Rates Error';
|
|
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.error, error: err.error });
|
|
});
|
|
};
|
|
|
|
export const getFile = (req, res, next) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Getting File..' });
|
|
const file = req.query.path ? req.query.path : (req.session.selectedNode.settings.channelBackupPath + sep + 'channel-' + req.query.channel?.replace(':', '-') + '.bak');
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'RTLConf', msg: 'Channel Point', data: req.query.channel });
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'RTLConf', msg: 'File Path', data: file });
|
|
fs.readFile(file, 'utf8', (errRes, data) => {
|
|
if (errRes) {
|
|
if (errRes.code && errRes.code === 'ENOENT') { errRes.code = 'File Not Found!'; }
|
|
const errMsg = 'Reading File Error';
|
|
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.error, error: err.error });
|
|
} else {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'File Data Received', data: data });
|
|
res.status(200).json(data);
|
|
}
|
|
});
|
|
};
|
|
|
|
export const getApplicationSettings = (req, res, next) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Getting RTL Configuration..' });
|
|
const confFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
|
|
fs.readFile(confFile, 'utf8', (errRes, data) => {
|
|
if (errRes) {
|
|
const errMsg = 'Get Node Config Error';
|
|
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.error, error: err.error });
|
|
} else {
|
|
const appConfData = common.removeSecureData(JSON.parse(data));
|
|
appConfData.allowPasswordUpdate = common.appConfig.allowPasswordUpdate;
|
|
appConfData.enable2FA = common.appConfig.enable2FA;
|
|
appConfData.selectedNodeIndex = (req.session.selectedNode && req.session.selectedNode.index ? req.session.selectedNode.index : common.selectedNode.index);
|
|
common.appConfig.selectedNodeIndex = appConfData.selectedNodeIndex;
|
|
const token = req.headers.authorization ? req.headers.authorization.split(' ')[1] : '';
|
|
jwt.verify(token, common.secret_key, (err, user) => {
|
|
if (err) {
|
|
// Delete unnecessary data for initial response (without security token)
|
|
const selNodeIdx = appConfData.nodes.findIndex((node) => node.index === appConfData.selectedNodeIndex) || 0;
|
|
appConfData.SSO = new SSO();
|
|
appConfData.secret2FA = '';
|
|
appConfData.dbDirectoryPath = '';
|
|
appConfData.nodes[selNodeIdx].authentication = new Authentication();
|
|
delete appConfData.nodes[selNodeIdx].settings.bitcoindConfigPath;
|
|
delete appConfData.nodes[selNodeIdx].settings.lnServerUrl;
|
|
delete appConfData.nodes[selNodeIdx].settings.swapServerUrl;
|
|
delete appConfData.nodes[selNodeIdx].settings.boltzServerUrl;
|
|
delete appConfData.nodes[selNodeIdx].settings.enableOffers;
|
|
delete appConfData.nodes[selNodeIdx].settings.enablePeerswap;
|
|
delete appConfData.nodes[selNodeIdx].settings.channelBackupPath;
|
|
appConfData.nodes = [appConfData.nodes[selNodeIdx]];
|
|
}
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'RTL Configuration Received', data: appConfData });
|
|
res.status(200).json(appConfData);
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
export const updateSelectedNode = (req, res, next) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating Selected Node..' });
|
|
const selNodeIndex = req.params.currNodeIndex ? +req.params.currNodeIndex : common.selectedNode ? +common.selectedNode.index : 1;
|
|
req.session.selectedNode = common.findNode(selNodeIndex);
|
|
common.selectedNode = req.session.selectedNode;
|
|
if (req.headers && req.headers.authorization && req.headers.authorization !== '') {
|
|
wsServer.updateLNWSClientDetails(req.session.id, +req.session.selectedNode.index, +req.params.prevNodeIndex);
|
|
if (req.params.prevNodeIndex !== '-1') {
|
|
databaseService.unloadDatabase(req.params.prevNodeIndex, req.session.id);
|
|
}
|
|
if (req.params.currNodeIndex !== '-1') {
|
|
databaseService.loadDatabase(req.session);
|
|
}
|
|
}
|
|
blockExplorerUrl = '';
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Selected Node Updated To ' + req.session.selectedNode.lnNode || '' });
|
|
res.status(200).json(common.removeAuthSecureData(JSON.parse(JSON.stringify(req.session.selectedNode))));
|
|
};
|
|
|
|
export const getConfig = (req, res, next) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Reading Configuration File..' });
|
|
let confFile = '';
|
|
let fileFormat = 'INI';
|
|
switch (req.params.nodeType) {
|
|
case 'ln':
|
|
confFile = req.session.selectedNode.authentication.configPath;
|
|
break;
|
|
case 'bitcoind':
|
|
confFile = req.session.selectedNode.settings.bitcoindConfigPath;
|
|
break;
|
|
case 'rtl':
|
|
fileFormat = 'JSON';
|
|
confFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
|
|
break;
|
|
default:
|
|
confFile = '';
|
|
break;
|
|
}
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'RTLConf', msg: 'Node Type', data: req.params.nodeType });
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'RTLConf', msg: 'File Path', data: confFile });
|
|
fs.readFile(confFile, 'utf8', (errRes, data) => {
|
|
if (errRes) {
|
|
const errMsg = 'Reading Config Error';
|
|
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.error, error: err.error });
|
|
} else {
|
|
let jsonConfig = {};
|
|
if (fileFormat === 'JSON') {
|
|
jsonConfig = JSON.parse(data);
|
|
} else {
|
|
fileFormat = 'INI';
|
|
data = data?.replace('color=#', 'color=');
|
|
jsonConfig = ini.parse(data);
|
|
if (jsonConfig['Application Options'] && jsonConfig['Application Options'].color) {
|
|
jsonConfig['Application Options'].color = '#' + jsonConfig['Application Options'].color;
|
|
}
|
|
if (req.params.nodeType === 'ln' && req.session.selectedNode.lnImplementation === 'ECL' && !jsonConfig['eclair.api.password']) {
|
|
fileFormat = 'HOCON';
|
|
jsonConfig = parseHocon(data);
|
|
}
|
|
}
|
|
jsonConfig = common.maskPasswords(jsonConfig);
|
|
const responseJSON = (fileFormat === 'JSON') ? jsonConfig : ini.stringify(jsonConfig)?.replace('color=\\#', 'color=#');
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Configuration File Data Received', data: responseJSON });
|
|
res.status(200).json({ format: fileFormat, data: responseJSON });
|
|
}
|
|
});
|
|
};
|
|
|
|
export const updateNodeSettings = (req, res, next) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating Node Settings..' });
|
|
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
|
|
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
|
|
const node = config.nodes.find((node) => (node.index === req.session.selectedNode.index));
|
|
if (node && node.settings) {
|
|
node.settings = req.body.settings;
|
|
if (req.body.authentication.boltzMacaroonPath) {
|
|
node.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath;
|
|
} else {
|
|
delete node.authentication.boltzMacaroonPath;
|
|
}
|
|
if (req.body.authentication.swapMacaroonPath) {
|
|
node.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath;
|
|
} else {
|
|
delete node.authentication.swapMacaroonPath;
|
|
}
|
|
}
|
|
try {
|
|
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
|
|
const selectedNode = common.findNode(req.session.selectedNode.index);
|
|
if (selectedNode && selectedNode.settings) {
|
|
selectedNode.settings = req.body.settings;
|
|
selectedNode.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath;
|
|
selectedNode.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath;
|
|
common.replaceNode(req, selectedNode);
|
|
}
|
|
let responseNode = JSON.parse(JSON.stringify(common.selectedNode));
|
|
responseNode = common.removeAuthSecureData(responseNode);
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Node Settings Updated', data: responseNode });
|
|
res.status(201).json(responseNode);
|
|
} catch (errRes) {
|
|
const errMsg = 'Update Node Settings Error';
|
|
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.error, error: err.error });
|
|
}
|
|
};
|
|
|
|
export const updateApplicationSettings = (req, res, next) => {
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating Application Settings..' });
|
|
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
|
|
try {
|
|
const config = common.addSecureData(req.body);
|
|
common.appConfig = JSON.parse(JSON.stringify(config));
|
|
delete config.selectedNodeIndex;
|
|
delete config.enable2FA;
|
|
delete config.allowPasswordUpdate;
|
|
delete config.rtlConfFilePath;
|
|
delete config.rtlPass;
|
|
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
|
|
const newConfig = JSON.parse(JSON.stringify(common.appConfig));
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Application Settings Updated', data: common.maskPasswords(newConfig) });
|
|
res.status(201).json(common.removeSecureData(newConfig));
|
|
} catch (errRes) {
|
|
const errMsg = 'Update Default Node Error';
|
|
const err = common.handleError({ statusCode: 500, message: errMsg, error: errRes }, 'RTLConf', errMsg, req.session.selectedNode);
|
|
return res.status(err.statusCode).json({ message: err.error, error: err.error });
|
|
}
|
|
};
|