Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
feat(disputes): change approach to getting netPNK and votesCounter
Browse files Browse the repository at this point in the history
netPNK will now be fetched from the store.
votesCounter will now be fetched from the contract via contract.getVoteCount in a loop.
  • Loading branch information
epiqueras authored and satello committed Feb 16, 2018
1 parent ba48e67 commit 366340f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
24 changes: 13 additions & 11 deletions src/abstractWrappers/Disputes.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,15 +516,17 @@ class Disputes extends AbstractWrapper {
arbitrableContractAddress
)

let votes = []
let isJuror = false
let votes = []
let hasRuled = false
let netPNK = 0
if (account) {
votes = await this.getVotesForJuror(arbitratorAddress, disputeId, account)
try {
const userData = await this.getUserDisputeFromStore(arbitratorAddress, disputeId, account)
isJuror = userData.isJuror
hasRuled = userData.hasRuled
netPNK = userData.netPNK || 0
} catch (e) {
isJuror = false
hasRuled = false
Expand All @@ -544,31 +546,31 @@ class Disputes extends AbstractWrapper {
// Arbitrable Contract Data
// FIXME hash not being stored in contract atm
hash: arbitrableContractAddress,
arbitrableContractAddress: arbitrableContractAddress,
arbitrableContractAddress,
arbitrableContractStatus: arbitrableContractData.status,
arbitratorAddress: arbitratorAddress,
arbitratorAddress,
partyA: arbitrableContractData.partyA,
partyB: arbitrableContractData.partyB,

// Dispute Data
disputeId: disputeId,
disputeId,
session: dispute.firstSession + dispute.numberOfAppeals,
numberOfAppeals: dispute.numberOfAppeals,
fee: dispute.arbitrationFeePerJuror,
deadline: deadline,
deadline,
disputeState: dispute.state,
disputeStatus: dispute.status,
voteCounters: dispute.voteCounters,
PNKRepartitions: dispute.PNKRepartitions,

// Store Data
description: constractStoreData ? constractStoreData.description : undefined,
email: constractStoreData ? constractStoreData.email : undefined,
evidence: evidence,
isJuror: isJuror,
votes: votes,
hasRuled: hasRuled,
ruling: ruling,
evidence,
isJuror,
votes,
hasRuled,
ruling,
netPNK
})
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/contractWrappers/KlerosWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,23 +374,24 @@ 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 = []
let voteCounters = []
let status
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))
}
for (let choice = 0; choice <= rulingChoices; choice++)
counter.push(contractInstance.getVoteCount(disputeId, appeal, choice).then(v => v.toNumber()))
voteCounters.push(counter)
PNKRepartitions.push(repartition)
}

[voteCounters, status] = await Promise.all(
[
Promise.all(voteCounters.map(counter => Promise.all(counter))),
contractInstance.disputeStatus(disputeId)
]
)

return {
arbitratedContract: dispute[0],
firstSession: dispute[1].toNumber(),
Expand All @@ -400,8 +401,7 @@ class KlerosWrapper extends ContractWrapper {
arbitrationFeePerJuror: this._Web3Wrapper.fromWei(dispute[5], 'ether'),
state: dispute[6].toNumber(),
voteCounters,
PNKRepartitions,
status: (await contractInstance.disputeStatus(disputeId)).toNumber()
status: status.toNumber()
}
} catch (e) {
throw new Error(e)
Expand Down
2 changes: 2 additions & 0 deletions src/test/kleros.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ describe('Kleros', () => {
expect(dispute.arbitratedContract).toEqual(contractArbitrableTransactionData.address)
expect(dispute.firstSession).toEqual((await klerosPOCInstance.session()).toNumber())
expect(dispute.numberOfAppeals).toEqual(0)
expect(dispute.voteCounters).toEqual(Array(dispute.numberOfAppeals + 1).fill(Array(dispute.rulingChoices + 1).fill(0)))

// check fetch resolution options
const resolutionOptions = await KlerosInstance.disputes.getRulingOptions(klerosCourt.address, 0)
Expand Down Expand Up @@ -498,6 +499,7 @@ describe('Kleros', () => {
expect(disputesForJuror[0].deadline).toBe(1000 * (newState.lastPeriodChange + (await klerosPOCInstance.timePerPeriod(newState.period)).toNumber()))
expect(disputesForJuror[0].arbitrableContractAddress).toEqual(contractArbitrableTransactionData.address)
expect(disputesForJuror[0].votes).toEqual([1,2,3])
expect(disputesForJuror[0].netPNK).toBe(0)

// stateful notifications juror
jurorStatefullNotifications = await KlerosInstance.notifications.getStatefulNotifications(juror, true)
Expand Down

0 comments on commit 366340f

Please sign in to comment.