Browse Source

Merge pull request #184 from SuperNETorg/bin-exec-fix

Bin exec fix
all-modes
pbca26 7 years ago
committed by GitHub
parent
commit
ac96c596fb
  1. 42
      main.js
  2. 60
      routes/cache.js
  3. 2
      routes/ports.js
  4. 361
      routes/shepherd.js

42
main.js

@ -170,23 +170,23 @@ function createLoadingWindow() {
// Status is 'open' if currently in use or 'closed' if available
if (status === 'closed') {
server.listen(appConfig.agamaPort, function() {
console.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`);
shepherd.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`);
shepherd.writeLog(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`);
// start sockets.io
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) {
console.log('EDEX GUI is connected...');
shepherd.log('EDEX GUI is connected...');
shepherd.writeLog('EDEX GUI is connected...');
client.on('event', function(data) { // listen for client requests
console.log(data);
shepherd.log(data);
});
client.on('disconnect', function(data) {
console.log('EDEX GUI is disconnected');
shepherd.log('EDEX GUI is disconnected');
});
client.on('join', function(data) {
console.log(data);
shepherd.log(data);
client.emit('messages', 'Sockets server is listening');
});
});
@ -194,11 +194,11 @@ function createLoadingWindow() {
} else {
willQuitApp = true;
server.listen(appConfig.agamaPort + 1, function() {
console.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort + 1}`);
shepherd.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort + 1}`);
shepherd.writeLog(`guiapp and sockets.io are listening on port ${appConfig.agamaPort + 1}`);
});
loadingWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort + 1}/gui/startup/agama-instance-error.html`);
console.log('another agama app is already running');
shepherd.log('another agama app is already running');
}
});
@ -407,24 +407,24 @@ function createWindow(status) {
function pm2Exit() {
const ConnectToPm2 = function() {
return new Promise(function(resolve, reject) {
console.log('Closing Main Window...');
shepherd.log('Closing Main Window...');
shepherd.writeLog('exiting app...');
shepherd.dumpCacheBeforeExit();
shepherd.quitKomodod(1000);
pm2.connect(true, function(err) {
console.log('connecting to pm2...');
shepherd.log('connecting to pm2...');
shepherd.writeLog('connecting to pm2...');
if (err) {
console.log(err);
shepherd.log(err);
}
});
const result = 'Connecting To Pm2: done';
console.log(result);
shepherd.log(result);
shepherd.writeLog(result);
resolve(result);
})
@ -432,12 +432,12 @@ function createWindow(status) {
const KillPm2 = function() {
return new Promise(function(resolve, reject) {
console.log('killing to pm2...');
shepherd.log('killing to pm2...');
shepherd.writeLog('killing to pm2...');
pm2.killDaemon(function(err) {
pm2.disconnect();
console.log('killed to pm2...');
shepherd.log('killed to pm2...');
shepherd.writeLog('killed to pm2...');
if (err)
@ -447,7 +447,7 @@ function createWindow(status) {
const result = 'Killing Pm2: done';
setTimeout(function() {
console.log(result);
shepherd.log(result);
shepherd.writeLog(result);
resolve(result);
@ -459,9 +459,9 @@ function createWindow(status) {
return new Promise(function(resolve, reject) {
const result = 'Hiding Main Window: done';
console.log('Exiting App...');
shepherd.log('Exiting App...');
mainWindow = null;
console.log(result);
shepherd.log(result);
resolve(result);
});
}
@ -479,7 +479,7 @@ function createWindow(status) {
KillPm2(); // required for normal app quit in iguana-less mode
app.quit();
console.log(result);
shepherd.log(result);
resolve(result);
});
}
@ -529,11 +529,11 @@ app.on('window-all-closed', function() {
// Emitted before the application starts closing its windows.
// Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
app.on('before-quit', function(event) {
console.log('before-quit');
shepherd.log('before-quit');
shepherd.killRogueProcess('iguana'); // kill any rogue iguana core instances
if (!forceQuitApp && mainWindow === null && loadingWindow != null) { // mainWindow not intitialised and loadingWindow not dereferenced
// loading window is still open
console.log('before-quit prevented');
shepherd.log('before-quit prevented');
shepherd.writeLog('quit app after loading is done');
closeAppAfterLoading = true;
let code = `$('#loading_status_text').html('Preparing to shutdown the wallet.<br/>Please wait while all daemons are closed...')`;
@ -547,7 +547,7 @@ app.on('before-quit', function(event) {
app.on('will-quit', function(event) {
if (!forceQuitApp && mainWindow === null && loadingWindow != null) {
// loading window is still open
console.log('will-quit while loading window active');
shepherd.log('will-quit while loading window active');
event.preventDefault();
}
});
@ -556,7 +556,7 @@ app.on('will-quit', function(event) {
// Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
app.on('quit', function(event) {
if (!forceQuitApp && mainWindow === null && loadingWindow != null) {
console.log('quit while loading window active');
shepherd.log('quit while loading window active');
event.preventDefault();
}
})

60
routes/cache.js

@ -15,7 +15,7 @@ cache.setVar = function(variable, value) {
*/
cache.dumpCacheBeforeExit = function() {
if (inMemCache) {
console.log('dumping cache before exit');
shepherd.log('dumping cache before exit');
fs.writeFileSync(`${cache.iguanaDir}/shepherd/cache-${inMemPubkey}.json`, JSON.stringify(inMemCache), 'utf8');
}
}
@ -27,7 +27,7 @@ cache.get = function(req, res, next) {
inMemPubkey = pubkey;
if (!inMemCache) {
console.log('serving cache from disk');
shepherd.log('serving cache from disk');
if (fs.existsSync(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`)) {
fs.readFile(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`, 'utf8', function(err, data) {
@ -49,13 +49,13 @@ cache.get = function(req, res, next) {
inMemCache = parsedJSON;
res.end(JSON.stringify(successObj));
} catch (e) {
console.log('JSON parse error while reading cache data from disk:');
console.log(e);
shepherd.log('JSON parse error while reading cache data from disk:');
shepherd.log(e);
if (e.toString().indexOf('at position') > -1) {
const errorPos = e.toString().split(' ');
console.log(`JSON error ---> ${data.substring(errorPos[errorPos.length - 1] - 20, errorPos[errorPos.length - 1] + 20)} | error sequence: ${data.substring(errorPos[errorPos.length - 1], errorPos[errorPos.length - 1] + 1)}`);
console.log('attempting to recover JSON data');
shepherd.log(`JSON error ---> ${data.substring(errorPos[errorPos.length - 1] - 20, errorPos[errorPos.length - 1] + 20)} | error sequence: ${data.substring(errorPos[errorPos.length - 1], errorPos[errorPos.length - 1] + 1)}`);
shepherd.log('attempting to recover JSON data');
fs.writeFile(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`, data.substring(0, errorPos[errorPos.length - 1]), function(err) {
const successObj = {
@ -195,8 +195,8 @@ cache.groomPost = function(req, res) {
res.end(JSON.stringify(errorObj));
} else {
inMemCache = JSON.parse(_payload);
console.log('appending groom post to in mem cache');
console.log('appending groom post to on disk cache');
shepherd.log('appending groom post to in mem cache');
shepherd.log('appending groom post to on disk cache');
fs.writeFile(`${cache.iguanaDir}/shepherd/cache-${_filename}.json`, _payload, function(err) {
if (err) {
@ -326,8 +326,8 @@ cache.one = function(req, res, next) {
inMemPubkey = pubkey;
callStack[coin] = 1;
console.log(callsArray);
console.log(`iguana core port ${iguanaCorePort}`);
shepherd.log(callsArray);
shepherd.log(`iguana core port ${iguanaCorePort}`);
if (!sessionKey) {
const errorObj = {
@ -349,7 +349,7 @@ cache.one = function(req, res, next) {
internalError = true;
}
console.log('cache-one call started');
shepherd.log('cache-one call started');
function fixJSON(data) {
if (data &&
@ -359,12 +359,12 @@ cache.one = function(req, res, next) {
return parsedJSON;
} catch (e) {
console.log(e);
shepherd.log(e);
if (e.toString().indexOf('at position') > -1) {
const errorPos = e.toString().split(' ');
console.log(`JSON error ---> ${data.substring(errorPos[errorPos.length - 1] - 20, errorPos[errorPos.length - 1] + 20)} | error sequence: ${data.substring(errorPos[errorPos.length - 1], errorPos[errorPos.length - 1] + 1)}`);
console.log('attempting to recover JSON data');
shepherd.log(`JSON error ---> ${data.substring(errorPos[errorPos.length - 1] - 20, errorPos[errorPos.length - 1] + 20)} | error sequence: ${data.substring(errorPos[errorPos.length - 1], errorPos[errorPos.length - 1] + 1)}`);
shepherd.log('attempting to recover JSON data');
return JSON.parse(data.substring(0, errorPos[errorPos.length - 1]));
}
if (e.toString().indexOf('Unexpected end of JSON input')) {
@ -379,23 +379,23 @@ cache.one = function(req, res, next) {
if (fs.existsSync(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`) &&
coin !== 'all') {
if (inMemCache) {
console.log('cache one from mem');
shepherd.log('cache one from mem');
outObj = inMemCache;
} else {
const _file = fs.readFileSync(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`, 'utf8');
console.log('cache one from disk');
shepherd.log('cache one from disk');
outObj = fixJSON(_file);
}
if (!outObj ||
!outObj.basilisk) {
console.log('no local basilisk info');
shepherd.log('no local basilisk info');
outObj['basilisk'] = {};
outObj['basilisk'][coin] = {};
} else {
if (!outObj['basilisk'][coin]) {
console.log('no local coin info');
shepherd.log('no local coin info');
outObj['basilisk'][coin] = {};
}
}
@ -438,7 +438,7 @@ cache.one = function(req, res, next) {
delete _dexUrls.getbalance;
}
console.log(`${coin} address ${address}`);
shepherd.log(`${coin} address ${address}`);
if (!outObj.basilisk[coin][address]) {
outObj.basilisk[coin][address] = {};
@ -524,7 +524,7 @@ cache.one = function(req, res, next) {
if (key === 'getbalance' &&
coin === 'KMD'/* &&
((_parsedJSON && _parsedJSON.balance === 0) || body === [])*/) {
console.log('fallback to kmd explorer ======>');
shepherd.log('fallback to kmd explorer ======>');
request({
url: `http://kmd.explorer.supernet.org/api/addr/${address}/?noTxList=1`,
method: 'GET'
@ -558,10 +558,10 @@ cache.one = function(req, res, next) {
outObj.basilisk[coin][address][key].data = JSON.parse(body);
outObj.basilisk[coin][address][key].timestamp = Date.now(); // add timestamp
outObj.basilisk[coin][address][key].status = 'done';
console.log(dexUrl);
console.log(body);
shepherd.log(dexUrl);
shepherd.log(body);
callStack[coin]--;
console.log(`${coin} _stack len ${callStack[coin]}`);
shepherd.log(`${coin} _stack len ${callStack[coin]}`);
cache.io.emit('messages', {
message: {
shepherd: {
@ -585,7 +585,7 @@ cache.one = function(req, res, next) {
outObj.basilisk[coin][address][key].timestamp = 1471620867 // add timestamp
outObj.basilisk[coin][address][key].status = 'done';
callStack[coin]--;
console.log(`${coin} _stack len ${callStack[coin]}`);
shepherd.log(`${coin} _stack len ${callStack[coin]}`);
cache.io.emit('messages', {
message: {
shepherd: {
@ -602,9 +602,9 @@ cache.one = function(req, res, next) {
}
});
} else {
console.log(`${key} is fresh, check back in ${(cacheGlobLifetime - checkTimestamp(outObj.basilisk[coin][address][key].timestamp))}s`);
shepherd.log(`${key} is fresh, check back in ${(cacheGlobLifetime - checkTimestamp(outObj.basilisk[coin][address][key].timestamp))}s`);
callStack[coin]--;
console.log(`${coin} _stack len ${callStack[coin]}`);
shepherd.log(`${coin} _stack len ${callStack[coin]}`);
cache.io.emit('messages', {
message: {
shepherd: {
@ -637,7 +637,7 @@ cache.one = function(req, res, next) {
},
});
outObj.basilisk[coin].addresses = addrArray;
console.log(addrArray);
shepherd.log(addrArray);
writeCache();
const addrCount = outObj.basilisk[coin].addresses ? outObj.basilisk[coin].addresses.length : 0;
@ -650,7 +650,7 @@ cache.one = function(req, res, next) {
callsArrayBTC--;
}
callStack[coin] = callStack[coin] + addrCount * (coin === 'BTC' || coin === 'SYS' ? callsArrayBTC : callsArray.length);
console.log(`${coin} stack len ${callStack[coin]}`);
shepherd.log(`${coin} stack len ${callStack[coin]}`);
cache.io.emit('messages', {
message: {
@ -713,7 +713,7 @@ cache.one = function(req, res, next) {
if (response &&
response.statusCode &&
response.statusCode === 200) {
console.log(JSON.parse(body).basilisk);
shepherd.log(JSON.parse(body).basilisk);
cache.io.emit('messages', {
message: {
shepherd: {
@ -777,7 +777,7 @@ cache.one = function(req, res, next) {
}
callStack[coin] = callStack[coin] + (coin === 'BTC' || coin === 'SYS' ? callsArrayBTC : callsArray.length);
console.log(`${coin} stack len ${callStack[coin]}`);
shepherd.log(`${coin} stack len ${callStack[coin]}`);
cache.io.emit('messages', {
message: {

2
routes/ports.js

@ -8,7 +8,7 @@ const assetChainPorts = {
'JUMBLR': '15106',
'BET': '14250',
'CRYPTO': '8516',
'HODL': '8010',
'HODL': '14431',
'SHARK': '10114',
'BOTS': '11964',
'MGW': '12386',

361
routes/shepherd.js

File diff suppressed because it is too large
Loading…
Cancel
Save