diff --git a/gui/main.html b/gui/main.html
index 1578187..19243b2 100644
--- a/gui/main.html
+++ b/gui/main.html
@@ -17,7 +17,6 @@
var ajax_data = {"herd":"iguana"};
console.log(ajax_data);
$.ajax({
- //async: false,
type: 'POST',
data: JSON.stringify(ajax_data),
url: 'http://127.0.0.1:17777/shepherd/herd',
@@ -41,7 +40,6 @@
var ajax_data = {"herd":"corsproxy"};
console.log(ajax_data);
$.ajax({
- //async: false,
type: 'POST',
data: JSON.stringify(ajax_data),
url: 'http://127.0.0.1:17777/shepherd/herd',
@@ -65,7 +63,6 @@
var ajax_data = {"herd":"komodod"};
console.log(ajax_data);
$.ajax({
- //async: false,
type: 'POST',
data: JSON.stringify(ajax_data),
url: 'http://127.0.0.1:17777/shepherd/herd',
diff --git a/main.js b/main.js
index d2e6020..dbe0bb9 100644
--- a/main.js
+++ b/main.js
@@ -68,7 +68,7 @@ if (appConfig.killIguanaOnStart) {
}
guiapp.use(function(req, res, next) {
- res.header('Access-Control-Allow-Origin', 'http://127.0.0.1:' + appConfig.iguanaAppPort);
+ res.header('Access-Control-Allow-Origin', '*'/*'http://127.0.0.1:' + appConfig.iguanaAppPort*/);
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
res.header('Access-Control-Allow-Credentials', 'true');
res.header('Access-Control-Allow-Headers', 'Content-Type');
@@ -112,18 +112,6 @@ var guipath = path.join(__dirname, '/gui');
guiapp.use('/gui', express.static(guipath));
guiapp.use('/shepherd', shepherd);
-/*if (cluster.isMaster && process.env.NODE_ENV !== "development") {
- for (var i = 0; i < numCPUs; i++) {
- cluster.fork();
- }
-}
-console.log(cluster)
-*/
-
-/*var rungui = guiapp.listen(appConfig.iguanaAppPort, function () {
- console.log('guiapp listening on port ' + appConfig.iguanaAppPort + '!');
-});*/
-
var server = require('http').createServer(guiapp),
io = require('socket.io').listen(server);
@@ -403,12 +391,8 @@ function createWindow (status) {
}
}
-//app.on('ready', function() {
- //createLoadingWindow
-//})
-
app.on('window-all-closed', function () {
- //if (os.platform() !== 'win32') { ig.kill(); }
+ //if (os.platform() !== 'win32') { ig.kill(); }
// in osx apps stay active in menu bar until explictly closed or quitted by CMD Q
// so we do not kill the app --> for the case user clicks again on the iguana icon
// we open just a new window and respawn iguana proc
@@ -417,34 +401,32 @@ 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.
+// 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');
- if (mainWindow === null && loadingWindow != null) { //mainWindow not intitialised and loadingWindow not dereferenced
- //loading window is still open
- if (os.platform() === 'darwin' || os.platform() === 'linux') {
- closeAppAfterLoading = true;
- let code = `$('#loading_status_text').html('Preparing to shutdown the wallet.
Please wait while all daemons are closed...')`;
- loadingWindow.webContents.executeJavaScript(code);
- }
+ if (mainWindow === null && loadingWindow != null) { // mainWindow not intitialised and loadingWindow not dereferenced
+ // loading window is still open
console.log('before-quit prevented');
+ closeAppAfterLoading = true;
+ let code = `$('#loading_status_text').html('Preparing to shutdown the wallet.
Please wait while all daemons are closed...')`;
+ loadingWindow.webContents.executeJavaScript(code);
event.preventDefault();
}
});
-//Emitted when all windows have been closed and the application will quit.
-//Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
+// Emitted when all windows have been closed and the application will quit.
+// Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
app.on('will-quit', function (event) {
if (mainWindow === null && loadingWindow != null) {
- //loading window is still open
+ // loading window is still open
console.log('will-quit while loading window active');
event.preventDefault();
}
});
-//Emitted when the application is quitting.
-//Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
+// Emitted when the application is quitting.
+// Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
app.on('quit', function (event) {
if (mainWindow === null && loadingWindow != null) {
console.log('quit while loading window active');
@@ -454,6 +436,6 @@ app.on('quit', function (event) {
app.on('activate', function () {
if (mainWindow === null) {
- //createWindow('open');
+ // createWindow('open');
}
});
\ No newline at end of file
diff --git a/package.json b/package.json
index cee83df..eba7184 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,7 @@
"md5": "^2.2.1",
"mkdirp": "^0.5.1",
"pm2": "^2.3.0",
+ "portscanner": "^2.1.1",
"ps-node": "^0.1.4",
"request": "^2.80.0",
"rimraf": "^2.6.1",
diff --git a/routes/fetchparams.js b/routes/fetchparams.js
index e2a8646..53fd0c9 100644
--- a/routes/fetchparams.js
+++ b/routes/fetchparams.js
@@ -33,8 +33,6 @@ if (os.platform() === 'linux') {
var PARAMS_DIR = process.env.HOME + '/.zcash-params';
}
-//PARAMS_DIR="$HOME/Library/Application Support/ZcashParams"
-
var SPROUT_FILES_DATA = [
{
'file': 'sprout-proving.key',
@@ -46,14 +44,7 @@ var SPROUT_FILES_DATA = [
];
var SPROUT_DL_URL = 'https://z.cash/downloads/';
-//console.log(SPROUT_FILES_DATA);
-
SPROUT_FILES_DATA.forEach(function(value, index) {
- //console.log(index);
- //console.log(value);
- //console.log(value.file);
- //console.log(value.hash);
-
fs.exists(value.file, function(exists) {
if (exists) {
console.log(value.file + ' already exists at location.');
@@ -94,12 +85,12 @@ SPROUT_FILES_DATA.forEach(function(value, index) {
})
.on('end', function () {
// Do something after request finishes
- console.log('download finished.')
+ console.log('download finished.');
var result = 'File ==> ' + value.file + ': DOWNLOADED';
})
.pipe(fs.createWriteStream(value.file));
- console.log(result)
+ console.log(result);
resolve(result);
})
}
diff --git a/routes/mock.js b/routes/mock.js
index 39e4156..e7ea99b 100644
--- a/routes/mock.js
+++ b/routes/mock.js
@@ -23,7 +23,13 @@ mock.get = function(req, res, next) {
if (_url.indexOf('/bitcoinrpc/getaddressesbyaccount') > -1) {
console.log(_url.indexOf('/bitcoinrpc/getaddressesbyaccount'));
res.end(JSON.stringify({
- 'result': ["RDbGxL8QYdEp8sMULaVZS2E6XThcTKT9Jd","RL4orv22Xch7PhM5w9jUHhVQhX6kF6GkfS","RUrxvPTEKGWEDTvAtgiqbUTTFE53Xdpj8a","RPJoLDa7RezvfUUBr7R3U8wrP16AgUsNw3","RQPTpRJEeafNx5hkDzgjcsPyU4E8RFVApT"]
+ 'result': [
+ "RDbGxL8QYdEp8sMULaVZS2E6XThcTKT9Jd",
+ "RL4orv22Xch7PhM5w9jUHhVQhX6kF6GkfS",
+ "RUrxvPTEKGWEDTvAtgiqbUTTFE53Xdpj8a",
+ "RPJoLDa7RezvfUUBr7R3U8wrP16AgUsNw3",
+ "RQPTpRJEeafNx5hkDzgjcsPyU4E8RFVApT"
+ ]
}));
}
if (_url.indexOf('/api/dex/listunspent') > -1 ||
diff --git a/routes/ports.js b/routes/ports.js
new file mode 100644
index 0000000..c5924e9
--- /dev/null
+++ b/routes/ports.js
@@ -0,0 +1,52 @@
+const assetChainPorts = {
+ 'komodod': '7771',
+ 'SUPERNET': '11341',
+ 'REVS': '10196',
+ 'WLC': '11667',
+ 'PANGEA': '10074',
+ 'DEX': '9503',
+ 'JUMBLR': '10789',
+ 'BET': '11222',
+ 'CRYPTO': '10420',
+ 'HODL': '8010',
+ 'SHARK': '14104',
+ 'BOTS': '10151',
+ 'MGW': '15524',
+ 'MVP': '11676',
+ 'KV': '9747',
+ 'CEAL': '13097',
+ 'MESH': '8400',
+ 'USD': '13967',
+ 'CHF': '15312',
+ 'CAD': '8720',
+ 'BRL': '9914',
+ 'BGN': '9110',
+ 'AUD': '8045',
+ 'PLN': '13493',
+ 'PHP': '11181',
+ 'NZD': '10915',
+ 'NOK': '11588',
+ 'MYR': '10688',
+ 'MXN': '13970',
+ 'KRW': '14020',
+ 'JPY': '13145',
+ 'INR': '10536',
+ 'ILS': '14638',
+ 'IDR': '14459',
+ 'HKD': '15409',
+ 'HUF': '13699',
+ 'GBP': '11505',
+ 'EUR': '8065',
+ 'DKK': '13830',
+ 'CNY': '10384',
+ 'ZAR': '15160',
+ 'TRY': '13924',
+ 'THB': '11847',
+ 'SGD': '14475',
+ 'SEK': '11447',
+ 'RON': '8675',
+ 'RUB': '8199',
+ 'CZK': '9482'
+};
+
+module.exports = assetChainPorts;
\ No newline at end of file
diff --git a/routes/shepherd.js b/routes/shepherd.js
index fa9eeee..acf4803 100644
--- a/routes/shepherd.js
+++ b/routes/shepherd.js
@@ -15,7 +15,8 @@ const electron = require('electron'),
pm2 = require('pm2'),
request = require('request'),
async = require('async'),
- rimraf = require('rimraf');
+ rimraf = require('rimraf'),
+ portscanner = require('portscanner');
Promise = require('bluebird');
@@ -23,6 +24,7 @@ const fixPath = require('fix-path');
var ps = require('ps-node'),
setconf = require('../private/setconf.js'),
kmdcli = require('../private/kmdcli.js'),
+ assetChainPorts = require('./ports.js')
shepherd = express.Router();
// IGUANA FILES AND CONFIG SETTINGS
@@ -305,10 +307,7 @@ shepherd.post('/debuglog', function(req, res) {
*/
shepherd.post('/herd', function(req, res) {
console.log('======= req.body =======');
- //console.log(req);
console.log(req.body);
- //console.log(req.body.herd);
- //console.log(req.body.options);
herder(req.body.herd, req.body.options);
@@ -320,52 +319,12 @@ shepherd.post('/herd', function(req, res) {
res.end(JSON.stringify(obj));
});
-
- /*
- *
- * ajax_data = { 'command': 'getinfo' };
- *
- * console.log(ajax_data);
- * $.ajax({
- * async: false,
- * type: 'POST',
- * data: JSON.stringify(ajax_data),
- * url: 'http://127.0.0.1:17777/shepherd/kmdcli',
- * contentType: 'application/json', // send as JSON
- * success: function(data, textStatus, jqXHR) {
- * var AjaxOutputData = JSON.parse(data);
- * console.log(AjaxOutputData);
- * },
- * error: function(xhr, textStatus, error) {
- * console.log(xhr.statusText);
- * console.log(textStatus);
- * console.log(error);
- * }
- * });
- *
- */
-/*shepherd.post('/kmdcli', function(req, res) {
- console.log('======= req.body =======');
- //console.log(req);
- console.log(req.body);
- console.log(req.body.command);
-
- kmdcli.command(req.body.command, function(err, command) {
- console.log(command);
- res.end(JSON.stringify(command));
- });
-});*/
-
/*
* type: POST
* params: herdname
*/
shepherd.post('/herdlist', function(req, res) {
- //console.log('======= req.body =======');
- //console.log(req);
- //console.log(req.body);
console.log(req.body.herdname);
- //console.log(req.body.options);
pm2.connect(true, function(err) {
if (err) throw err; // TODO: proper error handling
@@ -394,9 +353,7 @@ shepherd.post('/herdlist', function(req, res) {
*/
shepherd.post('/slay', function(req, res) {
console.log('======= req.body =======');
- //console.log(req);
console.log(req.body);
- //console.log(req.body.slay);
slayer(req.body.slay);
var obj = {
@@ -412,9 +369,7 @@ shepherd.post('/slay', function(req, res) {
*/
shepherd.post('/setconf', function(req, res) {
console.log('======= req.body =======');
- //console.log(req);
console.log(req.body);
- //console.log(req.body.chain);
if (os.platform() === 'win32' && req.body.chain == 'komodod') {
setkomodoconf = spawn(path.join(__dirname, '../assets/bin/win64/genkmdconf.bat'));
@@ -435,9 +390,7 @@ shepherd.post('/setconf', function(req, res) {
*/
shepherd.post('/getconf', function(req, res) {
console.log('======= req.body =======');
- //console.log(req);
console.log(req.body);
- //console.log(req.body.chain);
var confpath = getConf(req.body.chain);
console.log('got conf path is:');
@@ -699,25 +652,35 @@ function herder(flock, data) {
console.log('komodod debug.log access err: ' + e);
}
+ // get komodod instance port
+ var _port = assetChainPorts[data.ac_name];
+
try {
- pm2.connect(true, function(err) { // start up pm2 god
- if (err) {
- console.error(err);
- process.exit(2);
- }
+ // check if komodod instance is already running
+ portscanner.checkPortStatus(_port, '127.0.0.1', function(error, status) {
+ // Status is 'open' if currently in use or 'closed' if available
+ if (status === 'closed') {
+ pm2.connect(true, function(err) { // start up pm2 god
+ if (err) {
+ console.error(err);
+ process.exit(2);
+ }
- pm2.start({
- script: komododBin, // path to binary
- name: data.ac_name, // REVS, USD, EUR etc.
- exec_mode : 'fork',
- cwd: komodoDir,
- args: data.ac_options
- //args: ["-server", "-ac_name=USD", "-addnode=78.47.196.146"], //separate the params with commas
- }, function(err, apps) {
- pm2.disconnect(); // Disconnect from PM2
- if (err)
- throw err;
- });
+ pm2.start({
+ script: komododBin, // path to binary
+ name: data.ac_name, // REVS, USD, EUR etc.
+ exec_mode : 'fork',
+ cwd: komodoDir,
+ args: data.ac_options
+ }, function(err, apps) {
+ pm2.disconnect(); // Disconnect from PM2
+ if (err)
+ throw err;
+ });
+ });
+ } else {
+ console.log('port ' + _port + ' (' + data.ac_name + ') is already in use');
+ }
});
} catch(e) {
console.log('failed to start komodod err: ' + e);
@@ -741,7 +704,6 @@ function herder(flock, data) {
exec_mode : 'fork',
cwd: zcashDir,
args: data.ac_options
- //args: ["-server", "-ac_name=USD", "-addnode=78.47.196.146"], //separate the params with commas
}, function(err, apps) {
pm2.disconnect(); // Disconnect from PM2
if (err)
@@ -778,7 +740,6 @@ function slayer(flock) {
console.log(flock);
pm2.delete(flock, function(err, ret) {
- //console.log(err);
pm2.disconnect();
console.log(ret);
});
@@ -882,8 +843,6 @@ function setConf(flock) {
var result = 'CheckConf is done';
setconf.status(DaemonConfPath, function(err, status) {
- //console.log(status[0]);
- //console.log(status[0].rpcuser);
var rpcuser = function() {
return new Promise(function(resolve, reject) {
var result = 'checking rpcuser...';
@@ -901,7 +860,6 @@ function setConf(flock) {
});
}
- //console.log(result)
resolve(result);
});
}
@@ -923,7 +881,6 @@ function setConf(flock) {
});
}
- //console.log(result)
resolve(result);
});
}
@@ -943,7 +900,6 @@ function setConf(flock) {
});
}
- //console.log(result)
resolve(result);
});
}
@@ -952,7 +908,7 @@ function setConf(flock) {
return new Promise(function(resolve, reject) {
var result = 'checking addnode...';
- if(status[0].hasOwnProperty('addnode')) {
+ if (status[0].hasOwnProperty('addnode')) {
console.log('addnode: OK');
} else {
console.log('addnode: NOT FOUND')
@@ -970,7 +926,6 @@ function setConf(flock) {
});
}
- //console.log(result)
resolve(result);
});
}
@@ -980,7 +935,7 @@ function setConf(flock) {
return rpcpass();
})
.then(server)
- .then(addnode)
+ .then(addnode);
});
setTimeout(function() {