diff options
author | chriseth <chris@ethereum.org> | 2017-07-12 21:46:33 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-07-12 21:55:11 +0800 |
commit | b1c1fb6c8314a8f756cb367bdaa73f4459f397f2 (patch) | |
tree | 7e9d18c3e48d0a90eb75cf3453354f3699d528d1 /test/compilationTests/gnosis/Oracles/DifficultyOracle.sol | |
parent | 91f17a366202f5cac21a5a469c682ad86fe9ede8 (diff) | |
download | dexon-solidity-b1c1fb6c8314a8f756cb367bdaa73f4459f397f2.tar.gz dexon-solidity-b1c1fb6c8314a8f756cb367bdaa73f4459f397f2.tar.zst dexon-solidity-b1c1fb6c8314a8f756cb367bdaa73f4459f397f2.zip |
Gnosis compilation contracts.
Diffstat (limited to 'test/compilationTests/gnosis/Oracles/DifficultyOracle.sol')
-rw-r--r-- | test/compilationTests/gnosis/Oracles/DifficultyOracle.sol | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/compilationTests/gnosis/Oracles/DifficultyOracle.sol b/test/compilationTests/gnosis/Oracles/DifficultyOracle.sol new file mode 100644 index 00000000..87351dfa --- /dev/null +++ b/test/compilationTests/gnosis/Oracles/DifficultyOracle.sol @@ -0,0 +1,63 @@ +pragma solidity ^0.4.11; +import "../Oracles/Oracle.sol"; + + +/// @title Difficulty oracle contract - Oracle to resolve difficulty events at given block +/// @author Stefan George - <stefan@gnosis.pm> +contract DifficultyOracle is Oracle { + + /* + * Events + */ + event OutcomeAssignment(uint difficulty); + + /* + * Storage + */ + uint public blockNumber; + uint public difficulty; + + /* + * Public functions + */ + /// @dev Contract constructor validates and sets target block number + /// @param _blockNumber Target block number + function DifficultyOracle(uint _blockNumber) + public + { + // Block has to be in the future + require(_blockNumber > block.number); + blockNumber = _blockNumber; + } + + /// @dev Sets difficulty as winning outcome for specified block + function setOutcome() + public + { + // Block number was reached and outcome was not set yet + require(block.number >= blockNumber && difficulty == 0); + difficulty = block.difficulty; + OutcomeAssignment(difficulty); + } + + /// @dev Returns if difficulty is set + /// @return Is outcome set? + function isOutcomeSet() + public + constant + returns (bool) + { + // Difficulty is always bigger than 0 + return difficulty > 0; + } + + /// @dev Returns difficulty + /// @return Outcome + function getOutcome() + public + constant + returns (int) + { + return int(difficulty); + } +} |