mirror of
https://github.com/Ride-The-Lightning/RTL.git
synced 2025-02-21 22:11:54 +01:00
incomplete 2
incomplete 2
This commit is contained in:
parent
d329a6fec6
commit
c9717fb8f4
23 changed files with 305 additions and 405 deletions
|
@ -1,56 +1,49 @@
|
|||
[{
|
||||
"index": "1",
|
||||
"lnNode": "LND Testnet # 1",
|
||||
"lnImplementation": "LND",
|
||||
"Authentication": {
|
||||
"macaroonPath": "/Users/suheb/Downloads",
|
||||
"nodeAuthType": "CUSTOM",
|
||||
"lndConfigPath": "",
|
||||
"rtlPass": "xxx"
|
||||
},
|
||||
"Settings": {
|
||||
"flgSidenavOpened": "true",
|
||||
"flgSidenavPinned": "true",
|
||||
"menu": "Vertical",
|
||||
"menuType": "Regular",
|
||||
"theme": "dark-blue",
|
||||
"satsToBTC": "false",
|
||||
"bitcoindConfigPath": "",
|
||||
"enableLogging": "true",
|
||||
"port": "3000",
|
||||
"lndServerUrl": "https://192.168.1.8:8080/v1"
|
||||
},
|
||||
"SSO":{
|
||||
"rtlSSO": 0,
|
||||
"rtlCookiePath": "",
|
||||
"logoutRedirectLink": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"index": "2",
|
||||
"lnNode": "LND Mainnet # 1",
|
||||
"lnImplementation": "LND",
|
||||
"Authentication": {
|
||||
"macaroonPath": "/Users/suheb/Downloads",
|
||||
"nodeAuthType": "CUSTOM",
|
||||
"lndConfigPath": "",
|
||||
"rtlPass": "xxx"
|
||||
},
|
||||
"Settings": {
|
||||
"flgSidenavOpened": "true",
|
||||
"flgSidenavPinned": "true",
|
||||
"menu": "Vertical",
|
||||
"menuType": "Regular",
|
||||
"theme": "dark-blue",
|
||||
"satsToBTC": "false",
|
||||
"bitcoindConfigPath": "",
|
||||
"enableLogging": "true",
|
||||
"port": "3000",
|
||||
"lndServerUrl": "https://192.168.1.20:8080/v1"
|
||||
},
|
||||
"SSO":{
|
||||
"multiPass": "multi",
|
||||
"SSO": {
|
||||
"rtlSSO": 0,
|
||||
"rtlCookiePath": "",
|
||||
"logoutRedirectLink": ""
|
||||
}
|
||||
}]
|
||||
},
|
||||
"nodes": [{
|
||||
"index": 1,
|
||||
"lnNode": "LND Testnet # 1",
|
||||
"lnImplementation": "LND",
|
||||
"Authentication": {
|
||||
"macaroonPath": "/Users/suheb/Downloads",
|
||||
"lndConfigPath": "C:\\Users\\suheb\\AppData\\Local\\Lnd\\lnd.conf"
|
||||
},
|
||||
"Settings": {
|
||||
"flgSidenavOpened": "true",
|
||||
"flgSidenavPinned": "true",
|
||||
"menu": "Vertical",
|
||||
"menuType": "Regular",
|
||||
"theme": "dark-blue",
|
||||
"satsToBTC": "false",
|
||||
"bitcoindConfigPath": "C:\\Bitcoind\\config\\path",
|
||||
"enableLogging": "true",
|
||||
"port": "3000",
|
||||
"lndServerUrl": "https://192.168.1.20:8080/v1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"index": 2,
|
||||
"lnNode": "LND Mainnet # 1",
|
||||
"lnImplementation": "LND",
|
||||
"Authentication": {
|
||||
"macaroonPath": "C:\\Users\\suheb\\AppData\\Local\\Lnd\\data\\chain\\bitcoin\\testnet"
|
||||
},
|
||||
"Settings": {
|
||||
"flgSidenavOpened": "true",
|
||||
"flgSidenavPinned": "true",
|
||||
"menu": "Vertical",
|
||||
"menuType": "Regular",
|
||||
"theme": "dark-blue",
|
||||
"satsToBTC": "false",
|
||||
"bitcoindConfigPath": "",
|
||||
"enableLogging": "true",
|
||||
"port": "3000",
|
||||
"lndServerUrl": "https://localhost:8080/v1"
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
|
53
common.js
53
common.js
|
@ -2,9 +2,9 @@ var fs = require('fs');
|
|||
var crypto = require('crypto');
|
||||
var common = {};
|
||||
|
||||
common.multi_node_setup = false;
|
||||
common.port = 3000;
|
||||
common.rtl_conf_file_path = '';
|
||||
common.rtl_multi_node_conf_file_path = '';
|
||||
common.lnd_server_url = '';
|
||||
common.lnd_config_path = '';
|
||||
common.node_auth_type = 'DEFAULT';
|
||||
|
@ -19,21 +19,48 @@ common.logout_redirect_link = '/login';
|
|||
common.cookie = '';
|
||||
common.secret_key = crypto.randomBytes(64).toString('hex');
|
||||
common.options = {};
|
||||
common.nodes = [];
|
||||
|
||||
common.setOptions = () => {
|
||||
var macaroon = fs.readFileSync(common.macaroon_path + '/admin.macaroon').toString('hex');
|
||||
common.options = {
|
||||
url: '',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
headers: {
|
||||
'Grpc-Metadata-macaroon': macaroon,
|
||||
},
|
||||
form: ''
|
||||
};
|
||||
return common.options;
|
||||
common.getOptions = (selNodeIndex) => {
|
||||
if(selNodeIndex === '') {
|
||||
return common.options;
|
||||
} else {
|
||||
return common.findNode(selNodeIndex).options;
|
||||
}
|
||||
};
|
||||
|
||||
common.setOptions = (selNodeIndex) => {
|
||||
if(selNodeIndex === '') {
|
||||
const macaroon = fs.readFileSync(common.macaroon_path + '/admin.macaroon').toString('hex');
|
||||
common.options = {
|
||||
url: '',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
headers: {
|
||||
'Grpc-Metadata-macaroon': macaroon,
|
||||
},
|
||||
form: ''
|
||||
};
|
||||
return common.options;
|
||||
} else {
|
||||
const selNode = common.findNode(selNodeIndex);
|
||||
const macaroon = fs.readFileSync(selNode.macaroon_path + '/admin.macaroon').toString('hex');
|
||||
selNode.options = {
|
||||
url: '',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
headers: {
|
||||
'Grpc-Metadata-macaroon': macaroon,
|
||||
},
|
||||
form: ''
|
||||
};
|
||||
return selNode.options;
|
||||
}
|
||||
}
|
||||
|
||||
common.findNode = (selNodeIndex) => {
|
||||
return common.nodes.find(node => node.index == selNodeIndex);
|
||||
}
|
||||
|
||||
common.convertToBTC = (num) => {
|
||||
return (num / 100000000).toFixed(6);
|
||||
|
|
449
connect.js
449
connect.js
|
@ -1,3 +1,4 @@
|
|||
var os = require('os');
|
||||
var fs = require('fs');
|
||||
var platform = require('os').platform();
|
||||
var crypto = require('crypto');
|
||||
|
@ -8,35 +9,30 @@ var path = require('path');
|
|||
var upperCase = require('upper-case');
|
||||
var logger = require('./controllers/logger');
|
||||
var connect = {};
|
||||
var errMsg = '';
|
||||
|
||||
const setDefaultConfig = () => {
|
||||
connect.setDefaultConfig = () => {
|
||||
var homeDir = os.userInfo().homedir;
|
||||
var macaroonPath = '';
|
||||
var lndConfigPath = '';
|
||||
var bitcoindConfigPath = '';
|
||||
|
||||
switch (platform) {
|
||||
case 'win32':
|
||||
macaroonPath = 'C:\\Users\\<user>\\AppData\\Local\\Lnd\\data\\chain\\bitcoin\\testnet';
|
||||
lndConfigPath = 'C:\\Users\\<user>\\AppData\\Local\\Lnd';
|
||||
bitcoindConfigPath = 'C:\\Users\\<user>\\AppData\\Local\\bitcoin\\bitcoin_testnet';
|
||||
macaroonPath = homeDir + '\\AppData\\Local\\Lnd\\data\\chain\\bitcoin\\mainnet';
|
||||
lndConfigPath = homeDir + '\\AppData\\Local\\Lnd\\lnd.conf';
|
||||
break;
|
||||
case 'darwin':
|
||||
macaroonPath = '/Users/<user>/Library/Application Support/Lnd/data/chain/bitcoin/testnet';
|
||||
lndConfigPath = '/Users/<user>/Library/Application Support/Lnd/';
|
||||
bitcoindConfigPath = '/Users/<user>/Library/Application Support/Bitcoin/';
|
||||
macaroonPath = homeDir + '/Library/Application Support/Lnd/data/chain/bitcoin/mainnet';
|
||||
lndConfigPath = homeDir + '/Library/Application Support/Lnd/lnd.conf';
|
||||
break;
|
||||
case 'linux':
|
||||
macaroonPath = '/home/admin/.lnd/data/chain/bitcoin/testnet';
|
||||
lndConfigPath = '/home/admin/.lnd/';
|
||||
bitcoindConfigPath = '/home/admin/.lnd/';
|
||||
macaroonPath = homeDir + '/.lnd/data/chain/bitcoin/mainnet';
|
||||
lndConfigPath = homeDir + '/.lnd/lnd.conf';
|
||||
break;
|
||||
default:
|
||||
macaroonPath = '';
|
||||
lndConfigPath = '';
|
||||
bitcoindConfigPath = '';
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return {
|
||||
Authentication: {
|
||||
macaroonPath: macaroonPath,
|
||||
|
@ -52,7 +48,6 @@ const setDefaultConfig = () => {
|
|||
theme: 'dark-blue',
|
||||
satsToBTC: false,
|
||||
lndServerUrl: 'https://localhost:8080/v1',
|
||||
bitcoindConfigPath: bitcoindConfigPath,
|
||||
enableLogging: false,
|
||||
port: 3000
|
||||
},
|
||||
|
@ -64,7 +59,7 @@ const setDefaultConfig = () => {
|
|||
};
|
||||
}
|
||||
|
||||
const normalizePort = val => {
|
||||
connect.normalizePort = val => {
|
||||
var port = parseInt(val, 10);
|
||||
if (isNaN(port)) {
|
||||
return val;
|
||||
|
@ -75,7 +70,7 @@ const normalizePort = val => {
|
|||
return false;
|
||||
};
|
||||
|
||||
const setMacaroonPath = (clArgs, config) => {
|
||||
connect.setMacaroonPath = (clArgs, config) => {
|
||||
if(undefined !== clArgs.lndir) {
|
||||
common.macaroon_path = clArgs.lndir;
|
||||
} else if (undefined !== process.env.MACAROON_PATH) {
|
||||
|
@ -89,7 +84,7 @@ const setMacaroonPath = (clArgs, config) => {
|
|||
}
|
||||
}
|
||||
|
||||
const validateConfigFile = (config) => {
|
||||
connect.validateSingleNodeConfig = (config) => {
|
||||
if(common.macaroon_path === '' || undefined === common.macaroon_path) {
|
||||
errMsg = 'Please set macaroon path through environment or RTL.conf!';
|
||||
}
|
||||
|
@ -144,7 +139,6 @@ const validateConfigFile = (config) => {
|
|||
common.rtl_pass = process.env.RTL_PASS;
|
||||
} else if (config.Authentication.rtlPass !== '' || undefined !== config.Authentication.rtlPass) {
|
||||
common.rtl_pass = config.Authentication.rtlPass;
|
||||
|
||||
}
|
||||
|
||||
if (upperCase(common.node_auth_type) === 'CUSTOM' && (common.rtl_pass === '' || undefined === common.rtl_pass)) {
|
||||
|
@ -157,16 +151,16 @@ const validateConfigFile = (config) => {
|
|||
common.enable_logging = config.Settings.enableLogging;
|
||||
} else if (undefined !== config.Authentication.enableLogging) {
|
||||
common.enable_logging = config.Authentication.enableLogging;
|
||||
}
|
||||
}
|
||||
if (common.enable_logging) {
|
||||
common.log_file = common.rtl_conf_file_path + '/logs/RTL.log';
|
||||
let exists = fs.existsSync(common.log_file);
|
||||
let exists = fs.existsSync(common.log_file);
|
||||
if (exists) {
|
||||
fs.writeFile(common.log_file, '', () => { });
|
||||
} else if ((!exists && config.Authentication.enableLogging) || (!exists && config.Settings.enableLogging)) {
|
||||
} else {
|
||||
try {
|
||||
var dirname = path.dirname(common.log_file);
|
||||
createDirectory(dirname);
|
||||
connect.createDirectory(dirname);
|
||||
var createStream = fs.createWriteStream(common.log_file);
|
||||
createStream.end();
|
||||
}
|
||||
|
@ -177,18 +171,67 @@ const validateConfigFile = (config) => {
|
|||
}
|
||||
|
||||
if (undefined !== process.env.PORT) {
|
||||
common.port = normalizePort(process.env.PORT);
|
||||
common.port = connect.normalizePort(process.env.PORT);
|
||||
} else if (undefined !== config.Settings.port) {
|
||||
common.port = normalizePort(config.Settings.port);
|
||||
common.port = connect.normalizePort(config.Settings.port);
|
||||
}
|
||||
|
||||
setSSOParams(config);
|
||||
connect.setSSOParams(config);
|
||||
if (errMsg !== '') {
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
}
|
||||
|
||||
const setSSOParams = (config) => {
|
||||
connect.validateMultiNodeConfig = (config) => {
|
||||
common.node_auth_type = 'CUSTOM';
|
||||
common.rtl_pass = config.multiPass;
|
||||
|
||||
config.nodes.forEach((node, idx) => {
|
||||
common.nodes[idx] = {};
|
||||
if(node.Authentication.macaroonPath === '' || undefined === node.Authentication.macaroonPath) {
|
||||
errMsg = 'Please set macaroon path for node index ' + node.index + ' in RTL-Multi-Node-Conf.json!';
|
||||
} else {
|
||||
common.nodes[idx].macaroon_path = node.Authentication.macaroonPath;
|
||||
}
|
||||
|
||||
if((node.Settings.lndServerUrl === '' || undefined === node.Settings.lndServerUrl)) {
|
||||
errMsg = errMsg + '\nPlease set LND server URL for node index ' + node.index + ' in RTL-Multi-Node-Conf.json!';
|
||||
} else {
|
||||
common.nodes[idx].lnd_server_url = node.Settings.lndServerUrl;
|
||||
}
|
||||
|
||||
common.nodes[idx].index = node.index;
|
||||
common.nodes[idx].ln_node = node.lnNode;
|
||||
common.nodes[idx].ln_implementation = node.lnImplementation;
|
||||
common.nodes[idx].lnd_config_path = (undefined !== node.Authentication.lndConfigPath) ? node.Authentication.lndConfigPath : '';
|
||||
common.nodes[idx].bitcoind_config_path = (undefined !== node.Settings.bitcoindConfigPath) ? node.Settings.bitcoindConfigPath : '';
|
||||
common.nodes[idx].enable_logging = (undefined !== node.Settings.enableLogging) ? node.Settings.enableLogging : false;
|
||||
common.nodes[idx].port = (undefined !== node.Settings.port) ? connect.normalizePort(node.Settings.port) : 3000;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connect.setSSOParams(config);
|
||||
if (errMsg !== '') { throw new Error(errMsg); }
|
||||
}
|
||||
|
||||
connect.setSSOParams = (config) => {
|
||||
if (undefined !== process.env.RTL_SSO) {
|
||||
common.rtl_sso = process.env.RTL_SSO;
|
||||
} else if (undefined !== config.SSO && undefined !== config.SSO.rtlSSO) {
|
||||
|
@ -210,11 +253,11 @@ const setSSOParams = (config) => {
|
|||
} else {
|
||||
common.rtl_cookie_path = common.rtl_conf_file_path + '/cookies/auth.cookie';
|
||||
}
|
||||
readCookie(common.rtl_cookie_path);
|
||||
connect.readCookie(common.rtl_cookie_path);
|
||||
}
|
||||
};
|
||||
|
||||
const createDirectory = (dirname) => {
|
||||
connect.createDirectory = (dirname) => {
|
||||
try {
|
||||
fs.mkdirSync(dirname);
|
||||
} catch (err) {
|
||||
|
@ -227,300 +270,116 @@ const createDirectory = (dirname) => {
|
|||
}
|
||||
}
|
||||
|
||||
const readCookie = (cookieFile) => {
|
||||
connect.readCookie = (cookieFile) => {
|
||||
let exists = fs.existsSync(cookieFile);
|
||||
if (exists) {
|
||||
common.cookie = fs.readFileSync(cookieFile, 'utf-8');
|
||||
} else {
|
||||
try {
|
||||
var dirname = path.dirname(cookieFile);
|
||||
createDirectory(dirname);
|
||||
connect.createDirectory(dirname);
|
||||
fs.writeFileSync(cookieFile, crypto.randomBytes(64).toString('hex'));
|
||||
common.cookie = fs.readFileSync(cookieFile, 'utf-8');
|
||||
}
|
||||
catch(err) {
|
||||
console.error('Something went wrong while creating cookie file: \n' + err);
|
||||
console.error('Something went wrong while reading cookie: \n' + err);
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String.random = function (length) {
|
||||
let radom13chars = function () {
|
||||
return Math.random().toString(16).substring(2, 15).toUpperCase();
|
||||
}
|
||||
let loops = Math.ceil(length / 13);
|
||||
return new Array(loops).fill(radom13chars).reduce((string, func) => {
|
||||
return string + func();
|
||||
}, '').substring(-length);
|
||||
}
|
||||
|
||||
const logEnvVariables = () => {
|
||||
if (!common.enable_logging) {
|
||||
return;
|
||||
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);
|
||||
}
|
||||
logger.info('\r\nConfig Setup Variable PORT: ' + common.port);
|
||||
logger.info('\r\nConfig Setup Variable LND_SERVER_URL: ' + common.lnd_server_url);
|
||||
logger.info('\r\nConfig Setup Variable MACAROON_PATH: ' + common.macaroon_path);
|
||||
logger.info('\r\nConfig Setup Variable NODE_AUTH_TYPE: ' + common.node_auth_type);
|
||||
logger.info('\r\nConfig Setup Variable LND_CONFIG_PATH: ' + common.lnd_config_path);
|
||||
logger.info('\r\nConfig Setup Variable RTL_CONFIG_PATH: ' + common.rtl_conf_file_path);
|
||||
logger.info('\r\nConfig Setup Variable BITCOIND_CONFIG_PATH: ' + common.bitcoind_config_path);
|
||||
logger.info('\r\nConfig Setup Variable RTL_SSO: ' + common.rtl_sso);
|
||||
logger.info('\r\nConfig Setup Variable RTL_COOKIE_PATH: ' + common.rtl_cookie_path);
|
||||
logger.info('\r\nConfig Setup Variable LOGOUT_REDIRECT_LINK: ' + common.logout_redirect_link);
|
||||
}
|
||||
|
||||
var errMsg = '';
|
||||
connect.setSingleNodeConfiguration = () => {
|
||||
common.rtl_conf_file_path = (undefined !== process.env.RTL_CONFIG_PATH) ? process.env.RTL_CONFIG_PATH.substring(0, process.env.RTL_CONFIG_PATH.length - 9) : path.normalize(__dirname);
|
||||
RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
|
||||
let exists = fs.existsSync(RTLConfFile);
|
||||
connect.logEnvVariables = () => {
|
||||
if (common.multi_node_setup) {
|
||||
common.nodes.forEach((node, idx) => {
|
||||
if (!node.enable_logging) { return; }
|
||||
logger.info('\r\nConfig Setup Variable NODE_SETUP: MULTI', node);
|
||||
logger.info('\r\nConfig Setup Variable RTL_SSO: ' + common.rtl_sso, node);
|
||||
logger.info('\r\nConfig Setup Variable RTL_COOKIE_PATH: ' + common.rtl_cookie_path, node);
|
||||
logger.info('\r\nConfig Setup Variable LOGOUT_REDIRECT_LINK: ' + common.logout_redirect_link + '\r\n', node);
|
||||
logger.info('\r\nConfig Setup Variable INDEX: ' + node.index, node);
|
||||
logger.info('\r\nConfig Setup Variable LN NODE: ' + node.ln_node, node);
|
||||
logger.info('\r\nConfig Setup Variable LN IMPLEMENTATION: ' + node.ln_implementation, node);
|
||||
logger.info('\r\nConfig Setup Variable PORT: ' + node.port, node);
|
||||
logger.info('\r\nConfig Setup Variable MACAROON_PATH: ' + node.macaroon_path, node);
|
||||
logger.info('\r\nConfig Setup Variable LND_SERVER_URL: ' + node.lnd_server_url, node);
|
||||
logger.info('\r\nConfig Setup Variable RTL_CONFIG_PATH: ' + node.rtl_conf_file_path, node);
|
||||
logger.info('\r\nConfig Setup Variable LND_CONFIG_PATH: ' + node.lnd_config_path, node);
|
||||
logger.info('\r\nConfig Setup Variable BITCOIND_CONFIG_PATH: ' + node.bitcoind_config_path, node);
|
||||
});
|
||||
} else {
|
||||
if (!common.enable_logging) { return; }
|
||||
logger.info('\r\nConfig Setup Variable NODE_SETUP: SINGLE');
|
||||
logger.info('\r\nConfig Setup Variable PORT: ' + common.port);
|
||||
logger.info('\r\nConfig Setup Variable LND_SERVER_URL: ' + common.lnd_server_url);
|
||||
logger.info('\r\nConfig Setup Variable MACAROON_PATH: ' + common.macaroon_path);
|
||||
logger.info('\r\nConfig Setup Variable NODE_AUTH_TYPE: ' + common.node_auth_type);
|
||||
logger.info('\r\nConfig Setup Variable LND_CONFIG_PATH: ' + common.lnd_config_path);
|
||||
logger.info('\r\nConfig Setup Variable RTL_CONFIG_PATH: ' + common.rtl_conf_file_path);
|
||||
logger.info('\r\nConfig Setup Variable BITCOIND_CONFIG_PATH: ' + common.bitcoind_config_path);
|
||||
logger.info('\r\nConfig Setup Variable RTL_SSO: ' + common.rtl_sso);
|
||||
logger.info('\r\nConfig Setup Variable RTL_COOKIE_PATH: ' + common.rtl_cookie_path);
|
||||
logger.info('\r\nConfig Setup Variable LOGOUT_REDIRECT_LINK: ' + common.logout_redirect_link);
|
||||
}
|
||||
}
|
||||
|
||||
connect.setSingleNodeConfiguration = (singleNodeFilePath) => {
|
||||
const exists = fs.existsSync(singleNodeFilePath);
|
||||
if (exists) {
|
||||
var config = ini.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
|
||||
setMacaroonPath(clArgs, config)
|
||||
validateConfigFile(config);
|
||||
logEnvVariables();
|
||||
var config = ini.parse(fs.readFileSync(singleNodeFilePath, 'utf-8'));
|
||||
connect.setMacaroonPath(clArgs, config);
|
||||
connect.validateSingleNodeConfig(config);
|
||||
connect.logEnvVariables();
|
||||
} else {
|
||||
try {
|
||||
fs.writeFileSync(RTLConfFile, ini.stringify(setDefaultConfig()));
|
||||
throw new Error('Please change default settings of macaroonPath, lndConfigPath and bitcoindConfigPath in RTL.conf and restart the server');
|
||||
fs.writeFileSync(singleNodeFilePath, ini.stringify(connect.setDefaultConfig()));
|
||||
var config = ini.parse(fs.readFileSync(singleNodeFilePath, 'utf-8'));
|
||||
connect.setMacaroonPath(clArgs, config);
|
||||
connect.validateSingleNodeConfig(config);
|
||||
connect.logEnvVariables();
|
||||
}
|
||||
catch(err) {
|
||||
console.error('Something went wrong while creating config file: \n' + err);
|
||||
console.error('Something went wrong while configuring the single node server: \n' + err);
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
connect.setNodeConfiguration = () => {
|
||||
common.rtl_conf_file_path = (undefined !== process.env.RTL_CONFIG_PATH) ? process.env.RTL_CONFIG_PATH.substring(0, process.env.RTL_CONFIG_PATH.length - 9) : path.normalize(__dirname);
|
||||
RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
|
||||
|
||||
common.rtl_multi_node_conf_file_path = (undefined !== process.env.RTL_MULTI_NODE_CONFIG_PATH) ? process.env.RTL_MULTI_NODE_CONFIG_PATH.substring(0, process.env.RTL_MULTI_NODE_CONFIG_PATH.length - 25) : path.normalize(__dirname);
|
||||
RTLMultiNodeConfFile = common.rtl_multi_node_conf_file_path + '/RTL-Multi-Node-Conf.json';
|
||||
|
||||
|
||||
connect.setMultiNodeConfiguration = (multiNodeFilePath) => {
|
||||
try {
|
||||
var config = JSON.parse(fs.readFileSync(multiNodeFilePath, 'utf-8'));
|
||||
connect.validateMultiNodeConfig(config);
|
||||
connect.logEnvVariables();
|
||||
}
|
||||
catch(err) {
|
||||
console.error('Something went wrong while configuring the multi node server: \n' + err);
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// MULTI NODE CODE
|
||||
// const setMacaroonPath = (clArgs, config) => {
|
||||
// if(undefined !== clArgs.lndir) {
|
||||
// common.macaroon_path = clArgs.lndir;
|
||||
// } else if (undefined !== process.env.MACAROON_PATH) {
|
||||
// common.macaroon_path = process.env.MACAROON_PATH;
|
||||
// } else {
|
||||
// if(undefined !== config.Authentication.macroonPath && config.Authentication.macroonPath !== '') {
|
||||
// common.macaroon_path = config.Authentication.macroonPath;
|
||||
// } else if(undefined !== config.Authentication.macaroonPath && config.Authentication.macaroonPath !== '') {
|
||||
// common.macaroon_path = config.Authentication.macaroonPath;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// const validateConfigFile = (config) => {
|
||||
// if(common.macaroon_path === '' || undefined === common.macaroon_path) {
|
||||
// errMsg = 'Please set macaroon path through environment or RTL.conf!';
|
||||
// }
|
||||
|
||||
// if(undefined !== process.env.LND_SERVER_URL) {
|
||||
// common.lnd_server_url = process.env.LND_SERVER_URL;
|
||||
// } else {
|
||||
// if((config.Authentication.lndServerUrl === '' || undefined === config.Authentication.lndServerUrl) && (config.Settings.lndServerUrl === '' || undefined === config.Settings.lndServerUrl)) {
|
||||
// errMsg = errMsg + '\nPlease set LND Server URL through environment or RTL.conf!';
|
||||
// } else {
|
||||
// if (config.Settings.lndServerUrl !== '' && undefined !== config.Settings.lndServerUrl) {
|
||||
// common.lnd_server_url = config.Settings.lndServerUrl;
|
||||
// } else if (config.Authentication.lndServerUrl !== '' && undefined !== config.Authentication.lndServerUrl) {
|
||||
// common.lnd_server_url = config.Authentication.lndServerUrl;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if(undefined !== process.env.NODE_AUTH_TYPE) {
|
||||
// common.node_auth_type = process.env.NODE_AUTH_TYPE;
|
||||
// } else {
|
||||
// if(config.Authentication.nodeAuthType === '' || undefined === config.Authentication.nodeAuthType) {
|
||||
// errMsg = errMsg + '\nPlease set Node Auth Type through environment/RTL.conf!';
|
||||
// } else {
|
||||
// common.node_auth_type = config.Authentication.nodeAuthType;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if(undefined !== process.env.LND_CONFIG_PATH) {
|
||||
// common.lnd_config_path = process.env.LND_CONFIG_PATH;
|
||||
// } else {
|
||||
// if(config.Authentication.lndConfigPath !== '' && undefined !== config.Authentication.lndConfigPath) {
|
||||
// common.lnd_config_path = config.Authentication.lndConfigPath;
|
||||
// } else {
|
||||
// if(upperCase(common.node_auth_type) === 'DEFAULT') {
|
||||
// errMsg = errMsg + '\nDefault Node Authentication can be set with LND Config Path only. Please set LND Config Path through environment or RTL.conf!';
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if(undefined !== process.env.BITCOIND_CONFIG_PATH) {
|
||||
// common.bitcoind_config_path = process.env.BITCOIND_CONFIG_PATH;
|
||||
// } else {
|
||||
// if(config.Settings.bitcoindConfigPath !== '' || undefined !== config.Settings.bitcoindConfigPath) {
|
||||
// common.bitcoind_config_path = config.Settings.bitcoindConfigPath;
|
||||
// } else if(config.Authentication.bitcoindConfigPath !== '' || undefined !== config.Authentication.bitcoindConfigPath) {
|
||||
// common.bitcoind_config_path = config.Authentication.bitcoindConfigPath;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (undefined !== process.env.RTL_PASS) {
|
||||
// common.rtl_pass = process.env.RTL_PASS;
|
||||
// } else if (config.Authentication.rtlPass !== '' || undefined !== config.Authentication.rtlPass) {
|
||||
// common.rtl_pass = config.Authentication.rtlPass;
|
||||
|
||||
// }
|
||||
|
||||
// if (upperCase(common.node_auth_type) === 'CUSTOM' && (common.rtl_pass === '' || undefined === common.rtl_pass)) {
|
||||
// errMsg = errMsg + '\nCustom Node Authentication can be set with RTL password only. Please set RTL Password through environment/RTL.conf';
|
||||
// }
|
||||
|
||||
// if (undefined !== process.env.ENABLE_LOGGING) {
|
||||
// common.enable_logging = process.env.ENABLE_LOGGING;
|
||||
// } else if (undefined !== config.Settings.enableLogging) {
|
||||
// common.enable_logging = config.Settings.enableLogging;
|
||||
// } else if (undefined !== config.Authentication.enableLogging) {
|
||||
// common.enable_logging = config.Authentication.enableLogging;
|
||||
// }
|
||||
// if (common.enable_logging) {
|
||||
// common.log_file = common.rtl_conf_file_path + '/logs/RTL.log';
|
||||
// let exists = fs.existsSync(common.log_file);
|
||||
// if (exists) {
|
||||
// fs.writeFile(common.log_file, '', () => { });
|
||||
// } else if ((!exists && config.Authentication.enableLogging) || (!exists && config.Settings.enableLogging)) {
|
||||
// try {
|
||||
// var dirname = path.dirname(common.log_file);
|
||||
// createDirectory(dirname);
|
||||
// var createStream = fs.createWriteStream(common.log_file);
|
||||
// createStream.end();
|
||||
// }
|
||||
// catch (err) {
|
||||
// console.error('Something went wrong while creating log file: \n' + err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (undefined !== process.env.PORT) {
|
||||
// common.port = normalizePort(process.env.PORT);
|
||||
// } else if (undefined !== config.Settings.port) {
|
||||
// common.port = normalizePort(config.Settings.port);
|
||||
// }
|
||||
|
||||
// setSSOParams(config);
|
||||
// if (errMsg !== '') {
|
||||
// throw new Error(errMsg);
|
||||
// }
|
||||
// }
|
||||
|
||||
// const setSSOParams = (config) => {
|
||||
// if (undefined !== process.env.RTL_SSO) {
|
||||
// common.rtl_sso = process.env.RTL_SSO;
|
||||
// } else if (undefined !== config.SSO && undefined !== config.SSO.rtlSSO) {
|
||||
// common.rtl_sso = config.SSO.rtlSSO;
|
||||
// }
|
||||
|
||||
// if (+common.rtl_sso) {
|
||||
// if (undefined !== process.env.LOGOUT_REDIRECT_LINK) {
|
||||
// common.logout_redirect_link = process.env.LOGOUT_REDIRECT_LINK;
|
||||
// } else if (undefined !== config.SSO && undefined !== config.SSO.logoutRedirectLink) {
|
||||
// common.logout_redirect_link = config.SSO.logoutRedirectLink;
|
||||
// }
|
||||
|
||||
|
||||
// if (undefined !== process.env.RTL_COOKIE_PATH) {
|
||||
// common.rtl_cookie_path = process.env.RTL_COOKIE_PATH;
|
||||
// } else if (undefined !== config.SSO && undefined !== config.SSO.rtlCookiePath) {
|
||||
// common.rtl_cookie_path = config.SSO.rtlCookiePath;
|
||||
// } else {
|
||||
// common.rtl_cookie_path = common.rtl_conf_file_path + '/cookies/auth.cookie';
|
||||
// }
|
||||
// readCookie(common.rtl_cookie_path);
|
||||
// }
|
||||
// };
|
||||
|
||||
// const createDirectory = (dirname) => {
|
||||
// try {
|
||||
// fs.mkdirSync(dirname);
|
||||
// } catch (err) {
|
||||
// if (err.code === 'EEXIST') {
|
||||
// return dirname;
|
||||
// }
|
||||
// if (err.code === 'ENOENT') {
|
||||
// throw new Error(`EACCES: permission denied, mkdir '${dirname}'`);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// const readCookie = (cookieFile) => {
|
||||
// let exists = fs.existsSync(cookieFile);
|
||||
// if (exists) {
|
||||
// common.cookie = fs.readFileSync(cookieFile, 'utf-8');
|
||||
// } else {
|
||||
// try {
|
||||
// var dirname = path.dirname(cookieFile);
|
||||
// createDirectory(dirname);
|
||||
// fs.writeFileSync(cookieFile, crypto.randomBytes(64).toString('hex'));
|
||||
// common.cookie = fs.readFileSync(cookieFile, 'utf-8');
|
||||
// }
|
||||
// catch(err) {
|
||||
// console.error('Something went wrong while creating cookie file: \n' + err);
|
||||
// throw new Error(err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// String.random = function (length) {
|
||||
// let radom13chars = function () {
|
||||
// return Math.random().toString(16).substring(2, 15).toUpperCase();
|
||||
// }
|
||||
// let loops = Math.ceil(length / 13);
|
||||
// return new Array(loops).fill(radom13chars).reduce((string, func) => {
|
||||
// return string + func();
|
||||
// }, '').substring(-length);
|
||||
// }
|
||||
|
||||
// const logEnvVariables = () => {
|
||||
// if (!common.enable_logging) {
|
||||
// return;
|
||||
// }
|
||||
// logger.info('\r\nConfig Setup Variable PORT: ' + common.port);
|
||||
// logger.info('\r\nConfig Setup Variable LND_SERVER_URL: ' + common.lnd_server_url);
|
||||
// logger.info('\r\nConfig Setup Variable MACAROON_PATH: ' + common.macaroon_path);
|
||||
// logger.info('\r\nConfig Setup Variable NODE_AUTH_TYPE: ' + common.node_auth_type);
|
||||
// logger.info('\r\nConfig Setup Variable LND_CONFIG_PATH: ' + common.lnd_config_path);
|
||||
// logger.info('\r\nConfig Setup Variable RTL_CONFIG_PATH: ' + common.rtl_conf_file_path);
|
||||
// logger.info('\r\nConfig Setup Variable BITCOIND_CONFIG_PATH: ' + common.bitcoind_config_path);
|
||||
// logger.info('\r\nConfig Setup Variable RTL_SSO: ' + common.rtl_sso);
|
||||
// logger.info('\r\nConfig Setup Variable RTL_COOKIE_PATH: ' + common.rtl_cookie_path);
|
||||
// logger.info('\r\nConfig Setup Variable LOGOUT_REDIRECT_LINK: ' + common.logout_redirect_link);
|
||||
// }
|
||||
|
||||
// var errMsg = '';
|
||||
// connect.configFileExists = () => {
|
||||
// common.rtl_conf_file_path = (undefined !== process.env.RTL_CONFIG_PATH) ? process.env.RTL_CONFIG_PATH.substring(0, process.env.RTL_CONFIG_PATH.length - 9) : path.normalize(__dirname);
|
||||
// RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
|
||||
// let exists = fs.existsSync(RTLConfFile);
|
||||
// if (exists) {
|
||||
// var config = ini.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
|
||||
// setMacaroonPath(clArgs, config)
|
||||
// validateConfigFile(config);
|
||||
// logEnvVariables();
|
||||
// } else {
|
||||
// try {
|
||||
// fs.writeFileSync(RTLConfFile, ini.stringify(setDefaultConfig()));
|
||||
// throw new Error('Please change default settings of macaroonPath, lndConfigPath and bitcoindConfigPath in RTL.conf and restart the server');
|
||||
// }
|
||||
// catch(err) {
|
||||
// console.error('Something went wrong while creating config file: \n' + err);
|
||||
// throw new Error(err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
connect.setServerConfiguration = () => {
|
||||
common.rtl_conf_file_path = (undefined !== process.env.RTL_CONFIG_PATH) ? process.env.RTL_CONFIG_PATH.substring(0, process.env.RTL_CONFIG_PATH.length - 9) : path.normalize(__dirname);
|
||||
singleNodeConfFile = common.rtl_conf_file_path + '/RTL.conf';
|
||||
multiNodeConfFile = common.rtl_conf_file_path + '/RTL-Multi-Node-Conf.json';
|
||||
const singleNodeExists = fs.existsSync(singleNodeConfFile);
|
||||
const multiNodeExists = fs.existsSync(multiNodeConfFile);
|
||||
if ((!multiNodeExists && singleNodeExists) || (!multiNodeExists && !singleNodeExists)) {
|
||||
common.multi_node_setup = false;
|
||||
connect.setSingleNodeConfiguration(singleNodeConfFile);
|
||||
} else if ((multiNodeExists && singleNodeExists) || (multiNodeExists && !singleNodeExists)) {
|
||||
common.multi_node_setup = true;
|
||||
connect.setMultiNodeConfiguration(multiNodeConfFile);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = connect;
|
||||
|
|
|
@ -101,11 +101,7 @@ exports.getMultiNodeConfig = (req, res, next) => {
|
|||
}
|
||||
} else {
|
||||
const multiNodeConfig = require('../RTL-Multi-Node-Conf.json');
|
||||
var nodeInfos = [];
|
||||
for(var key in multiNodeConfig) {
|
||||
nodeInfos.push({"index":multiNodeConfig[key].index, "lnNode":multiNodeConfig[key].lnNode, "lnImpl":multiNodeConfig[key].lnImplementation});
|
||||
}
|
||||
res.status(200).json({ nodes: nodeInfos });
|
||||
res.status(200).json(multiNodeConfig);
|
||||
}
|
||||
});
|
||||
};
|
|
@ -1,6 +1,7 @@
|
|||
var ini = require('ini');
|
||||
var fs = require('fs');
|
||||
var common = require('../common');
|
||||
var connect = require('../connect');
|
||||
const jwt = require("jsonwebtoken");
|
||||
var upperCase = require('upper-case');
|
||||
var atob = require('atob');
|
||||
|
@ -32,6 +33,7 @@ exports.authenticateUser = (req, res, next) => {
|
|||
// Replace access_key value from req.cookies['access-key'] to req.body.password to test SSO on http
|
||||
// const access_key = atob(req.body.password);
|
||||
if (common.cookie === access_key) {
|
||||
connect.refreshCookie(common.rtl_cookie_path);
|
||||
const token = jwt.sign(
|
||||
{ user: 'Custom_User', lndConfigPath: common.lnd_config_path, macaroonPath: common.macaroon_path },
|
||||
common.secret_key
|
||||
|
@ -44,9 +46,9 @@ exports.authenticateUser = (req, res, next) => {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
password = atob(req.body.password);
|
||||
const password = atob(req.body.password);
|
||||
selNode = req.body.node;
|
||||
if(selNode === '') {
|
||||
if (undefined === selNode || selNode === '') {
|
||||
if(upperCase(common.node_auth_type) === 'CUSTOM') {
|
||||
if (common.rtl_pass === password) {
|
||||
var rpcUser = 'Custom_User';
|
||||
|
@ -65,15 +67,19 @@ exports.authenticateUser = (req, res, next) => {
|
|||
fs.readFile(common.lnd_config_path, 'utf8', function (err, data) {
|
||||
if (err) {
|
||||
logger.error('\r\nAuthenticate: 45: ' + JSON.stringify(Date.now()) + ': ERROR: LND Config Reading Failed!');
|
||||
err.description = 'You might be connecting RTL remotely to your LND node OR You might be missing rpcpass in your lnd.conf.';
|
||||
err.description = err.description + ' If the former modify the RTL.conf for remote setting.';
|
||||
err.description = err.description + ' If the later modify the lnd.conf to include rpcpass';
|
||||
res.status(500).json({
|
||||
message: "LND Config Reading Failed!",
|
||||
error: err
|
||||
});
|
||||
} else {
|
||||
const jsonLNDConfig = ini.parse(data);
|
||||
if (undefined !== jsonLNDConfig.Bitcoind && undefined !== jsonLNDConfig.Bitcoind['bitcoind.rpcpass']) {
|
||||
if (jsonLNDConfig.Bitcoind['bitcoind.rpcpass'] === password) {
|
||||
var rpcUser = (undefined !== jsonLNDConfig.Bitcoind['bitcoind.rpcuser']) ? jsonLNDConfig.Bitcoind['bitcoind.rpcuser'] : '';
|
||||
if ((undefined !== jsonLNDConfig.Bitcoind && undefined !== jsonLNDConfig.Bitcoind['bitcoind.rpcpass']) || (undefined !== jsonLNDConfig['bitcoind.rpcpass'])) {
|
||||
if ((undefined !== jsonLNDConfig.Bitcoind && jsonLNDConfig.Bitcoind['bitcoind.rpcpass'] === password) || (undefined !== jsonLNDConfig['bitcoind.rpcpass'] && jsonLNDConfig['bitcoind.rpcpass'] === password)) {
|
||||
var rpcUser = (undefined !== jsonLNDConfig.Bitcoind && undefined !== jsonLNDConfig.Bitcoind['bitcoind.rpcuser']) ? jsonLNDConfig.Bitcoind['bitcoind.rpcuser'] : '';
|
||||
rpcUser = (rpcUser === '' && undefined !== jsonLNDConfig['bitcoind.rpcuser']) ? jsonLNDConfig['bitcoind.rpcuser'] : '';
|
||||
const token = jwt.sign(
|
||||
{ user: rpcUser, lndConfigPath: common.lnd_config_path, macaroonPath: common.macaroon_path },
|
||||
common.secret_key
|
||||
|
@ -95,7 +101,6 @@ exports.authenticateUser = (req, res, next) => {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@ var logger = require('./logger');
|
|||
var options = {};
|
||||
|
||||
exports.getBalance = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/balance/' + req.params.source;
|
||||
options.qs = req.query;
|
||||
request(options).then((body) => {
|
||||
|
|
|
@ -25,7 +25,7 @@ getAliasForChannel = (channel, channelType) => {
|
|||
}
|
||||
|
||||
exports.getChannels = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
if (undefined === req.params.channelType || req.params.channelType === 'all') {
|
||||
options.url = common.lnd_server_url + '/channels';
|
||||
} else {
|
||||
|
@ -74,7 +74,7 @@ exports.getChannels = (req, res, next) => {
|
|||
};
|
||||
|
||||
exports.postChannel = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/channels';
|
||||
options.form = {
|
||||
node_pubkey_string: req.body.node_pubkey,
|
||||
|
@ -108,7 +108,7 @@ exports.postChannel = (req, res, next) => {
|
|||
};
|
||||
|
||||
exports.postTransactions = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/channels/transactions';
|
||||
if(req.body.paymentReq) {
|
||||
options.form = JSON.stringify({
|
||||
|
@ -149,7 +149,7 @@ exports.postTransactions = (req, res, next) => {
|
|||
|
||||
exports.closeChannel = (req, res, next) => {
|
||||
req.setTimeout(60000 * 10); // timeout 10 mins
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
let channelpoint = req.params.channelPoint.replace(':', '/');
|
||||
options.url = common.lnd_server_url + '/channels/' + channelpoint + '?force=' + req.query.force;
|
||||
logger.info('\r\nChannels: 144: ' + JSON.stringify(Date.now()) + ': INFO: Closing Channel: ' + options.url);
|
||||
|
@ -174,7 +174,7 @@ exports.closeChannel = (req, res, next) => {
|
|||
}
|
||||
|
||||
exports.postChanPolicy = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/chanpolicy';
|
||||
if(req.body.chanPoint === 'all') {
|
||||
options.form = JSON.stringify({
|
||||
|
|
|
@ -4,7 +4,7 @@ var logger = require('./logger');
|
|||
var options = {};
|
||||
|
||||
exports.getFees = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/fees';
|
||||
request(options).then((body) => {
|
||||
logger.info('\r\nFees: 8: ' + JSON.stringify(Date.now()) + ': INFO: Fee Received: ' + JSON.stringify(body));
|
||||
|
|
|
@ -4,7 +4,7 @@ var logger = require('./logger');
|
|||
var options = {};
|
||||
|
||||
exports.getInfo = (req, res, next) => {
|
||||
options = common.setOptions();
|
||||
options = common.setOptions('');
|
||||
options.url = common.lnd_server_url + '/getinfo';
|
||||
logger.info('\r\nCalling getinfo from lnd server url: INFO: ' + options.url);
|
||||
request(options).then((body) => {
|
||||
|
|
|
@ -4,7 +4,7 @@ var logger = require('./logger');
|
|||
var options = {};
|
||||
|
||||
exports.getDescribeGraph = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/graph';
|
||||
request.get(options).then((body) => {
|
||||
const body_str = (undefined === body) ? '' : JSON.stringify(body);
|
||||
|
@ -28,7 +28,7 @@ exports.getDescribeGraph = (req, res, next) => {
|
|||
};
|
||||
|
||||
exports.getGraphInfo = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/graph/info';
|
||||
request.get(options).then((body) => {
|
||||
const body_str = (undefined === body) ? '' : JSON.stringify(body);
|
||||
|
@ -57,7 +57,7 @@ exports.getGraphInfo = (req, res, next) => {
|
|||
};
|
||||
|
||||
exports.getGraphNode = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/graph/node/' + req.params.pubKey;
|
||||
request(options).then((body) => {
|
||||
logger.info('\r\nGraph: 59: ' + JSON.stringify(Date.now()) + ': INFO: Node Info Received: ' + JSON.stringify(body));
|
||||
|
@ -81,7 +81,7 @@ exports.getGraphNode = (req, res, next) => {
|
|||
};
|
||||
|
||||
exports.getGraphEdge = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/graph/edge/' + req.params.chanid;
|
||||
request(options).then((body) => {
|
||||
logger.info('\r\nGraph: 79: ' + JSON.stringify(Date.now()) + ': INFO: Edge Info Received: ' + JSON.stringify(body));
|
||||
|
|
|
@ -3,6 +3,7 @@ var options = require("../connect");
|
|||
var common = require('../common');
|
||||
|
||||
exports.getGraphInfo = (req, res, next) => {
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/graph/info';
|
||||
request.get(options, (error, response, body) => {
|
||||
const body_str = (undefined === body) ? '' : JSON.stringify(body);
|
||||
|
|
|
@ -4,7 +4,7 @@ var logger = require('./logger');
|
|||
var options = {};
|
||||
|
||||
exports.getInvoice = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/invoice/' + req.params.rHashStr;
|
||||
request(options).then((body) => {
|
||||
logger.info('\r\nInvoice: 8: ' + JSON.stringify(Date.now()) + ': INFO: Invoice Info Received: ' + JSON.stringify(body));
|
||||
|
@ -25,7 +25,7 @@ exports.getInvoice = (req, res, next) => {
|
|||
};
|
||||
|
||||
exports.listInvoices = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/invoices';
|
||||
request(options).then((body) => {
|
||||
const body_str = (undefined === body) ? '' : JSON.stringify(body);
|
||||
|
@ -59,7 +59,7 @@ exports.listInvoices = (req, res, next) => {
|
|||
};
|
||||
|
||||
exports.addInvoice = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/invoices';
|
||||
options.form = JSON.stringify({
|
||||
memo: req.body.memo,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
var fs = require('fs');
|
||||
var common = require('../common');
|
||||
|
||||
exports.info = (msgStr) => {
|
||||
exports.info = (msgStr, selNode = {}) => {
|
||||
if (msgStr.indexOf('Config Setup Variable') === -1) {
|
||||
console.log('Console: ' + msgStr);
|
||||
}
|
||||
if(common.enable_logging) {
|
||||
if(!common.multi_node_setup && common.enable_logging) {
|
||||
fs.appendFile(common.log_file, msgStr, function(err) {
|
||||
if (err) {
|
||||
return ({ error: 'Updating Log Failed!' });
|
||||
|
@ -14,11 +14,21 @@ exports.info = (msgStr) => {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(common.multi_node_setup && selNode.enable_logging) {
|
||||
fs.appendFile(selNode.log_file, msgStr, function(err) {
|
||||
if (err) {
|
||||
return ({ error: 'Updating Log Failed!' });
|
||||
} else {
|
||||
return ({ message: 'Log Updated Successfully' });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
exports.error = (msgStr) => {
|
||||
exports.error = (msgStr, selNode = {}) => {
|
||||
console.error('Console: ' + msgStr);
|
||||
if(common.enable_logging) {
|
||||
if(!common.multi_node_setup && common.enable_logging) {
|
||||
fs.appendFile(common.log_file, msgStr, function(err) {
|
||||
if (err) {
|
||||
return ({ error: 'Updating Log Failed!' });
|
||||
|
@ -27,4 +37,14 @@ exports.error = (msgStr) => {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(common.multi_node_setup && selNode.enable_logging) {
|
||||
fs.appendFile(selNode.log_file, msgStr, function(err) {
|
||||
if (err) {
|
||||
return ({ error: 'Updating Log Failed!' });
|
||||
} else {
|
||||
return ({ message: 'Log Updated Successfully' });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ var logger = require('./logger');
|
|||
var options = {};
|
||||
|
||||
exports.getNewAddress = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/newaddress?type=' + req.query.type;
|
||||
request(options).then((body) => {
|
||||
const body_str = (undefined === body) ? '' : JSON.stringify(body);
|
||||
|
|
|
@ -4,7 +4,7 @@ var logger = require('./logger');
|
|||
var options = {};
|
||||
|
||||
exports.decodePayment = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/payreq/' + req.params.payRequest;
|
||||
request(options).then((body) => {
|
||||
const body_str = (undefined === body) ? '' : JSON.stringify(body);
|
||||
|
|
|
@ -4,7 +4,7 @@ var logger = require('./logger');
|
|||
var options = {};
|
||||
|
||||
exports.getPayments = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/payments';
|
||||
request(options).then((body) => {
|
||||
const body_str = (undefined === body) ? '' : JSON.stringify(body);
|
||||
|
|
|
@ -16,9 +16,8 @@ getAliasForPeers = (peer) => {
|
|||
});
|
||||
}
|
||||
|
||||
exports.getPeers = (req, res, next) =>
|
||||
{
|
||||
options = common.options;
|
||||
exports.getPeers = (req, res, next) => {
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/peers';
|
||||
request(options).then(function (body) {
|
||||
let peers = (undefined === body.peers) ? [] : body.peers;
|
||||
|
@ -43,7 +42,7 @@ exports.getPeers = (req, res, next) =>
|
|||
};
|
||||
|
||||
exports.postPeer = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/peers';
|
||||
options.form = JSON.stringify({
|
||||
addr: { host: req.body.host, pubkey: req.body.pubkey },
|
||||
|
@ -86,7 +85,7 @@ exports.postPeer = (req, res, next) => {
|
|||
};
|
||||
|
||||
exports.deletePeer = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/peers/' + req.params.peerPubKey;
|
||||
request.delete(options).then((body) => {
|
||||
logger.info('\r\nPeers: 81: ' + JSON.stringify(Date.now()) + ': INFO: Detach Peer Response: ' + JSON.stringify(body));
|
||||
|
|
|
@ -4,7 +4,7 @@ var logger = require('./logger');
|
|||
var options = {};
|
||||
|
||||
exports.forwardingHistory = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/switch';
|
||||
options.form = {};
|
||||
if (undefined !== req.body.num_max_events) {
|
||||
|
|
|
@ -4,7 +4,7 @@ var logger = require('./logger');
|
|||
var options = {};
|
||||
|
||||
exports.getTransactions = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/transactions';
|
||||
request(options).then((body) => {
|
||||
const body_str = (undefined === body) ? '' : JSON.stringify(body);
|
||||
|
@ -34,7 +34,7 @@ exports.getTransactions = (req, res, next) => {
|
|||
};
|
||||
|
||||
exports.postTransactions = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
options.url = common.lnd_server_url + '/transactions';
|
||||
options.form = {
|
||||
amount: req.body.amount,
|
||||
|
|
|
@ -4,7 +4,7 @@ var logger = require('./logger');
|
|||
var options = {};
|
||||
|
||||
exports.operateWallet = (req, res, next) => {
|
||||
options = common.options;
|
||||
options = common.getOptions('');
|
||||
var requestBody = {
|
||||
wallet_password: Buffer.from(req.body.wallet_password).toString('base64')
|
||||
};
|
||||
|
|
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "rtl",
|
||||
"version": "0.2.16-beta",
|
||||
"version": "0.2.17-beta",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "rtl",
|
||||
"version": "0.2.16-beta",
|
||||
"version": "0.2.17-beta",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
|
|
2
rtl.js
2
rtl.js
|
@ -2,7 +2,7 @@ const app = require("./app");
|
|||
const common = require("./common");
|
||||
const debug = require("debug")("node-angular");
|
||||
const http = require("http");
|
||||
var connect = require('./connect').setSingleNodeConfiguration(); //Do NOT Remove
|
||||
var connect = require('./connect').setServerConfiguration(); //Do NOT Remove
|
||||
|
||||
const onError = error => {
|
||||
if (error.syscall !== "listen") {
|
||||
|
|
Loading…
Add table
Reference in a new issue