From 077a27c3984812face8ebc0dfadc7e09e115e48f Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sun, 12 Nov 2017 00:49:15 +0300 Subject: [PATCH] stop/remove native coin; spv auth fixes --- main.js | 3 +- package.json | 1 + routes/shepherd/daemonControl.js | 1 + routes/shepherd/electrum/keys.js | 15 ++++++- routes/shepherd/quitDaemon.js | 69 ++++++++++++++++++++++++++++++++ routes/shepherd/rpc.js | 2 +- version | 2 +- 7 files changed, 88 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index cf9aaa3..1a80500 100644 --- a/main.js +++ b/main.js @@ -476,7 +476,8 @@ function createWindow(status) { let _appClosingInterval; - if (!Object.keys(shepherd.coindInstanceRegistry).length) { + if (!Object.keys(shepherd.coindInstanceRegistry).length || + !appConfig.stopNativeDaemonsOnQuit) { closeApp(); } else { createAppCloseWindow(); diff --git a/package.json b/package.json index a47b36d..4213f1c 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "fix-path": "^2.1.0", "fs-extra": "^1.0.0", "graceful-fs": "^4.1.11", + "js-sha256": "^0.7.1", "nodejs-aes256": "^1.0.1", "portscanner": "^2.1.1", "ps-node": "^0.1.5", diff --git a/routes/shepherd/daemonControl.js b/routes/shepherd/daemonControl.js index 6565845..3f35e9d 100644 --- a/routes/shepherd/daemonControl.js +++ b/routes/shepherd/daemonControl.js @@ -726,6 +726,7 @@ module.exports = (shepherd) => { .then(RemoveLines) .then(CheckConf); } + /* * type: POST * params: herd diff --git a/routes/shepherd/electrum/keys.js b/routes/shepherd/electrum/keys.js index a18c4b3..a476999 100644 --- a/routes/shepherd/electrum/keys.js +++ b/routes/shepherd/electrum/keys.js @@ -1,6 +1,15 @@ +const sha256 = require('js-sha256'); + module.exports = (shepherd) => { - shepherd.seedToWif = (seed, network, iguana) => { - const bytes = shepherd.sha256(seed, { asBytes: true }); + shepherd.seedToWif = (seed, network, iguana, old) => { + let bytes; + + if (old) { + bytes = shepherd.sha256(seed, { asBytes: true }); + } else { + const hash = sha256.create().update(seed); + bytes = hash.array(); + } if (iguana) { bytes[0] &= 248; @@ -23,6 +32,8 @@ module.exports = (shepherd) => { key.compressed = true; + // shepherd.log(`seed: ${seed}`, true); + // shepherd.log(`network ${network}`, true); // shepherd.log(`seedtowif priv key ${key.privateWif}`, true); // shepherd.log(`seedtowif pub key ${key.publicAddress}`, true); diff --git a/routes/shepherd/quitDaemon.js b/routes/shepherd/quitDaemon.js index dd0feb5..90be58d 100644 --- a/routes/shepherd/quitDaemon.js +++ b/routes/shepherd/quitDaemon.js @@ -77,5 +77,74 @@ module.exports = (shepherd) => { } } + shepherd.post('/coind/stop', (req, res) => { + const _chain = req.body.chain; + let _coindQuitCmd = shepherd.komodocliBin; + let _arg = []; + + if (_chain) { + _arg.push(`-ac_name=${_chain}`); + + if (shepherd.appConfig.dataDir.length) { + _arg.push(`-datadir=${shepherd.appConfig.dataDir + (_chain ? '/' + _chain : '')}`); + } + } else if (!_chain && shepherd.appConfig.dataDir.length) { + _arg.push(`-datadir=${shepherd.appConfig.dataDir}`); + } + + console.log(JSON.stringify(shepherd.coindInstanceRegistry, null, '\t')); + + _arg.push('stop'); + shepherd.execFile(`${_coindQuitCmd}`, _arg, (error, stdout, stderr) => { + shepherd.log(`stdout: ${stdout}`); + shepherd.log(`stderr: ${stderr}`); + + if (stdout.indexOf('EOF reached') > -1 || + stderr.indexOf('EOF reached') > -1 || + (error && error.toString().indexOf('Command failed') > -1 && !stderr) || // win "special snowflake" case + stdout.indexOf('connect to server: unknown (code -1)') > -1 || + stderr.indexOf('connect to server: unknown (code -1)') > -1) { + delete shepherd.coindInstanceRegistry[_chain ? _chain : 'komodo']; + const obj = { + msg: 'success', + result: 'result', + }; + + res.end(JSON.stringify(obj)); + } else { + if (stdout.indexOf('Komodo server stopping') > -1) { + delete shepherd.coindInstanceRegistry[_chain ? _chain : 'komodo']; + + const obj = { + msg: 'success', + result: 'result', + }; + + res.end(JSON.stringify(obj)); + } else { + const obj = { + msg: 'error', + result: 'result', + }; + + res.end(JSON.stringify(obj)); + } + } + }); + }); + + shepherd.post('/coins/remove', (req, res) => { + const _chain = req.body.chain; + + delete shepherd.coindInstanceRegistry[_chain ? _chain : 'komodo']; + + const obj = { + msg: 'success', + result: 'result', + }; + + res.end(JSON.stringify(obj)); + }); + return shepherd; }; diff --git a/routes/shepherd/rpc.js b/routes/shepherd/rpc.js index 4664a16..a2fe65c 100644 --- a/routes/shepherd/rpc.js +++ b/routes/shepherd/rpc.js @@ -74,8 +74,8 @@ module.exports = (shepherd) => { } else { const _mode = req.body.payload.mode === 'passthru' ? 'passthru' : 'default'; const _chain = req.body.payload.chain === 'KMD' ? null : req.body.payload.chain; - let _cmd = req.body.payload.cmd; const _params = req.body.payload.params ? ` ${req.body.payload.params}` : ''; + let _cmd = req.body.payload.cmd; if (!shepherd.rpcConf[_chain]) { shepherd.getConf(req.body.payload.chain === 'KMD' || !req.body.payload.chain && shepherd.kmdMainPassiveMode ? 'komodod' : req.body.payload.chain); diff --git a/version b/version index 86f2374..35815dc 100644 --- a/version +++ b/version @@ -1,3 +1,3 @@ -version=0.2.0.23a +version=0.2.0.24a type=e-beta minversion=0.2.0.2 \ No newline at end of file