1pragma solidity >=0.0;
2import "../Oracles/Oracle.sol";
3
4
5/// @title Centralized oracle contract - Allows the contract owner to set an outcome
6/// @author Stefan George - <stefan@gnosis.pm>
7contract CentralizedOracle is Oracle {
8
9    /*
10     *  Events
11     */
12    event OwnerReplacement(address indexed newOwner);
13    event OutcomeAssignment(int outcome);
14
15    /*
16     *  Storage
17     */
18    address public owner;
19    bytes public ipfsHash;
20    bool public isSet;
21    int public outcome;
22
23    /*
24     *  Modifiers
25     */
26    modifier isOwner () {
27        // Only owner is allowed to proceed
28        require(msg.sender == owner);
29        _;
30    }
31
32    /*
33     *  Public functions
34     */
35    /// @dev Constructor sets owner address and IPFS hash
36    /// @param _ipfsHash Hash identifying off chain event description
37    constructor(address _owner, bytes memory _ipfsHash)
38    {
39        // Description hash cannot be null
40        require(_ipfsHash.length == 46);
41        owner = _owner;
42        ipfsHash = _ipfsHash;
43    }
44
45    /// @dev Replaces owner
46    /// @param newOwner New owner
47    function replaceOwner(address newOwner)
48        public
49        isOwner
50    {
51        // Result is not set yet
52        require(!isSet);
53        owner = newOwner;
54        emit OwnerReplacement(newOwner);
55    }
56
57    /// @dev Sets event outcome
58    /// @param _outcome Event outcome
59    function setOutcome(int _outcome)
60        public
61        isOwner
62    {
63        // Result is not set yet
64        require(!isSet);
65        isSet = true;
66        outcome = _outcome;
67        emit OutcomeAssignment(_outcome);
68    }
69
70    /// @dev Returns if winning outcome is set
71    /// @return Is outcome set?
72    function isOutcomeSet()
73        public
74        override
75        view
76        returns (bool)
77    {
78        return isSet;
79    }
80
81    /// @dev Returns outcome
82    /// @return Outcome
83    function getOutcome()
84        public
85        override
86        view
87        returns (int)
88    {
89        return outcome;
90    }
91}
92