diff --git a/lib/plugins/common/json-rpc.js b/lib/plugins/common/json-rpc.js index 03cad38f..7bb14fae 100644 --- a/lib/plugins/common/json-rpc.js +++ b/lib/plugins/common/json-rpc.js @@ -3,8 +3,9 @@ const axios = require('axios') const uuid = require('uuid') const fs = require('fs') const _ = require('lodash/fp') +const coinUtils = require('../../coin-utils') -module.exports = {fetch, parseConf} +module.exports = { fetch, parseConf, rpcConfig } function fetch (account = {}, method, params) { params = _.defaultTo([], params) @@ -63,3 +64,17 @@ function parseConf (confPath) { return res } + +function rpcConfig (cryptoRec) { + try { + const configPath = coinUtils.configPath(cryptoRec) + const config = parseConf(configPath) + return { + username: config.rpcuser, + password: config.rpcpassword, + port: config.rpcport || cryptoRec.defaultPort + } + } catch (err) { + throw new Error('Wallet is currently not installed') + } +} diff --git a/lib/plugins/wallet/bitcoind/bitcoind.js b/lib/plugins/wallet/bitcoind/bitcoind.js index 238fcca1..d05b9d93 100644 --- a/lib/plugins/wallet/bitcoind/bitcoind.js +++ b/lib/plugins/wallet/bitcoind/bitcoind.js @@ -6,24 +6,11 @@ const E = require('../../../error') const coinUtils = require('../../../coin-utils') const cryptoRec = coinUtils.getCryptoCurrency('BTC') -const configPath = coinUtils.configPath(cryptoRec) const unitScale = cryptoRec.unitScale - -function rpcConfig () { - try { - const config = jsonRpc.parseConf(configPath) - return { - username: config.rpcuser, - password: config.rpcpassword, - port: config.rpcport || cryptoRec.defaultPort - } - } catch (err) { - throw new Error('wallet is currently not installed') - } -} +const rpcConfig = jsonRpc.rpcConfig(cryptoRec) function fetch (method, params) { - return jsonRpc.fetch(rpcConfig(), method, params) + return jsonRpc.fetch(rpcConfig, method, params) } function checkCryptoCode (cryptoCode) { diff --git a/lib/plugins/wallet/dashd/dashd.js b/lib/plugins/wallet/dashd/dashd.js index 1ef6ee66..a552e112 100644 --- a/lib/plugins/wallet/dashd/dashd.js +++ b/lib/plugins/wallet/dashd/dashd.js @@ -7,24 +7,11 @@ const BN = require('../../../bn') const E = require('../../../error') const cryptoRec = coinUtils.getCryptoCurrency('DASH') -const configPath = coinUtils.configPath(cryptoRec) const unitScale = cryptoRec.unitScale - -function rpcConfig () { - try { - const config = jsonRpc.parseConf(configPath) - return { - username: config.rpcuser, - password: config.rpcpassword, - port: config.rpcport || cryptoRec.defaultPort - } - } catch (err) { - throw new Error('wallet is currently not installed') - } -} +const rpcConfig = jsonRpc.rpcConfig(cryptoRec) function fetch (method, params) { - return jsonRpc.fetch(rpcConfig(), method, params) + return jsonRpc.fetch(rpcConfig, method, params) } function checkCryptoCode (cryptoCode) { diff --git a/lib/plugins/wallet/litecoind/litecoind.js b/lib/plugins/wallet/litecoind/litecoind.js index 5601c6e4..98f3347d 100644 --- a/lib/plugins/wallet/litecoind/litecoind.js +++ b/lib/plugins/wallet/litecoind/litecoind.js @@ -7,23 +7,11 @@ const BN = require('../../../bn') const E = require('../../../error') const cryptoRec = coinUtils.getCryptoCurrency('LTC') -const configPath = coinUtils.configPath(cryptoRec) const unitScale = cryptoRec.unitScale +const rpcConfig = jsonRpc.rpcConfig(cryptoRec) -function rpcConfig () { - try { - const config = jsonRpc.parseConf(configPath) - return { - username: config.rpcuser, - password: config.rpcpassword, - port: config.rpcport || cryptoRec.defaultPort - } - } catch (err) { - throw new Error('wallet is currently not installed') - } -} function fetch (method, params) { - return jsonRpc.fetch(rpcConfig(), method, params) + return jsonRpc.fetch(rpcConfig, method, params) } function checkCryptoCode (cryptoCode) { diff --git a/lib/plugins/wallet/zcashd/zcashd.js b/lib/plugins/wallet/zcashd/zcashd.js index 459bd5a3..95ed65aa 100644 --- a/lib/plugins/wallet/zcashd/zcashd.js +++ b/lib/plugins/wallet/zcashd/zcashd.js @@ -8,24 +8,11 @@ const BN = require('../../../bn') const E = require('../../../error') const cryptoRec = coinUtils.getCryptoCurrency('ZEC') -const configPath = coinUtils.configPath(cryptoRec) const unitScale = cryptoRec.unitScale - -function rpcConfig () { - try { - const config = jsonRpc.parseConf(configPath) - return { - username: config.rpcuser, - password: config.rpcpassword, - port: config.rpcport || cryptoRec.defaultPort - } - } catch (err) { - throw new Error('wallet is currently not installed') - } -} +const rpcConfig = jsonRpc.rpcConfig(cryptoRec) function fetch (method, params) { - return jsonRpc.fetch(rpcConfig(), method, params) + return jsonRpc.fetch(rpcConfig, method, params) } function checkCryptoCode (cryptoCode) {