From 9411b2ea69c6c2956c1cd417604e9687b1993c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Mon, 24 Jan 2022 15:56:43 +0000 Subject: [PATCH] fix: blockchain status --- lib/blockchain/install.js | 20 ++++++++++++++++--- .../wallet/bitcoincashd/bitcoincashd.js | 2 +- lib/plugins/wallet/bitcoind/bitcoind.js | 2 +- lib/plugins/wallet/dashd/dashd.js | 2 +- lib/plugins/wallet/litecoind/litecoind.js | 2 +- lib/plugins/wallet/monerod/monerod.js | 5 ++++- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/blockchain/install.js b/lib/blockchain/install.js index 16e2dd4e..02b60fdd 100644 --- a/lib/blockchain/install.js +++ b/lib/blockchain/install.js @@ -119,8 +119,22 @@ function getBlockchainSyncStatus (cryptoList) { return settingsLoader.loadLatest() .then(settings => { - const blockchainStatuses = _.reduce((acc, value) => - _.includes(value.cryptoCode, _.keys(installedCryptos) ? ({ ...acc, [value.cryptoCode]: wallet.checkBlockchainStatus(settings, value.cryptoCode) }) : ({ ...acc })), + const blockchainStatuses = _.reduce((acc, value) => { + const processStatus = common.es(`sudo supervisorctl status ${value.code} | awk '{ print $2 }'`).trim() + return wallet.checkBlockchainStatus(settings, value.cryptoCode) + .then(res => { + console.log('res', res) + return _.includes(value.cryptoCode, _.keys(installedCryptos) ? ({ ...acc, [value.cryptoCode]: res }) : ({ ...acc })) + }) + .catch(err => { + console.log('err', err) + if (processStatus === 'RUNNING') { + console.log(`Detected ${value.cryptoCode} installed on this machine, but couldn't establish a connection. Is this plugin configured via admin?`) + return { ...acc, [value.cryptoCode]: 'syncing' } + } + return { ...acc } + }) + }, {}, cryptoList ) @@ -154,7 +168,7 @@ function run () { validate: (a) => { return getBlockchainSyncStatus(cryptos) .then(chains => { - const result = _.reduce((acc, value) => ({ ...acc, [value]: _.isNil() ? 1 : acc[value] + 1 }), {}, _.values(chains)) + const result = _.reduce((acc, value) => ({ ...acc, [value]: _.isNil(acc[value]) ? 1 : acc[value] + 1 }), {}, _.values(chains)) return result.syncing > 0 || _.size(a) > 0 && _.size(a) <= 2 }) } diff --git a/lib/plugins/wallet/bitcoincashd/bitcoincashd.js b/lib/plugins/wallet/bitcoincashd/bitcoincashd.js index c969cc71..4bc7a0fd 100644 --- a/lib/plugins/wallet/bitcoincashd/bitcoincashd.js +++ b/lib/plugins/wallet/bitcoincashd/bitcoincashd.js @@ -126,7 +126,7 @@ function supportsBatching (cryptoCode) { function checkBlockchainStatus (cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => fetch('getblockchaininfo')) - .then(res => !!res['initialblockdownload'] ? 'ready' : 'syncing') + .then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready') } module.exports = { diff --git a/lib/plugins/wallet/bitcoind/bitcoind.js b/lib/plugins/wallet/bitcoind/bitcoind.js index f08acb46..3075a3fa 100644 --- a/lib/plugins/wallet/bitcoind/bitcoind.js +++ b/lib/plugins/wallet/bitcoind/bitcoind.js @@ -179,7 +179,7 @@ function supportsBatching (cryptoCode) { function checkBlockchainStatus (cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => fetch('getblockchaininfo')) - .then(res => !!res['initialblockdownload'] ? 'ready' : 'syncing') + .then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready') } module.exports = { diff --git a/lib/plugins/wallet/dashd/dashd.js b/lib/plugins/wallet/dashd/dashd.js index c9e6a656..b28e3d59 100644 --- a/lib/plugins/wallet/dashd/dashd.js +++ b/lib/plugins/wallet/dashd/dashd.js @@ -121,7 +121,7 @@ function supportsBatching (cryptoCode) { function checkBlockchainStatus (cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => fetch('getblockchaininfo')) - .then(res => !!res['initialblockdownload'] ? 'ready' : 'syncing') + .then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready') } module.exports = { diff --git a/lib/plugins/wallet/litecoind/litecoind.js b/lib/plugins/wallet/litecoind/litecoind.js index 452a2553..7ae5f9b2 100644 --- a/lib/plugins/wallet/litecoind/litecoind.js +++ b/lib/plugins/wallet/litecoind/litecoind.js @@ -121,7 +121,7 @@ function supportsBatching (cryptoCode) { function checkBlockchainStatus (cryptoCode) { return checkCryptoCode(cryptoCode) .then(() => fetch('getblockchaininfo')) - .then(res => !!res['initialblockdownload'] ? 'ready' : 'syncing') + .then(res => !!res['initialblockdownload'] ? 'syncing' : 'ready') } module.exports = { diff --git a/lib/plugins/wallet/monerod/monerod.js b/lib/plugins/wallet/monerod/monerod.js index 1c9f8561..37d46a77 100644 --- a/lib/plugins/wallet/monerod/monerod.js +++ b/lib/plugins/wallet/monerod/monerod.js @@ -219,7 +219,10 @@ function checkBlockchainStatus (cryptoCode) { } return jsonRpc.fetchDigest(rpcConfig, 'get_info') - .then(res => !!res.synchronized ? 'ready' : 'syncing') + .then(res => { + console.log('res XMR', res) + return !!res.synchronized ? 'ready' : 'syncing' + }) } catch (err) { throw new Error('XMR daemon is currently not installed') }