2
0
mirror of https://github.com/Ride-The-Lightning/RTL synced 2024-10-31 09:20:27 +00:00
RTL/common.js
ShahanaFarooqui c6f6798882 MultiNode Backend Complete
MultiNode Backend Complete
2019-04-06 20:20:40 -04:00

79 lines
1.7 KiB
JavaScript

var fs = require('fs');
var crypto = require('crypto');
var common = {};
common.multi_node_setup = false;
common.rtl_conf_file_path = '';
common.node_auth_type = 'DEFAULT';
common.rtl_pass = '';
common.rtl_sso = 0;
common.port = 3000;
common.rtl_cookie_path = '';
common.logout_redirect_link = '/login';
common.cookie = '';
common.secret_key = crypto.randomBytes(64).toString('hex');
common.nodes = [];
common.selectedNode = {};
common.getSelectedNode = () => {
return common.selectedNode;
};
common.getSelLNDServerUrl = () => {
return common.selectedNode.lnd_server_url;
};
common.getOptions = () => {
return common.selectedNode.options;
};
common.setOptions = () => {
common.nodes.forEach(node => {
node.options = {
url: '',
rejectUnauthorized: false,
json: true,
headers: {
'Grpc-Metadata-macaroon': fs.readFileSync(node.macaroon_path + '/admin.macaroon').toString('hex'),
},
form: ''
};
});
}
common.findNode = (selNodeIndex) => {
return common.nodes.find(node => node.index == selNodeIndex);
}
common.convertToBTC = (num) => {
return (num / 100000000).toFixed(6);
};
common.convertTimestampToDate = (num) => {
return new Date(+num * 1000).toUTCString();
};
common.sortAscByKey = (array, key) => {
return array.sort(function (a, b) {
var x = a[key]; var y = b[key];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
common.sortDescByKey = (array, key) => {
return array.sort(function (a, b) {
var x = a[key]; var y = b[key];
return ((x > y) ? -1 : ((x < y) ? 1 : 0));
});
}
common.newestOnTop = (array, key, value) => {
var index = array.findIndex(function (item) {
return item[key] === value
});
var newlyAddedRecord = array.splice(index, 1);
array.unshift(newlyAddedRecord[0]);
return array;
}
module.exports = common;