From 6f211ac120c117b2291c400fb9d7427b3676faed Mon Sep 17 00:00:00 2001 From: pbca26 Date: Mon, 12 Jun 2017 23:14:19 +0300 Subject: [PATCH 01/11] coind optional start param --- routes/shepherd.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/routes/shepherd.js b/routes/shepherd.js index f4e5daf..0b05699 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -94,6 +94,10 @@ shepherd.appConfig = { "v2": true, "useBasiliskInstance": true, "debug": true, + "cli": { + "passthru": false, + "default": false + } }; shepherd.writeLog = function(data) { @@ -1219,10 +1223,24 @@ function herder(flock, data) { if (status === 'closed') { // start komodod via exec if (data.ac_name === 'komodod') { - console.log('exec' + komododBin + ' ' + data.ac_options.join(' ')); - shepherd.writeLog('exec' + komododBin + ' ' + data.ac_options.join(' ')); + const _customParamDict = { + 'silent': '&', + 'reindex': '-reindex', + 'change': '-pubkey=' + }; + const _customParam; + + if (data.ac_custom_param === 'silent' || + data.ac_custom_param === 'reindex') { + _customParam = ' ' + _customParamDict[data.ac_custom_param]; + } else if (data.ac_custom_param === 'change' && data.ac_custom_param_value) { + _customParam = ' ' + _customParamDict[data.ac_custom_param] + data.ac_custom_param_value; + } + + console.log('exec' + komododBin + ' ' + data.ac_options.join(' ') + _customParam); + shepherd.writeLog('exec' + komododBin + ' ' + data.ac_options.join(' ') + _customParam); - exec(komododBin + ' ' + data.ac_options.join(' '), { + exec(komododBin + ' ' + data.ac_options.join(' ') + _customParam, { maxBuffer: 1024 * 10000 // 10 mb }, function(error, stdout, stderr) { // console.log('stdout: ' + stdout); From 79a12ffa0cee9b6e9f7a41b96cdc188c4a6840e7 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Tue, 13 Jun 2017 09:32:20 +0300 Subject: [PATCH 02/11] cli chain param fix --- routes/shepherd.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/shepherd.js b/routes/shepherd.js index 0b05699..d9654f8 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -305,7 +305,7 @@ shepherd.post('/cli', function(req, res, next) { res.end(JSON.stringify(errorObj)); } else { const _mode = req.body.payload.mode === 'passthru' ? 'passthru' : 'default'; - const _chain = req.body.payload.chain ? req.body.payload.chain : ''; + const _chain = req.body.payload.chain === 'KMD' ? null : req.body.payload.chain; const _cmd = req.body.payload.cmd; const _params = req.body.payload.params ? ' ' + req.body.payload.params : ''; @@ -1228,7 +1228,7 @@ function herder(flock, data) { 'reindex': '-reindex', 'change': '-pubkey=' }; - const _customParam; + let _customParam; if (data.ac_custom_param === 'silent' || data.ac_custom_param === 'reindex') { From 4291b97609f976bfdf2af5c72f13264d26b73d6c Mon Sep 17 00:00:00 2001 From: pbca26 Date: Wed, 14 Jun 2017 09:44:59 +0300 Subject: [PATCH 03/11] extended cli to make rpc calls to json server --- routes/shepherd.js | 77 +++++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 21 deletions(-) diff --git a/routes/shepherd.js b/routes/shepherd.js index d9654f8..f52f8b6 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -17,6 +17,7 @@ const electron = require('electron'), async = require('async'), rimraf = require('rimraf'), portscanner = require('portscanner'), + btoa = require('btoa'), Promise = require('bluebird'); const fixPath = require('fix-path'); @@ -296,7 +297,7 @@ shepherd.post('/cli', function(req, res, next) { }; res.end(JSON.stringify(errorObj)); - } else if (!req.body.payload.cmd.match(/^[0-9a-zA-Z \[\]"'/\\]+$/g)) { + } else if (!req.body.payload.cmd.match(/^[0-9a-zA-Z _\[\]"'/\\]+$/g)) { const errorObj = { 'msg': 'error', 'result': 'wrong cli string format' @@ -309,30 +310,64 @@ shepherd.post('/cli', function(req, res, next) { const _cmd = req.body.payload.cmd; const _params = req.body.payload.params ? ' ' + req.body.payload.params : ''; - exec(komodocliBin + (_chain ? ' -ac_name=' + _chain : '') + ' ' + _cmd + _params, function(error, stdout, stderr) { - console.log('stdout: ' + stdout) - console.log('stderr: ' + stderr) - if (error !== null) { - console.log('exec error: ' + error) - } + if (_mode === 'default') { + const auth = { + user: 'user2492216534', + pass: 'pass343c4e8953af5eafda16bdd65054fc7aac276c8bcbede1fdfdf44fb43dce95cd20', + port: 12167 + }; - let responseObj; + const options = { + url: 'http://localhost:' + auth.port, + method: 'POST', + auth: { + 'user': auth.user, + 'pass': auth.pass + }, + body: JSON.stringify({ + 'agent': 'bitcoinrpc', + 'method': _cmd + /*'params': [ + ]*/ + }) + }; - if (stderr) { - responseObj = { - 'msg': 'error', - 'result': stderr - }; - } else { - responseObj = { - 'msg': 'success', - 'result': stdout - }; - } + request(options, function (error, response, body) { + if (response && + response.statusCode && + response.statusCode === 200) { + res.end(body); + } else { + // TODO: error + } + }); + } else { + exec(komodocliBin + (_chain ? ' -ac_name=' + _chain : '') + ' ' + _cmd + _params, function(error, stdout, stderr) { + console.log('stdout: ' + stdout); + console.log('stderr: ' + stderr); - res.end(JSON.stringify(responseObj)); - }); + if (error !== null) { + console.log('exec error: ' + error); + } + + let responseObj; + + if (stderr) { + responseObj = { + 'msg': 'error', + 'result': stderr + }; + } else { + responseObj = { + 'msg': 'success', + 'result': stdout + }; + } + + res.end(JSON.stringify(responseObj)); + }); + } } }); From 061c08d3fb1a258e651137196218c23a02518218 Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Thu, 15 Jun 2017 11:52:17 +0200 Subject: [PATCH 04/11] added btoa npm package --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 5ec5300..151a01f 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "dependencies": { "bluebird": "^3.4.7", "body-parser": "^1.15.2", + "btoa": "^1.1.2", "corsproxy": "^1.5.0", "electron": "^1.6.5", "express": "^4.14.0", From fd61185d7e38ab682b1b32a4bef4b19080dfabd6 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Fri, 16 Jun 2017 12:20:21 +0300 Subject: [PATCH 05/11] getconf route (wip) --- routes/shepherd.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/routes/shepherd.js b/routes/shepherd.js index f52f8b6..75f3dc7 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -285,6 +285,10 @@ shepherd.quitKomodod = function(chain) { }); } +shepherd.getConf = function(chain) { + // get komodod user and pass +} + /* * type: POST * params: payload @@ -310,7 +314,6 @@ shepherd.post('/cli', function(req, res, next) { const _cmd = req.body.payload.cmd; const _params = req.body.payload.params ? ' ' + req.body.payload.params : ''; - if (_mode === 'default') { const auth = { user: 'user2492216534', From 0f84368a52553f9760f26cbfef44dfbcf3a9f7b9 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sat, 17 Jun 2017 14:01:56 +0300 Subject: [PATCH 06/11] rpc bypass --- gui/EasyDEX-GUI | 2 +- main.js | 4 +-- routes/cache.js | 32 ++++++++++++++++++-- routes/ports.js | 2 +- routes/shepherd.js | 74 +++++++++++++++++++++++++++++++++++----------- 5 files changed, 89 insertions(+), 25 deletions(-) diff --git a/gui/EasyDEX-GUI b/gui/EasyDEX-GUI index 72c3a47..ba50df3 160000 --- a/gui/EasyDEX-GUI +++ b/gui/EasyDEX-GUI @@ -1 +1 @@ -Subproject commit 72c3a472674774be19dbd4a512b44e2fbc41d34d +Subproject commit ba50df3108aa7c3dc27583f15e4f85d80ac08cda diff --git a/main.js b/main.js index 25cbaa8..69c8e4b 100644 --- a/main.js +++ b/main.js @@ -277,13 +277,13 @@ function createWindow (status) { pm2Exit(); } - const staticMenu = Menu.buildFromTemplate([ //if static + const staticMenu = Menu.buildFromTemplate([ // if static { role: 'copy' }, { type: 'separator' }, { role: 'selectall' }, ]); - const editMenu = Menu.buildFromTemplate([ //if editable + const editMenu = Menu.buildFromTemplate([ // if editable { role: 'undo' }, { role: 'redo' }, { type: 'separator' }, diff --git a/routes/cache.js b/routes/cache.js index 3885102..4d02038 100644 --- a/routes/cache.js +++ b/routes/cache.js @@ -519,9 +519,35 @@ cache.one = function(req, res, next) { const _parsedJSON = JSON.parse(body); if (key === 'getbalance' && coin === 'KMD'/* && - ((_parsedJSON && _parsedJSON.balance === 0) || _parsedJSON === [])*/) { - console.log('fallback to kmd explorer'); - //http://kmd.explorer.supernet.org/api/addr/RDbGxL8QYdEp8sMULaVZS2E6XThcTKT9Jd/?noTxList=1 + ((_parsedJSON && _parsedJSON.balance === 0) || body === [])*/) { + console.log('fallback to kmd explorer ======>'); + request({ + url: 'http://kmd.explorer.supernet.org/api/addr/' + address + '/?noTxList=1', + method: 'GET' + }, function (error, response, body) { + if (response && + response.statusCode && + response.statusCode === 200) { + console.log(JSON.stringify(body)); + /*cache.io.emit('messages', { + 'message': { + 'shepherd': { + 'method': 'cache-one', + 'status': 'in progress', + 'iguanaAPI': { + 'method': key, + 'coin': coin, + 'address': address, + 'status': 'done', + 'resp': body + } + } + } + });*/ + } else { + + } + }); } outObj.basilisk[coin][address][key] = {}; diff --git a/routes/ports.js b/routes/ports.js index c5924e9..d854e97 100644 --- a/routes/ports.js +++ b/routes/ports.js @@ -2,7 +2,7 @@ const assetChainPorts = { 'komodod': '7771', 'SUPERNET': '11341', 'REVS': '10196', - 'WLC': '11667', + 'WLC': '12167', 'PANGEA': '10074', 'DEX': '9503', 'JUMBLR': '10789', diff --git a/routes/shepherd.js b/routes/shepherd.js index 75f3dc7..ee5326d 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -29,7 +29,8 @@ var ps = require('ps-node'), iguanaInstanceRegistry = {}, syncOnlyIguanaInstanceInfo = {}, syncOnlyInstanceInterval = -1, - guiLog = {}; + guiLog = {}, + rpcConf = {}; // IGUANA FILES AND CONFIG SETTINGS var iguanaConfsDirSrc = path.join(__dirname, '../assets/deps/confs'), @@ -276,17 +277,46 @@ shepherd.quitKomodod = function(chain) { // exit komodod gracefully console.log('exec ' + komodocliBin + (chain ? ' -ac_name=' + chain : '') + ' stop'); exec(komodocliBin + (chain ? ' -ac_name=' + chain : '') + ' stop', function(error, stdout, stderr) { - console.log('stdout: ' + stdout) - console.log('stderr: ' + stderr) + console.log('stdout: ' + stdout); + console.log('stderr: ' + stderr); if (error !== null) { - console.log('exec error: ' + error) + console.log('exec error: ' + error); } }); } shepherd.getConf = function(chain) { - // get komodod user and pass + const _confLocation = chain === 'komodod' ? `${komodoDir}/komodo.conf` : `${komodoDir}/${chain}/${chain}.conf`; + + if (fs.existsSync(_confLocation)) { + const _port = assetChainPorts[chain]; + const _rpcConf = fs.readFileSync(_confLocation, 'utf8'); + + if (_rpcConf.length) { + let _match; + let parsedRpcConfig = { + user: '', + pass: '', + port: _port + }; + + if (_match = _rpcConf.match(/rpcuser=\s*(.*)/)) { + parsedRpcConfig.user = _match[1]; + } + + if ((_match = _rpcConf.match(/rpcpass=\s*(.*)/)) || + (_match = _rpcConf.match(/rpcpassword=\s*(.*)/))) { + parsedRpcConfig.pass = _match[1]; + } + + rpcConf[chain === 'komodod' ? 'KMD' : chain] = parsedRpcConfig; + } else { + console.log(`${_confLocation} is empty`); + } + } else { + console.log(`${_confLocation} doesnt exist`); + } } /* @@ -314,26 +344,32 @@ shepherd.post('/cli', function(req, res, next) { const _cmd = req.body.payload.cmd; const _params = req.body.payload.params ? ' ' + req.body.payload.params : ''; + if (!rpcConf[_chain]) { + shepherd.getConf(req.body.payload.chain === 'KMD' ? 'komodod' : req.body.payload.chain); + } + if (_mode === 'default') { - const auth = { - user: 'user2492216534', - pass: 'pass343c4e8953af5eafda16bdd65054fc7aac276c8bcbede1fdfdf44fb43dce95cd20', - port: 12167 + const _body = { + 'agent': 'bitcoinrpc', + 'method': _cmd }; + if (_params) { + const _body = { + 'agent': 'bitcoinrpc', + 'method': _cmd, + 'params': _params + }; + } + const options = { - url: 'http://localhost:' + auth.port, + url: 'http://localhost:' + rpcConf[_chain].port, method: 'POST', auth: { - 'user': auth.user, - 'pass': auth.pass + 'user': rpcConf[_chain].user, + 'pass': rpcConf[_chain].pass }, - body: JSON.stringify({ - 'agent': 'bitcoinrpc', - 'method': _cmd - /*'params': [ - ]*/ - }) + body: JSON.stringify(_body) }; request(options, function (error, response, body) { @@ -342,6 +378,8 @@ shepherd.post('/cli', function(req, res, next) { response.statusCode === 200) { res.end(body); } else { + console.log(error); + console.log(body); // TODO: error } }); From 582dc73a1aaeecb6387922d7e84a10608987deed Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sun, 18 Jun 2017 16:02:32 +0300 Subject: [PATCH 07/11] code cleanup --- main.js | 58 ++++++++++---------- package.json | 1 - private/mainmenu.js | 9 ---- private/setconf.js | 41 +++----------- routes/cache.js | 88 ++++++++++++++++--------------- routes/mock.js | 4 +- routes/shepherd.js | 126 ++++++++++++++++++++++---------------------- 7 files changed, 145 insertions(+), 182 deletions(-) diff --git a/main.js b/main.js index 69c8e4b..f4971c3 100644 --- a/main.js +++ b/main.js @@ -22,7 +22,6 @@ var express = require('express'), pm2 = require('pm2'), cluster = require('cluster'), numCPUs = require('os').cpus().length, - //coincli = require('./private/coincli.js'), ipc = require('electron').ipcMain; Promise = require('bluebird'); @@ -37,7 +36,7 @@ app.setVersion(appBasicInfo.version); if (os.platform() === 'linux') { process.env.ELECTRON_RUN_AS_NODE = true; - console.log(process.env); + // console.log(process.env); } // GUI APP settings and starting gui on address http://120.0.0.1:17777 @@ -48,25 +47,25 @@ shepherd.createIguanaDirs(); const appSessionHash = md5(Date.now()); -shepherd.writeLog('app init ' + appSessionHash); -shepherd.writeLog('app info: ' + appBasicInfo.name + ' ' + appBasicInfo.version); +shepherd.writeLog(`app init ${appSessionHash}`); +shepherd.writeLog(`app info: ${appBasicInfo.name} ${appBasicInfo.version}`); shepherd.writeLog('sys info:'); -shepherd.writeLog('totalmem_readable: ' + formatBytes(os.totalmem())); -shepherd.writeLog('arch: ' + os.arch()); -shepherd.writeLog('cpu: ' + os.cpus()[0].model); -shepherd.writeLog('cpu_cores: ' + os.cpus().length); -shepherd.writeLog('platform: ' + os.platform()); -shepherd.writeLog('os_release: ' + os.release()); -shepherd.writeLog('os_type: ' + os.type()); +shepherd.writeLog(`totalmem_readable: ${formatBytes(os.totalmem())}`); +shepherd.writeLog(`arch: ${os.arch()}`); +shepherd.writeLog(`cpu: ${os.cpus()[0].model}`); +shepherd.writeLog(`cpu_cores: ${os.cpus().length}`); +shepherd.writeLog(`platform: ${os.platform()}`); +shepherd.writeLog(`os_release: ${os.release()}`); +shepherd.writeLog(`os_type: ${os.type()}`); var appConfig = shepherd.loadLocalConfig(); // load app config -shepherd.writeLog('app started in ' + (appConfig.dev ? 'dev mode' : ' user mode')); +shepherd.writeLog(`app started in ${(appConfig.dev ? 'dev mode' : ' user mode')}`); shepherd.setConfKMD(); if (appConfig.killIguanaOnStart) { - var iguanaGrep; + let iguanaGrep; if (os.platform() === 'darwin') { iguanaGrep = "ps -p $(ps -A | grep -m1 iguana | awk '{print $1}') | grep -i iguana"; @@ -79,23 +78,25 @@ if (appConfig.killIguanaOnStart) { } exec(iguanaGrep, function(error, stdout, stderr) { if (stdout.indexOf('iguana') > -1) { + const pkillCmd = os.platform() === 'win32' ? 'taskkill /f /im iguana.exe' : 'pkill -15 iguana'; + console.log('found another iguana process(es)'); shepherd.writeLog('found another iguana process(es)'); - const pkillCmd = os.platform() === 'win32' ? 'taskkill /f /im iguana.exe' : 'pkill -15 iguana'; exec(pkillCmd, function(error, stdout, stderr) { - console.log(pkillCmd + ' is issued'); - shepherd.writeLog(pkillCmd + ' is issued'); + console.log(`${pkillCmd} is issued`); + shepherd.writeLog(`${pkillCmd} is issued`); + if (error !== null) { - console.log(pkillCmd + ' exec error: ' + error); - shepherd.writeLog(pkillCmd + ' exec error: ' + error); + console.log(`${pkillCmd} exec error: ${error}`); + shepherd.writeLog(`${pkillCmd} exec error: ${error}`); }; }); } if (error !== null) { - console.log(iguanaGrep + ' exec error: ' + error); - shepherd.writeLog(iguanaGrep + ' exec error: ' + error); + console.log(`${iguanaGrep} exec error: ${error}`); + shepherd.writeLog(`${iguanaGrep} exec error: ${error}`); }; }); } @@ -138,7 +139,7 @@ guiapp.use(bodyParser.urlencoded({ })); // support encoded bodies guiapp.get('/', function (req, res) { - res.send('Iguana app server'); + res.send('Agama app server'); }); var guipath = path.join(__dirname, '/gui'); @@ -149,11 +150,11 @@ var server = require('http').createServer(guiapp), io = require('socket.io').listen(server); server.listen(appConfig.agamaPort, function() { - console.log('guiapp and sockets.io are listening on port ' + appConfig.agamaPort + '!'); - shepherd.writeLog('guiapp and sockets.io are listening on port ' + appConfig.agamaPort + '!'); + console.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`); + 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.agamaPort); // 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) { console.log('EDEX GUI is connected...'); @@ -184,7 +185,6 @@ if (os.platform() === 'win32') { var iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/agama_app_icon.ico'); } - let mainWindow; let loadingWindow; let willQuitApp = false; @@ -204,7 +204,7 @@ function createLoadingWindow() { loadingWindow.createWindow = createWindow; // expose createWindow to front-end scripts // load our index.html (i.e. easyDEX GUI) - loadingWindow.loadURL('http://' + appConfig.host + ':' + appConfig.agamaPort + '/gui/'); + loadingWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/`); shepherd.writeLog('show loading window'); // DEVTOOLS - only for dev purposes - ca333 @@ -304,14 +304,14 @@ function createWindow (status) { if (appConfig.dev) { mainWindow.loadURL('http://127.0.0.1:3000'); } else { - mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.agamaPort + '/gui/EasyDEX-GUI/react/build'); + mainWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/EasyDEX-GUI/react/build`); } } else { shepherd.writeLog('show edex gui'); - mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.agamaPort + '/gui/EasyDEX-GUI/'); + mainWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/EasyDEX-GUI/`); } } else { - mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.agamaPort + '/gui/main.html'); + mainWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/main.html`); } mainWindow.webContents.on('context-menu', (e, params) => { //context-menu returns params diff --git a/package.json b/package.json index 151a01f..5ec5300 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "dependencies": { "bluebird": "^3.4.7", "body-parser": "^1.15.2", - "btoa": "^1.1.2", "corsproxy": "^1.5.0", "electron": "^1.6.5", "express": "^4.14.0", diff --git a/private/mainmenu.js b/private/mainmenu.js index 3fac3f0..07cbbdf 100644 --- a/private/mainmenu.js +++ b/private/mainmenu.js @@ -55,15 +55,6 @@ const template = [ focusedWindow.webContents.toggleDevTools(); } }, - /*{ - label: 'Relaunch app', - click (item, focusedWindow) { - if (focusedWindow) - app.relaunch({ args: process.argv.slice(1).concat([ '--relaunch' ]) }); - app.exit(0); - } - TODO: figure out a way to restart iguana and komodod, reload gui - },*/ { type: 'separator' }, diff --git a/private/setconf.js b/private/setconf.js index a1c0c39..777b2a1 100644 --- a/private/setconf.js +++ b/private/setconf.js @@ -41,9 +41,8 @@ var coind_conf = module.exports = { * */ function parse_status_block(block) { - var match; - - var parsed = { + let match; + let parsed = { settings: 'exists' }; @@ -98,45 +97,17 @@ function parse_status(callback) { } else { callback(error, stdout.trim().split('\n\n').map(parse_status_block)); - //stdout.trim().split(/\s\*-usb:/g).map(parse_status_block)); - //console.log(stdout.trim().split(/\s\*-usb:/g)) } }; } -/** - * The **coind_conf status** command is used to query the status of all - * configured interfaces. - * - * @static - * @category coind_conf - * @param {function} callback The callback function. - * @example - * - * var coind_conf = require('./coind_conf'); - * - * coind_conf.status(function(err, status) { - * console.log(status); - * }); - * - * // => - * [ - * { - * "rpcuser": "pi", - * "rpcpass": "c892f76fc45365d50cb744ec1d5cdde659c98e0b", - * "rpcport": "8336", - * "server": "1" - * } - * ] - * - */ function status(confPath, callback) { - //console.log(confPath); - if (os.platform() === 'darwin' || os.platform() === 'linux') { - this.exec('cat "' + confPath + '"', parse_status(callback)); + if (os.platform() === 'darwin' || + os.platform() === 'linux') { + this.exec(`cat "${confPath}"`, parse_status(callback)); } if (os.platform() === 'win32') { - this.exec('type "' + confPath + '"', parse_status(callback)); + this.exec(`type "${confPath}"`, parse_status(callback)); } } \ No newline at end of file diff --git a/routes/cache.js b/routes/cache.js index 4d02038..d9bc537 100644 --- a/routes/cache.js +++ b/routes/cache.js @@ -16,7 +16,7 @@ cache.setVar = function(variable, value) { cache.dumpCacheBeforeExit = function() { if (inMemCache) { console.log('dumping cache before exit'); - fs.writeFileSync(cache.iguanaDir + '/shepherd/cache-' + inMemPubkey + '.json', JSON.stringify(inMemCache), 'utf8'); + fs.writeFileSync(`${cache.iguanaDir}/shepherd/cache-${inMemPubkey}.json`, JSON.stringify(inMemCache), 'utf8'); } } @@ -29,8 +29,8 @@ cache.get = function(req, res, next) { if (!inMemCache) { console.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) { + if (fs.existsSync(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`)) { + fs.readFile(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`, 'utf8', function (err, data) { if (err) { const errorObj = { 'msg': 'error', @@ -54,10 +54,10 @@ cache.get = function(req, res, next) { 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(`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'); - fs.writeFile(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json', data.substring(0, errorPos[errorPos.length - 1]), function(err) { + fs.writeFile(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`, data.substring(0, errorPos[errorPos.length - 1]), function(err) { const successObj = { 'msg': 'success', 'result': data.substring(0, errorPos[errorPos.length - 1]) @@ -73,7 +73,7 @@ cache.get = function(req, res, next) { } else { const errorObj = { 'msg': 'error', - 'result': 'no file with handle ' + pubkey + 'result': `no file with handle ${pubkey}` }; res.end(JSON.stringify(errorObj)); @@ -100,8 +100,8 @@ cache.groomGet = function(req, res, next) { const _filename = req.query.filename; if (_filename) { - if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json')) { - fs.readFile(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json', 'utf8', function (err, data) { + if (fs.existsSync(`${cache.iguanaDir}/shepherd/cache-${_filename}.json`)) { + fs.readFile(`${cache.iguanaDir}/shepherd/cache-${_filename}.json`, 'utf8', function (err, data) { if (err) { const errorObj = { 'msg': 'error', @@ -121,7 +121,7 @@ cache.groomGet = function(req, res, next) { } else { const errorObj = { 'msg': 'error', - 'result': 'no file with name ' + _filename + 'result': `no file with name ${_filename}` }; res.end(JSON.stringify(errorObj)); @@ -140,10 +140,10 @@ cache.groomDelete = function(req, res, next) { const _filename = req.body.filename; if (_filename) { - if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json')) { + if (fs.existsSync(`${cache.iguanaDir}/shepherd/cache-${_filename}.json`)) { inMemCache = null; - fs.unlink(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json', function(err) { + fs.unlink(`${cache.iguanaDir}/shepherd/cache-${_filename}.json`, function(err) { if (err) { const errorObj = { 'msg': 'error', @@ -163,7 +163,7 @@ cache.groomDelete = function(req, res, next) { } else { const errorObj = { 'msg': 'error', - 'result': 'no file with name ' + _filename + 'result': `no file with name ${_filename}` }; res.end(JSON.stringify(errorObj)); @@ -198,7 +198,7 @@ cache.groomPost = function(req, res) { console.log('appending groom post to in mem cache'); console.log('appending groom post to on disk cache'); - fs.writeFile(cache.iguanaDir + '/shepherd/cache-' + _filename + '.json', _payload, function (err) { + fs.writeFile(`${cache.iguanaDir}/shepherd/cache-${_filename}.json`, _payload, function (err) { if (err) { const errorObj = { 'msg': 'error', @@ -271,7 +271,7 @@ checkCallStack = function() { */ cache.one = function(req, res, next) { if (req.query.pubkey && - !fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + req.query.pubkey + '.json')) { + !fs.existsSync(`${cache.iguanaDir}/shepherd/cache-${req.query.pubkey}.json`)) { cacheCallInProgress = false; } @@ -282,8 +282,8 @@ cache.one = function(req, res, next) { if (!cacheCallInProgress) { cache.dumpCacheBeforeExit(); - if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + req.query.pubkey + '.json')) { - let _data = fs.readFileSync(cache.iguanaDir + '/shepherd/cache-' + req.query.pubkey + '.json', 'utf8'); + if (fs.existsSync(`${cache.iguanaDir}/shepherd/cache-${req.query.pubkey}.json`)) { + let _data = fs.readFileSync(`${cache.iguanaDir}/shepherd/cache-${req.query.pubkey}.json`, 'utf8'); if (_data) { inMemCache = JSON.parse(_data); _data = _data.replace('waiting', 'failed'); @@ -327,7 +327,7 @@ cache.one = function(req, res, next) { inMemPubkey = pubkey; callStack[coin] = 1; console.log(callsArray); - console.log('iguana core port ' + iguanaCorePort); + console.log(`iguana core port ${iguanaCorePort}`); if (!sessionKey) { const errorObj = { @@ -354,7 +354,7 @@ cache.one = function(req, res, next) { function fixJSON(data) { if (data && data.length) { try { - var parsedJSON = JSON.parse(data); + const parsedJSON = JSON.parse(data); return parsedJSON; } catch (e) { @@ -362,7 +362,7 @@ cache.one = function(req, res, next) { 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(`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])); } @@ -375,14 +375,13 @@ cache.one = function(req, res, next) { } } - if (fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json') && coin !== 'all') { + if (fs.existsSync(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`) && coin !== 'all') { if (inMemCache) { console.log('cache one from mem'); outObj = inMemCache; } else { - var _file = fs.readFileSync(cache.iguanaDir + '/shepherd/cache-' + pubkey + '.json', 'utf8'); + const _file = fs.readFileSync(`${cache.iguanaDir}/shepherd/cache-${pubkey}.json`, 'utf8'); console.log('cache one from disk'); - //outObj = _file ? JSON.parse(_file) : {}; outObj = fixJSON(_file); } @@ -419,23 +418,24 @@ cache.one = function(req, res, next) { function execDEXRequests(coin, address) { let dexUrls = { - '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, - '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 + '&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}`, + '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}&symbol=${coin}&address=${address}` }, _dexUrls = {}; - for (var a = 0; a < callsArray.length; a++) { + for (let a = 0; a < callsArray.length; a++) { _dexUrls[callsArray[a]] = dexUrls[callsArray[a]]; } - if (coin === 'BTC' || coin === 'SYS') { + if (coin === 'BTC' || + coin === 'SYS') { delete _dexUrls.refresh; delete _dexUrls.getbalance; } - console.log(coin + ' address ' + address); + console.log(`${coin} address ${address}`); if (!outObj.basilisk[coin][address]) { outObj.basilisk[coin][address] = {}; @@ -493,7 +493,7 @@ cache.one = function(req, res, next) { }); outObj.basilisk[coin][address][key].status = 'in progress'; request({ - url: mock ? 'http://localhost:17777/shepherd/mock?url=' + dexUrl : dexUrl, + url: mock ? `http://localhost:17777/shepherd/mock?url=${dexUrl}` : dexUrl, method: 'GET' }, function (error, response, body) { if (response && @@ -522,7 +522,7 @@ cache.one = function(req, res, next) { ((_parsedJSON && _parsedJSON.balance === 0) || body === [])*/) { console.log('fallback to kmd explorer ======>'); request({ - url: 'http://kmd.explorer.supernet.org/api/addr/' + address + '/?noTxList=1', + url: `http://kmd.explorer.supernet.org/api/addr/${address}/?noTxList=1`, method: 'GET' }, function (error, response, body) { if (response && @@ -557,7 +557,7 @@ cache.one = function(req, res, next) { console.log(dexUrl); console.log(body); callStack[coin]--; - console.log(coin + ' _stack len ' + callStack[coin]); + console.log(`${coin} _stack len ${callStack[coin]}`); cache.io.emit('messages', { 'message': { 'shepherd': { @@ -581,7 +581,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]); + console.log(`${coin} _stack len ${callStack[coin]}`); cache.io.emit('messages', { 'message': { 'shepherd': { @@ -598,9 +598,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'); + console.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]); + console.log(`${coin} _stack len ${callStack[coin]}`); cache.io.emit('messages', { 'message': { 'shepherd': { @@ -637,7 +637,7 @@ cache.one = function(req, res, next) { writeCache(); const addrCount = outObj.basilisk[coin].addresses ? outObj.basilisk[coin].addresses.length : 0; - var callsArrayBTC = callsArray.length; + let callsArrayBTC = callsArray.length; if (callsArray.indexOf('getbalance') > - 1) { callsArrayBTC--; @@ -646,7 +646,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]); + console.log(`${coin} stack len ${callStack[coin]}`); cache.io.emit('messages', { 'message': { @@ -668,9 +668,9 @@ cache.one = function(req, res, next) { if (addresses) { parseAddresses(coin, addresses); } else { - const tempUrl = 'http://' + cache.appConfig.host + ':' + cache.appConfig.iguanaCorePort + '/api/bitcoinrpc/getaddressesbyaccount?userpass=' + sessionKey + '&coin=' + coin + '&account=*'; + const tempUrl = `http://${cache.appConfig.host}:${cache.appConfig.iguanaCorePort}/api/bitcoinrpc/getaddressesbyaccount?userpass=${sessionKey}&coin=${coin}&account=*`; request({ - url: mock ? 'http://localhost:17777/shepherd/mock?url=' + tempUrl : tempUrl, + url: mock ? `http://localhost:17777/shepherd/mock?url=${tempUrl}` : tempUrl, method: 'GET' }, function (error, response, body) { if (response && @@ -701,9 +701,9 @@ cache.one = function(req, res, next) { }); if (coin === 'all') { - const tempUrl = 'http://' + cache.appConfig.host + ':' + cache.appConfig.iguanaCorePort + '/api/InstantDEX/allcoins?userpass=' + sessionKey; + const tempUrl = `http://${cache.appConfig.host}:${cache.appConfig.iguanaCorePort}/api/InstantDEX/allcoins?userpass=${sessionKey}`; request({ - url: mock ? 'http://localhost:17777/shepherd/mock?url=' + tempUrl : tempUrl, + url: mock ? `http://localhost:17777/shepherd/mock?url=${tempUrl}` : tempUrl, method: 'GET' }, function (error, response, body) { if (response && @@ -763,15 +763,17 @@ cache.one = function(req, res, next) { getAddresses(coin); } } else { - var callsArrayBTC = callsArray.length; // restrict BTC and SYS only to listunspent and listtransactions calls + let callsArrayBTC = callsArray.length; // restrict BTC and SYS only to listunspent and listtransactions calls + if (callsArray.indexOf('getbalance') > - 1) { callsArrayBTC--; } if (callsArray.indexOf('refresh') > - 1) { callsArrayBTC--; } + callStack[coin] = callStack[coin] + (coin === 'BTC' || coin === 'SYS' ? callsArrayBTC : callsArray.length); - console.log(coin + ' stack len ' + callStack[coin]); + console.log(`${coin} stack len ${callStack[coin]}`); cache.io.emit('messages', { 'message': { diff --git a/routes/mock.js b/routes/mock.js index e7ea99b..163f6f8 100644 --- a/routes/mock.js +++ b/routes/mock.js @@ -3,14 +3,14 @@ const fs = require('fs-extra'), async = require('async'), url = require('url'); -var mock = {}; +let mock = {}; mock.setVar = function(variable, value) { mock[variable] = value; } mock.get = function(req, res, next) { - var _url = req.query.url; + const _url = req.query.url; if (_url.indexOf('/InstantDEX/allcoins') > -1) { res.end(JSON.stringify({ diff --git a/routes/shepherd.js b/routes/shepherd.js index ee5326d..2ab42b2 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -17,13 +17,11 @@ const electron = require('electron'), async = require('async'), rimraf = require('rimraf'), portscanner = require('portscanner'), - btoa = require('btoa'), Promise = require('bluebird'); const fixPath = require('fix-path'); var ps = require('ps-node'), setconf = require('../private/setconf.js'), - //coincli = require('../private/coincli.js'), assetChainPorts = require('./ports.js'), shepherd = express.Router(), iguanaInstanceRegistry = {}, @@ -41,32 +39,32 @@ var iguanaConfsDirSrc = path.join(__dirname, '../assets/deps/confs'), if (os.platform() === 'darwin') { fixPath(); var iguanaBin = path.join(__dirname, '../assets/bin/osx/iguana'), - iguanaDir = process.env.HOME + '/Library/Application Support/iguana', - iguanaConfsDir = iguanaDir + '/confs', + iguanaDir = `${process.env.HOME}/Library/Application Support/iguana`, + iguanaConfsDir = `${iguanaDir}/confs`, komododBin = path.join(__dirname, '../assets/bin/osx/komodod'), komodocliBin = path.join(__dirname, '../assets/bin/osx/komodo-cli'), - komodoDir = process.env.HOME + '/Library/Application Support/Komodo', + komodoDir = `${process.env.HOME}/Library/Application Support/Komodo`, zcashdBin = '/Applications/ZCashSwingWalletUI.app/Contents/MacOS/zcashd', zcashcliBin = '/Applications/ZCashSwingWalletUI.app/Contents/MacOS/zcash-cli', - zcashDir = process.env.HOME + '/Library/Application Support/Zcash'; + zcashDir = `${process.env.HOME}/Library/Application Support/Zcash`; } if (os.platform() === 'linux') { var iguanaBin = path.join(__dirname, '../assets/bin/linux64/iguana'), - iguanaDir = process.env.HOME + '/.iguana', - iguanaConfsDir = iguanaDir + '/confs', + iguanaDir = `${process.env.HOME}/.iguana`, + iguanaConfsDir = `${iguanaDir}/confs`, iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/128x128.png'), komododBin = path.join(__dirname, '../assets/bin/linux64/komodod'), komodocliBin = path.join(__dirname, '../assets/bin/linux64/komodo-cli'), - komodoDir = process.env.HOME + '/.komodo'; + komodoDir = `${process.env.HOME}/.komodo`; } if (os.platform() === 'win32') { var iguanaBin = path.join(__dirname, '../assets/bin/win64/iguana.exe'); iguanaBin = path.normalize(iguanaBin); - iguanaDir = process.env.APPDATA + '/iguana'; + iguanaDir = `${process.env.APPDATA}/iguana`; iguanaDir = path.normalize(iguanaDir); - iguanaConfsDir = process.env.APPDATA + '/iguana/confs'; + iguanaConfsDir = `${process.env.APPDATA}/iguana/confs`; iguanaConfsDir = path.normalize(iguanaConfsDir); iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/agama_app_icon.ico'), iguanaConfsDirSrc = path.normalize(iguanaConfsDirSrc), @@ -74,7 +72,7 @@ if (os.platform() === 'win32') { komododBin = path.normalize(komododBin), komodocliBin = path.join(__dirname, '../assets/bin/win64/komodo-cli.exe'), komodocliBin = path.normalize(komodocliBin), - komodoDir = process.env.APPDATA + '/Komodo', + komodoDir = `${process.env.APPDATA}/Komodo`, komodoDir = path.normalize(komodoDir); } @@ -103,17 +101,17 @@ shepherd.appConfig = { }; shepherd.writeLog = function(data) { - const logLocation = iguanaDir + '/shepherd'; + const logLocation = `${iguanaDir}/shepherd`; const timeFormatted = new Date(Date.now()).toLocaleString('en-US', { hour12: false }); - if (fs.existsSync(logLocation + '/agamalog.txt')) { - fs.appendFile(logLocation + '/agamalog.txt', timeFormatted + ' ' + data + '\r\n', function (err) { + if (fs.existsSync(`${logLocation}/agamalog.txt`)) { + fs.appendFile(`${logLocation}/agamalog.txt`, `${timeFormatted} ${data}\r\n`, function (err) { if (err) { console.log('error writing log file'); } }); } else { - fs.writeFile(logLocation + '/agamalog.txt', timeFormatted + ' ' + data + '\r\n', function (err) { + fs.writeFile(`${logLocation}/agamalog.txt`, `${timeFormatted} ${data}\r\n`, function (err) { if (err) { console.log('error writing log file'); } @@ -124,19 +122,21 @@ 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); + 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}/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'); + console.log(`created shepherd folder at ${iguanaDir}/shepherd`); + shepherd.writeLog(`create shepherd folder at ${iguanaDir}/shepherd`); } } else { console.log('shepherd folder already exists'); @@ -144,8 +144,8 @@ shepherd.createIguanaDirs = function() { } shepherd.get('/coinslist', function(req, res, next) { - if (fs.existsSync(iguanaDir + '/shepherd/coinslist.json')) { - fs.readFile(iguanaDir + '/shepherd/coinslist.json', 'utf8', function (err, data) { + if (fs.existsSync(`${iguanaDir}/shepherd/coinslist.json`)) { + fs.readFile(`${iguanaDir}/shepherd/coinslist.json`, 'utf8', function (err, data) { if (err) { const errorObj = { 'msg': 'error', @@ -177,7 +177,7 @@ shepherd.get('/coinslist', function(req, res, next) { * params: payload */ shepherd.post('/guilog', function(req, res, next) { - const logLocation = iguanaDir + '/shepherd'; + const logLocation = `${iguanaDir}/shepherd`; if (!guiLog[shepherd.appSessionHash]) { guiLog[shepherd.appSessionHash] = {}; @@ -196,7 +196,7 @@ shepherd.post('/guilog', function(req, res, next) { }; } - fs.writeFile(logLocation + '/agamalog.json', JSON.stringify(guiLog), function (err) { + fs.writeFile(`${logLocation}/agamalog.json`, JSON.stringify(guiLog), function (err) { if (err) { shepherd.writeLog('error writing gui log file'); } @@ -213,8 +213,8 @@ shepherd.post('/guilog', function(req, res, next) { 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 (fs.existsSync(`${iguanaDir}/shepherd/agamalog.${logExt}`)) { + fs.readFile(`${iguanaDir}/shepherd/agamalog.${logExt}`, 'utf8', function (err, data) { if (err) { const errorObj = { 'msg': 'error', @@ -234,7 +234,7 @@ shepherd.get('/getlog', function(req, res, next) { } else { const errorObj = { 'msg': 'error', - 'result': 'agama.' + logExt + ' doesn\'t exist' + 'result': `agama.${logExt} doesnt exist` }; res.end(JSON.stringify(errorObj)); @@ -252,7 +252,7 @@ shepherd.post('/coinslist', function(req, res, next) { res.end(JSON.stringify(errorObj)); } else { - fs.writeFile(cache.iguanaDir + '/shepherd/coinslist.json', JSON.stringify(_payload), function (err) { + fs.writeFile(`${cache.iguanaDir}/shepherd/coinslist.json`, JSON.stringify(_payload), function (err) { if (err) { const errorObj = { 'msg': 'error', @@ -277,11 +277,11 @@ shepherd.quitKomodod = function(chain) { // exit komodod gracefully console.log('exec ' + komodocliBin + (chain ? ' -ac_name=' + chain : '') + ' stop'); exec(komodocliBin + (chain ? ' -ac_name=' + chain : '') + ' stop', function(error, stdout, stderr) { - console.log('stdout: ' + stdout); - console.log('stderr: ' + stderr); + console.log(`stdout: ${stdout}`); + console.log(`stderr: ${stderr}`); if (error !== null) { - console.log('exec error: ' + error); + console.log(`exec error: ${error}`); } }); } @@ -349,21 +349,21 @@ shepherd.post('/cli', function(req, res, next) { } if (_mode === 'default') { - const _body = { + let _body = { 'agent': 'bitcoinrpc', 'method': _cmd }; - if (_params) { - const _body = { + if (req.body.payload.params) { + _body = { 'agent': 'bitcoinrpc', 'method': _cmd, - 'params': _params + 'params': req.body.payload.params === ' ' ? [''] : req.body.payload.params }; } const options = { - url: 'http://localhost:' + rpcConf[_chain].port, + url: `http://localhost:${rpcConf[_chain].port}`, method: 'POST', auth: { 'user': rpcConf[_chain].user, @@ -372,24 +372,24 @@ shepherd.post('/cli', function(req, res, next) { body: JSON.stringify(_body) }; + // send back body on both success and error + // this bit replicates iguana core's behaviour request(options, function (error, response, body) { if (response && response.statusCode && response.statusCode === 200) { res.end(body); } else { - console.log(error); - console.log(body); - // TODO: error + res.end(body); } }); } else { exec(komodocliBin + (_chain ? ' -ac_name=' + _chain : '') + ' ' + _cmd + _params, function(error, stdout, stderr) { - console.log('stdout: ' + stdout); - console.log('stderr: ' + stderr); + console.log(`stdout: ${stdout}`); + console.log(`stderr: ${stderr}`); if (error !== null) { - console.log('exec error: ' + error); + console.log(`exec error: ${error}`); } let responseObj; @@ -437,14 +437,14 @@ shepherd.post('/appconf', function(req, res, next) { }); shepherd.saveLocalAppConf = function(appSettings) { - var appConfFileName = iguanaDir + '/config.json'; + let appConfFileName = `${iguanaDir}/config.json`; _fs.access(iguanaDir, fs.constants.R_OK, function(err) { if (!err) { var FixFilePermissions = function() { return new Promise(function(resolve, reject) { - var result = 'config.json file permissions updated to Read/Write'; + const result = 'config.json file permissions updated to Read/Write'; fsnode.chmodSync(appConfFileName, '0666'); @@ -458,7 +458,7 @@ shepherd.saveLocalAppConf = function(appSettings) { var FsWrite = function() { return new Promise(function(resolve, reject) { - var result = 'config.json write file is done' + const result = 'config.json write file is done'; fs.writeFile(appConfFileName, JSON.stringify(appSettings) @@ -473,8 +473,8 @@ shepherd.saveLocalAppConf = function(appSettings) { fsnode.chmodSync(appConfFileName, '0666'); 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); + 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); }); @@ -487,15 +487,15 @@ shepherd.saveLocalAppConf = function(appSettings) { } shepherd.loadLocalConfig = function() { - if (fs.existsSync(iguanaDir + '/config.json')) { - var localAppConfig = fs.readFileSync(iguanaDir + '/config.json', 'utf8'); + if (fs.existsSync(`${iguanaDir}/config.json`)) { + let localAppConfig = fs.readFileSync(`${iguanaDir}/config.json`, 'utf8'); console.log('app config set from local file'); shepherd.writeLog('app config set from local file'); // find diff between local and hardcoded configs // append diff to local config var compareJSON = function(obj1, obj2) { - var result = {}; + let result = {}; for (var i in obj1) { if (!obj2.hasOwnProperty(i)) { @@ -537,15 +537,15 @@ shepherd.loadLocalConfig = function() { shepherd.appConfig = shepherd.loadLocalConfig(); -console.log('iguana dir: ' + iguanaDir); -console.log('iguana bin: ' + iguanaBin); +console.log(`iguana dir: ${iguanaDir}`); +console.log(`iguana bin: ${iguanaBin}`); console.log('--------------------------') -console.log('iguana dir: ' + komododBin); -console.log('iguana bin: ' + komodoDir); -shepherd.writeLog('iguana dir: ' + iguanaDir); -shepherd.writeLog('iguana bin: ' + iguanaBin); -shepherd.writeLog('iguana dir: ' + komododBin); -shepherd.writeLog('iguana bin: ' + komodoDir); +console.log(`iguana dir: ${komododBin}`); +console.log(`iguana bin: ${komodoDir}`); +shepherd.writeLog(`iguana dir: ${iguanaDir}`); +shepherd.writeLog(`iguana bin: ${iguanaBin}`); +shepherd.writeLog(`iguana dir: ${komododBin}`); +shepherd.writeLog(`iguana bin: ${komodoDir}`); // END IGUANA FILES AND CONFIG SETTINGS // default route @@ -606,7 +606,7 @@ shepherd.getSyncOnlyForksInfo = function() { if (iguanaInstanceRegistry[port].mode.indexOf('/sync') > -1) { syncOnlyIguanaInstanceInfo[port] = {}; request({ - url: 'http://localhost:' + port + '/api/bitcoinrpc/getinfo?userpass=tmpIgRPCUser@' + shepherd.appSessionHash, + url: `http://localhost:${port}/api/bitcoinrpc/getinfo?userpass=tmpIgRPCUser@${shepherd.appSessionHash}`, method: 'GET' }, function (error, response, body) { if (response && @@ -621,7 +621,7 @@ shepherd.getSyncOnlyForksInfo = function() { } }); request({ - url: 'http://localhost:' + port + '/api/SuperNET/activehandle?userpass=' + shepherd.appSessionHash, + url: `http://localhost:${port}/api/SuperNET/activehandle?userpass=${shepherd.appSessionHash}`, method: 'GET' }, function (error, response, body) { if (response && @@ -689,7 +689,7 @@ shepherd.get('/forks/restart', function(req, res, next) { 'msg': 'success', 'result': 'restarted' }; - shepherd.writeLog('iguana fork pmid ' + _pmid + ' restarted'); + shepherd.writeLog(`iguana fork pmid ${_pmid} restarted`); res.end(JSON.stringify(successObj)); }); From 2cf88a530c641dac72f7230e2bbcf56ed71610ab Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sun, 18 Jun 2017 10:20:38 -0700 Subject: [PATCH 08/11] fixed KMD truncate debug.log bug --- routes/shepherd.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/routes/shepherd.js b/routes/shepherd.js index 2ab42b2..692e93a 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -363,11 +363,11 @@ shepherd.post('/cli', function(req, res, next) { } const options = { - url: `http://localhost:${rpcConf[_chain].port}`, + url: `http://localhost:${rpcConf[req.body.payload.chain].port}`, method: 'POST', auth: { - 'user': rpcConf[_chain].user, - 'pass': rpcConf[_chain].pass + 'user': rpcConf[req.body.payload.chain].user, + 'pass': rpcConf[req.body.payload.chain].pass }, body: JSON.stringify(_body) }; @@ -1266,7 +1266,7 @@ function herder(flock, data) { } if (flock === 'komodod') { - var kmdDebugLogLocation = ( data.ac_name ? komodoDir + '/' + data.ac_name : komodoDir ) + '/debug.log'; + var kmdDebugLogLocation = ( data.ac_name !== 'komodod' ? komodoDir + '/' + data.ac_name : komodoDir ) + '/debug.log'; console.log('komodod flock selected...'); console.log('selected data: ' + data); shepherd.writeLog('komodod flock selected...'); From 4033a4922a3c7c0dd5893e095eab1f31dadd82a9 Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Mon, 19 Jun 2017 20:31:38 +0200 Subject: [PATCH 09/11] code cleanup #2 --- routes/shepherd.js | 344 ++++++++++++++++++++++++--------------------- 1 file changed, 180 insertions(+), 164 deletions(-) diff --git a/routes/shepherd.js b/routes/shepherd.js index 692e93a..e2bf486 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -456,7 +456,7 @@ shepherd.saveLocalAppConf = function(appSettings) { }); } - var FsWrite = function() { + const FsWrite = function() { return new Promise(function(resolve, reject) { const result = 'config.json write file is done'; @@ -489,15 +489,16 @@ shepherd.saveLocalAppConf = function(appSettings) { shepherd.loadLocalConfig = function() { if (fs.existsSync(`${iguanaDir}/config.json`)) { let localAppConfig = fs.readFileSync(`${iguanaDir}/config.json`, 'utf8'); + console.log('app config set from local file'); shepherd.writeLog('app config set from local file'); // find diff between local and hardcoded configs // append diff to local config - var compareJSON = function(obj1, obj2) { + const compareJSON = function(obj1, obj2) { let result = {}; - for (var i in obj1) { + for (let i in obj1) { if (!obj2.hasOwnProperty(i)) { result[i] = obj1[i]; } @@ -507,9 +508,10 @@ shepherd.loadLocalConfig = function() { }; if (localAppConfig) { - var compareConfigs = compareJSON(shepherd.appConfig, JSON.parse(localAppConfig)); + const compareConfigs = compareJSON(shepherd.appConfig, JSON.parse(localAppConfig)); + if (Object.keys(compareConfigs).length) { - var newConfig = Object.assign(JSON.parse(localAppConfig), compareConfigs); + const newConfig = Object.assign(JSON.parse(localAppConfig), compareConfigs); console.log('config diff is found, updating local config'); console.log('config diff:'); @@ -558,7 +560,7 @@ shepherd.get('/', function(req, res, next) { * */ shepherd.get('/appconf', function(req, res, next) { - var obj = shepherd.loadLocalConfig(); + const obj = shepherd.loadLocalConfig(); res.send(obj); }); @@ -567,7 +569,7 @@ shepherd.get('/appconf', function(req, res, next) { * */ shepherd.get('/sysinfo', function(req, res, next) { - var obj = shepherd.SystemInfo(); + const obj = shepherd.SystemInfo(); res.send(obj); }); @@ -576,7 +578,7 @@ shepherd.get('/sysinfo', function(req, res, next) { * */ shepherd.get('/appinfo', function(req, res, next) { - var obj = shepherd.appInfo(); + const obj = shepherd.appInfo(); res.send(obj); }); @@ -645,7 +647,7 @@ shepherd.getSyncOnlyForksInfo = function() { * */ shepherd.get('/forks/info/start', function(req, res, next) { - var successObj = { + const successObj = { 'msg': 'success', 'result': 'started' }; @@ -659,7 +661,7 @@ shepherd.get('/forks/info/start', function(req, res, next) { * */ shepherd.get('/forks/info/show', function(req, res, next) { - var successObj = { + const successObj = { 'msg': 'success', 'result': JSON.stringify(syncOnlyIguanaInstanceInfo) }; @@ -672,7 +674,7 @@ shepherd.get('/forks/info/show', function(req, res, next) { * */ shepherd.get('/forks/restart', function(req, res, next) { - var _pmid = req.query.pmid; + const _pmid = req.query.pmid; pm2.connect(function(err) { if (err) { @@ -685,7 +687,7 @@ shepherd.get('/forks/restart', function(req, res, next) { } pm2.disconnect(); - var successObj = { + const successObj = { 'msg': 'success', 'result': 'restarted' }; @@ -701,7 +703,7 @@ shepherd.get('/forks/restart', function(req, res, next) { * */ shepherd.get('/forks/stop', function(req, res, next) { - var _pmid = req.query.pmid; + const _pmid = req.query.pmid; pm2.connect(function(err) { if (err) { @@ -714,12 +716,12 @@ shepherd.get('/forks/stop', function(req, res, next) { } pm2.disconnect(); - var successObj = { + const successObj = { 'msg': 'success', 'result': 'stopped' }; - shepherd.writeLog('iguana fork pmid ' + _pmid + ' stopped'); + shepherd.writeLog(`iguana fork pmid ${_pmid} stopped`); res.end(JSON.stringify(successObj)); }); @@ -731,7 +733,7 @@ shepherd.get('/forks/stop', function(req, res, next) { * */ shepherd.get('/forks', function(req, res, next) { - var successObj = { + const successObj = { 'msg': 'success', 'result': iguanaInstanceRegistry }; @@ -755,8 +757,8 @@ shepherd.post('/forks', function(req, res, next) { process.exit(2); } - console.log('iguana core fork port ' + _port); - shepherd.writeLog('iguana core fork port ' + _port); + console.log(`iguana core fork port ${_port}`); + shepherd.writeLog(`iguana core fork port ${_port}`); pm2.start({ script: iguanaBin, // path to binary @@ -783,7 +785,7 @@ shepherd.post('/forks', function(req, res, next) { }, 20000); } - var successObj = { + const successObj = { 'msg': 'success', 'result': _port }; @@ -793,8 +795,8 @@ shepherd.post('/forks', function(req, res, next) { pm2.disconnect(); // Disconnect from PM2 if (err) { throw err; - shepherd.writeLog('iguana fork error: ' + err); - console.log('iguana fork error: ' + err); + shepherd.writeLog(`iguana fork error: ${err}`); + console.log(`iguana fork error: ${err}`); } }); }); @@ -861,7 +863,7 @@ shepherd.get('/mock', function(req, res, next) { * params: herd, lastLines */ shepherd.post('/debuglog', function(req, res) { - var _herd = req.body.herdname, + let _herd = req.body.herdname, _lastNLines = req.body.lastLines, _location; @@ -871,16 +873,16 @@ shepherd.post('/debuglog', function(req, res) { _location = komodoDir; } - shepherd.readDebugLog(_location + '/debug.log', _lastNLines) + shepherd.readDebugLog(`${_location}/debug.log`, _lastNLines) .then(function(result) { - var _obj = { + const _obj = { 'msg': 'success', 'result': result }; res.end(JSON.stringify(_obj)); }, function(result) { - var _obj = { + const _obj = { 'msg': 'error', 'result': result }; @@ -899,7 +901,7 @@ shepherd.post('/herd', function(req, res) { herder(req.body.herd, req.body.options); - var obj = { + const obj = { 'msg': 'success', 'result': 'result' }; @@ -907,13 +909,13 @@ shepherd.post('/herd', function(req, res) { res.end(JSON.stringify(obj)); if (req.body.herd === 'komodod') { - var _port = assetChainPorts[req.body.options.ac_name]; + const _port = assetChainPorts[req.body.options.ac_name]; // check if komodod instance is already running setTimeout(function() { portscanner.checkPortStatus(_port, '127.0.0.1', function(error, status) { // Status is 'open' if currently in use or 'closed' if available if (status === 'closed') { - shepherd.writeLog('komodod service start error at port ' + _port + ', reason: port is closed'); + shepherd.writeLog(`komodod service start error at port ${_port}, reason: port is closed`); cache.io.emit('service', { 'komodod': { 'error': 'start error' @@ -945,7 +947,7 @@ shepherd.post('/herdlist', function(req, res) { shepherd.writeLog(list[0].pm2_env.status); shepherd.writeLog(list[0].pid); - var obj = { + const obj = { 'herdname': req.body.herdname, 'status': list[0].pm2_env.status, 'pid': list[0].pid @@ -964,7 +966,7 @@ shepherd.post('/slay', function(req, res) { console.log(req.body); slayer(req.body.slay); - var obj = { + const obj = { 'msg': 'success', 'result': 'result' }; @@ -987,7 +989,7 @@ shepherd.post('/setconf', function(req, res) { setConf(req.body.chain); } - var obj = { + const obj = { 'msg': 'success', 'result': 'result' }; @@ -1002,13 +1004,14 @@ shepherd.post('/getconf', function(req, res) { console.log('======= req.body ======='); console.log(req.body); - var confpath = getConf(req.body.chain); + const confpath = getConf(req.body.chain); + console.log('got conf path is:'); console.log(confpath); shepherd.writeLog('got conf path is:'); shepherd.writeLog(confpath); - var obj = { + const obj = { 'msg': 'success', 'result': confpath }; @@ -1021,11 +1024,11 @@ shepherd.post('/getconf', function(req, res) { * params: coin, type */ shepherd.get('/kick', function(req, res, next) { - var _coin = req.query.coin, - _type = req.query.type; + const _coin = req.query.coin; + const _type = req.query.type; if (!_coin) { - var errorObj = { + const errorObj = { 'msg': 'error', 'result': 'no coin name provided' }; @@ -1034,7 +1037,7 @@ shepherd.get('/kick', function(req, res, next) { } if (!_type) { - var errorObj = { + const errorObj = { 'msg': 'error', 'result': 'no type provided' }; @@ -1042,7 +1045,7 @@ shepherd.get('/kick', function(req, res, next) { res.end(JSON.stringify(errorObj)); } - var kickStartDirs = { + const kickStartDirs = { 'soft': [ { 'name': 'DB/[coin]', @@ -1120,37 +1123,38 @@ shepherd.get('/kick', function(req, res, next) { if (_coin && _type) { - for (var i = 0; i < kickStartDirs[_type].length; i++) { - var currentKickItem = kickStartDirs[_type][i]; + for (let i = 0; i < kickStartDirs[_type].length; i++) { + let currentKickItem = kickStartDirs[_type][i]; console.log('deleting ' + currentKickItem.type + (currentKickItem.match ? ' ' + currentKickItem.match : '') + ' ' + iguanaDir + '/' + currentKickItem.name.replace('[coin]', _coin)); - if (currentKickItem.type === 'folder' || currentKickItem.type === 'file') { + if (currentKickItem.type === 'folder' || + currentKickItem.type === 'file') { rimraf(iguanaDir + '/' + currentKickItem.name.replace('[coin]', _coin), function(err) { if (err) { throw err; } }); } else if (currentKickItem.type === 'pattern') { - var dirItems = fs.readdirSync(iguanaDir + '/' + currentKickItem.name.replace('[coin]', _coin)); + let dirItems = fs.readdirSync(`${iguanaDir}/currentKickItem.name.replace('[coin]', _coin)`); if (dirItems && dirItems.length) { - for (var j = 0; j < dirItems.length; j++) { + for (let j = 0; j < dirItems.length; j++) { if (dirItems[j].indexOf(currentKickItem.match) > -1) { - rimraf(iguanaDir + '/' + currentKickItem.name.replace('[coin]', _coin) + '/' + dirItems[j], function(err) { + rimraf(`${iguanaDir}/${currentKickItem.name.replace('[coin]', _coin)}/${dirItems[j]}`, function(err) { if (err) { throw err; } }); - console.log('deleting ' + dirItems[j]); + console.log(`deleting ${dirItems[j]}`); } } } } } - var successObj = { + const successObj = { 'msg': 'success', 'result': 'kickstart: brutal is executed' }; @@ -1165,16 +1169,17 @@ shepherd.readDebugLog = function(fileLocation, lastNLines) { if (lastNLines) { _fs.access(fileLocation, fs.constants.R_OK, function(err) { if (err) { - console.log('error reading ' + fileLocation); - shepherd.writeLog('error reading ' + fileLocation); - reject('readDebugLog error: ' + err); + console.log(`error reading ${fileLocation}`); + shepherd.writeLog(`error reading ${fileLocation}`); + reject(`readDebugLog error: ${err}`); } else { - console.log('reading ' + fileLocation); + console.log(`reading ${fileLocation}`); _fs.readFile(fileLocation, 'utf-8', function(err, data) { if (err) throw err; - var lines = data.trim().split('\n'), - lastLine = lines.slice(lines.length - lastNLines, lines.length).join('\n'); + const lines = data.trim().split('\n'); + const lastLine = lines.slice(lines.length - lastNLines, lines.length).join('\n'); + resolve(lastLine); }); } @@ -1194,9 +1199,9 @@ function herder(flock, data) { if (flock === 'iguana') { console.log('iguana flock selected...'); - console.log('selected data: ' + data); + console.log(`selected data: ${data}`); shepherd.writeLog('iguana flock selected...'); - shepherd.writeLog('selected data: ' + data); + shepherd.writeLog(`selected data: ${data}`); // MAKE SURE IGUANA DIR IS THERE FOR USER mkdirp(iguanaDir, function(err) { @@ -1211,7 +1216,7 @@ function herder(flock, data) { }); // ADD SHEPHERD FOLDER - mkdirp(iguanaDir + '/shepherd', function(err) { + mkdirp(`${iguanaDir}/shepherd`, function(err) { if (err) console.error(err); else @@ -1227,8 +1232,8 @@ function herder(flock, data) { if (err) return console.error(err); - console.log('confs files copied successfully at: ' + iguanaConfsDir); - shepherd.writeLog('confs files copied successfully at: ' + iguanaConfsDir); + console.log(`confs files copied successfully at: ${iguanaConfsDir}`); + shepherd.writeLog(`confs files copied successfully at: ${iguanaConfsDir}`); }); pm2.connect(true,function(err) { //start up pm2 god @@ -1237,14 +1242,14 @@ function herder(flock, data) { process.exit(2); } - console.log('iguana core port ' + shepherd.appConfig.iguanaCorePort); - shepherd.writeLog('iguana core port ' + shepherd.appConfig.iguanaCorePort); + console.log(`iguana core port ${shepherd.appConfig.iguanaCorePort}`); + shepherd.writeLog(`iguana core port ${shepherd.appConfig.iguanaCorePort}`); pm2.start({ script: iguanaBin, // path to binary name: 'IGUANA', exec_mode : 'fork', - args: ['-port=' + shepherd.appConfig.iguanaCorePort], + args: [`-port=${shepherd.appConfig.iguanaCorePort}`], cwd: iguanaDir //set correct iguana directory }, function(err, apps) { iguanaInstanceRegistry[shepherd.appConfig.iguanaCorePort] = { @@ -1253,40 +1258,41 @@ function herder(flock, data) { 'pid': apps[0].process.pid, 'pmid': apps[0].pm2_env.pm_id }; - shepherd.writeLog('iguana core started at port ' + shepherd.appConfig.iguanaCorePort + ' pid ' + apps[0].process.pid); + shepherd.writeLog(`iguana core started at port ${shepherd.appConfig.iguanaCorePort} pid ${apps[0].process.pid}`); pm2.disconnect(); // Disconnect from PM2 if (err) { throw err; - shepherd.writeLog('iguana core port ' + shepherd.appConfig.iguanaCorePort); - console.log('iguana fork error: ' + err); + shepherd.writeLog(`iguana core port ${shepherd.appConfig.iguanaCorePort}`); + console.log(`iguana fork error: ${err}`); } }); }); } if (flock === 'komodod') { - var kmdDebugLogLocation = ( data.ac_name !== 'komodod' ? komodoDir + '/' + data.ac_name : komodoDir ) + '/debug.log'; + let kmdDebugLogLocation = (data.ac_name !== 'komodod' ? komodoDir + '/' + data.ac_name : komodoDir) + '/debug.log'; + console.log('komodod flock selected...'); - console.log('selected data: ' + data); + console.log(`selected data: ${data}`); shepherd.writeLog('komodod flock selected...'); - shepherd.writeLog('selected data: ' + data); + shepherd.writeLog(`selected data: ${data}`); // truncate debug.log try { _fs.access(kmdDebugLogLocation, fs.constants.R_OK, function(err) { if (err) { - console.log('error accessing ' + kmdDebugLogLocation); - shepherd.writeLog('error accessing ' + kmdDebugLogLocation); + console.log(`error accessing ${kmdDebugLogLocation}`); + shepherd.writeLog(`error accessing ${kmdDebugLogLocation}`); } else { - console.log('truncate ' + kmdDebugLogLocation); - shepherd.writeLog('truncate ' + kmdDebugLogLocation); + console.log(`truncate ${kmdDebugLogLocation}`); + shepherd.writeLog(`truncate ${kmdDebugLogLocation}`); fs.unlink(kmdDebugLogLocation); } }); } catch(e) { - console.log('komodod debug.log access err: ' + e); - shepherd.writeLog('komodod debug.log access err: ' + e); + console.log(`komodod debug.log access err: ${e}`); + shepherd.writeLog(`komodod debug.log access err: ${e}`); } // get komodod instance port @@ -1304,29 +1310,29 @@ function herder(flock, data) { 'reindex': '-reindex', 'change': '-pubkey=' }; - let _customParam; + let _customParam = ''; if (data.ac_custom_param === 'silent' || - data.ac_custom_param === 'reindex') { + data.ac_custom_param === 'reindex') { _customParam = ' ' + _customParamDict[data.ac_custom_param]; } else if (data.ac_custom_param === 'change' && data.ac_custom_param_value) { _customParam = ' ' + _customParamDict[data.ac_custom_param] + data.ac_custom_param_value; } - console.log('exec' + komododBin + ' ' + data.ac_options.join(' ') + _customParam); - shepherd.writeLog('exec' + komododBin + ' ' + data.ac_options.join(' ') + _customParam); + console.log(`exec ${komododBin} ${data.ac_options.join(' ')}${_customParam}`); + shepherd.writeLog(`exec ${komododBin} ${data.ac_options.join(' ')}${_customParam}`); - exec(komododBin + ' ' + data.ac_options.join(' ') + _customParam, { + exec(`${komododBin} ${data.ac_options.join(' ')}${_customParam}`, { maxBuffer: 1024 * 10000 // 10 mb }, function(error, stdout, stderr) { // console.log('stdout: ' + stdout); // console.log('stderr: ' + stderr); - shepherd.writeLog('stdout: ' + stdout); - shepherd.writeLog('stderr: ' + stderr); + shepherd.writeLog(`stdout: ${stdout}`); + shepherd.writeLog(`stderr: ${stderr}`); if (error !== null) { - console.log('exec error: ' + error) - shepherd.writeLog('exec error: ' + error); + console.log(`exec error: ${error}`) + shepherd.writeLog(`exec error: ${error}`); } }); } else { @@ -1343,7 +1349,7 @@ function herder(flock, data) { cwd: komodoDir, args: data.ac_options }, function(err, apps) { - shepherd.writeLog('komodod fork started ' + data.ac_name + ' ' + JSON.stringify(data.ac_options)); + shepherd.writeLog(`komodod fork started ${data.ac_name} ${JSON.stringify(data.ac_options)}`); pm2.disconnect(); // Disconnect from PM2 if (err) @@ -1352,22 +1358,23 @@ function herder(flock, data) { }); } } else { - console.log('port ' + _port + ' (' + data.ac_name + ') is already in use'); - shepherd.writeLog('port ' + _port + ' (' + data.ac_name + ') is already in use'); + console.log(`port ${_port} (${data.ac_name}) is already in use`); + shepherd.writeLog(`port ${_port} (${data.ac_name}) is already in use`); } }); } catch(e) { - console.log('failed to start komodod err: ' + e); - shepherd.writeLog('failed to start komodod err: ' + e); + console.log(`failed to start komodod err: ${e}`); + shepherd.writeLog(`failed to start komodod err: ${e}`); } } if (flock === 'zcashd') { - var kmdDebugLogLocation = zcashDir + '/debug.log'; + let kmdDebugLogLocation = `${zcashDir}/debug.log`; + console.log('zcashd flock selected...'); - console.log('selected data: ' + data); + console.log(`selected data: ${data}`); shepherd.writeLog('zcashd flock selected...'); - shepherd.writeLog('selected data: ' + data); + shepherd.writeLog(`selected data: ${data}`); pm2.connect(true, function(err) { // start up pm2 god if (err) { @@ -1382,7 +1389,7 @@ function herder(flock, data) { cwd: zcashDir, args: data.ac_options }, function(err, apps) { - shepherd.writeLog('zcashd fork started ' + data.ac_name + ' ' + JSON.stringify(data.ac_options)); + shepherd.writeLog(`zcashd fork started ${data.ac_name} ${JSON.stringify(data.ac_options)}`); pm2.disconnect(); // Disconnect from PM2 if (err) @@ -1394,7 +1401,7 @@ function herder(flock, data) { // deprecated, to be removed if (flock === 'corsproxy') { console.log('corsproxy flock selected...'); - console.log('selected data: ' + data); + console.log(`selected data: ${data}`); pm2.connect(true,function(err) { //start up pm2 god if (err) { @@ -1421,7 +1428,7 @@ function slayer(flock) { pm2.delete(flock, function(err, ret) { pm2.disconnect(); - shepherd.writeLog('deleting flock ' + flock); + shepherd.writeLog(`deleting flock ${flock}`); shepherd.writeLog(ret); console.log(ret); @@ -1429,26 +1436,29 @@ function slayer(flock) { } shepherd.setConfKMD = function() { + let komodoDir; + let zcashDir; + if (os.platform() === 'darwin') { - var komodoDir = process.env.HOME + '/Library/Application Support/Komodo', - ZcashDir = process.env.HOME + '/Library/Application Support/Zcash'; + komodoDir = `${process.env.HOME}/Library/Application Support/Komodo`; + ZcashDir = `${process.env.HOME}/Library/Application Support/Zcash`; } if (os.platform() === 'linux') { - var komodoDir = process.env.HOME + '/.komodo', - ZcashDir = process.env.HOME + '/.zcash'; + komodoDir = `${process.env.HOME}/.komodo`; + ZcashDir = `${process.env.HOME}/.zcash`; } if (os.platform() === 'win32') { - var komodoDir = process.env.APPDATA + '/Komodo', - ZcashDir = process.env.APPDATA + '/Zcash'; + komodoDir = `${process.env.APPDATA}/Komodo`; + ZcashDir = `${process.env.APPDATA}/Zcash`; } // check if kmd conf exists - _fs.access(komodoDir + '/komodo.conf', fs.constants.R_OK, function(err) { + _fs.access(`${komodoDir}/komodo.conf`, fs.constants.R_OK, function(err) { if (err) { console.log('creating komodo conf'); - shepherd.writeLog('creating komodo conf in ' + komodoDir + '/komodo.conf'); + shepherd.writeLog(`creating komodo conf in ${komodoDir}/komodo.conf`); setConf('komodod'); } else { shepherd.writeLog('komodo conf exists'); @@ -1458,39 +1468,45 @@ shepherd.setConfKMD = function() { } function setConf(flock) { + let komodoDir; + let zcashDir; + console.log(flock); - shepherd.writeLog('setconf ' + flock); + shepherd.writeLog(`setconf ${flock}`); if (os.platform() === 'darwin') { - var komodoDir = process.env.HOME + '/Library/Application Support/Komodo', - ZcashDir = process.env.HOME + '/Library/Application Support/Zcash'; + komodoDir = `${process.env.HOME}/Library/Application Support/Komodo`; + ZcashDir = `${process.env.HOME}/Library/Application Support/Zcash`; } if (os.platform() === 'linux') { - var komodoDir = process.env.HOME + '/.komodo', - ZcashDir = process.env.HOME + '/.zcash'; + komodoDir = `${process.env.HOME}/.komodo`; + ZcashDir = `${process.env.HOME}/.zcash`; } if (os.platform() === 'win32') { - var komodoDir = process.env.APPDATA + '/Komodo', - ZcashDir = process.env.APPDATA + '/Zcash'; + komodoDir = `${process.env.APPDATA}/Komodo`; + ZcashDir = `${process.env.APPDATA}/Zcash`; } + let DaemonConfPath; switch (flock) { case 'komodod': - var DaemonConfPath = komodoDir + '/komodo.conf'; + DaemonConfPath = `${komodoDir}/komodo.conf`; + if (os.platform() === 'win32') { DaemonConfPath = path.normalize(DaemonConfPath); } break; case 'zcashd': - var DaemonConfPath = ZcashDir + '/zcash.conf'; + DaemonConfPath = `${ZcashDir}/zcash.conf`; + if (os.platform() === 'win32') { DaemonConfPath = path.normalize(DaemonConfPath); } break; default: - var DaemonConfPath = komodoDir + '/' + flock + '/' + flock + '.conf'; + DaemonConfPath = `${komodoDir}/${flock}/${flock}.conf`; if (os.platform() === 'win32') { DaemonConfPath = path.normalize(DaemonConfPath); @@ -1498,11 +1514,11 @@ function setConf(flock) { } console.log(DaemonConfPath); - shepherd.writeLog('setconf ' + DaemonConfPath); + shepherd.writeLog(`setconf ${DaemonConfPath}`); - var CheckFileExists = function() { + const CheckFileExists = function() { return new Promise(function(resolve, reject) { - var result = 'Check Conf file exists is done' + const result = 'Check Conf file exists is done' fs.ensureFile(DaemonConfPath, function(err) { console.log(err); // => null @@ -1510,39 +1526,39 @@ function setConf(flock) { setTimeout(function() { console.log(result); - shepherd.writeLog('setconf ' + result); + shepherd.writeLog(`setconf ${result}`); resolve(result); }, 2000); }); } - var FixFilePermissions = function() { + const FixFilePermissions = function() { return new Promise(function(resolve, reject) { - var result = 'Conf file permissions updated to Read/Write'; + const result = 'Conf file permissions updated to Read/Write'; fsnode.chmodSync(DaemonConfPath, '0666'); setTimeout(function() { console.log(result); - shepherd.writeLog('setconf ' + result); + shepherd.writeLog(`setconf ${result}`); resolve(result); }, 1000); }); } - var RemoveLines = function() { + const RemoveLines = function() { return new Promise(function(resolve, reject) { - var result = 'RemoveLines is done' + const result = 'RemoveLines is done' fs.readFile(DaemonConfPath, 'utf8', function(err, data) { if (err) { - shepherd.writeLog('setconf error ' + err); + shepherd.writeLog(`setconf error '${err}`); return console.log(err); } - var rmlines = data.replace(/(?:(?:\r\n|\r|\n)\s*){2}/gm, '\n'); + const rmlines = data.replace(/(?:(?:\r\n|\r|\n)\s*){2}/gm, '\n'); fs.writeFile(DaemonConfPath, rmlines, 'utf8', function(err) { if (err) @@ -1552,7 +1568,7 @@ function setConf(flock) { fsnode.chmodSync(DaemonConfPath, '0666'); setTimeout(function() { - shepherd.writeLog('setconf ' + result); + shepherd.writeLog(`setconf ${result}`); console.log(result); resolve(result); @@ -1562,23 +1578,23 @@ function setConf(flock) { var CheckConf = function() { return new Promise(function(resolve, reject) { - var result = 'CheckConf is done'; + const result = 'CheckConf is done'; setconf.status(DaemonConfPath, function(err, status) { - var rpcuser = function() { + const rpcuser = function() { return new Promise(function(resolve, reject) { - var result = 'checking rpcuser...'; + const result = 'checking rpcuser...'; if (status[0].hasOwnProperty('rpcuser')) { console.log('rpcuser: OK'); shepherd.writeLog('rpcuser: OK'); } else { - var randomstring = md5(Math.random() * Math.random() * 999); + const randomstring = md5(Math.random() * Math.random() * 999); console.log('rpcuser: NOT FOUND'); shepherd.writeLog('rpcuser: NOT FOUND'); - fs.appendFile(DaemonConfPath, '\nrpcuser=user' + randomstring.substring(0, 16), (err) => { + fs.appendFile(DaemonConfPath, `\nrpcuser=user${randomstring.substring(0, 16)}`, (err) => { if (err) throw err; console.log('rpcuser: ADDED'); @@ -1590,9 +1606,9 @@ function setConf(flock) { }); } - var rpcpass = function() { + const rpcpass = function() { return new Promise(function(resolve, reject) { - var result = 'checking rpcpassword...'; + const result = 'checking rpcpassword...'; if (status[0].hasOwnProperty('rpcpassword')) { console.log('rpcpassword: OK'); @@ -1603,7 +1619,7 @@ function setConf(flock) { console.log('rpcpassword: NOT FOUND'); shepherd.writeLog('rpcpassword: NOT FOUND'); - fs.appendFile(DaemonConfPath, '\nrpcpassword=' + randomstring, (err) => { + fs.appendFile(DaemonConfPath, `\nrpcpassword=${randomstring}`, (err) => { if (err) throw err; console.log('rpcpassword: ADDED'); @@ -1615,9 +1631,9 @@ function setConf(flock) { }); } - var server = function() { + const server = function() { return new Promise(function(resolve, reject) { - var result = 'checking server...'; + const result = 'checking server...'; if (status[0].hasOwnProperty('server')) { console.log('server: OK'); @@ -1640,7 +1656,7 @@ function setConf(flock) { var addnode = function() { return new Promise(function(resolve, reject) { - var result = 'checking addnode...'; + const result = 'checking addnode...'; if (status[0].hasOwnProperty('addnode')) { console.log('addnode: OK'); @@ -1676,7 +1692,7 @@ function setConf(flock) { setTimeout(function() { console.log(result); - shepherd.writeLog('checkconf addnode ' + result); + shepherd.writeLog(`checkconf addnode ${result}`); resolve(result); }, 2000); @@ -1685,13 +1701,13 @@ function setConf(flock) { var MakeConfReadOnly = function() { return new Promise(function(resolve, reject) { - var result = 'Conf file permissions updated to Read Only'; + const result = 'Conf file permissions updated to Read Only'; fsnode.chmodSync(DaemonConfPath, '0400'); setTimeout(function() { console.log(result); - shepherd.writeLog('MakeConfReadOnly ' + result); + shepherd.writeLog(`MakeConfReadOnly ${result}`); resolve(result); }, 1000); @@ -1708,26 +1724,26 @@ function setConf(flock) { } function getConf(flock) { - var komodoDir = '', + let komodoDir = '', ZcashDir = '', DaemonConfPath = ''; console.log(flock); - shepherd.writeLog('getconf flock: ' + flock); + shepherd.writeLog(`getconf flock: ${flock}`); if (os.platform() === 'darwin') { - komodoDir = process.env.HOME + '/Library/Application Support/Komodo'; - ZcashDir = process.env.HOME + '/Library/Application Support/Zcash'; + komodoDir = `${process.env.HOME}/Library/Application Support/Komodo`; + ZcashDir = `${process.env.HOME}/Library/Application Support/Zcash`; } if (os.platform() === 'linux') { - komodoDir = process.env.HOME + '/.komodo'; - ZcashDir = process.env.HOME + '/.zcash'; + komodoDir = `${process.env.HOME}/.komodo`; + ZcashDir = `${process.env.HOME}/.zcash`; } if (os.platform() === 'win32') { - komodoDir = process.env.APPDATA + '/Komodo'; - ZcashDir = process.env.APPDATA + '/Zcash'; + komodoDir = `${process.env.APPDATA}/Komodo`; + ZcashDir = `${process.env.APPDATA}/Zcash`; } switch (flock) { @@ -1745,13 +1761,13 @@ function getConf(flock) { } break; default: - DaemonConfPath = komodoDir + '/' + flock; + DaemonConfPath = `${komodoDir}/${flock}`; if (os.platform() === 'win32') { DaemonConfPath = path.normalize(DaemonConfPath); } } - shepherd.writeLog('getconf path: ' + DaemonConfPath); + shepherd.writeLog(`getconf path: ${DaemonConfPath}`); console.log(DaemonConfPath); return DaemonConfPath; } @@ -1760,22 +1776,22 @@ function formatBytes(bytes, decimals) { if (bytes === 0) return '0 Bytes'; - var k = 1000, - dm = decimals + 1 || 3, - sizes = [ - 'Bytes', - 'KB', - 'MB', - 'GB', - 'TB', - 'PB', - 'EB', - 'ZB', - 'YB' - ], - i = Math.floor(Math.log(bytes) / Math.log(k)); - - return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; + const k = 1000, + dm = decimals + 1 || 3, + sizes = [ + 'Bytes', + 'KB', + 'MB', + 'GB', + 'TB', + 'PB', + 'EB', + 'ZB', + 'YB' + ], + i = Math.floor(Math.log(bytes) / Math.log(k)); + + return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`; } shepherd.SystemInfo = function() { @@ -1801,8 +1817,8 @@ shepherd.appInfo = function() { iguanaBin, komodoDir, komododBin, - configLocation: iguanaDir + '/config.json', - cacheLocation: iguanaDir + '/shepherd', + configLocation: `${iguanaDir}/config.json`, + cacheLocation: `${iguanaDir}/shepherd`, }; return { From 0026f507591faefa19e6cafddeb9fc13454340d7 Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Tue, 20 Jun 2017 17:19:52 +0200 Subject: [PATCH 10/11] code cleanup #3 --- main.js | 92 ++++++++++++++++------------------------------ routes/shepherd.js | 20 +++++----- 2 files changed, 42 insertions(+), 70 deletions(-) diff --git a/main.js b/main.js index f4971c3..22dbbe0 100644 --- a/main.js +++ b/main.js @@ -142,12 +142,12 @@ guiapp.get('/', function (req, res) { res.send('Agama app server'); }); -var guipath = path.join(__dirname, '/gui'); +const guipath = path.join(__dirname, '/gui'); guiapp.use('/gui', express.static(guipath)); guiapp.use('/shepherd', shepherd); -var server = require('http').createServer(guiapp), - io = require('socket.io').listen(server); +const server = require('http').createServer(guiapp); +const io = require('socket.io').listen(server); server.listen(appConfig.agamaPort, function() { console.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`); @@ -177,12 +177,13 @@ shepherd.setVar('appBasicInfo', appBasicInfo); shepherd.setVar('appSessionHash', appSessionHash); module.exports = guiapp; +var iguanaIcon; if (os.platform() === 'linux') { - var iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/128x128.png'); + iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/128x128.png'); } if (os.platform() === 'win32') { - var iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/agama_app_icon.ico'); + iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/agama_app_icon.ico'); } let mainWindow; @@ -227,35 +228,6 @@ function createLoadingWindow() { e.preventDefault(); } }); - - /* - * 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); - }); - } - }); } app.on('ready', createLoadingWindow); @@ -314,8 +286,8 @@ function createWindow (status) { mainWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/main.html`); } - mainWindow.webContents.on('context-menu', (e, params) => { //context-menu returns params - const { selectionText, isEditable } = params; //params obj + mainWindow.webContents.on('context-menu', (e, params) => { // context-menu returns params + const { selectionText, isEditable } = params; // params obj if (isEditable) { editMenu.popup(mainWindow); @@ -328,7 +300,7 @@ function createWindow (status) { // mainWindow.webContents.openDevTools() function pm2Exit() { - var ConnectToPm2 = function() { + const ConnectToPm2 = function() { return new Promise(function(resolve, reject) { console.log('Closing Main Window...'); shepherd.writeLog('exiting app...'); @@ -349,7 +321,7 @@ function createWindow (status) { } }); - var result = 'Connecting To Pm2: done'; + const result = 'Connecting To Pm2: done'; console.log(result); shepherd.writeLog(result); @@ -357,7 +329,7 @@ function createWindow (status) { }) } - var KillPm2 = function() { + const KillPm2 = function() { return new Promise(function(resolve, reject) { console.log('killing to pm2...'); shepherd.writeLog('killing to pm2...'); @@ -371,7 +343,7 @@ function createWindow (status) { throw err; }); - var result = 'Killing Pm2: done'; + const result = 'Killing Pm2: done'; setTimeout(function() { console.log(result); @@ -382,21 +354,21 @@ function createWindow (status) { }) } - var HideMainWindow = function() { + const HideMainWindow = function() { return new Promise(function(resolve, reject) { console.log('Exiting App...'); mainWindow = null; - var result = 'Hiding Main Window: done'; + const result = 'Hiding Main Window: done'; console.log(result); resolve(result); }); } - var QuitApp = function() { + const QuitApp = function() { return new Promise(function(resolve, reject) { app.quit(); - var result = 'Quiting App: done'; + const result = 'Quiting App: done'; console.log(result); resolve(result); }); @@ -471,20 +443,20 @@ function formatBytes(bytes, decimals) { if (bytes === 0) return '0 Bytes'; - var k = 1000, - dm = decimals + 1 || 3, - sizes = [ - 'Bytes', - 'KB', - 'MB', - 'GB', - 'TB', - 'PB', - 'EB', - 'ZB', - 'YB' - ], - i = Math.floor(Math.log(bytes) / Math.log(k)); - - return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; + const k = 1000, + dm = decimals + 1 || 3, + sizes = [ + 'Bytes', + 'KB', + 'MB', + 'GB', + 'TB', + 'PB', + 'EB', + 'ZB', + 'YB' + ], + i = Math.floor(Math.log(bytes) / Math.log(k)); + + return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`; } \ No newline at end of file diff --git a/routes/shepherd.js b/routes/shepherd.js index e2bf486..746d25b 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -342,7 +342,7 @@ shepherd.post('/cli', function(req, res, next) { const _mode = req.body.payload.mode === 'passthru' ? 'passthru' : 'default'; const _chain = req.body.payload.chain === 'KMD' ? null : req.body.payload.chain; const _cmd = req.body.payload.cmd; - const _params = req.body.payload.params ? ' ' + req.body.payload.params : ''; + const _params = req.body.payload.params ? ` ${req.body.payload.params}` : ''; if (!rpcConf[_chain]) { shepherd.getConf(req.body.payload.chain === 'KMD' ? 'komodod' : req.body.payload.chain); @@ -442,7 +442,7 @@ shepherd.saveLocalAppConf = function(appSettings) { _fs.access(iguanaDir, fs.constants.R_OK, function(err) { if (!err) { - var FixFilePermissions = function() { + const FixFilePermissions = function() { return new Promise(function(resolve, reject) { const result = 'config.json file permissions updated to Read/Write'; @@ -762,9 +762,9 @@ shepherd.post('/forks', function(req, res, next) { pm2.start({ script: iguanaBin, // path to binary - name: 'IGUANA ' + _port + ' ' + mode + ' / ' + coin, + name: `IGUANA ${_port} ${mode} / ${coin}`, exec_mode : 'fork', - args: ['-port=' + _port], + args: [`-port=${_port}`], cwd: iguanaDir //set correct iguana directory }, function(err, apps) { iguanaInstanceRegistry[_port] = { @@ -1296,7 +1296,7 @@ function herder(flock, data) { } // get komodod instance port - var _port = assetChainPorts[data.ac_name]; + const _port = assetChainPorts[data.ac_name]; try { // check if komodod instance is already running @@ -1314,9 +1314,9 @@ function herder(flock, data) { if (data.ac_custom_param === 'silent' || data.ac_custom_param === 'reindex') { - _customParam = ' ' + _customParamDict[data.ac_custom_param]; + _customParam = ` ${_customParamDict[data.ac_custom_param]}`; } else if (data.ac_custom_param === 'change' && data.ac_custom_param_value) { - _customParam = ' ' + _customParamDict[data.ac_custom_param] + data.ac_custom_param_value; + _customParam = ` ${_customParamDict[data.ac_custom_param]}${data.ac_custom_param_value}`; } console.log(`exec ${komododBin} ${data.ac_options.join(' ')}${_customParam}`); @@ -1576,7 +1576,7 @@ function setConf(flock) { }); } - var CheckConf = function() { + const CheckConf = function() { return new Promise(function(resolve, reject) { const result = 'CheckConf is done'; @@ -1654,7 +1654,7 @@ function setConf(flock) { }); } - var addnode = function() { + const addnode = function() { return new Promise(function(resolve, reject) { const result = 'checking addnode...'; @@ -1699,7 +1699,7 @@ function setConf(flock) { }); } - var MakeConfReadOnly = function() { + const MakeConfReadOnly = function() { return new Promise(function(resolve, reject) { const result = 'Conf file permissions updated to Read Only'; From 256a6177eca355842c971a5acc658c15f6495273 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Tue, 20 Jun 2017 10:32:51 -0700 Subject: [PATCH 11/11] added binary artifacts dl sh mac --- binary_artifacts_mac.sh | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 binary_artifacts_mac.sh diff --git a/binary_artifacts_mac.sh b/binary_artifacts_mac.sh new file mode 100644 index 0000000..f6928ac --- /dev/null +++ b/binary_artifacts_mac.sh @@ -0,0 +1,66 @@ +echo Refreshing binaries from artifacts.supernet.org +echo ========================================= +echo Step: Removing old binaries +mkdir -p build +cd build +rm -rvf artifacts.supernet.org +echo +echo Step: Cloning latest binaries for build +mkdir -p artifacts.supernet.org/latest/osx +curl "https://artifacts.supernet.org/latest/osx/iguana" -o "artifacts.supernet.org/latest/osx/iguana" +curl "https://artifacts.supernet.org/latest/osx/komodo-cli" -o "artifacts.supernet.org/latest/osx/komodo-cli" +curl "https://artifacts.supernet.org/latest/osx/komodod" -o "artifacts.supernet.org/latest/osx/komodod" +curl "https://artifacts.supernet.org/latest/osx/libgcc_s.1.dylib" -o "artifacts.supernet.org/latest/osx/libgcc_s.1.dylib" +curl "https://artifacts.supernet.org/latest/osx/libgomp.1.dylib" -o "artifacts.supernet.org/latest/osx/libgomp.1.dylib" +curl "https://artifacts.supernet.org/latest/osx/libnanomsg.5.0.0.dylib" -o "artifacts.supernet.org/latest/osx/libnanomsg.5.0.0.dylib" +curl "https://artifacts.supernet.org/latest/osx/libstdc%2B%2B.6.dylib" -o "artifacts.supernet.org/latest/osx/libstdc++.6.dylib" + +chmod -R +x artifacts.supernet.org/latest/ +cd .. +echo ========================================= +echo +echo ========================================= +echo Step: Moving osx binaries from artifacts to assets/bin/osx/ +echo +mv -fv build/artifacts.supernet.org/latest/osx/iguana assets/bin/osx/ +mv -fv build/artifacts.supernet.org/latest/osx/komodo-cli assets/bin/osx/ +mv -fv build/artifacts.supernet.org/latest/osx/komodod assets/bin/osx/ +mv -fv build/artifacts.supernet.org/latest/osx/libgcc_s.1.dylib assets/bin/osx/ +mv -fv build/artifacts.supernet.org/latest/osx/libgomp.1.dylib assets/bin/osx/ +mv -fv build/artifacts.supernet.org/latest/osx/libnanomsg.5.0.0.dylib assets/bin/osx/ +mv -fv build/artifacts.supernet.org/latest/osx/libstdc++.6.dylib assets/bin/osx/ +echo +echo ========================================= +echo Step: Moving Win64 binaries from artifacts to assets/bin/win64/ +echo +mv -fv build/artifacts.supernet.org/latest/windows/genkmdconf.bat assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/iguana.exe assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/index.html assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/komodo-cli.exe assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/komodo-tx.exe assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/komodod.exe assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/libcrypto-1_1.dll assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/libcurl-4.dll assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/libcurl.dll assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/libgcc_s_sjlj-1.dll assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/libnanomsg.dll assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/libssl-1_1.dll assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/libwinpthread-1.dll assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/nanomsg.dll assets/bin/win64/ +mv -fv build/artifacts.supernet.org/latest/windows/pthreadvc2.dll assets/bin/win64/ +echo +echo ========================================= +echo Step: Moving linux64 binaries from artifacts to assets/bin/linux64 +echo +mv -fv build/artifacts.supernet.org/latest/linux/iguana assets/bin/linux64/ +mv -fv build/artifacts.supernet.org/latest/linux/komodo-cli assets/bin/linux64/ +mv -fv build/artifacts.supernet.org/latest/linux/komodod assets/bin/linux64/ +echo +echo ========================================= +echo Step: Cleaning artifacts data +echo +rm -rf build/ +echo +echo ========================================= +echo Step: Finished Updating binaries from artifacts +echo \ No newline at end of file