fix: handle errors when wallet is unreachable

This commit is contained in:
José Oliveira 2021-02-24 19:46:43 +00:00 committed by Josh Harvey
parent 209bc1fabe
commit 145a21cc8d
2 changed files with 25 additions and 16 deletions

View file

@ -48,6 +48,7 @@ function split (str) {
}
function parseConf (confPath) {
try {
const conf = fs.readFileSync(confPath)
const lines = conf.toString().split('\n')
@ -60,6 +61,8 @@ function parseConf (confPath) {
res[keyVal[0]] = keyVal[1]
}
return res
} catch (e) {
throw new Error('wallet is currently not installed')
}
}

View file

@ -9,16 +9,22 @@ const E = require('../../../error')
const cryptoRec = coinUtils.getCryptoCurrency('ZEC')
const configPath = coinUtils.configPath(cryptoRec)
const unitScale = cryptoRec.unitScale
const config = jsonRpc.parseConf(configPath)
const rpcConfig = {
function rpcConfig () {
try {
const config = jsonRpc.parseConf(configPath)
return {
username: config.rpcuser,
password: config.rpcpassword,
port: config.rpcport || cryptoRec.defaultPort
}
} catch (err) {
throw err
}
}
function fetch (method, params) {
return jsonRpc.fetch(rpcConfig, method, params)
return jsonRpc.fetch(rpcConfig(), method, params)
}
function checkCryptoCode (cryptoCode) {