MultiNode Backend Complete

MultiNode Backend Complete
This commit is contained in:
ShahanaFarooqui 2019-04-06 20:20:40 -04:00
parent 9d18a888d8
commit c6f6798882
21 changed files with 150 additions and 118 deletions

View File

@ -1,48 +0,0 @@
{
"multiPass": "multi",
"port": "3000",
"SSO": {
"rtlSSO": 0,
"rtlCookiePath": "",
"logoutRedirectLink": ""
},
"nodes": [{
"index": 1,
"lnNode": "LND Testnet # 1",
"lnImplementation": "LND",
"Authentication": {
"macaroonPath": "C:\\Users\\suheb\\AppData\\Local\\Lnd\\data\\chain\\bitcoin\\testnet",
"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:\\bitcoin\\bitcoin_mainnet\\bitcoin.conf",
"enableLogging": "true",
"lndServerUrl": "https://localhost: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",
"lndServerUrl": "https://localhost:8080/v1"
}
}]
}

47
RTL-Multi-Node-Conf.json Normal file
View File

@ -0,0 +1,47 @@
{
"multiPass":"aaa",
"port":"3000",
"SSO": {
"rtlSSO":0,
"rtlCookiePath":"",
"logoutRedirectLink":""
},
"nodes":[{
"index":1,
"lnNode":"LND Testnet # 1",
"lnImplementation":"LND",
"Authentication":{
"macaroonPath":"C:\\Users\\suheb\\AppData\\Local\\Lnd\\data\\chain\\bitcoin\\testnet",
"lndConfigPath":"C:\\Users\\suheb\\AppData\\Local\\Lnd\\lnd.conf"
},
"Settings":{
"flgSidenavOpened":"true",
"flgSidenavPinned":"true",
"menu":"Vertical",
"menuType":"Regular",
"theme":"light-blue-gray",
"satsToBTC":"false",
"bitcoindConfigPath":"C:\\bitcoin\\bitcoin_mainnet\\bitcoin.conf",
"enableLogging":"true",
"lndServerUrl":"https://localhost:8080/v1"
}
}, {
"index":2,
"lnNode":"LND Mainnet # 1",
"lnImplementation":"LND",
"Authentication":{
"macaroonPath":"C:\\Workspace"
},
"Settings":{
"flgSidenavOpened":"true",
"flgSidenavPinned":"true",
"menu":"Vertical",
"menuType":"Regular",
"theme":"dark-pink",
"satsToBTC":"false",
"bitcoindConfigPath":"",
"enableLogging":"true",
"lndServerUrl":"https://192.168.1.20:8080/v1"
}
}]
}

View File

