2019-03-02 12:55:19 -05:00
|
|
|
var fs = require('fs');
|
2019-02-24 22:16:41 +09:00
|
|
|
var crypto = require('crypto');
|
2018-10-09 20:08:05 -04:00
|
|
|
var common = {};
|
|
|
|
|
2019-04-05 22:52:00 -04:00
|
|
|
common.multi_node_setup = false;
|
2019-02-09 15:37:36 -05:00
|
|
|
common.rtl_conf_file_path = '';
|
2019-02-12 08:36:04 -05:00
|
|
|
common.node_auth_type = 'DEFAULT';
|
2019-02-16 17:43:12 -05:00
|
|
|
common.rtl_pass = '';
|
2019-02-12 08:36:04 -05:00
|
|
|
common.rtl_sso = 0;
|
2019-04-06 18:42:09 -04:00
|
|
|
common.port = 3000;
|
2019-02-12 18:13:09 -05:00
|
|
|
common.rtl_cookie_path = '';
|
2019-02-12 08:36:04 -05:00
|
|
|
common.logout_redirect_link = '/login';
|
|
|
|
common.cookie = '';
|
2019-02-24 12:00:39 -05:00
|
|
|
common.secret_key = crypto.randomBytes(64).toString('hex');
|
2019-04-05 22:52:00 -04:00
|
|
|
common.nodes = [];
|
2019-04-06 20:20:40 -04:00
|
|
|
common.selectedNode = {};
|
2019-03-02 12:55:19 -05:00
|
|
|
|
2019-04-06 20:20:40 -04:00
|
|
|
common.getSelLNDServerUrl = () => {
|
|
|
|
return common.selectedNode.lnd_server_url;
|
|
|
|
};
|
|
|
|
|
|
|
|
common.getOptions = () => {
|
|
|
|
return common.selectedNode.options;
|
2019-04-05 22:52:00 -04:00
|
|
|
};
|
|
|
|
|
2019-04-06 18:42:09 -04:00
|
|
|
common.setOptions = () => {
|
2019-05-27 14:55:09 -04:00
|
|
|
if(undefined !== common.nodes[0].options && undefined !== common.nodes[0].options.headers) { return; }
|
|
|
|
try {
|
|
|
|
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: ''
|
|
|
|
};
|
|
|
|
});
|
|
|
|
// Options cannot be set before selected node initializes. Updating selected node's options separatly
|
|
|
|
common.selectedNode.options = {
|
2019-04-05 22:52:00 -04:00
|
|
|
url: '',
|
|
|
|
rejectUnauthorized: false,
|
|
|
|
json: true,
|
|
|
|
headers: {
|
2019-05-27 14:55:09 -04:00
|
|
|
'Grpc-Metadata-macaroon': fs.readFileSync(common.selectedNode.macaroon_path + '/admin.macaroon').toString('hex'),
|
2019-04-05 22:52:00 -04:00
|
|
|
},
|
|
|
|
form: ''
|
|
|
|
};
|
2019-05-27 14:55:09 -04:00
|
|
|
} catch(err) {
|
|
|
|
common.nodes.forEach(node => {
|
|
|
|
node.options = {
|
|
|
|
url: '',
|
|
|
|
rejectUnauthorized: false,
|
|
|
|
json: true,
|
|
|
|
form: ''
|
|
|
|
};
|
|
|
|
});
|
|
|
|
// Options cannot be set before selected node initializes. Updating selected node's options separatly
|
|
|
|
common.selectedNode.options = {
|
|
|
|
url: '',
|
|
|
|
rejectUnauthorized: false,
|
|
|
|
json: true,
|
|
|
|
form: ''
|
|
|
|
};
|
|
|
|
}
|
2019-03-02 12:55:19 -05:00
|
|
|
}
|
|
|
|
|
2019-04-05 22:52:00 -04:00
|
|
|
common.findNode = (selNodeIndex) => {
|
|
|
|
return common.nodes.find(node => node.index == selNodeIndex);
|
|
|
|
}
|
2018-10-09 20:08:05 -04:00
|
|
|
|
|
|
|
common.convertToBTC = (num) => {
|
|
|
|
return (num / 100000000).toFixed(6);
|
|
|
|
};
|
|
|
|
|
|
|
|
common.convertTimestampToDate = (num) => {
|
2019-03-02 12:55:19 -05:00
|
|
|
return new Date(+num * 1000).toUTCString();
|
2018-10-09 20:08:05 -04:00
|
|
|
};
|
|
|
|
|
2019-01-19 18:47:56 -05:00
|
|
|
common.sortAscByKey = (array, key) => {
|
2019-03-02 12:55:19 -05:00
|
|
|
return array.sort(function (a, b) {
|
|
|
|
var x = a[key]; var y = b[key];
|
|
|
|
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
|
|
|
|
});
|
2019-01-19 18:47:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
common.sortDescByKey = (array, key) => {
|
2019-03-02 12:55:19 -05:00
|
|
|
return array.sort(function (a, b) {
|
|
|
|
var x = a[key]; var y = b[key];
|
|
|
|
return ((x > y) ? -1 : ((x < y) ? 1 : 0));
|
|
|
|
});
|
2019-01-19 18:47:56 -05:00
|
|
|
}
|
|
|
|
|
2019-02-04 18:49:19 -05:00
|
|
|
common.newestOnTop = (array, key, value) => {
|
2019-03-02 12:55:19 -05:00
|
|
|
var index = array.findIndex(function (item) {
|
|
|
|
return item[key] === value
|
|
|
|
});
|
|
|
|
var newlyAddedRecord = array.splice(index, 1);
|
|
|
|
array.unshift(newlyAddedRecord[0]);
|
|
|
|
return array;
|
2019-02-04 18:49:19 -05:00
|
|
|
}
|
|
|
|
|
2019-02-24 12:00:39 -05:00
|
|
|
module.exports = common;
|