diff --git a/lib/blockchain/common.js b/lib/blockchain/common.js index 4f76ac3e..1c91bf57 100644 --- a/lib/blockchain/common.js +++ b/lib/blockchain/common.js @@ -76,33 +76,28 @@ function es (cmd) { return res.toString() } +function generateSupervisorConfig (cryptoCode, command, isWallet = false) { + return `[program:${cryptoCode}${isWallet ? `-wallet` : ``}] +command=nice ${command} +autostart=true +autorestart=true +stderr_logfile=/var/log/supervisor/${cryptoCode}${isWallet ? `-wallet` : ``}.err.log +stdout_logfile=/var/log/supervisor/${cryptoCode}${isWallet ? `-wallet` : ``}.out.log +environment=HOME="/root" +` +} + function writeSupervisorConfig (coinRec, cmd, walletCmd = '') { if (isInstalledSoftware(coinRec)) return const blockchain = coinRec.code if (!_.isNil(coinRec.wallet)) { - const supervisorConfigWallet = `[program:${blockchain}-wallet] -command=nice ${walletCmd} -autostart=true -autorestart=true -stderr_logfile=/var/log/supervisor/${blockchain}-wallet.err.log -stdout_logfile=/var/log/supervisor/${blockchain}-wallet.out.log -environment=HOME="/root" -` - + const supervisorConfigWallet = generateSupervisorConfig(blockchain, walletCmd, true) writeFile(`/etc/supervisor/conf.d/${coinRec.code}-wallet.conf`, supervisorConfigWallet) } - const supervisorConfig = `[program:${blockchain}] -command=nice ${cmd} -autostart=true -autorestart=true -stderr_logfile=/var/log/supervisor/${blockchain}.err.log -stdout_logfile=/var/log/supervisor/${blockchain}.out.log -environment=HOME="/root" -` - + const supervisorConfig = generateSupervisorConfig(blockchain, cmd) writeFile(`/etc/supervisor/conf.d/${coinRec.code}.conf`, supervisorConfig) } @@ -125,7 +120,7 @@ function fetchAndInstall (coinRec) { const binDir = requiresUpdate ? binaries.defaultDir : binaries.dir es(`wget -q ${url}`) - coinRec.cryptoCode === 'XMR' + es(`echo ${downloadFile} | awk -F. '{print $NF}'`) === 'bz2' ? es(`tar -xf ${downloadFile}`) : es(`tar -xzf ${downloadFile}`) diff --git a/lib/plugins/wallet/monerod/monerod.js b/lib/plugins/wallet/monerod/monerod.js index bf54f1cf..0a766f8d 100644 --- a/lib/plugins/wallet/monerod/monerod.js +++ b/lib/plugins/wallet/monerod/monerod.js @@ -14,16 +14,22 @@ const cryptoRec = utils.getCryptoCurrency('XMR') const configPath = utils.configPath(cryptoRec, blockchainUtils.blockchainDir()) const walletDir = path.resolve(utils.cryptoDir(cryptoRec, blockchainUtils.blockchainDir()), 'wallets') const unitScale = cryptoRec.unitScale -const config = jsonRpc.parseConf(configPath) -const rpcConfig = { - username: config['rpc-login'].split(':')[0], - password: config['rpc-login'].split(':')[1], - port: cryptoRec.walletPort || cryptoRec.defaultPort +function rpcConfig () { + try { + const config = jsonRpc.parseConf(configPath) + return { + username: config['rpc-login'].split(':')[0], + password: config['rpc-login'].split(':')[1], + port: cryptoRec.walletPort || cryptoRec.defaultPort + } + } catch (err) { + throw new Error('wallet is currently not installed') + } } function fetch (method, params) { - return jsonRpc.fetchDigest(rpcConfig, method, params) + return jsonRpc.fetchDigest(rpcConfig(), method, params) } function handleError (error) { @@ -55,11 +61,11 @@ function handleError (error) { } function openWallet () { - return fetch('open_wallet', { filename: 'Wallet', password: rpcConfig.password }) + return fetch('open_wallet', { filename: 'Wallet', password: rpcConfig().password }) } function createWallet () { - return fetch('create_wallet', { filename: 'Wallet', password: rpcConfig.password, language: 'English' }) + return fetch('create_wallet', { filename: 'Wallet', password: rpcConfig().password, language: 'English' }) .then(() => new Promise(() => setTimeout(() => openWallet(), 3000))) .then(() => fetch('auto_refresh')) } @@ -173,7 +179,7 @@ function newFunding (account, cryptoCode) { function cryptoNetwork (account, cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => { - switch(parseInt(rpcConfig.port, 10)) { + switch(parseInt(rpcConfig().port, 10)) { case 18083: return 'main' case 28083: