Browse Source

cleanup

pkg_automation_electrum
pbca26 7 years ago
parent
commit
381cc54fd3
  1. 5
      main.js
  2. 1
      routes/shepherd.js
  3. 6
      routes/shepherd/addCoinShortcuts.js
  4. 19
      routes/shepherd/appInfo.js
  5. 18
      routes/shepherd/auth.js
  6. 239
      routes/shepherd/binsTestUtil.js
  7. 9
      routes/shepherd/coindWalletKeys.js
  8. 9
      routes/shepherd/coins.js
  9. 18
      routes/shepherd/coinsList.js
  10. 27
      routes/shepherd/config.js
  11. 27
      routes/shepherd/daemonControl.js
  12. 12
      routes/shepherd/dashboardUpdate.js
  13. 18
      routes/shepherd/debugLog.js
  14. 18
      routes/shepherd/downloadBins.js
  15. 27
      routes/shepherd/downloadPatch.js
  16. 9
      routes/shepherd/downloadZcparams.js
  17. 27
      routes/shepherd/electrum/auth.js
  18. 9
      routes/shepherd/electrum/balance.js
  19. 18
      routes/shepherd/electrum/block.js
  20. 39
      routes/shepherd/electrum/coins.js
  21. 27
      routes/shepherd/electrum/createtx.js
  22. 9
      routes/shepherd/electrum/estimate.js
  23. 37
      routes/shepherd/electrum/keys.js
  24. 9
      routes/shepherd/electrum/listunspent.js
  25. 9
      routes/shepherd/electrum/merkle.js
  26. 29
      routes/shepherd/electrum/network.js
  27. 28
      routes/shepherd/electrum/transactions.js
  28. 9
      routes/shepherd/kickstart.js
  29. 27
      routes/shepherd/log.js
  30. 35
      routes/shepherd/pin.js
  31. 18
      routes/shepherd/quitDaemon.js
  32. 9
      routes/shepherd/rpc.js

5
main.js

@ -57,7 +57,6 @@ shepherd.createAgamaDirs();
const appSessionHash = md5(Date.now().toString());
const _spvFees = shepherd.getSpvFees();
shepherd.writeLog(`app init ${appSessionHash}`);
shepherd.writeLog(`app info: ${appBasicInfo.name} ${appBasicInfo.version}`);
shepherd.writeLog('sys info:');
shepherd.writeLog(`totalmem_readable: ${formatBytes(os.totalmem())}`);
@ -68,7 +67,9 @@ shepherd.writeLog(`platform: ${osPlatform}`);
shepherd.writeLog(`os_release: ${os.release()}`);
shepherd.writeLog(`os_type: ${os.type()}`);
shepherd.log(`app init ${appSessionHash}`);
if (process.argv.indexOf('devmode') > -1) {
shepherd.log(`app init ${appSessionHash}`);
}
shepherd.log(`app info: ${appBasicInfo.name} ${appBasicInfo.version}`);
shepherd.log('sys info:');
shepherd.log(`totalmem_readable: ${formatBytes(os.totalmem())}`);

1
routes/shepherd.js

@ -107,7 +107,6 @@ shepherd = require('./shepherd/dex/electrumServersList.js')(shepherd);
// core
shepherd = require('./shepherd/addCoinShortcuts.js')(shepherd);
shepherd = require('./shepherd/dashboardUpdate.js')(shepherd);
shepherd = require('./shepherd/binsTestUtil.js')(shepherd);
shepherd = require('./shepherd/binsUtils.js')(shepherd);
shepherd = require('./shepherd/downloadUtil.js')(shepherd);
shepherd = require('./shepherd/init.js')(shepherd);

6
routes/shepherd/addCoinShortcuts.js

