feat: blockchain status checking no longer dependent on plugin status

This commit is contained in:
Sérgio Salgado 2022-02-24 20:57:12 +00:00
parent 3c33695b9d
commit f23f31e4d9
4 changed files with 23 additions and 27 deletions

View file

@ -118,32 +118,24 @@ function plugin (crypto) {
}
function getBlockchainSyncStatus (cryptoList) {
const installedCryptos = _.reduce((acc, value) => ({ ...acc, [value.cryptoCode]: isInstalledSoftware(value) && isInstalledVolume(value) }), {}, cryptoList)
return settingsLoader.loadLatest()
.then(settings => {
const installedButNotConfigured = []
const blockchainStatuses = _.reduce((acc, value) => {
const processStatus = common.es(`sudo supervisorctl status ${value.code} | awk '{ print $2 }'`).trim()
return acc.then(a => {
return wallet.checkBlockchainStatus(settings, value.cryptoCode)
.then(res => _.includes(value.cryptoCode, _.keys(installedCryptos)) ? Promise.resolve({ ...a, [value.cryptoCode]: res }) : Promise.resolve({ ...a }))
.catch(() => {
if (processStatus === 'RUNNING') {
installedButNotConfigured.push(value.cryptoCode)
return Promise.resolve({ ...a, [value.cryptoCode]: 'syncing' })
return wallet.checkBlockchainStatus(settings, value.cryptoCode)
.then(res => Promise.resolve({ ...a, [value.cryptoCode]: res }))
}
return Promise.resolve({ ...a })
})
})
},
Promise.resolve({}),
cryptoList
)
return Promise.all([blockchainStatuses, installedButNotConfigured])
return blockchainStatuses
})
.then(([blockchainStatuses, installedButNotConfigured]) => ({ blockchainStatuses, installedButNotConfigured }))
}
function run () {
@ -166,11 +158,7 @@ function run () {
const validateAnswers = async (answers) => {
if (_.size(answers) > 2) return { message: `Please insert a maximum of two coins to install.`, isValid: false }
return getBlockchainSyncStatus(cryptos)
.then(({ blockchainStatuses, installedButNotConfigured }) => {
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?`)
}
.then(blockchainStatuses => {
const result = _.reduce((acc, value) => ({ ...acc, [value]: _.isNil(acc[value]) ? 1 : acc[value] + 1 }), {}, _.values(blockchainStatuses))
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 }

View file

@ -228,6 +228,7 @@ function newFunding (account, cryptoCode, settings, operatorId) {
function checkBlockchainStatus (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(pify(web3.eth.isSyncing))
.then(res => _.isObject(res) ? 'syncing' : 'ready')
.then(() => connect(`http://localhost:${coins.utils.getCryptoCurrency(cryptoCode).defaultPort}`))
.then(() => web3.eth.syncing)
.then(res => res === false ? 'ready' : 'syncing')
}

View file

@ -202,10 +202,7 @@ function checkBlockchainStatus (cryptoCode) {
}
return jsonRpc.fetchDigest(rpcConfig, 'get_info')
.then(res => {
console.log('res XMR', res)
return !!res.synchronized ? 'ready' : 'syncing'
})
.then(res => !!res.synchronized ? 'ready' : 'syncing')
} catch (err) {
throw new Error('XMR daemon is currently not installed')
}

View file

@ -239,8 +239,18 @@ function supportsBatching (settings, cryptoCode) {
}
function checkBlockchainStatus (settings, cryptoCode) {
return fetchWallet(settings, cryptoCode)
.then(r => r.wallet.checkBlockchainStatus(cryptoCode))
const walletDaemons = {
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']