2019-04-05 22:52:00 -04:00
|
|
|
var os = require('os');
|
2018-09-14 21:31:01 -04:00
|
|
|
var fs = require('fs');
|
2019-03-31 11:39:41 -04:00
|
|
|
var platform = require('os').platform();
|
2019-02-24 22:16:41 +09:00
|
|
|
var crypto = require('crypto');
|
2019-05-06 21:56:11 -04:00
|
|
|
var hash = crypto.createHash('sha256');
|
2019-01-01 11:26:51 -05:00
|
|
|
var common = require('./common');
|
2019-01-01 15:47:32 -05:00
|
|
|
var path = require('path');
|
2019-02-13 21:31:26 -05:00
|
|
|
var logger = require('./controllers/logger');
|
2019-03-02 12:55:19 -05:00
|
|
|
var connect = {};
|
2019-04-05 22:52:00 -04:00
|
|
|
var errMsg = '';
|
2019-06-17 17:26:46 -04:00
|
|
|
var request = require('request');
|
2019-07-28 14:00:15 -04:00
|
|
|
common.path_separator = (platform === 'win32') ? '\\' : '/';
|
2019-01-01 11:26:51 -05:00
|
|
|
|
2019-04-05 22:52:00 -04:00
|
|
|
connect.setDefaultConfig = () => {
|
|
|
|
var homeDir = os.userInfo().homedir;
|
2019-03-17 17:53:25 -04:00
|
|
|
var macaroonPath = '';
|
2019-09-02 00:11:37 -04:00
|
|
|
var configPath = '';
|
2019-03-31 11:39:41 -04:00
|
|
|
switch (platform) {
|
|
|
|
case 'win32':
|
2019-04-05 22:52:00 -04:00
|
|
|
macaroonPath = homeDir + '\\AppData\\Local\\Lnd\\data\\chain\\bitcoin\\mainnet';
|
2019-09-02 00:11:37 -04:00
|
|
|
configPath = homeDir + '\\AppData\\Local\\Lnd\\lnd.conf';
|
2019-11-13 23:09:14 -05:00
|
|
|
channelBackupPath = homeDir + '\\backup\\node-1';
|
2019-03-31 11:39:41 -04:00
|
|
|
break;
|
|
|
|
case 'darwin':
|
2019-04-05 22:52:00 -04:00
|
|
|
macaroonPath = homeDir + '/Library/Application Support/Lnd/data/chain/bitcoin/mainnet';
|
2019-09-02 00:11:37 -04:00
|
|
|
configPath = homeDir + '/Library/Application Support/Lnd/lnd.conf';
|
2019-11-13 23:09:14 -05:00
|
|
|
channelBackupPath = homeDir + '/backup/node-1';
|
2019-03-31 11:39:41 -04:00
|
|
|
break;
|
|
|
|
case 'linux':
|
2019-04-05 22:52:00 -04:00
|
|
|
macaroonPath = homeDir + '/.lnd/data/chain/bitcoin/mainnet';
|
2019-09-02 00:11:37 -04:00
|
|
|
configPath = homeDir + '/.lnd/lnd.conf';
|
2019-11-13 23:09:14 -05:00
|
|
|
channelBackupPath = homeDir + '/backup/node-1';
|
2019-03-31 11:39:41 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
macaroonPath = '';
|
2019-09-02 00:11:37 -04:00
|
|
|
configPath = '';
|
2019-11-13 23:09:14 -05:00
|
|
|
channelBackupPath = '';
|
2019-03-31 11:39:41 -04:00
|
|
|
break;
|
2019-04-05 22:52:00 -04:00
|
|
|
}
|
2019-03-17 17:53:25 -04:00
|
|
|
return {
|
2020-01-20 11:15:04 -05:00
|
|
|
multiPass: "password",
|
|
|
|
port: "3000",
|
|
|
|
defaultNodeIndex: 1,
|
2019-03-17 17:53:25 -04:00
|
|
|
SSO: {
|
|
|
|
rtlSSO: 0,
|
2019-11-13 23:09:14 -05:00
|
|
|
rtlCookiePath: "",
|
|
|
|
logoutRedirectLink: ""
|
|
|
|
},
|
2020-01-20 11:15:04 -05:00
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
index: 1,
|
|
|
|
lnNode: "LND Node 1",
|
|
|
|
lnImplementation: "LND",
|
|
|
|
Authentication: {
|
|
|
|
macaroonPath: macaroonPath,
|
|
|
|
configPath: configPath,
|
|
|
|
},
|
|
|
|
Settings: {
|
|
|
|
userPersona: 'MERCHANT',
|
|
|
|
themeMode: "DAY",
|
|
|
|
themeColor: "PURPLE",
|
|
|
|
channelBackupPath: channelBackupPath,
|
|
|
|
enableLogging: false,
|
|
|
|
lnServerUrl: "https://localhost:8080/v1",
|
|
|
|
fiatConversion: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2019-03-17 17:53:25 -04:00
|
|
|
}
|
2019-02-16 17:43:12 -05:00
|
|
|
|
2019-04-05 22:52:00 -04:00
|
|
|
connect.normalizePort = val => {
|
2019-02-16 17:43:12 -05:00
|
|
|
var port = parseInt(val, 10);
|
|
|
|
if (isNaN(port)) {
|
|
|
|
return val;
|
2019-01-01 11:26:51 -05:00
|
|
|
}
|
2019-02-16 17:43:12 -05:00
|
|
|
if (port >= 0) {
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
return false;
|
2019-01-01 11:26:51 -05:00
|
|
|
};
|
2018-09-14 21:31:01 -04:00
|
|
|
|
2019-04-05 22:52:00 -04:00
|
|
|
connect.setMacaroonPath = (clArgs, config) => {
|
2019-04-06 18:42:09 -04:00
|
|
|
common.nodes[0] = {};
|
|
|
|
common.nodes[0].index = 1;
|
2020-01-17 13:45:01 -05:00
|
|
|
if(clArgs.lndir) {
|
2019-04-06 18:42:09 -04:00
|
|
|
common.nodes[0].macaroon_path = clArgs.lndir;
|
2020-01-17 13:45:01 -05:00
|
|
|
} else if (process.env.MACAROON_PATH) {
|
2019-04-06 18:42:09 -04:00
|
|
|
common.nodes[0].macaroon_path = process.env.MACAROON_PATH;
|
2019-01-01 11:26:51 -05:00
|
|
|
} else {
|
2020-01-17 13:45:01 -05:00
|
|
|
if(config.Authentication.macroonPath && config.Authentication.macroonPath !== '') {
|
2019-04-06 18:42:09 -04:00
|
|
|
common.nodes[0].macaroon_path = config.Authentication.macroonPath;
|
2020-01-17 13:45:01 -05:00
|
|
|
} else if(config.Authentication.macaroonPath && config.Authentication.macaroonPath !== '') {
|
2019-04-06 18:42:09 -04:00
|
|
|
common.nodes[0].macaroon_path = config.Authentication.macaroonPath;
|
2019-01-18 22:04:16 -05:00
|
|
|
}
|
2018-09-14 21:31:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-20 11:15:04 -05:00
|
|
|
connect.convertCustomToHash = () => {
|
|
|
|
common.rtl_conf_file_path = process.env.RTL_CONFIG_PATH ? process.env.RTL_CONFIG_PATH : path.normalize(__dirname);
|
|
|
|
try {
|
|
|
|
RTLConfFile = common.rtl_conf_file_path + common.path_separator + 'RTL-Config.json';
|
|
|
|
var config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
|
|
|
|
config.multiPassHashed = hash.update(config.multiPass).digest('hex');
|
|
|
|
delete config.multiPass;
|
|
|
|
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
|
|
|
|
console.log('Please note that, RTL has encrypted the plaintext password into its corresponding hash.');
|
|
|
|
return config.multiPassHashed;
|
|
|
|
} catch (err) {
|
|
|
|
errMsg = errMsg + '\nPassword hashing failed!';
|
2019-04-06 18:42:09 -04:00
|
|
|
}
|
2019-01-01 11:26:51 -05:00
|
|
|
}
|
|
|
|
|
2020-01-20 11:15:04 -05:00
|
|
|
connect.validateNodeConfig = (config) => {
|
2019-11-06 12:39:55 -05:00
|
|
|
if(!+config.SSO.rtlSSO) {
|
2020-01-17 13:45:01 -05:00
|
|
|
if (process.env.RTL_PASS) {
|
2019-11-06 12:39:55 -05:00
|
|
|
common.rtl_pass = hash.update(process.env.RTL_PASS).digest('hex');
|
2020-01-17 13:45:01 -05:00
|
|
|
} else if (config.multiPassHashed !== '' && config.multiPassHashed) {
|
2019-11-06 12:39:55 -05:00
|
|
|
common.rtl_pass = config.multiPassHashed;
|
2020-01-17 13:45:01 -05:00
|
|
|
} else if (config.multiPass !== '' && config.multiPass) {
|
2020-01-20 11:15:04 -05:00
|
|
|
common.rtl_pass = connect.convertCustomToHash();
|
2019-04-05 22:52:00 -04:00
|
|
|
} else {
|
2020-01-20 11:15:04 -05:00
|
|
|
errMsg = errMsg + '\nNode Authentication can be set with multiPass only. Please set multiPass in RTL-Config.json';
|
2019-04-05 22:52:00 -04:00
|
|
|
}
|
2019-05-06 21:56:11 -04:00
|
|
|
}
|
2020-01-17 13:45:01 -05:00
|
|
|
common.port = (config.port) ? connect.normalizePort(config.port) : 3000;
|
2019-10-27 16:39:40 -04:00
|
|
|
if (config.nodes && config.nodes.length > 0) {
|
|
|
|
config.nodes.forEach((node, idx) => {
|
|
|
|
common.nodes[idx] = {};
|
|
|
|
if(node.Authentication.macaroonPath === '' || undefined === node.Authentication.macaroonPath) {
|
2020-01-20 11:15:04 -05:00
|
|
|
errMsg = 'Please set macaroon path for node index ' + node.index + ' in RTL-Config.json!';
|
2019-10-27 16:39:40 -04:00
|
|
|
} else {
|
|
|
|
common.nodes[idx].macaroon_path = node.Authentication.macaroonPath;
|
|
|
|
}
|
2019-04-05 22:52:00 -04:00
|
|
|
|
2019-10-27 16:39:40 -04:00
|
|
|
if(
|
|
|
|
(node.Settings.lndServerUrl === '' || undefined === node.Settings.lndServerUrl)
|
|
|
|
&& (node.Settings.lnServerUrl === '' || undefined === node.Settings.lnServerUrl)
|
|
|
|
) {
|
2020-01-20 11:15:04 -05:00
|
|
|
errMsg = errMsg + '\nPlease set server URL for node index ' + node.index + ' in RTL-Config.json!';
|
2019-10-27 16:39:40 -04:00
|
|
|
} else {
|
|
|
|
common.nodes[idx].ln_server_url = node.Settings.lndServerUrl ? node.Settings.lndServerUrl : node.Settings.lnServerUrl;
|
|
|
|
}
|
2019-04-05 22:52:00 -04:00
|
|
|
|
2019-10-27 16:39:40 -04:00
|
|
|
common.nodes[idx].index = node.index;
|
|
|
|
common.nodes[idx].ln_node = node.lnNode;
|
|
|
|
common.nodes[idx].ln_implementation = node.lnImplementation;
|
2020-01-09 22:50:02 -05:00
|
|
|
common.nodes[idx].fiat_conversion = node.Settings.fiatConversion ? node.Settings.fiatConversion : false;
|
|
|
|
if(common.nodes[idx].fiat_conversion) {
|
|
|
|
common.nodes[idx].currency_unit = node.Settings.currencyUnit ? node.Settings.currencyUnit : 'USD';
|
|
|
|
}
|
2019-11-13 23:09:14 -05:00
|
|
|
|
2020-01-17 13:45:01 -05:00
|
|
|
if (node.Authentication && node.Authentication.lndConfigPath) {
|
2019-10-27 16:39:40 -04:00
|
|
|
common.nodes[idx].config_path = node.Authentication.lndConfigPath;
|
2020-01-17 13:45:01 -05:00
|
|
|
} else if (node.Authentication && node.Authentication.configPath) {
|
2019-10-27 16:39:40 -04:00
|
|
|
common.nodes[idx].config_path = node.Authentication.configPath;
|
2019-04-05 22:52:00 -04:00
|
|
|
} else {
|
2019-10-27 16:39:40 -04:00
|
|
|
common.nodes[idx].config_path = '';
|
|
|
|
}
|
2020-01-17 13:45:01 -05:00
|
|
|
common.nodes[idx].bitcoind_config_path = (node.Settings.bitcoindConfigPath) ? node.Settings.bitcoindConfigPath : '';
|
|
|
|
common.nodes[idx].enable_logging = (node.Settings.enableLogging) ? node.Settings.enableLogging : false;
|
|
|
|
common.nodes[idx].channel_backup_path = (node.Settings.channelBackupPath) ? node.Settings.channelBackupPath : common.rtl_conf_file_path + common.path_separator + 'backup' + common.path_separator + 'node-' + node.index;
|
2019-10-27 16:39:40 -04:00
|
|
|
try {
|
|
|
|
connect.createDirectory(common.nodes[idx].channel_backup_path);
|
|
|
|
let exists = fs.existsSync(common.nodes[idx].channel_backup_path + common.path_separator + 'channel-all.bak');
|
|
|
|
if (!exists) {
|
|
|
|
try {
|
|
|
|
var createStream = fs.createWriteStream(common.nodes[idx].channel_backup_path + common.path_separator + 'channel-all.bak');
|
|
|
|
createStream.end();
|
|
|
|
} catch (err) {
|
|
|
|
console.error('Something went wrong while creating backup file: \n' + err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.error('Something went wrong while creating backup file: \n' + err);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (common.nodes[idx].enable_logging) {
|
|
|
|
common.nodes[idx].log_file = common.rtl_conf_file_path + '/logs/RTL-Node-' + node.index + '.log';
|
|
|
|
const log_file = common.nodes[idx].log_file;
|
|
|
|
if (fs.existsSync(log_file)) {
|
|
|
|
fs.writeFile(log_file, '', () => { });
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
var dirname = path.dirname(log_file);
|
|
|
|
connect.createDirectory(dirname);
|
|
|
|
var createStream = fs.createWriteStream(log_file);
|
|
|
|
createStream.end();
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
console.error('Something went wrong while creating log file ' + log_file + ': \n' + err);
|
|
|
|
}
|
2019-04-05 22:52:00 -04:00
|
|
|
}
|
|
|
|
}
|
2019-10-27 16:39:40 -04:00
|
|
|
});
|
|
|
|
}
|
2019-04-05 22:52:00 -04:00
|
|
|
|
|
|
|
connect.setSSOParams(config);
|
|
|
|
if (errMsg !== '') { throw new Error(errMsg); }
|
|
|
|
}
|
|
|
|
|
|
|
|
connect.setSSOParams = (config) => {
|
2020-01-17 13:45:01 -05:00
|
|
|
if (process.env.RTL_SSO) {
|
2019-02-16 17:43:12 -05:00
|
|
|
common.rtl_sso = process.env.RTL_SSO;
|
2020-01-17 13:45:01 -05:00
|
|
|
} else if (config.SSO && config.SSO.rtlSSO) {
|
2019-02-16 17:43:12 -05:00
|
|
|
common.rtl_sso = config.SSO.rtlSSO;
|
|
|
|
}
|
2019-02-12 08:36:04 -05:00
|
|
|
|
2019-02-16 17:43:12 -05:00
|
|
|
if (+common.rtl_sso) {
|
2020-01-17 13:45:01 -05:00
|
|
|
if (process.env.LOGOUT_REDIRECT_LINK) {
|
2019-02-25 21:16:55 -05:00
|
|
|
common.logout_redirect_link = process.env.LOGOUT_REDIRECT_LINK;
|
2020-01-17 13:45:01 -05:00
|
|
|
} else if (config.SSO && config.SSO.logoutRedirectLink) {
|
2019-02-25 21:16:55 -05:00
|
|
|
common.logout_redirect_link = config.SSO.logoutRedirectLink;
|
|
|
|
}
|
2019-05-06 21:56:11 -04:00
|
|
|
|
2020-01-17 13:45:01 -05:00
|
|
|
if (process.env.RTL_COOKIE_PATH) {
|
2019-02-25 21:16:55 -05:00
|
|
|
common.rtl_cookie_path = process.env.RTL_COOKIE_PATH;
|
2020-01-17 13:45:01 -05:00
|
|
|
} else if (config.SSO && config.SSO.rtlCookiePath) {
|
2019-02-25 21:16:55 -05:00
|
|
|
common.rtl_cookie_path = config.SSO.rtlCookiePath;
|
|
|
|
} else {
|
|
|
|
common.rtl_cookie_path = common.rtl_conf_file_path + '/cookies/auth.cookie';
|
|
|
|
}
|
2019-11-05 19:26:40 -05:00
|
|
|
if (common.rtl_cookie_path === '') {
|
|
|
|
errMsg = 'Please set rtlCookiePath value for single sign on option!';
|
|
|
|
} else {
|
|
|
|
connect.readCookie(common.rtl_cookie_path);
|
|
|
|
}
|
2019-02-12 08:36:04 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-05 22:52:00 -04:00
|
|
|
connect.createDirectory = (dirname) => {
|
2019-02-12 08:36:04 -05:00
|
|
|
try {
|
2019-06-17 17:26:46 -04:00
|
|
|
const sep = path.sep;
|
|
|
|
const initDir = path.isAbsolute(dirname) ? sep : '';
|
|
|
|
dirname.split(sep).reduce((parentDir, childDir) => {
|
|
|
|
const curDir = path.resolve(parentDir, childDir);
|
|
|
|
if (!fs.existsSync(curDir)) {
|
|
|
|
fs.mkdirSync(curDir);
|
|
|
|
}
|
|
|
|
return curDir;
|
|
|
|
}, initDir);
|
2019-02-12 08:36:04 -05:00
|
|
|
} catch (err) {
|
|
|
|
if (err.code === 'EEXIST') {
|
|
|
|
return dirname;
|
|
|
|
}
|
|
|
|
if (err.code === 'ENOENT') {
|
|
|
|
throw new Error(`EACCES: permission denied, mkdir '${dirname}'`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 22:52:00 -04:00
|
|
|
connect.readCookie = (cookieFile) => {
|
2019-02-12 08:36:04 -05:00
|
|
|
let exists = fs.existsSync(cookieFile);
|
|
|
|
if (exists) {
|
2019-11-05 19:26:40 -05:00
|
|
|
try {
|
|
|
|
common.cookie = fs.readFileSync(cookieFile, 'utf-8');
|
|
|
|
} catch (err) {
|
|
|
|
console.error('Something went wrong while reading cookie: \n' + err);
|
|
|
|
throw new Error(err);
|
|
|
|
}
|
2019-02-12 08:36:04 -05:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
var dirname = path.dirname(cookieFile);
|
2019-04-05 22:52:00 -04:00
|
|
|
connect.createDirectory(dirname);
|
2019-02-24 22:16:41 +09:00
|
|
|
fs.writeFileSync(cookieFile, crypto.randomBytes(64).toString('hex'));
|
2019-02-12 08:36:04 -05:00
|
|
|
common.cookie = fs.readFileSync(cookieFile, 'utf-8');
|
|
|
|
}
|
|
|
|
catch(err) {
|
2019-11-06 12:39:55 -05:00
|
|
|
console.error('Something went wrong while reading the cookie: \n' + err);
|
2019-02-12 08:36:04 -05:00
|
|
|
throw new Error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 22:52:00 -04:00
|
|
|
connect.refreshCookie = (cookieFile) => {
|
|
|
|
try {
|
|
|
|
fs.writeFileSync(cookieFile, crypto.randomBytes(64).toString('hex'));
|
|
|
|
common.cookie = fs.readFileSync(cookieFile, 'utf-8');
|
|
|
|
}
|
|
|
|
catch(err) {
|
|
|
|
console.error('Something went wrong while refreshing cookie: \n' + err);
|
|
|
|
throw new Error(err);
|
|
|
|
}
|
2019-02-12 08:36:04 -05:00
|
|
|
}
|
|
|
|
|
2019-04-05 22:52:00 -04:00
|
|
|
connect.logEnvVariables = () => {
|
2020-01-20 11:15:04 -05:00
|
|
|
if (common.nodes && common.nodes.length > 0) {
|
2019-04-05 22:52:00 -04:00
|
|
|
common.nodes.forEach((node, idx) => {
|
|
|
|
if (!node.enable_logging) { return; }
|
2020-01-20 11:15:04 -05:00
|
|
|
logger.info({fileName: 'Config Setup Variable', msg: 'PORT: ' + common.port, node});
|
2020-01-17 13:45:01 -05:00
|
|
|
logger.info({fileName: 'Config Setup Variable', msg: 'DEFAULT NODE INDEX: ' + common.selectedNode.index});
|
|
|
|
logger.info({fileName: 'Config Setup Variable', msg: 'SSO: ' + common.rtl_sso, node});
|
|
|
|
logger.info({fileName: 'Config Setup Variable', msg: 'LOGOUT REDIRECT LINK: ' + common.logout_redirect_link + '\r\n', node});
|
2019-07-27 14:20:17 -04:00
|
|
|
logger.info({fileName: 'Config Setup Variable', msg: 'INDEX: ' + node.index, node});
|
|
|
|
logger.info({fileName: 'Config Setup Variable', msg: 'LN NODE: ' + node.ln_node, node});
|
|
|
|
logger.info({fileName: 'Config Setup Variable', msg: 'LN IMPLEMENTATION: ' + node.ln_implementation, node});
|
2020-01-17 13:45:01 -05:00
|
|
|
logger.info({fileName: 'Config Setup Variable', msg: 'FIAT CONVERSION: ' + node.fiatConversion, node});
|
|
|
|
logger.info({fileName: 'Config Setup Variable', msg: 'CURRENCY UNIT: ' + node.currency_unit, node});
|
2020-01-20 11:15:04 -05:00
|
|
|
logger.info({fileName: 'Config Setup Variable', msg: 'LN SERVER URL: ' + node.ln_server_url, node});
|
2019-04-05 22:52:00 -04:00
|
|
|
});
|
2019-02-13 21:31:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-18 21:02:29 -04:00
|
|
|
connect.getAllNodeAllChannelBackup = (node) => {
|
2019-07-28 14:00:15 -04:00
|
|
|
let channel_backup_file = node.channel_backup_path + common.path_separator + 'channel-all.bak';
|
2019-06-18 21:02:29 -04:00
|
|
|
let options = {
|
2019-09-02 00:11:37 -04:00
|
|
|
url: node.ln_server_url + '/channels/backup',
|
2019-06-18 21:02:29 -04:00
|
|
|
rejectUnauthorized: false,
|
|
|
|
json: true,
|
|
|
|
headers: {'Grpc-Metadata-macaroon': fs.readFileSync(node.macaroon_path + '/admin.macaroon').toString('hex')}
|
|
|
|
};
|
|
|
|
request(options, function (err, res, body) {
|
|
|
|
if (err) {
|
2019-07-27 14:20:17 -04:00
|
|
|
logger.error({fileName: 'Connect', lineNum: 443, msg: 'Channel Backup Response Failed: ' + JSON.stringify(err)});
|
2019-06-18 21:02:29 -04:00
|
|
|
} else {
|
|
|
|
fs.writeFile(channel_backup_file, JSON.stringify(body), function(err) {
|
|
|
|
if (err) {
|
|
|
|
if (node.ln_node) {
|
2019-07-27 14:20:17 -04:00
|
|
|
logger.error({fileName: 'Connect', lineNum: 448, msg: 'Channel Backup Failed for Node ' + node.ln_node + ' with error response: ' + JSON.stringify(err)});
|
2019-06-18 21:02:29 -04:00
|
|
|
} else {
|
2019-07-27 14:20:17 -04:00
|
|
|
logger.error({fileName: 'Connect', lineNum: 450, msg: 'Channel Backup Failed: ' + JSON.stringify(err)});
|
2019-06-18 21:02:29 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (node.ln_node) {
|
2019-07-27 14:20:17 -04:00
|
|
|
logger.info({fileName: 'Connect', msg: 'Channel Backup Successful for Node: ' + node.ln_node});
|
2019-06-18 21:02:29 -04:00
|
|
|
} else {
|
2019-07-27 14:20:17 -04:00
|
|
|
logger.info({fileName: 'Connect', msg: 'Channel Backup Successful'});
|
2019-06-18 21:02:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2019-06-18 21:24:40 -04:00
|
|
|
connect.setSelectedNode = (config) => {
|
2020-01-17 13:45:01 -05:00
|
|
|
if(config.defaultNodeIndex) {
|
|
|
|
common.selectedNode = common.findNode(config.defaultNodeIndex);
|
2019-06-18 21:24:40 -04:00
|
|
|
} else {
|
2020-01-17 13:45:01 -05:00
|
|
|
common.selectedNode = common.findNode(common.nodes[0].index);
|
|
|
|
}
|
2019-06-18 21:24:40 -04:00
|
|
|
}
|
|
|
|
|
2019-04-05 22:52:00 -04:00
|
|
|
connect.setServerConfiguration = () => {
|
2020-01-20 11:15:04 -05:00
|
|
|
try {
|
|
|
|
common.rtl_conf_file_path = (process.env.RTL_CONFIG_PATH) ? process.env.RTL_CONFIG_PATH : path.normalize(__dirname);
|
|
|
|
confFileFullPath = common.rtl_conf_file_path + common.path_separator + 'RTL-Config.json';
|
|
|
|
if (!fs.existsSync(confFileFullPath)) {
|
|
|
|
fs.writeFileSync(confFileFullPath, JSON.stringify(connect.setDefaultConfig()));
|
|
|
|
}
|
|
|
|
var config = JSON.parse(fs.readFileSync(confFileFullPath, 'utf-8'));
|
|
|
|
connect.validateNodeConfig(config);
|
|
|
|
connect.setSelectedNode(config);
|
|
|
|
connect.logEnvVariables();
|
|
|
|
} catch(err) {
|
|
|
|
console.error('Something went wrong while configuring the node server: \n' + err);
|
|
|
|
throw new Error(err);
|
2019-04-05 22:52:00 -04:00
|
|
|
}
|
|
|
|
}
|
2019-03-31 11:39:41 -04:00
|
|
|
|
|
|
|
module.exports = connect;
|