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

Commit

Permalink
feat: implement appealCreatedAt
Browse files Browse the repository at this point in the history
  • Loading branch information
satello committed Jun 5, 2018
1 parent 11f77b4 commit 2517bf4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
26 changes: 26 additions & 0 deletions src/contracts/implementations/arbitrator/KlerosPOC.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,32 @@ class KlerosPOC extends ContractImplementation {
return eventLogTimestamps
}

/**
* Get the event log for the dispute creation.
* @param {Number} disputeId - The block number that the dispute was created.
* @returns {Promise}
*/
getAppealCreationTimestamps = async (startBlock, numberOfAppeals) => {
const eventLogs = await this._getNewPeriodEventLogs(
blockNumber,
arbitratorConstants.PERIOD.VOTE,
numberOfAppeals + 1
)

const eventLogTimestamps = [startBlock]

// skip first execute phase as this is the original ruling
for (let i=1; i<eventLogs.length; i++) {
const eventLog = eventLogs[i]

const timestamp = await this._getTimestampForBlock(eventLog.blockNumber)

eventLogTimestamps.push(timestamp * 1000)
}

return eventLogTimestamps
}

/**
* Get the event log for the dispute creation.
* @param {Number} disputeId - The block number that the dispute was created.
Expand Down
12 changes: 8 additions & 4 deletions src/resources/Disputes.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,9 @@ class Disputes {

// Get dispute data from the store
let appealDraws = []
let appealCreatedAt = null
let appealCreatedAt = []
let appealDeadlines = []
let appealRuledAt = []
let netPNK = 0
let startBlock
try {
const userData = await this._StoreProviderInstance.getDispute(
Expand Down Expand Up @@ -198,6 +197,10 @@ class Disputes {
startBlock,
dispute.numberOfAppeals
)
appealCreatedAt = await this._ArbitratorInstance.getAppealCreationTimestamps(
startBlock,
dispute.numberOfAppeals
)
}

const netPNK = await this._ArbitratorInstance.getNetTokensForDispute(
Expand Down Expand Up @@ -241,6 +244,7 @@ class Disputes {
;[ruling, canRule] = await Promise.all(rulingPromises)

appealJuror[appeal] = {
createdAt: appealCreatedAt[appeal],
fee: dispute.arbitrationFeePerJuror * draws.length,
draws,
canRule
Expand Down Expand Up @@ -272,8 +276,8 @@ class Disputes {
disputeStatus: dispute.status,
appealJuror,
appealRulings,
appealCreatedAt, // there is only one timestamp for when dispute was first created
netPNK
netPNK,
disputeCreatedAt,

// Store Data
title: contractStoreData ? contractStoreData.title : undefined,
Expand Down
10 changes: 10 additions & 0 deletions src/resources/Notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ class Notifications {
const notification = await this._newNotification(
account,
event.transactionHash,
event.blockNumber,
openDispute.disputeId, // use disputeId instead of logIndex since it doens't have its own event
notificationConstants.TYPE.APPEAL_POSSIBLE,
'A ruling has been made. Appeal is possible',
Expand Down Expand Up @@ -354,6 +355,7 @@ class Notifications {
const notification = await this._newNotification(
account,
txHash,
event.blockNumber,
event.logIndex,
notificationConstants.TYPE.DISPUTE_CREATED,
'New Dispute Created',
Expand Down Expand Up @@ -392,6 +394,7 @@ class Notifications {
const notification = await this._newNotification(
account,
event.transactionHash,
event.blockNumber,
event.logIndex,
notificationConstants.TYPE.APPEAL_POSSIBLE,
'A ruling has been made. Appeal is possible',
Expand Down Expand Up @@ -429,6 +432,7 @@ class Notifications {
const notification = await this._newNotification(
account,
event.transactionHash,
event.blockNumber,
event.logIndex,
notificationConstants.TYPE.RULING_APPEALED,
'A ruling been appealed',
Expand Down Expand Up @@ -460,6 +464,7 @@ class Notifications {
const notification = await this._newNotification(
account,
event.transactionHash,
event.blockNumber,
event.logIndex,
notificationConstants.TYPE.TOKEN_SHIFT,
'Tokens have been redistributed',
Expand Down Expand Up @@ -492,6 +497,7 @@ class Notifications {
const notification = await this._newNotification(
account,
event.transactionHash,
event.blockNumber,
event.logIndex,
notificationConstants.TYPE.ARBITRATION_REWARD,
'Juror awarded arbitration fee',
Expand Down Expand Up @@ -558,13 +564,17 @@ class Notifications {
_newNotification = async (
account,
txHash,
blockNumber,
logIndex,
notificationType,
message = '',
data = {},
read = false
) => {
if (this._StoreProviderInstance) {
// update last block we have processed an event for
await this._StoreProviderInstance.updateLastBlock(account, blockNumber)

const response = await this._StoreProviderInstance.newNotification(
account,
txHash,
Expand Down
6 changes: 1 addition & 5 deletions src/utils/StoreProviderWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class StoreProviderWrapper {
`${this._storeUri}/${userAddress}`
)
if (response.status !== 201)
throw new Error(errorConstants.REQUEST_FAILED(response.responseText))
throw new Error(errorConstants.REQUEST_FAILED(response))
userProfile = response.body
}

Expand Down Expand Up @@ -229,10 +229,6 @@ class StoreProviderWrapper {
`${this._storeUri}/${userAddress}/contracts/${contractAddress}`
)

if (httpResponse.status !== 201) {
throw new Error(errorConstants.REQUEST_FAILED(httpResponse.error))
}

return _.filter(
httpResponse.body[0].contracts,
contract => contract.address === contractAddress
Expand Down

0 comments on commit 2517bf4

Please sign in to comment.