2018-10-24 12:52:11 +00:00
|
|
|
pragma solidity >=0.0;
|
2017-07-12 13:46:33 +00:00
|
|
|
import "../Oracles/Oracle.sol";
|
|
|
|
|
|
|
|
|
|
|
|
/// @title Centralized oracle contract - Allows the contract owner to set an outcome
|
|
|
|
/// @author Stefan George - <stefan@gnosis.pm>
|
|
|
|
contract CentralizedOracle is Oracle {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Events
|
|
|
|
*/
|
|
|
|
event OwnerReplacement(address indexed newOwner);
|
|
|
|
event OutcomeAssignment(int outcome);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Storage
|
|
|
|
*/
|
|
|
|
address public owner;
|
|
|
|
bytes public ipfsHash;
|
|
|
|
bool public isSet;
|
|
|
|
int public outcome;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modifiers
|
|
|
|
*/
|
|
|
|
modifier isOwner () {
|
|
|
|
// Only owner is allowed to proceed
|
|
|
|
require(msg.sender == owner);
|
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Public functions
|
|
|
|
*/
|
|
|
|
/// @dev Constructor sets owner address and IPFS hash
|
|
|
|
/// @param _ipfsHash Hash identifying off chain event description
|
2018-07-14 21:42:01 +00:00
|
|
|
constructor(address _owner, bytes memory _ipfsHash)
|
2017-07-12 13:46:33 +00:00
|
|
|
public
|
|
|
|
{
|
|
|
|
// Description hash cannot be null
|
|
|
|
require(_ipfsHash.length == 46);
|
|
|
|
owner = _owner;
|
|
|
|
ipfsHash = _ipfsHash;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @dev Replaces owner
|
|
|
|
/// @param newOwner New owner
|
|
|
|
function replaceOwner(address newOwner)
|
|
|
|
public
|
|
|
|
isOwner
|
|
|
|
{
|
|
|
|
// Result is not set yet
|
|
|
|
require(!isSet);
|
|
|
|
owner = newOwner;
|
2018-06-27 08:35:38 +00:00
|
|
|
emit OwnerReplacement(newOwner);
|
2017-07-12 13:46:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @dev Sets event outcome
|
|
|
|
/// @param _outcome Event outcome
|
|
|
|
function setOutcome(int _outcome)
|
|
|
|
public
|
|
|
|
isOwner
|
|
|
|
{
|
|
|
|
// Result is not set yet
|
|
|
|
require(!isSet);
|
|
|
|
isSet = true;
|
|
|
|
outcome = _outcome;
|
2018-06-27 08:35:38 +00:00
|
|
|
emit OutcomeAssignment(_outcome);
|
2017-07-12 13:46:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @dev Returns if winning outcome is set
|
|
|
|
/// @return Is outcome set?
|
|
|
|
function isOutcomeSet()
|
|
|
|
public
|
2019-09-16 12:33:43 +00:00
|
|
|
override
|
2018-07-02 09:14:28 +00:00
|
|
|
view
|
2017-07-12 13:46:33 +00:00
|
|
|
returns (bool)
|
|
|
|
{
|
|
|
|
return isSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @dev Returns outcome
|
|
|
|
/// @return Outcome
|
|
|
|
function getOutcome()
|
|
|
|
public
|
2019-09-16 12:33:43 +00:00
|
|
|
override
|
2018-07-02 09:14:28 +00:00
|
|
|
view
|
2017-07-12 13:46:33 +00:00
|
|
|
returns (int)
|
|
|
|
{
|
|
|
|
return outcome;
|
|
|
|
}
|
|
|
|
}
|