Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
153 lines (125 sloc) 5.07 KB
pragma solidity ^0.4.18;
import './Owned.sol';
import './RealityCheck.sol';
contract Arbitrator is Owned {
RealityCheck public realitycheck;
mapping(bytes32 => uint256) public arbitration_bounties;
uint256 dispute_fee;
mapping(bytes32 => uint256) custom_dispute_fees;
event LogRequestArbitration(
bytes32 indexed question_id,
uint256 fee_paid,
address requester,
uint256 remaining
);
event LogSetRealityCheck(
address realitycheck
);
event LogSetQuestionFee(
uint256 fee
);
event LogSetDisputeFee(
uint256 fee
);
event LogSetCustomDisputeFee(
bytes32 indexed question_id,
uint256 fee
);
/// @notice Constructor. Sets the deploying address as owner.
function Arbitrator()
public {
owner = msg.sender;
}
/// @notice Set the Reality Check contract address
/// @param addr The address of the Reality Check contract
function setRealityCheck(address addr)
onlyOwner
public {
realitycheck = RealityCheck(addr);
LogSetRealityCheck(addr);
}
/// @notice Set the default fee
/// @param fee The default fee amount
function setDisputeFee(uint256 fee)
onlyOwner
public {
dispute_fee = fee;
LogSetDisputeFee(fee);
}
/// @notice Set a custom fee for this particular question
/// @param question_id The question in question
/// @param fee The fee amount
function setCustomDisputeFee(bytes32 question_id, uint256 fee)
onlyOwner
public {
custom_dispute_fees[question_id] = fee;
LogSetCustomDisputeFee(question_id, fee);
}
/// @notice Return the dispute fee for the specified question. 0 indicates that we won't arbitrate it.
/// @param question_id The question in question
/// @dev Uses a general default, but can be over-ridden on a question-by-question basis.
function getDisputeFee(bytes32 question_id)
public constant returns (uint256) {
return (custom_dispute_fees[question_id] > 0) ? custom_dispute_fees[question_id] : dispute_fee;
}
/// @notice Set a fee for asking a question with us as the arbitrator
/// @param fee The fee amount
/// @dev Default is no fee. Unlike the dispute fee, 0 is an acceptable setting.
/// You could set an impossibly high fee if you want to prevent us being used as arbitrator unless we submit the question.
/// (Submitting the question ourselves is not implemented here.)
/// This fee can be used as a revenue source, an anti-spam measure, or both.
function setQuestionFee(uint256 fee)
onlyOwner
public {
realitycheck.setQuestionFee(fee);
LogSetQuestionFee(fee);
}
/// @notice Submit the arbitrator's answer to a question.
/// @param question_id The question in question
/// @param answer The answer
/// @param answerer The answerer. If arbitration changed the answer, it should be the payer. If not, the old answerer.
function submitAnswerByArbitrator(bytes32 question_id, bytes32 answer, address answerer)
onlyOwner
public {
delete arbitration_bounties[question_id];
realitycheck.submitAnswerByArbitrator(question_id, answer, answerer);
}
/// @notice Request arbitration, freezing the question until we send submitAnswerByArbitrator
/// @dev The bounty can be paid only in part, in which case the last person to pay will be considered the payer
/// Will trigger an error if the notification fails, eg because the question has already been finalized
/// @param question_id The question in question
/// @param max_previous If specified, reverts if a bond higher than this was submitted after you sent your transaction.
function requestArbitration(bytes32 question_id, uint256 max_previous)
external payable returns (bool) {
uint256 arbitration_fee = getDisputeFee(question_id);
require(arbitration_fee > 0);
arbitration_bounties[question_id] += msg.value;
uint256 paid = arbitration_bounties[question_id];
if (paid >= arbitration_fee) {
realitycheck.notifyOfArbitrationRequest(question_id, msg.sender, max_previous);
LogRequestArbitration(question_id, msg.value, msg.sender, 0);
return true;
} else {
require(!realitycheck.isFinalized(question_id));
LogRequestArbitration(question_id, msg.value, msg.sender, arbitration_fee - paid);
return false;
}
}
/// @notice Withdraw any accumulated fees to the specified address
/// @param addr The address to which the balance should be sent
function withdraw(address addr)
onlyOwner
public {
addr.transfer(this.balance);
}
function()
public payable {
}
/// @notice Withdraw any accumulated question fees from the specified address into this contract
/// @dev Funds can then be liberated from this contract with our withdraw() function
function callWithdraw()
onlyOwner
public {
realitycheck.withdraw();
}
}