feat: blockchain status checking no longer dependent on plugin status
This commit is contained in:
parent
3c33695b9d
commit
f23f31e4d9
4 changed files with 23 additions and 27 deletions
|
|
@ -118,32 +118,24 @@ function plugin (crypto) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBlockchainSyncStatus (cryptoList) {
|
function getBlockchainSyncStatus (cryptoList) {
|
||||||
const installedCryptos = _.reduce((acc, value) => ({ ...acc, [value.cryptoCode]: isInstalledSoftware(value) && isInstalledVolume(value) }), {}, cryptoList)
|
|
||||||
|
|
||||||
return settingsLoader.loadLatest()
|
return settingsLoader.loadLatest()
|
||||||
.then(settings => {
|
.then(settings => {
|
||||||
const installedButNotConfigured = []
|
|
||||||
const blockchainStatuses = _.reduce((acc, value) => {
|
const blockchainStatuses = _.reduce((acc, value) => {
|
||||||
const processStatus = common.es(`sudo supervisorctl status ${value.code} | awk '{ print $2 }'`).trim()
|
const processStatus = common.es(`sudo supervisorctl status ${value.code} | awk '{ print $2 }'`).trim()
|
||||||
return acc.then(a => {
|
return acc.then(a => {
|
||||||
return wallet.checkBlockchainStatus(settings, value.cryptoCode)
|
if (processStatus === 'RUNNING') {
|
||||||
.then(res => _.includes(value.cryptoCode, _.keys(installedCryptos)) ? Promise.resolve({ ...a, [value.cryptoCode]: res }) : Promise.resolve({ ...a }))
|
return wallet.checkBlockchainStatus(settings, value.cryptoCode)
|
||||||
.catch(() => {
|
.then(res => Promise.resolve({ ...a, [value.cryptoCode]: res }))
|
||||||
if (processStatus === 'RUNNING') {
|
}
|
||||||
installedButNotConfigured.push(value.cryptoCode)
|
return Promise.resolve({ ...a })
|
||||||
return Promise.resolve({ ...a, [value.cryptoCode]: 'syncing' })
|
|
||||||
}
|
|
||||||
return Promise.resolve({ ...a })
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
Promise.resolve({}),
|
Promise.resolve({}),
|
||||||
cryptoList
|
cryptoList
|
||||||
)
|
)
|
||||||
|
|
||||||
return Promise.all([blockchainStatuses, installedButNotConfigured])
|
return blockchainStatuses
|
||||||
})
|
})
|
||||||
.then(([blockchainStatuses, installedButNotConfigured]) => ({ blockchainStatuses, installedButNotConfigured }))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function run () {
|
function run () {
|
||||||
|
|
@ -166,11 +158,7 @@ function run () {
|
||||||
const validateAnswers = async (answers) => {
|
const validateAnswers = async (answers) => {
|
||||||
if (_.size(answers) > 2) return { message: `Please insert a maximum of two coins to install.`, isValid: false }
|
if (_.size(answers) > 2) return { message: `Please insert a maximum of two coins to install.`, isValid: false }
|
||||||
return getBlockchainSyncStatus(cryptos)
|
return getBlockchainSyncStatus(cryptos)
|
||||||
.then(({ blockchainStatuses, installedButNotConfigured }) => {
|
.then(blockchainStatuses => {
|
||||||
if (!_.isEmpty(installedButNotConfigured)) {
|
|
||||||
logger.warn(`Detected ${_.join(' and ', installedButNotConfigured)} installed on this machine, but couldn't establish connection. ${_.size(installedButNotConfigured) === 1 ? `Is this plugin` : `Are these plugins`} configured via admin?`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = _.reduce((acc, value) => ({ ...acc, [value]: _.isNil(acc[value]) ? 1 : acc[value] + 1 }), {}, _.values(blockchainStatuses))
|
const result = _.reduce((acc, value) => ({ ...acc, [value]: _.isNil(acc[value]) ? 1 : acc[value] + 1 }), {}, _.values(blockchainStatuses))
|
||||||
if (_.size(answers) + result.syncing > 2) {
|
if (_.size(answers) + result.syncing > 2) {
|
||||||
return { message: `Installing these coins would pass the 2 parallel blockchain synchronization limit. Please try again with fewer coins or try again later.`, isValid: false }
|
return { message: `Installing these coins would pass the 2 parallel blockchain synchronization limit. Please try again with fewer coins or try again later.`, isValid: false }
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,7 @@ function newFunding (account, cryptoCode, settings, operatorId) {
|
||||||
|
|
||||||
function checkBlockchainStatus (cryptoCode) {
|
function checkBlockchainStatus (cryptoCode) {
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(pify(web3.eth.isSyncing))
|
.then(() => connect(`http://localhost:${coins.utils.getCryptoCurrency(cryptoCode).defaultPort}`))
|
||||||
.then(res => _.isObject(res) ? 'syncing' : 'ready')
|
.then(() => web3.eth.syncing)
|
||||||
|
.then(res => res === false ? 'ready' : 'syncing')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -202,10 +202,7 @@ function checkBlockchainStatus (cryptoCode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonRpc.fetchDigest(rpcConfig, 'get_info')
|
return jsonRpc.fetchDigest(rpcConfig, 'get_info')
|
||||||
.then(res => {
|
.then(res => !!res.synchronized ? 'ready' : 'syncing')
|
||||||
console.log('res XMR', res)
|
|
||||||
return !!res.synchronized ? 'ready' : 'syncing'
|
|
||||||
})
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error('XMR daemon is currently not installed')
|
throw new Error('XMR daemon is currently not installed')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -239,8 +239,18 @@ function supportsBatching (settings, cryptoCode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkBlockchainStatus (settings, cryptoCode) {
|
function checkBlockchainStatus (settings, cryptoCode) {
|
||||||
return fetchWallet(settings, cryptoCode)
|
const walletDaemons = {
|
||||||
.then(r => r.wallet.checkBlockchainStatus(cryptoCode))
|
BTC: require('./plugins/wallet/bitcoind/bitcoind.js'),
|
||||||
|
BCH: require('./plugins/wallet/bitcoincashd/bitcoincashd.js'),
|
||||||
|
DASH: require('./plugins/wallet/dashd/dashd.js'),
|
||||||
|
ETH: require('./plugins/wallet/geth/base.js'),
|
||||||
|
LTC: require('./plugins/wallet/litecoind/litecoind.js'),
|
||||||
|
XMR: require('./plugins/wallet/monerod/monerod.js'),
|
||||||
|
ZEC: require('./plugins/wallet/zcashd/zcashd.js')
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve(walletDaemons[cryptoCode])
|
||||||
|
.then(({ checkBlockchainStatus }) => checkBlockchainStatus(cryptoCode))
|
||||||
}
|
}
|
||||||
|
|
||||||
const coinFilter = ['ETH']
|
const coinFilter = ['ETH']
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue