Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/contracts/abstractions/Arbitrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,29 @@ class Arbitrator extends AbstractContract {
// update user profile for each dispute
await Promise.all(
myDisputes.map(async dispute => {
const disputeCreationLog = await this._contractImplementation.getDisputeCreationEvent(
dispute.disputeId
)

if (!disputeCreationLog)
throw new Error('Could not fetch dispute creation event log')
// update profile for account
await this._StoreProvider.updateDisputeProfile(
account,
dispute.arbitratorAddress,
dispute.disputeId,
{
appealDraws: dispute.appealDraws
appealDraws: dispute.appealDraws,
blockNumber: disputeCreationLog.blockNumber
}
)
})
)

this._StoreProvider.updateUserProfile(account, {
session: currentSession
})
// FIXME do we want to store session?
// this._StoreProvider.updateUserProfile(account, {
// session: currentSession
// })
}

return _getDisputesForUserFromStore(account)
Expand Down
26 changes: 15 additions & 11 deletions src/contracts/implementations/arbitrator/KlerosPOC.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,13 @@ class KlerosPOC extends ContractImplementation {
disputeId,
draws
)

const lastRuling = (await this.contractInstance.getLastSessionVote(
disputeId,
account
)).toNumber()
const currentSession = await this.getSession(this.contractAddress)

const currentSession = await this.getSession(this.contractAddress)
return validDraws && lastRuling !== currentSession
}

Expand Down Expand Up @@ -631,18 +632,19 @@ class KlerosPOC extends ContractImplementation {

/**
* Get the event log for the dispute creation.
* @param {number} startBlock - The block number that the dispute was created.
* @param {number} blockNumber - The block number that the dispute was created.
* @param {number} numberOfAppeals - the number of appeals we need to fetch events for.
* @returns {number[]} an array of timestamps
*/
getAppealCreationTimestamps = async (startBlock, numberOfAppeals) => {
getAppealCreationTimestamps = async (blockNumber, numberOfAppeals) => {
const eventLogs = await this._getNewPeriodEventLogs(
startBlock,
blockNumber,
arbitratorConstants.PERIOD.VOTE,
numberOfAppeals + 1
)

const eventLogTimestamps = [startBlock]
const creationTimestamp = await this._getTimestampForBlock(blockNumber)
const eventLogTimestamps = [creationTimestamp * 1000]

// skip first execute phase as this is the original ruling
for (let i = 1; i < eventLogs.length; i++) {
Expand All @@ -662,16 +664,18 @@ class KlerosPOC extends ContractImplementation {
* @returns {object} dispute creation event log.
*/
getDisputeCreationEvent = async disputeId => {
const eventLogs = await EventListener.getNextEventLogs(
const eventLogs = await EventListener.getEventLogs(
this,
'DisputeCreation',
0
0,
'latest',
{ _disputeId: disputeId }
)

for (let i = 0; i < eventLogs.length; i++) {
const log = eventLogs[i]

if (log.args.disputeID.toNumber() === disputeId) return log
if (log.args._disputeID.toNumber() === disputeId) return log
}

return null
Expand All @@ -684,7 +688,7 @@ class KlerosPOC extends ContractImplementation {
* @returns {number} The net total PNK
*/
getNetTokensForDispute = async (disputeId, account) => {
const eventLogs = await EventListener.getNextEventLogs(
const eventLogs = await EventListener.getEventLogs(
this,
'TokenShift',
0,
Expand All @@ -695,7 +699,7 @@ class KlerosPOC extends ContractImplementation {
let netPNK = 0
for (let i = 0; i < eventLogs.length; i++) {
const event = eventLogs[i]
if (event.args.disputeID.toNumber() === disputeId)
if (event.args._disputeID.toNumber() === disputeId)
netPNK += event.args._amount.toNumber()
}

Expand All @@ -718,7 +722,7 @@ class KlerosPOC extends ContractImplementation {
* @returns {object[]} an array of event logs.
*/
_getNewPeriodEventLogs = async (blockNumber, periodNumber, appeals = 0) => {
const logs = await EventListener.getNextEventLogs(
const logs = await EventListener.getEventLogs(
this,
'NewPeriod',
blockNumber
Expand Down
Loading