Created
August 17, 2018 14:18
-
-
Save gititGoro/18d9b16c4cf7af1a90d527203bee7564 to your computer and use it in GitHub Desktop.
a simple implementation of the Ulex dispute resolution mechanism.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//TODO: a hash of an offchain secret verdict for each judge in case proof is required that the verdict is unanimous | |
//TODO: an appeals round mechanism | |
//TODO: a contract for remedies instead of simple eth payments. | |
pragma solidity ^0.4.18; | |
contract Judges { | |
mapping(address=>bool) judges; | |
function addJudge(address judge) public { | |
judges[judge]=true; | |
} | |
function isJudge (address judge) public view returns (bool){ | |
return judges[judge]; | |
} | |
} | |
contract Party { | |
uint remedy; //set in ether | |
address judge; | |
address judgesContract; | |
function setJudgesContract(address judges) public{ | |
judgesContract = judges; | |
} | |
function pickJudge(address j) public{ | |
require(Judges(judgesContract).isJudge(j)==true); | |
judge = judge; | |
} | |
function getJudge() public view returns (address) { | |
return judge; | |
} | |
} | |
contract Court { | |
mapping (address=>bool) defendant; | |
mapping (address=>bool) plaintiff; | |
mapping (address=>mapping(address=>bool)) openCases; | |
mapping (address=>uint) remedies; | |
function openCase (address _defendant, address _plaintiff) public payable { | |
require(_plaintiff == msg.sender); | |
defendant[_defendant] = true; | |
plaintiff[_plaintiff] = true; | |
openCases[_defendant][_plaintiff] = true; | |
remedies[_plaintiff] += msg.value; | |
} | |
function setDefendantRemedy(address _plaintiff) public payable { | |
require (remedies[_plaintiff]==msg.value); | |
remedies[msg.sender] = msg.value; | |
} | |
function hasAccusation(address _defendant) public view returns (bool) { | |
return defendant[_defendant]; | |
} | |
function renderVerdict(address guiltyParty, address innocentParty) public payable { | |
require(openCases[guiltyParty][innocentParty] == true || openCases[innocentParty][guiltyParty] ==true); | |
require(remedies[guiltyParty]==remedies[innocentParty] && remedies[guiltyParty]>0); | |
address guiltyPartyJudge = Party(guiltyParty).getJudge(); | |
address innocentPartyJudge = Party(innocentParty).getJudge(); | |
require (Party(guiltyPartyJudge).getJudge() == Party(innocentPartyJudge).getJudge()); // both judges must have picked the same 3rd judge | |
require (Party(guiltyPartyJudge).getJudge() == msg.sender); // the verdict renderer must be the 3rd judge; | |
openCases[guiltyParty][innocentParty] = false; | |
openCases[innocentParty][guiltyParty] =false; // case closed | |
innocentParty.transfer(msg.value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment