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

Commit

Permalink
feat(disputes): fetch session and period inside getDataForDispute and…
Browse files Browse the repository at this point in the history
… change var names
  • Loading branch information
epiqueras authored and satello committed Mar 15, 2018
1 parent 7e7f68f commit 9c08d20
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 50 deletions.
18 changes: 4 additions & 14 deletions CHANGELOG.md
Expand Up @@ -3,63 +3,53 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="0.0.67"></a>
## [0.0.67](https://github.com/kleros/kleros-api/compare/v0.0.65...v0.0.67) (2018-03-07)

## [0.0.67](https://github.com/kleros/kleros-api/compare/v0.0.65...v0.0.67) (2018-03-07)

### Bug Fixes

* **disputes:** fix bug in determining canRule ([49e2fc2](https://github.com/kleros/kleros-api/commit/49e2fc2))
* check session of jurors last vote ([bf4fde5](https://github.com/kleros/kleros-api/commit/bf4fde5))
* fix test on develop ([8f361c8](https://github.com/kleros/kleros-api/commit/8f361c8))



<a name="0.0.66"></a>
## [0.0.66](https://github.com/kleros/kleros-api/compare/v0.0.65...v0.0.66) (2018-03-07)

## [0.0.66](https://github.com/kleros/kleros-api/compare/v0.0.65...v0.0.66) (2018-03-07)

### Bug Fixes

* fix test on develop ([8f361c8](https://github.com/kleros/kleros-api/commit/8f361c8))
* **disputes:** fix bug in determining canRule ([6628fb7](https://github.com/kleros/kleros-api/commit/6628fb7))



<a name="0.0.65"></a>
## [0.0.65](https://github.com/kleros/kleros-api/compare/v0.0.62...v0.0.65) (2018-03-05)

## [0.0.65](https://github.com/kleros/kleros-api/compare/v0.0.62...v0.0.65) (2018-03-05)

### Bug Fixes

* **kleros-wrapper:** use correct index for juror.atStake ([143bbc0](https://github.com/kleros/kleros-api/commit/143bbc0)), closes [#63](https://github.com/kleros/kleros-api/issues/63)
* **notifications:** make sure appeal possible notifications unique ([30ea202](https://github.com/kleros/kleros-api/commit/30ea202))


### Features

* **disputes:** all functions working with new structure ([66541a6](https://github.com/kleros/kleros-api/commit/66541a6))
* **disputes:** DRY out fetch open disputes for session and add deadline event handler ([77b21ce](https://github.com/kleros/kleros-api/commit/77b21ce))
* **disputes:** skeleton for new dispute data ([0b99b55](https://github.com/kleros/kleros-api/commit/0b99b55))



<a name="0.0.64"></a>
## [0.0.64](https://github.com/kleros/kleros-api/compare/v0.0.62...v0.0.64) (2018-03-05)

## [0.0.64](https://github.com/kleros/kleros-api/compare/v0.0.62...v0.0.64) (2018-03-05)

### Bug Fixes

* **notifications:** make sure appeal possible notifications unique ([b7c55e6](https://github.com/kleros/kleros-api/commit/b7c55e6))


### Features

* **disputes:** all functions working with new structure ([66541a6](https://github.com/kleros/kleros-api/commit/66541a6))
* **disputes:** DRY out fetch open disputes for session and add deadline event handler ([77b21ce](https://github.com/kleros/kleros-api/commit/77b21ce))
* **disputes:** skeleton for new dispute data ([0b99b55](https://github.com/kleros/kleros-api/commit/0b99b55))



<a name="0.0.63"></a>

## [0.0.63](https://github.com/kleros/kleros-api/compare/v0.0.62...v0.0.63) (2018-03-05)
Expand Down
13 changes: 4 additions & 9 deletions package.json
@@ -1,12 +1,9 @@
{
"name": "kleros-api",
"version": "0.0.67",
"description": "A Javascript library that makes it easy to build relayers and other DApps that use the Kleros protocol.",
"keywords": [
"Blockchain",
"Ethereum",
"Kleros"
],
"description":
"A Javascript library that makes it easy to build relayers and other DApps that use the Kleros protocol.",
"keywords": ["Blockchain", "Ethereum", "Kleros"],
"homepage": "https://kleros.io",
"repository": "github:kleros/kleros-api",
"bugs": "https://github.com/kleros/kleros-api/issues",
Expand All @@ -32,9 +29,7 @@
"build": "webpack --env.NODE_ENV=production -p"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
"extends": ["@commitlint/config-conventional"]
},
"devDependencies": {
"babel-core": "^6.26.0",
Expand Down
47 changes: 20 additions & 27 deletions src/abstractWrappers/Disputes.js
Expand Up @@ -30,7 +30,7 @@ class Disputes extends AbstractWrapper {
contractAddress = arbitratorAddress,
address = account
) => {
const disputeId = event.args._disputeID.toNumber()
const disputeId = event.args._disputeId.toNumber()
const disputeData = await this.getDataForDispute(
contractAddress,
disputeId,
Expand Down Expand Up @@ -74,7 +74,7 @@ class Disputes extends AbstractWrapper {
contractAddress = arbitratorAddress,
address = defaultAccount
) => {
const disputeId = event.args._disputeID.toNumber()
const disputeId = event.args._disputeId.toNumber()
const account = event.args._account
const amountShift = event.args._amount.toNumber()
// juror won/lost tokens
Expand Down Expand Up @@ -332,8 +332,7 @@ class Disputes extends AbstractWrapper {
this.getDataForDispute(
dispute.arbitratorAddress,
dispute.disputeId,
account,
arbitratorData
account
)
)
)
Expand Down Expand Up @@ -652,29 +651,23 @@ class Disputes extends AbstractWrapper {
/**
* Get data for a dispute.
* @param {string} arbitratorAddress - The arbitrator contract's address.
* @param {number} disputeID - The dispute's ID.
* @param {number} disputeId - The dispute's ID.
* @param {string} account - The juror's address.
* @param {object} [arbitratorData={}] - Optional arbitrator data for computing `canRepartition`.
* @returns {object} - Data object for the dispute that uses data from the contract and the store.
* TODO: Should we return what we have in the store even if dispute is not in the contract?
*/
getDataForDispute = async (
arbitratorAddress,
disputeID,
account,
{ session, period } = {}
) => {
getDataForDispute = async (arbitratorAddress, disputeId, account) => {
this._checkArbitratorWrappersSet()
this._checkArbitrableWrappersSet()

// Get dispute data from contract, and throw if not found. Also get current session and period
const dispute = await this._Arbitrator.getDispute(
arbitratorAddress,
disputeID
)
const [dispute, arbitratorData] = Promise.all([
this._Arbitrator.getDispute(arbitratorAddress, disputeId),
this._Arbitrator.getData(arbitratorAddress, account)
])
if (!dispute) {
throw new Error(
`Dispute with arbitrator: ${arbitratorAddress} and disputeId: ${disputeID} does not exist`
`Dispute with arbitrator: ${arbitratorAddress} and disputeId: ${disputeId} does not exist`
)
}

Expand All @@ -698,7 +691,7 @@ class Disputes extends AbstractWrapper {
try {
const userData = await this._StoreProvider.getDisputeData(
arbitratorAddress,
disputeID,
disputeId,
account
)
if (userData.appealDraws) appealDraws = userData.appealDraws
Expand All @@ -724,36 +717,36 @@ class Disputes extends AbstractWrapper {
let canRepartition = false
let canExecute = false
let ruling
const promises = [
const rulingPromises = [
this._Arbitrator.currentRulingForDispute(
arbitratorAddress,
disputeID,
disputeId,
appeal
)
]

// Extra info for the last appeal
if (isLastAppeal) {
if (draws.length > 0)
promises.push(
rulingPromises.push(
this._Arbitrator.canRuleDispute(
arbitratorAddress,
disputeID,
disputeId,
draws,
account
)
)

if (session && period)
if (arbitratorData.session && arbitratorData.period)
canRepartition =
lastSession <= session && // Not appealed to the next session
period === arbitratorConstants.PERIOD.EXECUTE && // Executable period
lastSession <= arbitratorData.session && // Not appealed to the next session
arbitratorData.period === arbitratorConstants.PERIOD.EXECUTE && // Executable period
dispute.state === disputeConstants.STATE.OPEN // Open dispute
canExecute = dispute.state === disputeConstants.STATE.EXECUTABLE // Executable state
}

// Wait for parallel requests to complete
;[ruling, canRule] = await Promise.all(promises)
;[ruling, canRule] = await Promise.all(rulingPromises)

appealJuror[appeal] = {
createdAt: appealCreatedAt[appeal],
Expand All @@ -780,7 +773,7 @@ class Disputes extends AbstractWrapper {
partyB: arbitrableContractData.partyB,

// Dispute Data
disputeID,
disputeId,
firstSession: dispute.firstSession,
lastSession,
numberOfAppeals: dispute.numberOfAppeals,
Expand Down

0 comments on commit 9c08d20

Please sign in to comment.