From 99885afdf0d5c5c1c076e269a934a9c1d845fd56 Mon Sep 17 00:00:00 2001
From: Petr Balashov <pbca26@gmail.com>
Date: Wed, 3 May 2017 15:25:33 +0200
Subject: [PATCH 1/4] free inMemCachee on shepherd groom delete

---
 main.js            | 5 +++--
 routes/cache.js    | 5 ++++-
 routes/shepherd.js | 2 +-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/main.js b/main.js
index 05e9fbc..7729cf0 100644
--- a/main.js
+++ b/main.js
@@ -21,7 +21,7 @@ var express = require('express'),
 		pm2 = require('pm2'),
 		cluster = require('cluster'),
 		numCPUs = require('os').cpus().length,
-		coincli = require('./private/coincli.js'),
+		//coincli = require('./private/coincli.js'),
 		ipc = require('electron').ipcMain;
 
 Promise = require('bluebird');
@@ -41,6 +41,7 @@ var shepherd = require('./routes/shepherd'),
 
 if (appConfig.killIguanaOnStart) {
 	var iguanaGrep;
+
 	if (os.platform() === 'darwin') {
 		iguanaGrep = "ps -p $(ps -A | grep -m1 iguana | awk '{print $1}') | grep -i iguana";
 	}
@@ -53,7 +54,7 @@ if (appConfig.killIguanaOnStart) {
 	exec(iguanaGrep, function(error, stdout, stderr) {
 		if (stdout.indexOf('iguana') > -1) {
 			console.log('found another iguana process(es)');
-			var pkillCmd = os.platform() === 'win32' ? 'taskkill /f /im iguana.exe' : 'pkill -9 iguana';
+			const pkillCmd = os.platform() === 'win32' ? 'taskkill /f /im iguana.exe' : 'pkill -9 iguana';
 
 			exec(pkillCmd, function(error, stdout, stderr) {
 				console.log(pkillCmd + ' is issued');
diff --git a/routes/cache.js b/routes/cache.js
index 882aa26..68bbfdc 100644
--- a/routes/cache.js
+++ b/routes/cache.js
@@ -141,6 +141,8 @@ cache.groomDelete = function(req, res, next) {
 
   if (_filename) {
     if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json')) {
+      inMemCache = {};
+      
       fs.unlink(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json', function(err) {
         if (err) {
           const errorObj = {
@@ -746,7 +748,8 @@ cache.one = function(req, res, next) {
               'method': 'cache-one',
               'status': 'in progress',
               'iguanaAPI': {
-                'totalStackLength': callStack[coin]
+                'totalStackLength': callStack[coin],
+                'currentStackLength': callStack[coin]
               }
             }
           }
diff --git a/routes/shepherd.js b/routes/shepherd.js
index b72dac3..759dd92 100644
--- a/routes/shepherd.js
+++ b/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'),
-    coincli = require('../private/coincli.js'),
+    //coincli = require('../private/coincli.js'),
     assetChainPorts = require('./ports.js')
     shepherd = express.Router(),
     iguanaInstanceRegistry = {};

From 9bec23cb021ffae7a76b5336ee1af78614a1c05d Mon Sep 17 00:00:00 2001
From: pbca26 <pbca26@gmail.com>
Date: Thu, 4 May 2017 09:28:03 +0300
Subject: [PATCH 2/4] sync only forks(wip)

---
 gui/EasyDEX-GUI    |  2 +-
 routes/shepherd.js | 72 +++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 69 insertions(+), 5 deletions(-)

diff --git a/gui/EasyDEX-GUI b/gui/EasyDEX-GUI
index 59ff487..04af9b1 160000
--- a/gui/EasyDEX-GUI
+++ b/gui/EasyDEX-GUI
@@ -1 +1 @@
-Subproject commit 59ff487c1f068700d381b07a4e873d2ab9d7c86d
+Subproject commit 04af9b16553cee3ca7cba950ebf1072f98ee0ece
diff --git a/routes/shepherd.js b/routes/shepherd.js
index 759dd92..156c75a 100644
--- a/routes/shepherd.js
+++ b/routes/shepherd.js
@@ -16,9 +16,8 @@ const electron = require('electron'),
       request = require('request'),
       async = require('async'),
       rimraf = require('rimraf'),
-      portscanner = require('portscanner');
-
-Promise = require('bluebird');
+      portscanner = require('portscanner'),
+      Promise = require('bluebird');
 
 const fixPath = require('fix-path');
 var ps = require('ps-node'),
@@ -26,7 +25,9 @@ var ps = require('ps-node'),
     //coincli = require('../private/coincli.js'),
     assetChainPorts = require('./ports.js')
     shepherd = express.Router(),
-    iguanaInstanceRegistry = {};
+    iguanaInstanceRegistry = {},
+    syncOnlyIguanaInstanceInfo = {},
+    syncOnlyInstanceInterval = -1;
 
 // IGUANA FILES AND CONFIG SETTINGS
 var iguanaConfsDirSrc = path.join(__dirname, '../assets/deps/confs'),
@@ -236,6 +237,59 @@ shepherd.setIO = function(io) {
 cache.setVar('iguanaDir', iguanaDir);
 cache.setVar('appConfig', shepherd.appConfig);
 
+shepherd.getSyncOnlyForksInfo = function() {
+  async.forEachOf(iguanaInstanceRegistry, function(data, port) {
+    if (iguanaInstanceRegistry[port].mode.indexOf('/sync') > -1) {
+      syncOnlyIguanaInstanceInfo[port] = {};
+      request({
+        url: 'http://localhost:' + port + '/api/bitcoinrpc/getinfo?userpass=tmpIgRPCUser@1234',
+        method: 'GET'
+      }, function (error, response, body) {
+        if (response && response.statusCode && response.statusCode === 200) {
+          console.log(body);
+          try {
+            syncOnlyIguanaInstanceInfo[port].getinfo = JSON.parse(body);
+          } catch(e) {}
+        } else {
+          // TODO: error
+        }
+      });
+      request({
+        url: 'http://localhost:' + port + '/api/SuperNET/activehandle?userpass=tmpIgRPCUser@1234',
+        method: 'GET'
+      }, function (error, response, body) {
+        if (response && response.statusCode && response.statusCode === 200) {
+          console.log(body);
+          try {
+            syncOnlyIguanaInstanceInfo[port].activehandle = JSON.parse(body);
+          } catch(e) {}
+        } else {
+          // TODO: error
+        }
+      });
+    }
+  });
+}
+
+shepherd.get('/forks/info/start', function(req, res, next) {
+  var successObj = {
+    'msg': 'success',
+    'result': 'started'
+  };
+
+  res.end(JSON.stringify(successObj));
+  shepherd.getSyncOnlyForksInfo();
+});
+
+shepherd.get('/forks/info/show', function(req, res, next) {
+  var successObj = {
+    'msg': 'success',
+    'result': JSON.stringify(syncOnlyIguanaInstanceInfo)
+  };
+
+  res.end(JSON.stringify(successObj));
+});
+
 /*
  *  type: GET
  *
@@ -337,6 +391,16 @@ shepherd.post('/forks', function(req, res, next) {
         };
         cache.setVar('iguanaInstances', iguanaInstanceRegistry);
 
+        // get sync only forks info
+        if (syncOnlyInstanceInterval === -1) {
+          setTimeout(function() {
+            shepherd.getSyncOnlyForksInfo();
+          }, 5000);
+          setInterval(function() {
+            shepherd.getSyncOnlyForksInfo();
+          }, 20000);
+        }
+
         var successObj = {
           'msg': 'success',
           'result': _port

From 1baefe2976d469749d8f7bd56561828955735cb8 Mon Sep 17 00:00:00 2001
From: Petr Balashov <pbca26@gmail.com>
Date: Thu, 4 May 2017 18:25:36 +0200
Subject: [PATCH 3/4] post app config(wip)

---
 routes/shepherd.js | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/routes/shepherd.js b/routes/shepherd.js
index 156c75a..0b61c02 100644
--- a/routes/shepherd.js
+++ b/routes/shepherd.js
@@ -111,6 +111,30 @@ shepherd.quitKomodod = function(chain) {
   });
 }
 
+/*
+ *  type: POST
+ *  params: payload
+ */
+shepherd.post('/appconf', function(req, res, next) {
+  if (!req.body.payload) {
+    const errorObj = {
+      'msg': 'error',
+      'result': 'no payload provided'
+    };
+
+    res.end(JSON.stringify(errorObj));
+  } else {
+    shepherd.saveLocalAppConf(req.body.payload);
+
+    const errorObj = {
+      'msg': 'success',
+      'result': 'config saved'
+    };
+
+    res.end(JSON.stringify(errorObj));
+  }
+});
+
 shepherd.saveLocalAppConf = function(appSettings) {
   var appConfFileName = iguanaDir + '/config.json';
 
@@ -237,6 +261,7 @@ shepherd.setIO = function(io) {
 cache.setVar('iguanaDir', iguanaDir);
 cache.setVar('appConfig', shepherd.appConfig);
 
+// fetch sync only forks info
 shepherd.getSyncOnlyForksInfo = function() {
   async.forEachOf(iguanaInstanceRegistry, function(data, port) {
     if (iguanaInstanceRegistry[port].mode.indexOf('/sync') > -1) {
@@ -271,6 +296,10 @@ shepherd.getSyncOnlyForksInfo = function() {
   });
 }
 
+/*
+ *  type: GET
+ *
+ */
 shepherd.get('/forks/info/start', function(req, res, next) {
   var successObj = {
     'msg': 'success',
@@ -281,6 +310,10 @@ shepherd.get('/forks/info/start', function(req, res, next) {
   shepherd.getSyncOnlyForksInfo();
 });
 
+/*
+ *  type: GET
+ *
+ */
 shepherd.get('/forks/info/show', function(req, res, next) {
   var successObj = {
     'msg': 'success',

From cde1fa176e2aed24b703dc8393bae3def270a4a2 Mon Sep 17 00:00:00 2001
From: pbca26 <pbca26@gmail.com>
Date: Fri, 5 May 2017 09:30:38 +0300
Subject: [PATCH 4/4] forks reg info resp

---
 routes/shepherd.js | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/routes/shepherd.js b/routes/shepherd.js
index 0b61c02..d71927d 100644
--- a/routes/shepherd.js
+++ b/routes/shepherd.js
@@ -271,7 +271,7 @@ shepherd.getSyncOnlyForksInfo = function() {
         method: 'GET'
       }, function (error, response, body) {
         if (response && response.statusCode && response.statusCode === 200) {
-          console.log(body);
+          // console.log(body);
           try {
             syncOnlyIguanaInstanceInfo[port].getinfo = JSON.parse(body);
           } catch(e) {}
@@ -284,7 +284,7 @@ shepherd.getSyncOnlyForksInfo = function() {
         method: 'GET'
       }, function (error, response, body) {
         if (response && response.statusCode && response.statusCode === 200) {
-          console.log(body);
+          // console.log(body);
           try {
             syncOnlyIguanaInstanceInfo[port].activehandle = JSON.parse(body);
           } catch(e) {}
@@ -292,6 +292,7 @@ shepherd.getSyncOnlyForksInfo = function() {
           // TODO: error
         }
       });
+      syncOnlyIguanaInstanceInfo[port].registry = iguanaInstanceRegistry[port];
     }
   });
 }