Skip to content

Commit 4085a66

Browse files
committed
fix: make views compatible with v2
don't merge
1 parent 0593720 commit 4085a66

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-8
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"solidity.compileUsingRemoteVersion": "v0.5.17+commit.d19bba13"
3+
}

contracts/view/GeneralizedTCRView.sol

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,32 @@ pragma solidity 0.5.17;
1010
pragma experimental ABIEncoderV2;
1111

1212
import { GeneralizedTCR, IArbitrator } from "../GeneralizedTCR.sol";
13-
import { BytesLib } from "solidity-bytes-utils/contracts/BytesLib.sol";
14-
import { RLPReader } from "solidity-rlp/contracts/RLPReader.sol";
13+
import { BytesLib } from "https://github.com/GNSPS/solidity-bytes-utils/blob/fa2792ea2ad6f868987d2e21f7aab867174fca3f/contracts/BytesLib.sol";
14+
import { RLPReader } from "https://github.com/hamdiallam/Solidity-RLP/blob/2e987867285e43a3643b456e3495351dd97aaf31/contracts/RLPReader.sol";
1515

1616
/* solium-disable max-len */
1717
/* solium-disable security/no-block-members */
1818
/* solium-disable security/no-send */ // It is the user responsibility to accept ETH.
1919

20+
// hack for v2 compatibility
21+
interface IArbitratorV2 {
22+
enum Period {
23+
evidence, // Evidence can be submitted. This is also when drawing has to take place.
24+
commit, // Jurors commit a hashed vote. This is skipped for courts without hidden votes.
25+
vote, // Jurors reveal/cast their vote depending on whether the court has hidden votes or not.
26+
appeal, // The dispute can be appealed.
27+
execution // Tokens are redistributed and the ruling is executed.
28+
}
29+
30+
function disputes(uint256 _disputeID) external view returns(uint96, address, uint8, bool);
31+
/**
32+
* @dev Compute the cost of appeal. It is recommended not to increase it often, as it can be higly time and gas consuming for the arbitrated contracts to cope with fee augmentation.
33+
* @param _disputeID ID of the dispute to be appealed.
34+
* @return cost Amount to be paid.
35+
*/
36+
function appealCost(uint256 _disputeID) external view returns (uint256 cost);
37+
}
38+
2039
/**
2140
* @title GeneralizedTCRView
2241
* A view contract to fetch, batch, parse and return GTCR contract data efficiently.
@@ -122,11 +141,16 @@ contract GeneralizedTCRView {
122141
disputeStatus: IArbitrator.DisputeStatus.Waiting,
123142
numberOfRequests: round.request.item.numberOfRequests
124143
});
125-
if (round.request.disputed && round.request.arbitrator.disputeStatus(result.disputeID) == IArbitrator.DisputeStatus.Appealable) {
144+
(,, uint8 period,) = IArbitratorV2(address(round.request.arbitrator)).disputes(result.disputeID);
145+
if (
146+
round.request.disputed &&
147+
disputeStatus(period) == IArbitrator.DisputeStatus.Appealable
148+
) {
126149
result.currentRuling = GeneralizedTCR.Party(round.request.arbitrator.currentRuling(result.disputeID));
127-
result.disputeStatus = round.request.arbitrator.disputeStatus(result.disputeID);
150+
result.disputeStatus = disputeStatus(period);
128151
(result.appealStart, result.appealEnd) = round.request.arbitrator.appealPeriod(result.disputeID);
129-
result.appealCost = round.request.arbitrator.appealCost(result.disputeID, result.arbitratorExtraData);
152+
result.appealCost =
153+
IArbitratorV2(address(round.request.arbitrator)).appealCost(result.disputeID);
130154
}
131155
}
132156

@@ -590,4 +614,11 @@ contract GeneralizedTCRView {
590614
feeRewards
591615
);
592616
}
617+
618+
// hack for v2 compatibility
619+
function disputeStatus(uint8 _period) public view returns(IArbitrator.DisputeStatus status) {
620+
if (_period < uint8(IArbitratorV2.Period.appeal)) status = IArbitrator.DisputeStatus.Waiting;
621+
else if (_period < uint8(IArbitratorV2.Period.execution)) status = IArbitrator.DisputeStatus.Appealable;
622+
else status = IArbitrator.DisputeStatus.Solved;
623+
}
593624
}

contracts/view/LightGeneralizedTCRView.sol

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ import {LightGeneralizedTCR, IArbitrator} from "../LightGeneralizedTCR.sol";
1616
/* solium-disable security/no-send */
1717
// It is the user responsibility to accept ETH.
1818

