diff --git a/packages/api/src/controllers/ValidatorsController.js b/packages/api/src/controllers/ValidatorsController.js index 4e6ddf955..fe19b9054 100644 --- a/packages/api/src/controllers/ValidatorsController.js +++ b/packages/api/src/controllers/ValidatorsController.js @@ -47,7 +47,10 @@ class ValidatorsController { ) const validatorsWithInfo = await Promise.all( - validators.resultSet.map(async (validator) => ({ ...validator, proTxInfo: await DashCoreRPC.getProTxInfo(validator.proTxHash) }))) + validators.resultSet.map(async (validator) => ({ + ...validator, + proTxInfo: await DashCoreRPC.getProTxInfo(validator.proTxHash) + }))) return response.send({ ...validators, diff --git a/packages/api/src/dashcoreRpc.js b/packages/api/src/dashcoreRpc.js index 9c3f90ed5..89ee4a701 100644 --- a/packages/api/src/dashcoreRpc.js +++ b/packages/api/src/dashcoreRpc.js @@ -12,15 +12,37 @@ const config = { const rpc = new RpcClient(config) class DashCoreRPC { - static async getProTxInfo (proTxHash) { + static async getRawTransaction (proTxHash) { try { - const { result } = await rpc.protx('info', proTxHash) + const { result } = await rpc.getRawTransaction(proTxHash, 1) + return result } catch (e) { console.error(e) throw new ServiceNotAvailableError() } } + + static async getProTxInfo (proTxHash, blockHash = undefined) { + try { + const args = ['info', proTxHash] + if (blockHash) args.push(blockHash) + + const { result } = await rpc.protx(...args) + + return result + } catch (e) { + if (e.code === -8) { + const { blockhash } = await this.getRawTransaction(proTxHash) + const result = await this.getProTxInfo(proTxHash, blockhash) + + return result + } + + console.error(e) + throw new ServiceNotAvailableError() + } + } } module.exports = DashCoreRPC