Browse Source

Merge pull request #100 from pbca26/master

app
all-modes
pbca26 8 years ago
committed by GitHub
parent
commit
07b4f3cbde
  1. 10
      gui/init.js
  2. 37
      gui/loading.js
  3. 37
      main.js
  4. 81
      routes/cache.js
  5. 2
      routes/shepherd.js

10
gui/init.js

@ -15,11 +15,6 @@ $(document).ready(function() {
if (appConf && !appConf.manualIguanaStart) {
StartIguana();
}
/*if (appConf && appConf.forks && appConf.forks.basilisk) {
setTimeout(function() {
StartBasiliskInstance();
}, 4000);
}*/
var portcheck;
@ -30,6 +25,11 @@ $(document).ready(function() {
if (result !== 'error') {
stopcheck();
if (appConf && appConf.forks && appConf.forks.basilisk) {
StartIguana_Cache();
}
$('#loading_status_text').text('Connecting to Basilisk Network...');
EDEX_DEXgetinfoAll(appConf.skipBasiliskNetworkCheck, appConf.minNotaries);
}

37
gui/loading.js

@ -65,28 +65,21 @@ function StartIguana() {
});
}
function StartBasiliskInstance() {
var ajax_data = { 'name': 'basilisk'};
console.log(ajax_data);
$.ajax({
type: 'POST',
data: JSON.stringify(ajax_data),
url: 'http://127.0.0.1:17777/shepherd/forks',
dataType: 'xml/html/script/json', // expected format for response
contentType: 'application/json', // send as JSON
success: function(data, textStatus, jqXHR) {
var AjaxOutputData = JSON.parse(data);
console.log('== Shepherd Forks Data OutPut ==');
console.log(AjaxOutputData);
},
error: function(xhr, textStatus, error) {
console.log(xhr.statusText);
if ( xhr.readyState == 0 ) {
}
console.log(textStatus);
console.log(error);
}
function StartIguana_Cache() {
var ajax_data = {
'mode': 'basilisk',
'coin': 'all'
};
var start_iguana_cache= $.ajax({
type: 'POST',
data: JSON.stringify(ajax_data),
url: 'http://127.0.0.1:17777/shepherd/forks',
contentType: 'application/json', // send as JSON
})
start_iguana_cache.done(function(data) {
_data = JSON.parse(data);
console.log(_data.result);
sessionStorage.setItem('IguanaCachePort', _data.result);
});
}

37
main.js

@ -21,7 +21,7 @@ var express = require('express'),
pm2 = require('pm2'),
cluster = require('cluster'),
numCPUs = require('os').cpus().length,
kmdcli = require('./private/kmdcli.js'),
coincli = require('./private/coincli.js'),
ipc = require('electron').ipcMain;
Promise = require('bluebird');
@ -240,14 +240,35 @@ function createLoadingWindow() {
}
});
ipc.on('invokeAction', function(event, data){
//console.log(data);
kmdcli.command(data, function(err, command) {
//console.log(command);
var result = command;
event.sender.send('kmdcliReply', result);
/*
* var ipc = require('electron').ipcRenderer;
* ipc.once('coincliReply', function(event, response){
* console.log(response);
* });
* ipc.send('InvokeCoinCliAction', '{"cli":"kmd","command":"getinfo"}');
*/
ipc.on('InvokeCoinCliAction', function(event, data){
console.log(JSON.stringify(data));
console.log(data.cli)
console.log(data.command)
if (data.cli == 'kmd') {
coincli.kmdcommand(data.command, function(err, command) {
//console.log(command);
var result = command;
event.sender.send('coincliReply', result);
});
}
if (data.cli == 'zec') {
coincli.zeccommand(data.command, function(err, command) {
//console.log(command);
var result = command;
event.sender.send('coincliReply', result);
});
}
});
});
//ca333 todo - add os detector to use correct binary - so we can use the same bundle on ALL OS platforms
/*if (os.platform() === 'win32') {
process.chdir(iguanaDir);

81
routes/cache.js

@ -152,37 +152,46 @@ cache.groomPost = function(req, res) {
var _filename = req.body.filename,
_payload = req.body.payload;
if (_filename) {
if (!_payload) {
if (!cacheCallInProgress) {
if (_filename) {
if (!_payload) {
var errorObj = {
'msg': 'error',
'result': 'no payload provided'
};
res.end(JSON.stringify(errorObj));
} else {
fs.writeFile(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json', _payload, function (err) {
if (err) {
var errorObj = {
'msg': 'error',
'result': err
};
res.end(JSON.stringify(errorObj));
} else {
var successObj = {
'msg': 'success',
'result': 'done'
};
res.end(JSON.stringify(successObj));
}
});
}
} else {
var errorObj = {
'msg': 'error',
'result': 'no payload provided'
'result': 'no file name provided'
};
res.end(JSON.stringify(errorObj));
} else {
fs.writeFile(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json', _payload, function (err) {
if (err) {
var errorObj = {
'msg': 'error',
'result': err
};
res.end(JSON.stringify(errorObj));
} else {
var successObj = {
'msg': 'success',
'result': 'done'
};
res.end(JSON.stringify(successObj));
}
});
}
} else {
var errorObj = {
'msg': 'error',
'result': 'no file name provided'
'result': 'another job is in progress'
};
res.end(JSON.stringify(errorObj));
@ -303,9 +312,35 @@ cache.one = function(req, res, next) {
console.log('cache-one call started');
function fixJSON(data) {
console.log(data);
if (data && data.length) {
try {
var parsedJSON = JSON.parse(data);
return parsedJSON;
} catch (e) {
console.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');
return JSON.parse(data.substring(0, errorPos[errorPos.length - 1]));
}
if (e.toString().indexOf('Unexpected end of JSON input')) {
return {};
}
}
} else {
return {};
}
}
if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json') && coin !== 'all') {
var _file = fs.readFileSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json', 'utf8');
outObj = _file ? JSON.parse(_file) : {};
//outObj = _file ? JSON.parse(_file) : {};
outObj = fixJSON(_file);
if (!outObj || !outObj.basilisk) {
console.log('no local basilisk info');

2
routes/shepherd.js

@ -23,7 +23,7 @@ Promise = require('bluebird');
const fixPath = require('fix-path');
var ps = require('ps-node'),
setconf = require('../private/setconf.js'),
kmdcli = require('../private/kmdcli.js'),
coincli = require('../private/coincli.js'),
assetChainPorts = require('./ports.js')
shepherd = express.Router(),
iguanaInstanceRegistry = {};

Loading…
Cancel
Save