19+
// hack for v2 compatibility
20+
interface IArbitratorV2 {
21+
enum Period {
22+
evidence, // Evidence can be submitted. This is also when drawing has to take place.
23+
commit, // Jurors commit a hashed vote. This is skipped for courts without hidden votes.
24+
vote, // Jurors reveal/cast their vote depending on whether the court has hidden votes or not.
25+
appeal, // The dispute can be appealed.
26+
execution // Tokens are redistributed and the ruling is executed.
27+
}
28+
29+
function disputes(uint256 _disputeID) external view returns(uint96, address, uint8, bool);
30+
/**
31+
* @dev Compute the cost of appeal. It is recommended not to increase it often, as it can be higly time and gas consuming for the arbitrated contracts to cope with fee augmentation.
32+
* @param _disputeID ID of the dispute to be appealed.
33+
* @return cost Amount to be paid.
34+
*/
35+
function appealCost(uint256 _disputeID) external view returns (uint256 cost);
36+
}
37+
1938
/**
2039
* @title LightGeneralizedTCRView
2140
* A view contract to fetch, batch, parse and return GTCR contract data efficiently.
@@ -115,14 +134,16 @@ contract LightGeneralizedTCRView {
115134
disputeStatus: IArbitrator.DisputeStatus.Waiting,
116135
numberOfRequests: round.request.item.numberOfRequests
117136
});
137+
(,, uint8 period,) = IArbitratorV2(address(round.request.arbitrator)).disputes(result.disputeID);
118138
if (
119139
round.request.disputed &&
120-
round.request.arbitrator.disputeStatus(result.disputeID) == IArbitrator.DisputeStatus.Appealable
140+
disputeStatus(period) == IArbitrator.DisputeStatus.Appealable
121141
) {
122142
result.currentRuling = LightGeneralizedTCR.Party(round.request.arbitrator.currentRuling(result.disputeID));
123-
result.disputeStatus = round.request.arbitrator.disputeStatus(result.disputeID);
143+
result.disputeStatus = disputeStatus(period);
124144
(result.appealStart, result.appealEnd) = round.request.arbitrator.appealPeriod(result.disputeID);
125-
result.appealCost = round.request.arbitrator.appealCost(result.disputeID, result.arbitratorExtraData);
145+
result.appealCost =
146+
IArbitratorV2(address(round.request.arbitrator)).appealCost(result.disputeID);
126147
}
127148
}
128149

@@ -334,4 +355,11 @@ contract LightGeneralizedTCRView {
334355
round = RoundData(request, false, [0, sumDeposit, 0], [false, true, false], sumDeposit);
335356
}
336357
}
358+
359+
// hack for v2 compatibility
360+
function disputeStatus(uint8 _period) public view returns(IArbitrator.DisputeStatus status) {
361+
if (_period < uint8(IArbitratorV2.Period.appeal)) status = IArbitrator.DisputeStatus.Waiting;
362+
else if (_period < uint8(IArbitratorV2.Period.execution)) status = IArbitrator.DisputeStatus.Appealable;
363+
else status = IArbitrator.DisputeStatus.Solved;
364+
}
337365
}

0 commit comments

Comments
 (0)