refactor: error handling on unconfigred wallet
This commit is contained in:
parent
e5846a92e0
commit
7f49684b67
5 changed files with 24 additions and 60 deletions
|
|
@ -3,8 +3,9 @@ const axios = require('axios')
|
||||||
const uuid = require('uuid')
|
const uuid = require('uuid')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
|
const coinUtils = require('../../coin-utils')
|
||||||
|
|
||||||
module.exports = {fetch, parseConf}
|
module.exports = { fetch, parseConf, rpcConfig }
|
||||||
|
|
||||||
function fetch (account = {}, method, params) {
|
function fetch (account = {}, method, params) {
|
||||||
params = _.defaultTo([], params)
|
params = _.defaultTo([], params)
|
||||||
|
|
@ -63,3 +64,17 @@ function parseConf (confPath) {
|
||||||
|
|
||||||
return res
|
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')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,24 +6,11 @@ const E = require('../../../error')
|
||||||
const coinUtils = require('../../../coin-utils')
|
const coinUtils = require('../../../coin-utils')
|
||||||
|
|
||||||
const cryptoRec = coinUtils.getCryptoCurrency('BTC')
|
const cryptoRec = coinUtils.getCryptoCurrency('BTC')
|
||||||
const configPath = coinUtils.configPath(cryptoRec)
|
|
||||||
const unitScale = cryptoRec.unitScale
|
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) {
|
function fetch (method, params) {
|
||||||
return jsonRpc.fetch(rpcConfig(), method, params)
|
return jsonRpc.fetch(rpcConfig, method, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCryptoCode (cryptoCode) {
|
function checkCryptoCode (cryptoCode) {
|
||||||
|
|
|
||||||
|
|
@ -7,24 +7,11 @@ const BN = require('../../../bn')
|
||||||
const E = require('../../../error')
|
const E = require('../../../error')
|
||||||
|
|
||||||
const cryptoRec = coinUtils.getCryptoCurrency('DASH')
|
const cryptoRec = coinUtils.getCryptoCurrency('DASH')
|
||||||
const configPath = coinUtils.configPath(cryptoRec)
|
|
||||||
const unitScale = cryptoRec.unitScale
|
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) {
|
function fetch (method, params) {
|
||||||
return jsonRpc.fetch(rpcConfig(), method, params)
|
return jsonRpc.fetch(rpcConfig, method, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCryptoCode (cryptoCode) {
|
function checkCryptoCode (cryptoCode) {
|
||||||
|
|
|
||||||
|
|
@ -7,23 +7,11 @@ const BN = require('../../../bn')
|
||||||
const E = require('../../../error')
|
const E = require('../../../error')
|
||||||
|
|
||||||
const cryptoRec = coinUtils.getCryptoCurrency('LTC')
|
const cryptoRec = coinUtils.getCryptoCurrency('LTC')
|
||||||
const configPath = coinUtils.configPath(cryptoRec)
|
|
||||||
const unitScale = cryptoRec.unitScale
|
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) {
|
function fetch (method, params) {
|
||||||
return jsonRpc.fetch(rpcConfig(), method, params)
|
return jsonRpc.fetch(rpcConfig, method, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCryptoCode (cryptoCode) {
|
function checkCryptoCode (cryptoCode) {
|
||||||
|
|
|
||||||
|
|
@ -8,24 +8,11 @@ const BN = require('../../../bn')
|
||||||
const E = require('../../../error')
|
const E = require('../../../error')
|
||||||
|
|
||||||
const cryptoRec = coinUtils.getCryptoCurrency('ZEC')
|
const cryptoRec = coinUtils.getCryptoCurrency('ZEC')
|
||||||
const configPath = coinUtils.configPath(cryptoRec)
|
|
||||||
const unitScale = cryptoRec.unitScale
|
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) {
|
function fetch (method, params) {
|
||||||
return jsonRpc.fetch(rpcConfig(), method, params)
|
return jsonRpc.fetch(rpcConfig, method, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCryptoCode (cryptoCode) {
|
function checkCryptoCode (cryptoCode) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue