From ba48e678e9c22ec64bd507503e489184af5d7140 Mon Sep 17 00:00:00 2001 From: epiqueras Date: Wed, 14 Feb 2018 23:22:10 -0800 Subject: [PATCH] feat(disputes): build voteCounters and PNKRepartitions from getters --- src/abstractWrappers/Disputes.js | 2 +- src/contractWrappers/KlerosWrapper.js | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/abstractWrappers/Disputes.js b/src/abstractWrappers/Disputes.js index 96a87ee..29faf48 100644 --- a/src/abstractWrappers/Disputes.js +++ b/src/abstractWrappers/Disputes.js @@ -559,7 +559,7 @@ class Disputes extends AbstractWrapper { disputeState: dispute.state, disputeStatus: dispute.status, voteCounters: dispute.voteCounters, - appealsRepartitioned: dispute.appealsRepartitioned, + PNKRepartitions: dispute.PNKRepartitions, // Store Data description: constractStoreData ? constractStoreData.description : undefined, diff --git a/src/contractWrappers/KlerosWrapper.js b/src/contractWrappers/KlerosWrapper.js index 90c2457..e0029e4 100644 --- a/src/contractWrappers/KlerosWrapper.js +++ b/src/contractWrappers/KlerosWrapper.js @@ -374,16 +374,33 @@ class KlerosWrapper extends ContractWrapper { const contractInstance = await this.load(contractAddress) try { const dispute = await contractInstance.disputes(disputeId) + + const numberOfAppeals = dispute[2].toNumber() + const rulingChoices = dispute[3].toNumber() + + const voteCounters = [] + const PNKRepartitions = [] + for (let appeal = 0; appeal <= numberOfAppeals; appeal++) { + const counter = [] + const repartition = [] + for (let choice = 0; choice <= rulingChoices; choice++) { + counter.push(contractInstance.getVoteCount(disputeId, appeal, choice)) + repartition.push(contractInstance.repartitionedPNK(disputeId, appeal, choice)) + } + voteCounters.push(counter) + PNKRepartitions.push(repartition) + } + return { arbitratedContract: dispute[0], firstSession: dispute[1].toNumber(), - numberOfAppeals: dispute[2].toNumber(), - rulingChoices: dispute[3].toNumber(), + numberOfAppeals, + rulingChoices, initialNumberJurors: dispute[4].toNumber(), arbitrationFeePerJuror: this._Web3Wrapper.fromWei(dispute[5], 'ether'), state: dispute[6].toNumber(), - voteCounters: dispute[8], - appealsRepartitioned: dispute[11], + voteCounters, + PNKRepartitions, status: (await contractInstance.disputeStatus(disputeId)).toNumber() } } catch (e) {