@ -13,9 +13,18 @@ common.logout_redirect_link = '/login';
common.cookie = '';
common.secret_key = crypto.randomBytes(64).toString('hex');
common.nodes = [];
common.selectedNode = {};
common.getOptions = (selNodeIndex) => {
return common.findNode(selNodeIndex).options;
common.getSelectedNode = () => {
return common.selectedNode;
};
common.getSelLNDServerUrl = () => {
return common.selectedNode.lnd_server_url;
};
common.getOptions = () => {
return common.selectedNode.options;
};
common.setOptions = () => {

View File

@ -3,6 +3,12 @@ var fs = require('fs');
var logger = require('./logger');
var common = require('../common');
exports.updateSelectedNode = (req, res, next) => {
const selNodeIndex = req.body.selNodeIndex
common.selectedNode = common.findNode(selNodeIndex);
res.status(200).json({status: 'Selected Node Updated!'});
};
exports.getRTLConfig = (req, res, next) => {
if(!common.multi_node_setup) {
var RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
@ -65,10 +71,33 @@ exports.updateUISettings = (req, res, next) => {
var RTLConfFile = '';
if(common.multi_node_setup) {
RTLConfFile = common.rtl_conf_file_path + '/RTL-Multi-Node-Conf.json';
var config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
config.nodes.find(node => {
if(node.index == common.selectedNode.index) {
node.Settings.flgSidenavOpened = req.body.updatedSettings.flgSidenavOpened;
node.Settings.flgSidenavPinned = req.body.updatedSettings.flgSidenavPinned;
node.Settings.menu = req.body.updatedSettings.menu;
node.Settings.menuType = req.body.updatedSettings.menuType;
node.Settings.theme = req.body.updatedSettings.theme;
node.Settings.satsToBTC = req.body.updatedSettings.satsToBTC;
}
});
try {
fs.writeFileSync(RTLConfFile, JSON.stringify(config));
logger.info('\r\nConf: 77: ' + JSON.stringify(Date.now()) + ': INFO: Updating UI Settings Succesful!');
res.status(201).json({message: 'UI Settings Updated Successfully'});
}
catch (err) {
logger.error('\r\nConf: 71: ' + JSON.stringify(Date.now()) + ': ERROR: Updating UI Settings Failed!');
res.status(500).json({
message: "Updating UI Settings Failed!",
error: 'Updating UI Settings Failed!'
});
}
} else {
RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
var config = ini.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
var settingsTemp = config.Settings;
const settingsTemp = config.Settings;
settingsTemp.flgSidenavOpened = req.body.updatedSettings.flgSidenavOpened;
settingsTemp.flgSidenavPinned = req.body.updatedSettings.flgSidenavPinned;
settingsTemp.menu = req.body.updatedSettings.menu;

View File

@ -48,9 +48,6 @@ exports.authenticateUser = (req, res, next) => {
} else {
const password = atob(req.body.password);
if (common.multi_node_setup) {
console.log('\n\nHERE:\n');
console.log(common.nodes);
console.log(common.rtl_pass);
if (common.rtl_pass === password) {
var rpcUser = 'Multi_Node_User';
const token = jwt.sign(

View File

@ -4,8 +4,8 @@ var logger = require('./logger');
var options = {};
exports.getBalance = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/balance/' + req.params.source;
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/balance/' + req.params.source;
options.qs = req.query;
request(options).then((body) => {
logger.info('\r\nBalance: 9: ' + JSON.stringify(Date.now()) + ': INFO: ' + 'Request params: ' + JSON.stringify(req.params) + 'Request Query: ' + JSON.stringify(req.query) + ' Balance Received: ' + JSON.stringify(body));

View File

@ -6,9 +6,9 @@ var options = {};
getAliasForChannel = (channel, channelType) => {
return new Promise(function(resolve, reject) {
if (undefined === channelType || channelType === 'all') {
options.url = common.findNode(1).lnd_server_url + '/graph/node/' + channel.remote_pubkey;
options.url = common.getSelLNDServerUrl() + '/graph/node/' + channel.remote_pubkey;
} else {
options.url = common.findNode(1).lnd_server_url + '/graph/node/' + channel.channel.remote_node_pub;
options.url = common.getSelLNDServerUrl() + '/graph/node/' + channel.channel.remote_node_pub;
}
request(options).then(function(aliasBody) {
logger.info('\r\nChannels: 13: ' + JSON.stringify(Date.now()) + ': INFO: Alias: ' + JSON.stringify(aliasBody.node.alias));
@ -25,11 +25,11 @@ getAliasForChannel = (channel, channelType) => {
}
exports.getChannels = (req, res, next) => {
options = common.getOptions(1);
options = common.getOptions();
if (undefined === req.params.channelType || req.params.channelType === 'all') {
options.url = common.findNode(1).lnd_server_url + '/channels';
options.url = common.getSelLNDServerUrl() + '/channels';
} else {
options.url = common.findNode(1).lnd_server_url + '/channels/' + req.params.channelType;
options.url = common.getSelLNDServerUrl() + '/channels/' + req.params.channelType;
}
options.qs = req.query;
request(options).then(function (body) {
@ -74,8 +74,8 @@ exports.getChannels = (req, res, next) => {
};
exports.postChannel = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/channels';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/channels';
options.form = {
node_pubkey_string: req.body.node_pubkey,
local_funding_amount: req.body.local_funding_amount,
@ -108,8 +108,8 @@ exports.postChannel = (req, res, next) => {
};
exports.postTransactions = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/channels/transactions';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/channels/transactions';
if(req.body.paymentReq) {
options.form = JSON.stringify({
payment_request: req.body.paymentReq
@ -149,9 +149,9 @@ exports.postTransactions = (req, res, next) => {
exports.closeChannel = (req, res, next) => {
req.setTimeout(60000 * 10); // timeout 10 mins
options = common.getOptions(1);
options = common.getOptions();
let channelpoint = req.params.channelPoint.replace(':', '/');
options.url = common.findNode(1).lnd_server_url + '/channels/' + channelpoint + '?force=' + req.query.force;
options.url = common.getSelLNDServerUrl() + '/channels/' + channelpoint + '?force=' + req.query.force;
logger.info('\r\nChannels: 144: ' + JSON.stringify(Date.now()) + ': INFO: Closing Channel: ' + options.url);
request.delete(options).then((body) => {
logger.info('\r\nChannels: 146: ' + JSON.stringify(Date.now()) + ': INFO: Close Channel Response: ' + JSON.stringify(body));
@ -174,8 +174,8 @@ exports.closeChannel = (req, res, next) => {
}
exports.postChanPolicy = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/chanpolicy';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/chanpolicy';
if(req.body.chanPoint === 'all') {
options.form = JSON.stringify({
global: true,

View File

@ -4,8 +4,8 @@ var logger = require('./logger');
var options = {};
exports.getFees = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/fees';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/fees';
request(options).then((body) => {
logger.info('\r\nFees: 8: ' + JSON.stringify(Date.now()) + ': INFO: Fee Received: ' + JSON.stringify(body));
if(undefined === body || body.error) {

View File

@ -4,10 +4,12 @@ var logger = require('./logger');
var options = {};
exports.getInfo = (req, res, next) => {
// Do Not Change the set options & selected Node code sequence
common.setOptions();
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/getinfo';
console.log(common.nodes);
common.selectedNode = common.findNode(common.nodes[0].index);
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/getinfo';
logger.info('\r\nCalling getinfo from lnd server url: INFO: ' + options.url);
request(options).then((body) => {
logger.info('\r\nGetInfo: 9: ' + JSON.stringify(Date.now()) + ': INFO: ' + JSON.stringify(body));

View File

@ -4,8 +4,8 @@ var logger = require('./logger');
var options = {};
exports.getDescribeGraph = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/graph';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/graph';
request.get(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');
@ -28,8 +28,8 @@ exports.getDescribeGraph = (req, res, next) => {
};
exports.getGraphInfo = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/graph/info';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/graph/info';
request.get(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');
@ -57,8 +57,8 @@ exports.getGraphInfo = (req, res, next) => {
};
exports.getGraphNode = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/graph/node/' + req.params.pubKey;
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/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));
if(undefined === body || body.error) {
@ -81,8 +81,8 @@ exports.getGraphNode = (req, res, next) => {
};
exports.getGraphEdge = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/graph/edge/' + req.params.chanid;
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/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));
if(undefined === body || body.error) {

View File

@ -3,12 +3,11 @@ var options = require("../connect");
var common = require('../common');
exports.getGraphInfo = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/graph/info';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/graph/info';
request.get(options, (error, response, body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');
console.log('Network Information Received: ' + body_str);
if(undefined === body || search_idx > -1 || body.error) {
res.status(500).json({
message: "Fetching network Info failed!",
@ -19,7 +18,6 @@ exports.getGraphInfo = (req, res, next) => {
body.btc_avg_channel_size = (undefined === body.avg_channel_size) ? 0 : common.convertToBTC(body.avg_channel_size);
body.btc_min_channel_size = (undefined === body.min_channel_size) ? 0 : common.convertToBTC(body.min_channel_size);
body.btc_max_channel_size = (undefined === body.max_channel_size) ? 0 : common.convertToBTC(body.max_channel_size);
console.log('Network Information After Rounding and Conversion: ' + body_str);
res.status(200).json(body);
}
});

View File

@ -4,8 +4,8 @@ var logger = require('./logger');
var options = {};
exports.getInvoice = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/invoice/' + req.params.rHashStr;
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/invoice/' + req.params.rHashStr;
request(options).then((body) => {
logger.info('\r\nInvoice: 8: ' + JSON.stringify(Date.now()) + ': INFO: Invoice Info Received: ' + JSON.stringify(body));
if(undefined === body || body.error) {
@ -25,8 +25,8 @@ exports.getInvoice = (req, res, next) => {
};
exports.listInvoices = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/invoices';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/invoices';
request(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');
@ -59,8 +59,8 @@ exports.listInvoices = (req, res, next) => {
};
exports.addInvoice = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/invoices';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/invoices';
options.form = JSON.stringify({
memo: req.body.memo,
value: req.body.amount

View File

@ -1,16 +1,13 @@
var fs = require('fs');
exports.getLNDSettings = (req, res, next) => {
console.log('Getting LND Conf Settings!');
fs.readFile(req.headers.filepath, function(err, data) {
if (err) {
console.log('Reading Config File Failed!');
res.status(500).json({
message: "Reading Config File Failed!",
error: err
});
} else {
console.log('LND Conf read successfully');
res.status(200).json(data.toString('utf8'));
}
});

View File

@ -4,8 +4,8 @@ var logger = require('./logger');
var options = {};
exports.getNewAddress = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/newaddress?type=' + req.query.type;
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/newaddress?type=' + req.query.type;
request(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');

View File

@ -4,8 +4,8 @@ var logger = require('./logger');
var options = {};
exports.decodePayment = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/payreq/' + req.params.payRequest;
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/payreq/' + req.params.payRequest;
request(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');

View File

@ -4,8 +4,8 @@ var logger = require('./logger');
var options = {};
exports.getPayments = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/payments';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/payments';
request(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');

View File

@ -5,7 +5,7 @@ var options = {};
getAliasForPeers = (peer) => {
return new Promise(function(resolve, reject) {
options.url = common.findNode(1).lnd_server_url + '/graph/node/' + peer.pub_key;
options.url = common.getSelLNDServerUrl() + '/graph/node/' + peer.pub_key;
request(options)
.then(function(aliasBody) {
logger.info('\r\nPeers: 11: ' + JSON.stringify(Date.now()) + ': INFO: Alias: ' + JSON.stringify(aliasBody.node.alias));
@ -17,8 +17,8 @@ getAliasForPeers = (peer) => {
}
exports.getPeers = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/peers';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/peers';
request(options).then(function (body) {
let peers = (undefined === body.peers) ? [] : body.peers;
Promise.all(
@ -42,8 +42,8 @@ exports.getPeers = (req, res, next) => {
};
exports.postPeer = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/peers';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/peers';
options.form = JSON.stringify({
addr: { host: req.body.host, pubkey: req.body.pubkey },
perm: req.body.perm
@ -56,7 +56,7 @@ exports.postPeer = (req, res, next) => {
error: (undefined === body) ? 'Error From Server!' : body.error
});
} else {
options.url = common.findNode(1).lnd_server_url + '/peers';
options.url = common.getSelLNDServerUrl() + '/peers';
request(options).then(function (body) {
let peers = (undefined === body.peers) ? [] : body.peers;
Promise.all(
@ -85,8 +85,8 @@ exports.postPeer = (req, res, next) => {
};
exports.deletePeer = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/peers/' + req.params.peerPubKey;
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/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));
if(undefined === body || body.error) {

View File

@ -4,8 +4,8 @@ var logger = require('./logger');
var options = {};
exports.forwardingHistory = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/switch';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/switch';
options.form = {};
if (undefined !== req.body.num_max_events) {
options.form.num_max_events = req.body.num_max_events;

View File

@ -4,8 +4,8 @@ var logger = require('./logger');
var options = {};
exports.getTransactions = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/transactions';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/transactions';
request(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');
@ -34,8 +34,8 @@ exports.getTransactions = (req, res, next) => {
};
exports.postTransactions = (req, res, next) => {
options = common.getOptions(1);
options.url = common.findNode(1).lnd_server_url + '/transactions';
options = common.getOptions();
options.url = common.getSelLNDServerUrl() + '/transactions';
options.form = {
amount: req.body.amount,
addr: req.body.address,

View File

@ -4,16 +4,16 @@ var logger = require('./logger');
var options = {};
exports.operateWallet = (req, res, next) => {
options = common.getOptions(1);
options = common.getOptions();
var requestBody = {
wallet_password: Buffer.from(req.body.wallet_password).toString('base64')
};
if (undefined === req.params.operation || req.params.operation === 'unlock') {
options.url = common.findNode(1).lnd_server_url + '/unlockwallet';
options.url = common.getSelLNDServerUrl() + '/unlockwallet';
options.form = JSON.stringify(requestBody);
err_message = 'Unlocking wallet failed! Verify that lnd is running and the wallet is locked!';
} else {
options.url = common.findNode(1).lnd_server_url + '/initwallet';
options.url = common.getSelLNDServerUrl() + '/initwallet';
options.form = JSON.stringify(requestBody);
err_message = 'Initializing wallet failed!';
}

View File

@ -6,5 +6,6 @@ const authCheck = require("./authCheck");
router.get("/rtlconf", RTLConfController.getRTLConfig);
router.post("/", authCheck, RTLConfController.updateUISettings);
router.get("/config/:nodeType", authCheck, RTLConfController.getConfig);
router.post("/updateSelNode", authCheck, RTLConfController.updateSelectedNode);
module.exports = router;