@ -40,7 +40,8 @@ module.exports = (shepherd) => {
body: JSON.stringify({
herd: 'komodod',
options: herdData,
})
token: shepherd.appSessionHash,
}),
};
shepherd.request(options, (error, response, body) => {
@ -90,7 +91,8 @@ module.exports = (shepherd) => {
body: JSON.stringify({
herd: 'komodod',
options: herdData[i],
})
token: shepherd.appSessionHash,
}),
};
shepherd.request(options, (error, response, body) => {

19
routes/shepherd/appInfo.js

@ -52,7 +52,6 @@ module.exports = (shepherd) => {
sysInfo,
releaseInfo,
dirs,
appSession: shepherd.appSessionHash,
};
}
@ -61,8 +60,17 @@ module.exports = (shepherd) => {
*
*/
shepherd.get('/sysinfo', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const obj = shepherd.SystemInfo();
res.send(obj);
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
/*
@ -70,8 +78,17 @@ module.exports = (shepherd) => {
*
*/
shepherd.get('/appinfo', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const obj = shepherd.appInfo();
res.send(obj);
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

18
routes/shepherd/auth.js

@ -3,7 +3,8 @@ module.exports = (shepherd) => {
* type: GET
*
*/
shepherd.get('/auth/status', (req, res, next) => { // not finished
shepherd.get('/auth/status', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
let successObj;
let _status = false;
@ -25,7 +26,22 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.checkToken = (token) => {
if (token === shepherd.appSessionHash ||
process.argv.indexOf('devmode') > -1) {
return true;
}
};
return shepherd;
};

239
routes/shepherd/binsTestUtil.js

@ -1,239 +0,0 @@
module.exports = (shepherd) => {
shepherd.testClearAll = () => {
return new shepherd.Promise((resolve, reject) => {
shepherd.fs.removeSync(`${iguanaTestDir}`);
resolve('done');
});
}
shepherd.testBins = (daemonName) => {
return new shepherd.Promise((resolve, reject) => {
const _bins = {
komodod: shepherd.komododBin,
komodoCli: shepherd.komodocliBin,
};
const _arg = null;
let _pid;
shepherd.log('testBins exec ' + _bins[daemonName]);
if (!shepherd.fs.existsSync(shepherd.agamaTestDir)) {
shepherd.fs.mkdirSync(shepherd.agamaTestDir);
}
try {
shepherd._fs.access(`${shepherd.agamaTestDir}/${daemonName}Test.log`, shepherd.fs.constants.R_OK, (err) => {
if (!err) {
try {
shepherd._fs.unlinkSync(`${shepherd.agamaTestDir}/${daemonName}Test.log`);
} catch (e) {}
} else {
shepherd.log(`path ${shepherd.agamaTestDir}/${daemonName}Test.log doesnt exist`);
}
});
} catch (e) {}
if (daemonName === 'komodod') {
try {
shepherd._fs.access(`${iguanaTestDir}/debug.log`, shepherd.fs.constants.R_OK, (err) => {
if (!err) {
shepherd._fs.unlinkSync(`${iguanaTestDir}/db.log`);
shepherd._fs.unlinkSync(`${iguanaTestDir}/debug.log`);
shepherd._fs.unlinkSync(`${iguanaTestDir}/komodo.conf`);
shepherd._fs.unlinkSync(`${iguanaTestDir}/komodod.pid`);
shepherd._fs.unlinkSync(`${iguanaTestDir}/komodostate`);
shepherd._fs.unlinkSync(`${iguanaTestDir}/realtime`);
shepherd._fs.unlinkSync(`${iguanaTestDir}/wallet.dat`);
shepherd._fs.unlinkSync(`${iguanaTestDir}/.lock`);
shepherd.fs.removeSync(`${iguanaTestDir}/blocks`);
shepherd.fs.removeSync(`${iguanaTestDir}/chainstate`);
shepherd.fs.removeSync(`${iguanaTestDir}/database`);
execKomodod();
} else {
shepherd.log(`test: nothing to remove in ${iguanaTestDir}`);
execKomodod();
}
});
} catch (e) {}
const execKomodod = () => {
let _komododTest = {
port: 'unknown',
start: 'unknown',
getinfo: 'unknown',
errors: {
assertFailed: false,
zcashParams: false,
},
};
const _komodoConf = 'rpcuser=user83f3afba8d714993\n' +
'rpcpassword=0d4430ca1543833e35bce5a0cc9e16b3\n' +
'server=1\n' +
'addnode=78.47.196.146\n' +
'addnode=5.9.102.210\n' +
'addnode=178.63.69.164\n' +
'addnode=88.198.65.74\n' +
'addnode=5.9.122.241\n' +
'addnode=144.76.94.3\n' +
'addnode=144.76.94.38\n' +
'addnode=89.248.166.91\n' +
'addnode=148.251.57.148\n' +
'addnode=149.56.28.84\n' +
'addnode=176.9.26.39\n' +
'addnode=94.102.63.199\n' +
'addnode=94.102.63.200\n' +
'addnode=104.255.64.3\n' +
'addnode=221.121.144.140\n' +
'addnode=103.18.58.150\n' +
'addnode=103.18.58.146\n' +
'addnode=213.202.253.10\n' +
'addnode=185.106.121.32\n' +
'addnode=27.100.36.201\n';
shepherd.fs.writeFile(`${iguanaTestDir}/komodo.conf`, _komodoConf, (err) => {
if (err) {
shepherd.log(`test: error writing komodo conf in ${iguanaTestDir}`);
}
});
shepherd.portscanner.checkPortStatus('7771', '127.0.0.1', (error, status) => {
// Status is 'open' if currently in use or 'closed' if available
if (status === 'closed') {
_komododTest.port = 'passed';
} else {
_komododTest.port = 'failed';
}
});
/*pm2.connect(true,function(err) { //start up pm2 god
if (err) {
shepherd.error(err);
process.exit(2);
}
pm2.start({
script: shepherd.komododBin, // path to binary
name: 'komodod',
exec_mode : 'fork',
args: [
'-daemon=0',
'-addnode=78.47.196.146',
`-datadir=${iguanaTestDir}/`
],
output: `${iguanaTestDir}/komododTest.log`,
mergeLogs: true,
}, function(err, apps) {
if (apps[0] &&
apps[0].process &&
apps[0].process.pid) {
_komododTest.start = 'success';
shepherd.log(`test: got komodod instance pid = ${apps[0].process.pid}`);
shepherd.writeLog(`test: komodod started with pid ${apps[0].process.pid}`);
} else {
_komododTest.start = 'failed';
shepherd.log(`unable to start komodod`);
}
pm2.disconnect(); // Disconnect from PM2
if (err) {
shepherd.writeLog(`test: error starting komodod`);
shepherd.log(`komodod fork err: ${err}`);
// throw err;
}
});
});*/
setTimeout(() => {
const options = {
url: `http://localhost:7771`,
method: 'POST',
auth: {
user: 'user83f3afba8d714993',
pass: '0d4430ca1543833e35bce5a0cc9e16b3',
},
body: JSON.stringify({
agent: 'bitcoinrpc',
method: 'getinfo',
}),
};
shepherd.request(options, (error, response, body) => {
if (response &&
response.statusCode &&
response.statusCode === 200) {
// res.end(body);
shepherd.log(JSON.stringify(body, null, '\t'));
} else {
// res.end(body);
shepherd.log(JSON.stringify(body, null, '\t'));
}
});
}, 10000);
setTimeout(() => {
pm2.delete('komodod');
resolve(_komododTest);
}, 20000);
}
// komodod debug.log hooks
//"{\"result\":{\"version\":1000850,\"protocolversion\":170002,\"KMDversion\":\"0.1.1\",\"notarized\":0,\"notarizedhash\":\"0000000000000000000000000000000000000000000000000000000000000000\",\"notarizedtxid\":\"0000000000000000000000000000000000000000000000000000000000000000\",\"notarizedtxid_height\":\"mempool\",\"notarized_confirms\":0,\"walletversion\":60000,\"balance\":0.00000000,\"interest\":0.00000000,\"blocks\":128,\"longestchain\":472331,\"timeoffset\":0,\"tiptime\":1473827710,\"connections\":1,\"proxy\":\"\",\"difficulty\":1,\"testnet\":false,\"keypoololdest\":1504118047,\"keypoolsize\":101,\"paytxfee\":0.00000000,\"relayfee\":0.00000100,\"errors\":\"\"},\"error\":null,\"id\":null}\n"
//2017-08-30 17:51:33 Error: Cannot find the Zcash network parameters in the following directory:
//"/home/pbca/.zcash-params"
//Please run 'zcash-fetch-params' or './zcutil/fetch-params.sh' and then restart.
//EXCEPTION: St13runtime_error
//Assertion failed.
//2017-08-30 17:51:14 Using config file /home/pbca/.iguana/test/komodo.conf
//2017-08-30 18:23:43 UpdateTip: new best=0a47c1323f393650f7221c217d19d149d002d35444f47fde61be2dd90fbde8e6 height=1 log2_work=5.0874628 tx=2 date=2016-09-13 19:04:01 progress=0.000001 cache=0.0MiB(1tx)
//2017-08-30 18:23:43 UpdateTip: new best=05076a4e1fc9af0f5fda690257b17ae20c12d4796dfba1624804d012c9ec00be height=2 log2_work=5.6724253 tx=3 date=2016-09-13 19:05:28 progress=0.000001 cache=0.0MiB(2tx)
/*shepherd.execFile(`${shepherd.komododBin}`, _arg, {
maxBuffer: 1024 * 10000 // 10 mb
}, function(error, stdout, stderr) {
shepherd.writeLog(`stdout: ${stdout}`);
shepherd.writeLog(`stderr: ${stderr}`);
if (error !== null) {
console.log(`exec error: ${error}`);
shepherd.writeLog(`exec error: ${error}`);
if (error.toString().indexOf('using -reindex') > -1) {
shepherd.io.emit('service', {
komodod: {
error: 'run -reindex',
}
});
}
}
});*/
}
});
}
// komodod datadir location test
shepherd.testLocation = (path) => {
return new shepherd.Promise((resolve, reject) => {
if (path.indexOf(' ') > -1) {
shepherd.log(`error testing path ${path}`);
resolve(-1);
} else {
shepherd.fs.lstat(path, (err, stats) => {
if (err) {
shepherd.log(`error testing path ${path}`);
resolve(-1);
} else {
if (stats.isDirectory()) {
resolve(true);
} else {
shepherd.log(`error testing path ${path} not a folder`);
resolve(false);
}
}
});
}
});
}
return shepherd;
};

9
routes/shepherd/coindWalletKeys.js

@ -4,6 +4,7 @@ module.exports = (shepherd) => {
*
*/
shepherd.get('/coindwalletkeys', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const wif = require('wif');
const fs = require('fs');
const chain = req.query.chain;
@ -93,6 +94,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

9
routes/shepherd/coins.js

@ -4,6 +4,7 @@ module.exports = (shepherd) => {
*
*/
shepherd.get('/InstantDEX/allcoins', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
let successObj;
let nativeCoindList = [];
let electrumCoinsList = [];
@ -25,6 +26,14 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

18
routes/shepherd/coinsList.js

@ -4,6 +4,7 @@ module.exports = (shepherd) => {
*
*/
shepherd.get('/coinslist', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
if (shepherd.fs.existsSync(`${shepherd.agamaDir}/shepherd/coinslist.json`)) {
shepherd.fs.readFile(`${shepherd.agamaDir}/shepherd/coinslist.json`, 'utf8', (err, data) => {
if (err) {
@ -28,6 +29,14 @@ module.exports = (shepherd) => {
result: 'coin list doesn\'t exist',
};
res.end(JSON.stringify(errorObj));
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
@ -37,6 +46,7 @@ module.exports = (shepherd) => {
* params: payload
*/
shepherd.post('/coinslist', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
const _payload = req.body.payload;
if (!_payload) {
@ -65,6 +75,14 @@ module.exports = (shepherd) => {
}
});
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

27
routes/shepherd/config.js

@ -105,6 +105,7 @@ module.exports = (shepherd) => {
* params: payload
*/
shepherd.post('/appconf', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
if (!req.body.payload) {
const errorObj = {
msg: 'error',
@ -122,6 +123,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
/*
@ -129,6 +138,7 @@ module.exports = (shepherd) => {
* params: none
*/
shepherd.post('/appconf/reset', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
shepherd.saveLocalAppConf(shepherd.defaultAppConfig);
const successObj = {
@ -137,6 +147,14 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
/*
@ -144,8 +162,17 @@ module.exports = (shepherd) => {
*
*/
shepherd.get('/appconf', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const obj = shepherd.loadLocalConfig();
res.send(obj);
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

27
routes/shepherd/daemonControl.js

@ -792,6 +792,7 @@ module.exports = (shepherd) => {
* params: herd
*/
shepherd.post('/herd', (req, res) => {
if (shepherd.checkToken(req.body.token)) {
const _body = req.body;
shepherd.log('herd req.body =>');
shepherd.log(_body);
@ -874,12 +875,21 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(obj));
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
/*
* type: POST
*/
shepherd.post('/setconf', (req, res) => {
if (shepherd.checkToken(req.body.token)) {
const _body = req.body;
shepherd.log('setconf req.body =>');
@ -898,12 +908,21 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(obj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
/*
* type: POST
*/
shepherd.post('/getconf', (req, res) => {
if (shepherd.checkToken(req.body.token)) {
const _body = req.body;
shepherd.log('getconf req.body =>');
@ -920,6 +939,14 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(obj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.setConfKMD = (isChips) => {

12
routes/shepherd/dashboardUpdate.js

@ -7,7 +7,9 @@ module.exports = (shepherd) => {
* params: coin
*/
shepherd.post('/native/dashboard/update', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
const _coin = req.body.coin;
const _token = req.body.token;
let _returnObj;
let _promiseStack;
@ -245,6 +247,7 @@ module.exports = (shepherd) => {
cmd: cmd,
params: params,
rpc2cli: req.body.rpc2cli,
token: _token,
};
} else {
_payload = {
@ -252,6 +255,7 @@ module.exports = (shepherd) => {
chain: coin,
cmd: cmd,
rpc2cli: req.body.rpc2cli,
token: _token,
};
}
@ -308,6 +312,14 @@ module.exports = (shepherd) => {
.then(result => {
getAddressesNative(_coin);
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

18
routes/shepherd/debugLog.js

@ -4,6 +4,7 @@ module.exports = (shepherd) => {
* params: herd, lastLines
*/
shepherd.post('/debuglog', (req, res) => {
if (shepherd.checkToken(req.body.token)) {
let _herd = req.body.herdname;
let _ac = req.body.ac;
let _lastNLines = req.body.lastLines;
@ -50,9 +51,18 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(_obj));
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.get('/coind/stdout', (req, res) => {
if (shepherd.checkToken(req.query.token)) {
const _daemonName = req.query.chain !== 'komodod' ? req.query.chain : 'komodod';
const _daemonLogName = `${shepherd.agamaDir}/${_daemonName}.log`;
@ -72,6 +82,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(_obj));
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.readDebugLog = (fileLocation, lastNLines) => {

18
routes/shepherd/downloadBins.js

@ -46,6 +46,7 @@ module.exports = (shepherd) => {
*/
// TODO: promises
shepherd.get('/update/bins/check', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const rootLocation = shepherd.path.join(__dirname, '../../');
const successObj = {
msg: 'success',
@ -92,6 +93,14 @@ module.exports = (shepherd) => {
}
});
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
/*
@ -100,6 +109,7 @@ module.exports = (shepherd) => {
* params:
*/
shepherd.get('/update/bins', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const rootLocation = shepherd.path.join(__dirname, '../../');
const _os = shepherd.os.platform();
const successObj = {
@ -159,6 +169,14 @@ module.exports = (shepherd) => {
}
});
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

27
routes/shepherd/downloadPatch.js

@ -5,6 +5,7 @@ module.exports = (shepherd) => {
* params: patchList
*/
shepherd.get('/update/patch', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const successObj = {
msg: 'success',
result: 'dl started'
@ -13,6 +14,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
shepherd.updateAgama();
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.updateAgama = () => {
@ -85,6 +94,7 @@ module.exports = (shepherd) => {
* params:
*/
shepherd.get('/update/patch/check', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const rootLocation = shepherd.path.join(__dirname, '../../');
const options = {
url: 'https://github.com/pbca26/dl-test/raw/master/version',
@ -130,6 +140,14 @@ module.exports = (shepherd) => {
});
}
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
/*
@ -138,6 +156,7 @@ module.exports = (shepherd) => {
* params:
*/
shepherd.get('/unpack', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const dlLocation = shepherd.path.join(__dirname, '../../');
const zip = new shepherd.AdmZip(`${dlLocation}patch.zip`);
zip.extractAllTo(/*target path*/ `${dlLocation}/patch/unpack`, /*overwrite*/true);
@ -148,6 +167,14 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

9
routes/shepherd/downloadZcparams.js

@ -67,6 +67,7 @@ module.exports = (shepherd) => {
* params:
*/
shepherd.get('/zcparamsdl', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
// const dlLocation = shepherd.zcashParamsDir + '/test';
const dlLocation = shepherd.zcashParamsDir;
const dlOption = req.query.dloption;
@ -128,6 +129,14 @@ module.exports = (shepherd) => {
}
});
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

27
routes/shepherd/electrum/auth.js

@ -4,6 +4,7 @@ const bitcoin = require('bitcoinjs-lib');
module.exports = (shepherd) => {
shepherd.post('/electrum/login', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
let _wifError = false;
for (let key in shepherd.electrumCoins) {
@ -50,9 +51,18 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.post('/electrum/lock', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
shepherd.electrumCoins.auth = false;
shepherd.electrumKeys = {};
@ -62,9 +72,18 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.post('/electrum/logout', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
shepherd.electrumCoins = {
auth: false,
};
@ -76,6 +95,14 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(obj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

9
routes/shepherd/electrum/balance.js

@ -1,5 +1,6 @@
module.exports = (shepherd) => {
shepherd.get('/electrum/getbalance', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const network = req.query.network || shepherd.findNetworkObj(req.query.coin);
const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[network].port, shepherd.electrumServers[network].address, shepherd.electrumServers[network].proto); // tcp or tls
@ -140,6 +141,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
}
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

18
routes/shepherd/electrum/block.js

@ -1,5 +1,6 @@
module.exports = (shepherd) => {
shepherd.get('/electrum/getblockinfo', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
shepherd.electrumGetBlockInfo(req.query.height, req.query.network)
.then((json) => {
const successObj = {
@ -9,6 +10,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.electrumGetBlockInfo = (height, network) => {
@ -28,6 +37,7 @@ module.exports = (shepherd) => {
}
shepherd.get('/electrum/getcurrentblock', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
shepherd.electrumGetCurrentBlock(req.query.network)
.then((json) => {
const successObj = {
@ -37,6 +47,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.electrumGetCurrentBlock = (network) => {

39
routes/shepherd/electrum/coins.js

@ -61,7 +61,6 @@ module.exports = (shepherd) => {
priv: _keys.priv,
pub: _keys.pub,
};
console.log(shepherd.electrumKeys[coin]);
}
return true;
@ -69,7 +68,28 @@ module.exports = (shepherd) => {
}
}
shepherd.get('/electrum/coin/changepub', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
shepherd.electrumKeys[req.query.coin].pub = req.query.pub;
const successObj = {
msg: 'success',
result: 'true',
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.get('/electrum/coins/add', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const result = shepherd.addElectrumCoin(req.query.coin);
const successObj = {
@ -78,9 +98,18 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.get('/electrum/coins', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
let _electrumCoins = JSON.parse(JSON.stringify(shepherd.electrumCoins)); // deep cloning
for (let key in _electrumCoins) {
@ -95,6 +124,14 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

27
routes/shepherd/electrum/createtx.js

@ -9,14 +9,14 @@ module.exports = (shepherd) => {
// TODO: finish unsigned for zcash, btc forks and pos coins
if (network === 'btg') {
shepherd.log('enable btg');
shepherd.log('enable btg', true);
tx = new bitcoinJSForks.TransactionBuilder(shepherd.getNetworkData(network));
tx.enableBitcoinGold(true);
} else {
tx = new shepherd.bitcoinJS.TransactionBuilder(shepherd.getNetworkData(network));
}
shepherd.log('buildSignedTx');
shepherd.log('buildSignedTx', true);
// console.log(`buildSignedTx priv key ${wif}`);
shepherd.log(`buildSignedTx pub key ${changeAddress}`, true);
// console.log('buildSignedTx std tx fee ' + shepherd.electrumServers[network].txfee);
@ -66,7 +66,7 @@ module.exports = (shepherd) => {
tx = new shepherd.bitcoinJS.TransactionBuilder(shepherd.getNetworkData(network));
}
shepherd.log('buildSignedTx');
shepherd.log('buildSignedTx', true);
// console.log(`buildSignedTx priv key ${wif}`);
shepherd.log(`buildSignedTx pub key ${key.getAddress().toString()}`, true);
// console.log('buildSignedTx std tx fee ' + shepherd.electrumServers[network].txfee);
@ -132,7 +132,7 @@ module.exports = (shepherd) => {
const pk = bitcoinJSForks.crypto.hash160(keyPair.getPublicKeyBuffer());
const spk = bitcoinJSForks.script.pubKeyHash.output.encode(pk);
shepherd.log(`buildSignedTx${network.toUpperCase()}`);
shepherd.log(`buildSignedTx${network.toUpperCase()}`, true);
for (let i = 0; i < utxo.length; i++) {
tx.addInput(utxo[i].txid, utxo[i].vout, bitcoinJSForks.Transaction.DEFAULT_SEQUENCE, spk);
@ -188,6 +188,7 @@ module.exports = (shepherd) => {
}
shepherd.get('/electrum/createrawtx', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
// TODO: unconf output(s) error message
const network = req.query.network || shepherd.findNetworkObj(req.query.coin);
const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[network].port, shepherd.electrumServers[network].address, shepherd.electrumServers[network].proto); // tcp or tls
@ -208,6 +209,7 @@ module.exports = (shepherd) => {
shepherd.listunspent(ecl, changeAddress, network, true, true)
.then((utxoList) => {
ecl.close();
console.log(utxoList);
if (utxoList &&
utxoList.length &&
@ -586,9 +588,18 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
}
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.get('/electrum/pushtx', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const rawtx = req.query.rawtx;
const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[req.query.network].port, shepherd.electrumServers[req.query.network].address, shepherd.electrumServers[req.query.network].proto); // tcp or tls
@ -606,6 +617,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

9
routes/shepherd/electrum/estimate.js

@ -1,5 +1,6 @@
module.exports = (shepherd) => {
shepherd.get('/electrum/estimatefee', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[req.query.network].port, shepherd.electrumServers[req.query.network].address, shepherd.electrumServers[req.query.network].proto); // tcp or tls
ecl.connect();
@ -15,6 +16,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.estimateTxSize = (numVins, numOuts) => {

37
routes/shepherd/electrum/keys.js

@ -10,7 +10,6 @@ const bs58check = require('bs58check');
module.exports = (shepherd) => {
shepherd.wifToWif = (wif, network) => {
network = network === 'KMD' ? 'komodo' : network.toLowerCase();
console.log(shepherd.getNetworkData(network));
const key = shepherd.isZcash(network) ? new bitcoinZcash.ECPair.fromWIF(wif, shepherd.getNetworkData(network), true) : new bitcoin.ECPair.fromWIF(wif, shepherd.getNetworkData(network), true);
return {
@ -51,6 +50,7 @@ module.exports = (shepherd) => {
}
shepherd.get('/electrum/wiftopub', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
let key = shepherd.isZcash(req.query.coin.toLowerCase()) ? bitcoinZcash.ECPair.fromWIF(req.query.wif, shepherd.electrumJSNetworks[req.query.coin], true) : bitcoin.ECPair.fromWIF(req.query.wif, shepherd.electrumJSNetworks[req.query.coin], true);
keys = {
priv: key.toWIF(),
@ -65,9 +65,18 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.get('/electrum/seedtowif', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
let keys = shepherd.seedToWif(req.query.seed, req.query.network, req.query.iguana);
const successObj = {
@ -78,9 +87,18 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.post('/electrum/keys', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
let _matchingKeyPairs = 0;
let _totalKeys = 0;
let _electrumKeys = {};
@ -138,6 +156,14 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.getSpvFees = () => {
@ -153,6 +179,7 @@ module.exports = (shepherd) => {
};
shepherd.post('/electrum/seed/bip39/match', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
const seed = bip39.mnemonicToSeed(req.body.seed);
const hdMaster = bitcoin.HDNode.fromSeedBuffer(seed, shepherd.electrumJSNetworks.komodo); // seed from above
const matchPattern = req.body.match;
@ -182,6 +209,14 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

9
routes/shepherd/electrum/listunspent.js

@ -155,6 +155,7 @@ module.exports = (shepherd) => {
}
shepherd.get('/electrum/listunspent', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const network = req.query.network || shepherd.findNetworkObj(req.query.coin);
const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[network].port, shepherd.electrumServers[network].address, shepherd.electrumServers[network].proto); // tcp or tls
@ -190,6 +191,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
});
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

9
routes/shepherd/electrum/merkle.js

@ -128,6 +128,7 @@ module.exports = (shepherd) => {
}
shepherd.get('/electrum/merkle/verify', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
shepherd.verifyMerkleByCoin(req.query.coin, req.query.txid, req.query.height)
.then((verifyMerkleRes) => {
const successObj = {
@ -139,6 +140,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

29
routes/shepherd/electrum/network.js

@ -92,6 +92,7 @@ module.exports = (shepherd) => {
}
shepherd.get('/electrum/servers', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
if (req.query.abbr) {
let _electrumServers = {};
@ -117,9 +118,18 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.get('/electrum/coins/server/set', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
shepherd.electrumCoins[req.query.coin].server = {
ip: req.query.address,
port: req.query.port,
@ -133,7 +143,7 @@ module.exports = (shepherd) => {
}
}
shepherd.log(JSON.stringify(shepherd.electrumCoins[req.query.coin], null, '\t'), true);
// shepherd.log(JSON.stringify(shepherd.electrumCoins[req.query.coin], null, '\t'), true);
const successObj = {
msg: 'success',
@ -141,9 +151,18 @@ module.exports = (shepherd) => {
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.get('/electrum/servers/test', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const ecl = new shepherd.electrumJSCore(req.query.port, req.query.address, 'tcp'); // tcp or tls
ecl.connect();
@ -171,6 +190,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
}
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

28
routes/shepherd/electrum/transactions.js

@ -14,6 +14,7 @@ module.exports = (shepherd) => {
}
shepherd.get('/electrum/listtransactions', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const network = req.query.network || shepherd.findNetworkObj(req.query.coin);
const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[network].port, shepherd.electrumServers[network].address, shepherd.electrumServers[network].proto); // tcp or tls
@ -205,9 +206,18 @@ module.exports = (shepherd) => {
}
});
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.get('/electrum/gettransaction', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const network = req.query.network || shepherd.findNetworkObj(req.query.coin);
const ecl = new shepherd.electrumJSCore(shepherd.electrumServers[network].port, shepherd.electrumServers[network].address, shepherd.electrumServers[network].proto); // tcp or tls
@ -226,6 +236,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.parseTransactionAddresses = (tx, targetAddress, network) => {
@ -346,9 +364,9 @@ module.exports = (shepherd) => {
}
shepherd.get('/electrum/decoderawtx', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const _network = shepherd.getNetworkData(req.query.network);
const _rawtx = req.query.rawtx;
console.log(_network);
//const _rawtx = '010000006f2c395a02d81487fc7f9d1be3ea900316730133c044af70cd76d21e988e71de0e9e85918f010000006a47304402202097acd391e1d0eaaf91844bd596e918fb71320e3e0c51554acb71a39e4ee98b0220548fd61d4ae77a08d70b01bf5340983a1ba63f6b71ad71d478af77011f96fd510121031ffc010d8abc4180b4c1a13962bf9153a78082e7f2ac18f7d14cb6a6634ca218feffffff2b31f6c9a7916f7cf128cae94b3fc10e4c74ca3a740e1a7a6fd6624e4e9a5c8b010000006a473044022063f014c5fbaa7614732e0ae486179a854215fc32c02230e13f69b7e81fa000e50220236a2ba6373b1854aafc59c5391ab7505062067f3d293c016cbb5d252b35a56a012102f307f17d282fc0eabf99227c2e0f3122ae9ecd7da0de099f0c6007d4c941b57bfeffffff021b797ad7120000001976a914c7a7142d743b3e6eebe76923f43bae477d3ce31a88acff086d66000000001976a91463800ff36b9c52b2ffe5564af1c2a38df4f0126788ac16381d00';
const decodedTx = shepherd.electrumJSTxDecoder(_rawtx, req.query.network, _network);
@ -395,6 +413,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
});
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

9
routes/shepherd/kickstart.js

@ -7,6 +7,7 @@ module.exports = (shepherd) => {
* params: coin, type
*/
shepherd.get('/kick', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const _coin = req.query.coin;
const _keepWallet = req.query.keepwallet;
@ -39,6 +40,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(successObj));
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

27
routes/shepherd/log.js

@ -40,12 +40,21 @@ module.exports = (shepherd) => {
}
shepherd.get('/log/runtime', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const successObj = {
msg: 'success',
result: req.query.spv && req.query.spv === 'true' ? shepherd.appRuntimeSPVLog : shepherd.appRuntimeLog,
};
res.end(JSON.stringify(successObj));
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.getAppRuntimeLog = () => {
@ -59,6 +68,7 @@ module.exports = (shepherd) => {
* params: payload
*/
shepherd.post('/guilog', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
const logLocation = `${shepherd.agamaDir}/shepherd`;
if (!shepherd.guiLog[shepherd.appSessionHash]) {
@ -90,6 +100,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(returnObj));
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
/*
@ -97,6 +115,7 @@ module.exports = (shepherd) => {
* params: type
*/
shepherd.get('/getlog', (req, res, next) => {
if (shepherd.checkToken(req.query.token)) {
const logExt = req.query.type === 'txt' ? 'txt' : 'json';
if (shepherd.fs.existsSync(`${shepherd.agamaDir}/shepherd/agamalog.${logExt}`)) {
@ -123,6 +142,14 @@ module.exports = (shepherd) => {
result: `agama.${logExt} doesnt exist`,
};
res.end(JSON.stringify(errorObj));
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});

35
routes/shepherd/pin.js

@ -7,6 +7,7 @@ module.exports = (shepherd) => {
* params: none
*/
shepherd.post('/encryptkey', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
if (req.body.key &&
req.body.string &&
req.body.pubkey) {
@ -34,15 +35,15 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(returnObj));
});
} else {
let errorObj = {
msg: 'error',
result: '',
};
const _paramsList = [
'key',
'string',
'pubkey'
];
let errorObj = {
msg: 'error',
result: '',
};
let _errorParamsList = [];
for (let i = 0; i < _paramsList.length; i++) {
@ -52,11 +53,20 @@ module.exports = (shepherd) => {
}
errorObj.result = `missing param ${_errorParamsList.join(', ')}`;
res.end(JSON.stringify(errorObj));
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.post('/decryptkey', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
if (req.body.key &&
req.body.pubkey) {
if (fs.existsSync(`${shepherd.agamaDir}/shepherd/pin/${req.body.pubkey}.pin`)) {
@ -104,11 +114,20 @@ module.exports = (shepherd) => {
result: 'missing key or pubkey param',
};
res.end(JSON.stringify(errorObj));
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.get('/getpinlist', (req, res, next) => {
if (shepherd.checkToken(req.body.token)) {
if (fs.existsSync(`${shepherd.agamaDir}/shepherd/pin`)) {
fs.readdir(`${shepherd.agamaDir}/shepherd/pin`, (err, items) => {
let _pins = [];
@ -141,6 +160,14 @@ module.exports = (shepherd) => {
result: 'pin folder doesnt exist',
};
res.end(JSON.stringify(errorObj));
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});

18
routes/shepherd/quitDaemon.js

@ -82,6 +82,7 @@ module.exports = (shepherd) => {
}
shepherd.post('/coind/stop', (req, res) => {
if (shepherd.checkToken(req.body.token)) {
const _chain = req.body.chain;
let _coindQuitCmd = shepherd.komodocliBin;
let _arg = [];
@ -135,9 +136,18 @@ module.exports = (shepherd) => {
}
}
});
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
shepherd.post('/coins/remove', (req, res) => {
if (shepherd.checkToken(req.body.token)) {
const _chain = req.body.chain;
if (req.body.mode === 'native') {
@ -164,6 +174,14 @@ module.exports = (shepherd) => {
res.end(JSON.stringify(obj));
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

9
routes/shepherd/rpc.js

@ -60,6 +60,7 @@ module.exports = (shepherd) => {
* params: payload
*/
shepherd.post('/cli', (req, res, next) => {
if (shepherd.checkToken(req.body.payload.token)) {
if (!req.body.payload) {
const errorObj = {
msg: 'error',
@ -325,6 +326,14 @@ module.exports = (shepherd) => {
});
}
}
} else {
const errorObj = {
msg: 'error',
result: 'unauthorized access',
};
res.end(JSON.stringify(errorObj));
}
});
return shepherd;

Loading…
Cancel
Save