-
Notifications
You must be signed in to change notification settings - Fork 47
/
DefaultFallbackOracle.sol
101 lines (91 loc) · 2.86 KB
/
DefaultFallbackOracle.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/// @title Abstract oracle contract - Functions to be implemented by oracles.
contract DefaultFallbackOracle {
/*
* Storage
*/
address owner;
// signer address => is valid?
mapping (address => bool) invalidSigners;
// description hash => signer address => is valid?
mapping (bytes32 => mapping (address => bool)) invalidSignersForDescriptions;
// description hash => OracleOutcome
mapping (bytes32 => OracleOutcome) oracleOutcomes;
struct OracleOutcome {
int outcome;
bool isSet;
}
/*
* Modifiers
*/
modifier isOwner() {
if (msg.sender != owner) {
// Only owner is allowed to do this action.
throw;
}
_;
}
/*
* Read and write functions
*/
/// @dev Sets signer as invalid.
/// @param signer Signer's address.
function setInvalidSigner(address signer)
public
isOwner
{
invalidSigners[signer] = true;
}
/// @dev Sets signer as invalid.
/// @param signer Signer's address.
function setInvalidSignerForDescription(bytes32 descriptionHash, address signer)
public
isOwner
{
invalidSignersForDescriptions[descriptionHash][signer] = true;
}
/// @dev Sets the outcome for an event.
/// @param descriptionHash Hash identifying off chain event description.
/// @param outcome Event's outcome.
function setOutcome(bytes32 descriptionHash, int outcome)
public
isOwner
{
OracleOutcome oracleOutcome = oracleOutcomes[descriptionHash];
oracleOutcome.outcome = outcome;
oracleOutcome.isSet = true;
}
/// @dev Contract constructor function sets owner.
function DefaultFallbackOracle() {
owner = msg.sender;
}
/*
* Read functions
*/
/// @dev Votes for given outcome by adding Ether sent to outcome's stake. Returns success.
/// @param signer Signer's address.
/// @return isValid Returns if signer is valid.
function isValidSigner(bytes32 descriptionHash, address signer)
public
returns (bool isValid)
{
return !(invalidSigners[signer] || invalidSignersForDescriptions[descriptionHash][signer]);
}
/// @dev Returns if winning outcome is set for given event.
/// @param descriptionHash Hash identifying an event.
/// @return isSet Returns if outcome is set.
function isOutcomeSet(bytes32 descriptionHash)
public
returns (bool isSet)
{
return oracleOutcomes[descriptionHash].isSet;
}
/// @dev Returns winning outcome for given event.
/// @param descriptionHash Hash identifying an event.
/// @return outcome Returns outcome.
function getOutcome(bytes32 descriptionHash)
public
returns (int outcome)
{
return oracleOutcomes[descriptionHash].outcome;
}
}