Skip to content

Commit

Permalink
feat(arbitration): implement arbitrator subcourts
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Mar 27, 2018
1 parent 04abfc3 commit 53b6263
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 9 deletions.
102 changes: 102 additions & 0 deletions contracts/standard/arbitration/ArbitratorCourt.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
pragma solidity ^0.4.15;

import "./Arbitrator.sol";

/**
* @title ArbitratorCourt
* @author Enrique Piqueras - <epiquerass@gmail.com>
* @notice An Arbitrator court in a tree of courts.
*/
contract ArbitratorCourt is Arbitrator {
/* Structs */

struct Court {
string name;
address _address;
}

/* Events */

/**
* @notice Called whenever the `parent` court changes for off-chain handling.
* @param _prevParentName The previous `parent`'s name.
* @param _prevParentAddress The previous `parent`'s address.
* @param _nextParentName The next `parent`'s name.
* @param _nextParentAddress The next `parent`'s address.
*/
event OnParentChange(string _prevParentName, address _prevParentAddress, string _nextParentName, address _nextParentAddress);

/**
* @notice Called whenever a sub court is added.
* @param _subCourtIndex The subcourt's index in this court.
* @param _subCourtName The subcourt's name.
* @param _subCourtAddress The subcourt's address.
*/
event OnSubCourtAdd(uint256 _subCourtIndex, string _subCourtName, address _subCourtAddress);

/**
* @notice Called whenever a sub court is removed.
* @param _subCourtIndex The subcourt's index in this court.
* @param _subCourtName The subcourt's name.
* @param _subCourtAddress The subcourt's address.
*/
event OnSubCourtRemove(uint256 _subCourtIndex, string _subCourtName, address _subCourtAddress);

/* Storage */

// Owner metadata
address public owner = msg.sender;

// Courts
Court parent; // Appeal to this arbitrator if it is set, otherwise reject appeal and finalize decision.
Court[] subCourts;

/* Modifiers */

/**
* @dev Makes a function only callable by the owner of this contract.
*/
modifier onlyOwner {
require(owner == msg.sender);
_;
}

/* External */

/**
* @notice Sets the `parent` court.
* @param _nextParentName The next `parent`'s name.
* @param _nextParentAddress The next `parent`'s address.
*/
function setParent(string _nextParentName, address _nextParentAddress) external onlyOwner {
// Emit event before overwriting `parent`
emit OnParentChange(parent.name, parent._address, _nextParentName, _nextParentAddress);

// Overwrite `parent`
parent = Court({ name: _nextParentName, _address: _nextParentAddress });
}

/**
* @notice Adds a new sub court.
* @param _subCourtName The subcourt's name.
* @param _subCourtAddress The subcourt's address.
*/
function addSubCourt(string _subCourtName, address _subCourtAddress) external onlyOwner {
uint256 _index = subCourts.push(Court({ name: _subCourtName, _address: _subCourtAddress })) - 1;
emit OnSubCourtAdd(_index, _subCourtName, _subCourtAddress);
}

/**
* @notice Removes a sub court.
* @param _subCourtIndex The subcourt's index.
*/
function removeSubCourt(uint256 _subCourtIndex) external onlyOwner {
require(_subCourtIndex >= 0 && _subCourtIndex < subCourts.length);

emit OnSubCourtRemove(_subCourtIndex, subCourts[_subCourtIndex].name, subCourts[_subCourtIndex]._address);

// Remove from subCourts array
for (uint256 i = _subCourtIndex; i < subCourts.length; i++) subCourts[i] = subCourts[i + 1];
subCourts.length--;
}
}
18 changes: 11 additions & 7 deletions contracts/standard/proxy/ArbitratorVersioningProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ import "./VersioningProxy.sol";
* @author Enrique Piqueras - <epiquerass@gmail.com>
* @notice An Arbitrator proxy that only exposes methods in the Arbitrator spec.
*/
contract ArbitratorVersioningProxy is Arbitrator, VersioningProxy {
contract ArbitratorVersioningProxy is Arbitrator, VersioningProxy {
/* Structs */

struct Dispute {
address arbitrator;
uint256 disputeID;
uint256 choices;
}
struct Dispute {
address arbitrator;
uint256 disputeID;
uint256 choices;
}

/* Storage */

Dispute[] public disputes;
Dispute[] public disputes;

/* Modifiers */

/**
* @dev Makes a function only callable if the dispute exists.
* @param _disputeID The ID of the dispute.
*/
modifier onlyIfDisputeExists(uint256 _disputeID) {
require(disputes[_disputeID].arbitrator != address(0));
_;
Expand Down
2 changes: 1 addition & 1 deletion contracts/standard/proxy/ExperimentalProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.4.15;
* @author Enrique Piqueras - <epiquerass@gmail.com>
* @notice An experimental base proxy contract that forwards all calls to the 'implementation' contract and optionally keeps all storage.
*/
contract ExperimentalProxy {
contract ExperimentalProxy {
/* Storage */

bool public storageIsEternal;
Expand Down
2 changes: 1 addition & 1 deletion contracts/standard/proxy/Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.4.15;
* @author Enrique Piqueras - <epiquerass@gmail.com>
* @notice A base proxy contract.
*/
contract Proxy {
contract Proxy {
/* Storage */

address public implementation;
Expand Down

0 comments on commit 53b6263

Please sign in to comment.