Browse Source

rpc/cli config switch

pkg_automation_electrum
pbca26 7 years ago
parent
commit
d31ce569b1
  1. 6
      routes/appConfig.js
  2. 2
      routes/shepherd/dashboardUpdate.js
  3. 116
      routes/shepherd/rpc.js
  4. 4
      version
  5. 2
      version_build

6
routes/appConfig.js

@ -18,6 +18,7 @@ const appConfig = {
failedRPCAttemptsThreshold: 10,
stopNativeDaemonsOnQuit: true,
lang: 'EN',
rpc2cli: false,
},
schema: {
host: {
@ -115,6 +116,11 @@ const appConfig = {
{ name: 'DE', label: 'German' }
],
},
rpc2cli: {
display: true,
displayName: 'Use CLI instead of RPC JSON server',
type: 'boolean',
},
},
};

2
routes/shepherd/dashboardUpdate.js

@ -244,12 +244,14 @@ module.exports = (shepherd) => {
chain: coin,
cmd: cmd,
params: params,
rpc2cli: req.body.rpc2cli,
};
} else {
_payload = {
mode: null,
chain: coin,
cmd: cmd,
rpc2cli: req.body.rpc2cli,
};
}

116
routes/shepherd/rpc.js

@ -77,7 +77,7 @@ 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;
const _params = req.body.payload.params ? ` ${req.body.payload.params}` : '';
let _params = req.body.payload.params ? ` ${req.body.payload.params}` : '';
let _cmd = req.body.payload.cmd;
if (!shepherd.rpcConf[_chain]) {
@ -85,6 +85,119 @@ module.exports = (shepherd) => {
}
if (_mode === 'default') {
if (req.body.payload.rpc2cli) {
let _coindCliBin = shepherd.komodocliBin;
if (shepherd.nativeCoindList &&
_chain &&
shepherd.nativeCoindList[_chain.toLowerCase()]) {
_coindCliBin = `${shepherd.coindRootDir}/${_chain.toLowerCase()}/${shepherd.nativeCoindList[_chain.toLowerCase()].bin.toLowerCase()}-cli`;
}
console.log(`cmd ${_cmd}`);
if (_params.indexOf('*')) {
_params = _params.replace('*', '"*"');
}
if (_params.indexOf(',') > -1) {
_params = _params.split(',');
}
if (_cmd.indexOf('getaddressesbyaccount') > -1) {
_cmd = 'getaddressesbyaccount ""';
}
console.log(typeof _params);
let _arg = (_chain ? ' -ac_name=' + _chain : '') + ' ' + _cmd + (typeof _params === 'object' ? _params.join(' ') : _params);
console.log(_arg);
if (shepherd.appConfig.dataDir.length) {
_arg = `${_arg} -datadir=${shepherd.appConfig.dataDir + (_chain ? '/' + key : '')}`;
}
/*_arg = _arg.trim().split(' ');
for (let i = 0; i < _arg.length; i++) {
if (_arg[i].indexOf('getaddressesbyaccount') > -1) {
_arg[i] = 'getaddressesbyaccount ""';
}
}*/
shepherd.exec(`"${_coindCliBin}" ${_arg}`, (error, stdout, stderr) => {
shepherd.log(`stdout: ${stdout}`);
shepherd.log(`stderr: ${stderr}`);
if (error !== null) {
shepherd.log(`exec error: ${error}`);
}
let responseObj;
/*error code: -5
error message:
Invalid Komodo address*/
if (stderr) {
let _res;
let _error;
if ((stderr.indexOf('{') > -1 && stderr.indexOf('}') > -1) ||
(stderr.indexOf('[') > -1 && stderr.indexOf(']') > -1)) {
_res = JSON.parse(stderr);
} else {
_res = stderr.trim();
}
if (stderr.indexOf('error code:') > -1) {
_error = {
code: stderr.substring(stderr.indexOf('error code:') + 11, stderr.indexOf('error message:') - stderr.indexOf('error code:')).trim(),
message: stderr.substring(stderr.indexOf('error message:') + 15, stderr.length).trim(),
};
}
if (_error) {
responseObj = {
error: _error,
};
} else {
responseObj = {
result: _res,
};
}
} else {
let _res;
let _error;
if ((stdout.indexOf('{') > -1 && stdout.indexOf('}') > -1) ||
(stdout.indexOf('[') > -1 && stdout.indexOf(']') > -1)) {
_res = JSON.parse(stdout);
} else {
_res = stdout.trim();
}
if (stdout.indexOf('error code:') > -1) {
_error = {
code: stdout.substring(stdout.indexOf('error code:') + 11, stdout.indexOf('error message:') - stdout.indexOf('error code:')).trim(),
message: stdout.substring(stdout.indexOf('error message:') + 15, stdout.length).trim(),
};
}
if (_error) {
responseObj = {
error: _error,
};
} else {
responseObj = {
result: _res,
};
}
}
res.end(JSON.stringify(responseObj));
shepherd.killRogueProcess('komodo-cli');
});
} else {
if (_cmd === 'debug' &&
_chain !== 'CHIPS') {
if (shepherd.nativeCoindList[_chain.toLowerCase()]) {
@ -172,6 +285,7 @@ module.exports = (shepherd) => {
});
}
}
}
} else {
let _coindCliBin = shepherd.komodocliBin;

4
version

@ -1,3 +1,3 @@
version=0.2.0.25j
type=j-beta
version=0.2.0.26a
type=a-beta
minversion=0.2.0.2

2
version_build

@ -1 +1 @@
0.2.0.25j-beta
0.2.0.26a-beta
Loading…
Cancel
Save