|
|
@ -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; |
|
|
|
|
|
|
|