Skip to content
Permalink
Browse files

feat(disputes): change approach to getting netPNK and votesCounter

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 366340f8e70d5863ca06ae1a5a461493be396e09
Showing with 27 additions and 23 deletions.
  1. +13 −11 src/abstractWrappers/Disputes.js
  2. +12 −12 src/contractWrappers/KlerosWrapper.js
  3. +2 −0 src/test/kleros.test.js
@@ -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
@@ -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
})
}
}
@@ -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(),
@@ -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)
@@ -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)
@@ -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)

0 comments on commit 366340f

Please sign in to comment.
You can’t perform that action at this time.