Browse Source

Merge branch 'master' into pkg_automation

pkg_automation_electrum
michal maxian 8 years ago
parent
commit
a9b045074f
  1. 2
      gui/init.js
  2. 15
      gui/loading.js
  3. 30
      main.js
  4. 2
      routes/cache.js
  5. 191
      routes/shepherd.js

2
gui/init.js

@ -26,7 +26,7 @@ $(document).ready(function() {
if (result !== 'error') { if (result !== 'error') {
stopcheck(); stopcheck();
if (appConf && appConf.forks && appConf.forks.basilisk) { if (appConf && appConf.useBasiliskInstance) {
StartIguana_Cache(); StartIguana_Cache();
} }

15
gui/loading.js

@ -123,6 +123,7 @@ function EDEX_DEXgetinfoAll(skip, minNotaries, appConf) {
'method': 'notarychains' 'method': 'notarychains'
}, },
tmp_index = 0, tmp_index = 0,
tmp_index_failed = 0,
get_dex_notarychains = IguanaAJAX('http://127.0.0.1:' + appConf.iguanaCorePort, ajax_data, 10000).done(function(data) { get_dex_notarychains = IguanaAJAX('http://127.0.0.1:' + appConf.iguanaCorePort, ajax_data, 10000).done(function(data) {
get_dex_notarychains = JSON.parse(get_dex_notarychains.responseText); get_dex_notarychains = JSON.parse(get_dex_notarychains.responseText);
if (minNotaries > get_dex_notarychains.length) { // if config value exceeds total num of notaries if (minNotaries > get_dex_notarychains.length) { // if config value exceeds total num of notaries
@ -143,11 +144,11 @@ function EDEX_DEXgetinfoAll(skip, minNotaries, appConf) {
console.log(ajax_data); console.log(ajax_data);
if (coin_value !== 'MESH' || coin_value !== 'CEAL') { if (coin_value !== 'MESH' || coin_value !== 'CEAL') {
var getinfo_each_chain = IguanaAJAX('http://127.0.0.1:' + appConf.iguanaCorePort, ajax_data).done(function(data) { var getinfo_each_chain = IguanaAJAX('http://127.0.0.1:' + appConf.iguanaCorePort, ajax_data, 10000).done(function(data) {
getinfo_each_chain = JSON.parse(getinfo_each_chain.responseText); getinfo_each_chain = JSON.parse(getinfo_each_chain.responseText);
console.log(getinfo_each_chain); console.log(getinfo_each_chain);
tmp_index = parseInt(coin_index) + 1; tmp_index++;
$('#loading_sub_status_text').text('Connection status... ' + tmp_index + '/' + get_dex_notarychains.length + ': ' + coin_value); $('#loading_sub_status_text').text('Connection status... ' + tmp_index + '/' + get_dex_notarychains.length + ': ' + coin_value);
if (getinfo_each_chain.error === 'less than required responses') { if (getinfo_each_chain.error === 'less than required responses') {
@ -156,13 +157,21 @@ function EDEX_DEXgetinfoAll(skip, minNotaries, appConf) {
$('#loading_sub_status_output_text').text('Output: Connected'); $('#loading_sub_status_output_text').text('Output: Connected');
} }
if ( tmp_index == minNotaries ) { if ( tmp_index + tmp_index_failed === minNotaries ) {
console.log('min notaries connected'); console.log('min notaries connected');
window.createWindow('open'); window.createWindow('open');
window.hide(); window.hide();
} }
}) })
.fail(function(xhr, textStatus, error) { .fail(function(xhr, textStatus, error) {
tmp_index_failed++;
if ( tmp_index + tmp_index_failed === minNotaries ) {
console.log('min notaries connected');
window.createWindow('open');
window.hide();
}
// handle request failures // handle request failures
console.log(xhr.statusText); console.log(xhr.statusText);
if ( xhr.readyState == 0 ) { if ( xhr.readyState == 0 ) {

30
main.js

@ -7,6 +7,7 @@ const electron = require('electron'),
path = require('path'), path = require('path'),
url = require('url'), url = require('url'),
os = require('os'), os = require('os'),
md5 = require('md5'),
spawn = require('child_process').spawn, spawn = require('child_process').spawn,
exec = require('child_process').exec, exec = require('child_process').exec,
{ Menu } = require('electron'), { Menu } = require('electron'),
@ -28,7 +29,7 @@ Promise = require('bluebird');
const appBasicInfo = { const appBasicInfo = {
name: 'Agama', name: 'Agama',
version: '0.1.6.2e-beta' version: '0.1.7.77a-beta'
}; };
app.setName(appBasicInfo.name); app.setName(appBasicInfo.name);
@ -41,9 +42,13 @@ if (os.platform() === 'linux') {
// GUI APP settings and starting gui on address http://120.0.0.1:17777 // GUI APP settings and starting gui on address http://120.0.0.1:17777
var shepherd = require('./routes/shepherd'), var shepherd = require('./routes/shepherd'),
guiapp = express(); guiapp = express();
shepherd.writeLog('app init'); shepherd.createIguanaDirs();
const appSessionHash = md5(new Date(Date.now()).toLocaleString);
shepherd.writeLog('app init ' + appSessionHash);
shepherd.writeLog('app info: ' + appBasicInfo.name + ' ' + appBasicInfo.version); shepherd.writeLog('app info: ' + appBasicInfo.name + ' ' + appBasicInfo.version);
shepherd.writeLog('sys info:'); shepherd.writeLog('sys info:');
shepherd.writeLog('totalmem_readable: ' + formatBytes(os.totalmem())); shepherd.writeLog('totalmem_readable: ' + formatBytes(os.totalmem()));
@ -143,12 +148,12 @@ guiapp.use('/shepherd', shepherd);
var server = require('http').createServer(guiapp), var server = require('http').createServer(guiapp),
io = require('socket.io').listen(server); io = require('socket.io').listen(server);
server.listen(appConfig.iguanaAppPort, function() { server.listen(appConfig.agamaPort, function() {
console.log('guiapp and sockets.io are listening on port ' + appConfig.iguanaAppPort + '!'); console.log('guiapp and sockets.io are listening on port ' + appConfig.agamaPort + '!');
shepherd.writeLog('guiapp and sockets.io are listening on port ' + appConfig.iguanaAppPort + '!'); shepherd.writeLog('guiapp and sockets.io are listening on port ' + appConfig.agamaPort + '!');
}); });
io.set('origins', appConfig.dev ? 'http://127.0.0.1:3000' : 'http://127.0.0.1:' + appConfig.iguanaAppPort); // set origin io.set('origins', appConfig.dev ? 'http://127.0.0.1:3000' : 'http://127.0.0.1:' + appConfig.agamaPort); // set origin
io.on('connection', function(client) { io.on('connection', function(client) {
console.log('EDEX GUI is connected...'); console.log('EDEX GUI is connected...');
@ -168,6 +173,7 @@ io.on('connection', function(client) {
shepherd.setIO(io); // pass sockets object to shepherd router shepherd.setIO(io); // pass sockets object to shepherd router
shepherd.setVar('appBasicInfo', appBasicInfo); shepherd.setVar('appBasicInfo', appBasicInfo);
shepherd.setVar('appSessionHash', appSessionHash);
module.exports = guiapp; module.exports = guiapp;
// END GUI App Settings // END GUI App Settings
@ -246,7 +252,7 @@ function createLoadingWindow() {
loadingWindow.createWindow = createWindow; // expose createWindow to front-end scripts loadingWindow.createWindow = createWindow; // expose createWindow to front-end scripts
// load our index.html (i.e. easyDEX GUI) // load our index.html (i.e. easyDEX GUI)
loadingWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/'); loadingWindow.loadURL('http://' + appConfig.host + ':' + appConfig.agamaPort + '/gui/');
shepherd.writeLog('show loading window'); shepherd.writeLog('show loading window');
// DEVTOOLS - only for dev purposes - ca333 // DEVTOOLS - only for dev purposes - ca333
@ -360,13 +366,15 @@ function createWindow (status) {
if (appConfig.v2) { if (appConfig.v2) {
shepherd.writeLog('show edex gui'); shepherd.writeLog('show edex gui');
mainWindow.loadURL('http://127.0.0.1:3000'); mainWindow.loadURL('http://127.0.0.1:3000');
//mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/EasyDEX-GUI/react/build'); mainWindow.appConfig = appConfig;
mainWindow.appSessionHash = appSessionHash;
//mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.agamaPort + '/gui/EasyDEX-GUI/react/build');
} else { } else {
shepherd.writeLog('show edex gui'); shepherd.writeLog('show edex gui');
mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/EasyDEX-GUI/'); mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.agamaPort + '/gui/EasyDEX-GUI/');
} }
} else { } else {
mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/main.html'); mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.agamaPort + '/gui/main.html');
} }
mainWindow.webContents.on('context-menu', (e, params) => { //context-menu returns params mainWindow.webContents.on('context-menu', (e, params) => { //context-menu returns params

2
routes/cache.js

@ -429,7 +429,7 @@ cache.one = function(req, res, next) {
'listunspent': 'http://' + cache.appConfig.host + ':' + iguanaCorePort + '/api/dex/listunspent?userpass=' + sessionKey + '&symbol=' + coin + '&address=' + address, 'listunspent': 'http://' + cache.appConfig.host + ':' + iguanaCorePort + '/api/dex/listunspent?userpass=' + sessionKey + '&symbol=' + coin + '&address=' + address,
'listtransactions': 'http://' + cache.appConfig.host + ':' + iguanaCorePort + '/api/dex/listtransactions?userpass=' + sessionKey + '&count=100&skip=0&symbol=' + coin + '&address=' + address, 'listtransactions': 'http://' + cache.appConfig.host + ':' + iguanaCorePort + '/api/dex/listtransactions?userpass=' + sessionKey + '&count=100&skip=0&symbol=' + coin + '&address=' + address,
'getbalance': 'http://' + cache.appConfig.host + ':' + iguanaCorePort + '/api/dex/getbalance?userpass=' + sessionKey + '&symbol=' + coin + '&address=' + address, 'getbalance': 'http://' + cache.appConfig.host + ':' + iguanaCorePort + '/api/dex/getbalance?userpass=' + sessionKey + '&symbol=' + coin + '&address=' + address,
'refresh': 'http://' + cache.appConfig.host + ':' + iguanaCorePort + '/api/basilisk/refresh?userpass=' + sessionKey + '&timeout=600000&symbol=' + coin + '&address=' + address 'refresh': 'http://' + cache.appConfig.host + ':' + iguanaCorePort + '/api/basilisk/refresh?userpass=' + sessionKey + '&symbol=' + coin + '&address=' + address
}, },
_dexUrls = {}; _dexUrls = {};

191
routes/shepherd.js

@ -23,11 +23,12 @@ const fixPath = require('fix-path');
var ps = require('ps-node'), var ps = require('ps-node'),
setconf = require('../private/setconf.js'), setconf = require('../private/setconf.js'),
//coincli = require('../private/coincli.js'), //coincli = require('../private/coincli.js'),
assetChainPorts = require('./ports.js') assetChainPorts = require('./ports.js'),
shepherd = express.Router(), shepherd = express.Router(),
iguanaInstanceRegistry = {}, iguanaInstanceRegistry = {},
syncOnlyIguanaInstanceInfo = {}, syncOnlyIguanaInstanceInfo = {},
syncOnlyInstanceInterval = -1; syncOnlyInstanceInterval = -1,
guiLog = {};
// IGUANA FILES AND CONFIG SETTINGS // IGUANA FILES AND CONFIG SETTINGS
var iguanaConfsDirSrc = path.join(__dirname, '../assets/deps/confs'), var iguanaConfsDirSrc = path.join(__dirname, '../assets/deps/confs'),
@ -80,10 +81,10 @@ shepherd.appConfig = {
"edexGuiOnly": true, "edexGuiOnly": true,
"iguanaGuiOnly": false, "iguanaGuiOnly": false,
"manualIguanaStart": false, "manualIguanaStart": false,
"skipBasiliskNetworkCheck": false, "skipBasiliskNetworkCheck": true,
"minNotaries": 8, "minNotaries": 8,
"host": "127.0.0.1", "host": "127.0.0.1",
"iguanaAppPort": 17777, "agamaPort": 17777,
"iguanaCorePort": 7778, "iguanaCorePort": 7778,
"maxDescriptors": { "maxDescriptors": {
"darwin": 90000, "darwin": 90000,
@ -91,16 +92,14 @@ shepherd.appConfig = {
}, },
"killIguanaOnStart": true, "killIguanaOnStart": true,
"dev": false, "dev": false,
"v2": false, "v2": true,
"forks": { "useBasiliskInstance": true,
"basilisk": false, "debug": true,
"all": false
}
}; };
shepherd.writeLog = function(data) { shepherd.writeLog = function(data) {
const logLocation = iguanaDir + '/shepherd'; const logLocation = iguanaDir + '/shepherd';
const timeFormatted = new Date(Date.now()).toLocaleString().replace('AM', '').replace('PM', ''); const timeFormatted = new Date(Date.now()).toLocaleString('en-US', { hour12: false });
if (fs.existsSync(logLocation + '/agamalog.txt')) { if (fs.existsSync(logLocation + '/agamalog.txt')) {
fs.appendFile(logLocation + '/agamalog.txt', timeFormatted + ' ' + data + '\r\n', function (err) { fs.appendFile(logLocation + '/agamalog.txt', timeFormatted + ' ' + data + '\r\n', function (err) {
@ -117,6 +116,28 @@ shepherd.writeLog = function(data) {
} }
} }
shepherd.createIguanaDirs = function() {
if (!fs.existsSync(iguanaDir)) {
fs.mkdirSync(iguanaDir);
if (fs.existsSync(iguanaDir)) {
console.log('created iguana folder at ' + iguanaDir);
shepherd.writeLog('created iguana folder at ' + iguanaDir);
}
} else {
console.log('iguana folder already exists');
}
if (!fs.existsSync(iguanaDir + '/shepherd')) {
fs.mkdirSync(iguanaDir + '/shepherd');
if (fs.existsSync(iguanaDir)) {
console.log('created shepherd folder at ' + iguanaDir + '/shepherd');
shepherd.writeLog('create shepherd folder at ' + iguanaDir + '/shepherd');
}
} else {
console.log('shepherd folder already exists');
}
}
shepherd.get('/coinslist', function(req, res, next) { shepherd.get('/coinslist', function(req, res, next) {
if (fs.existsSync(iguanaDir + '/shepherd/coinslist.json')) { if (fs.existsSync(iguanaDir + '/shepherd/coinslist.json')) {
fs.readFile(iguanaDir + '/shepherd/coinslist.json', 'utf8', function (err, data) { fs.readFile(iguanaDir + '/shepherd/coinslist.json', 'utf8', function (err, data) {
@ -146,6 +167,75 @@ shepherd.get('/coinslist', function(req, res, next) {
} }
}); });
/*
* type: POST
* params: payload
*/
shepherd.post('/guilog', function(req, res, next) {
const logLocation = iguanaDir + '/shepherd';
if (!guiLog[shepherd.appSessionHash]) {
guiLog[shepherd.appSessionHash] = {};
}
if (guiLog[shepherd.appSessionHash][req.body.timestamp]) {
guiLog[shepherd.appSessionHash][req.body.timestamp].status = req.body.status;
guiLog[shepherd.appSessionHash][req.body.timestamp].response = req.body.response;
} else {
guiLog[shepherd.appSessionHash][req.body.timestamp] = {
'function': req.body.function,
'type': req.body.type,
'url': req.body.url,
'payload': req.body.payload,
'status': req.body.status,
};
}
fs.writeFile(logLocation + '/agamalog.json', JSON.stringify(guiLog), function (err) {
if (err) {
shepherd.writeLog('error writing gui log file');
}
const returnObj = {
'msg': 'success',
'result': 'gui log entry is added'
};
res.end(JSON.stringify(returnObj));
});
});
shepherd.get('/getlog', function(req, res, next) {
const logExt = req.query.type === 'txt' ? 'txt' : 'json';
if (fs.existsSync(iguanaDir + '/shepherd/agamalog.' + logExt)) {
fs.readFile(iguanaDir + '/shepherd/agamalog.' + logExt, 'utf8', function (err, data) {
if (err) {
const errorObj = {
'msg': 'error',
'result': err
};
res.end(JSON.stringify(errorObj));
} else {
const successObj = {
'msg': 'success',
'result': data ? JSON.parse(data) : ''
};
res.end(JSON.stringify(successObj));
}
});
} else {
const errorObj = {
'msg': 'error',
'result': 'agama.' + logExt + ' doesn\'t exist'
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.post('/coinslist', function(req, res, next) { shepherd.post('/coinslist', function(req, res, next) {
const _payload = req.body.payload; const _payload = req.body.payload;
@ -184,6 +274,7 @@ shepherd.quitKomodod = function(chain) {
exec(komodocliBin + (chain ? ' ac_name=' + chain : '') + ' stop', function(error, stdout, stderr) { exec(komodocliBin + (chain ? ' ac_name=' + chain : '') + ' stop', function(error, stdout, stderr) {
console.log('stdout: ' + stdout) console.log('stdout: ' + stdout)
console.log('stderr: ' + stderr) console.log('stderr: ' + stderr)
if (error !== null) { if (error !== null) {
console.log('exec error: ' + error) console.log('exec error: ' + error)
} }
@ -217,46 +308,51 @@ shepherd.post('/appconf', function(req, res, next) {
shepherd.saveLocalAppConf = function(appSettings) { shepherd.saveLocalAppConf = function(appSettings) {
var appConfFileName = iguanaDir + '/config.json'; var appConfFileName = iguanaDir + '/config.json';
var FixFilePermissions = function() { _fs.access(iguanaDir, fs.constants.R_OK, function(err) {
return new Promise(function(resolve, reject) { if (!err) {
var result = 'config.json file permissions updated to Read/Write';
fsnode.chmodSync(appConfFileName, '0666'); var FixFilePermissions = function() {
return new Promise(function(resolve, reject) {
var result = 'config.json file permissions updated to Read/Write';
setTimeout(function() { fsnode.chmodSync(appConfFileName, '0666');
console.log(result);
shepherd.writeLog(result);
resolve(result);
}, 1000);
});
}
var FsWrite = function() { setTimeout(function() {
return new Promise(function(resolve, reject) { console.log(result);
var result = 'config.json write file is done' shepherd.writeLog(result);
resolve(result);
fs.writeFile(appConfFileName, }, 1000);
JSON.stringify(appSettings) });
.replace(/,/g, ',\n') // format json in human readable form }
.replace(/:/g, ': ')
.replace(/{/g, '{\n')
.replace(/}/g, '\n}'), 'utf8', function(err) {
if (err)
return console.log(err);
});
fsnode.chmodSync(appConfFileName, '0666'); var FsWrite = function() {
setTimeout(function() { return new Promise(function(resolve, reject) {
console.log(result); var result = 'config.json write file is done'
console.log('app conf.json file is created successfully at: ' + iguanaConfsDir);
shepherd.writeLog('app conf.json file is created successfully at: ' + iguanaConfsDir); fs.writeFile(appConfFileName,
resolve(result); JSON.stringify(appSettings)
}, 2000); .replace(/,/g, ',\n') // format json in human readable form
}); .replace(/:/g, ': ')
} .replace(/{/g, '{\n')
.replace(/}/g, '\n}'), 'utf8', function(err) {
if (err)
return console.log(err);
});
FsWrite() fsnode.chmodSync(appConfFileName, '0666');
.then(FixFilePermissions()); setTimeout(function() {
console.log(result);
console.log('app conf.json file is created successfully at: ' + iguanaConfsDir);
shepherd.writeLog('app conf.json file is created successfully at: ' + iguanaConfsDir);
resolve(result);
}, 2000);
});
}
FsWrite()
.then(FixFilePermissions());
}
});
} }
shepherd.loadLocalConfig = function() { shepherd.loadLocalConfig = function() {
@ -1070,8 +1166,8 @@ function herder(flock, data) {
exec(komododBin + ' ' + data.ac_options.join(' '), { exec(komododBin + ' ' + data.ac_options.join(' '), {
maxBuffer: 1024 * 10000 // 10 mb maxBuffer: 1024 * 10000 // 10 mb
}, function(error, stdout, stderr) { }, function(error, stdout, stderr) {
console.log('stdout: ' + stdout); // console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr); // console.log('stderr: ' + stderr);
shepherd.writeLog('stdout: ' + stdout); shepherd.writeLog('stdout: ' + stdout);
shepherd.writeLog('stderr: ' + stderr); shepherd.writeLog('stderr: ' + stderr);
@ -1560,6 +1656,7 @@ shepherd.appInfo = function() {
sysInfo, sysInfo,
releaseInfo, releaseInfo,
dirs, dirs,
appSession: shepherd.appSessionHash
}; };
} }

Loading…
Cancel
Save