-
Notifications
You must be signed in to change notification settings - Fork 27
/
Feed.sol
96 lines (78 loc) · 3.1 KB
/
Feed.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
pragma solidity ^0.5.13;
import "../modules/EventMetadata.sol";
import "../modules/Operated.sol";
import "../modules/Template.sol";
import "../modules/ProofHashes.sol";
/// @title Feed
/// @author Stephane Gosselin (@thegostep) for Numerai Inc
/// @dev Security contact: [email protected]
/// @dev Version: 1.2.0
contract Feed is ProofHashes, Operated, EventMetadata, Template {
event Initialized(address operator, bytes32 proofHash, bytes metadata);
/// @notice Constructor
/// @dev Access Control: only factory
/// State Machine: before all
/// @param operator Address of the operator that overrides access control
/// @param proofHash Proofhash (bytes32) sha256 hash of timestampled data
/// @param metadata Data (any format) to emit as event on initialization
function initialize(
address operator,
bytes32 proofHash,
bytes memory metadata
) public initializeTemplate() {
// set operator
if (operator != address(0)) {
Operated._setOperator(operator);
}
// submit proofHash
if (proofHash != bytes32(0)) {
ProofHashes._submitHash(proofHash);
}
// set metadata
if (metadata.length != 0) {
EventMetadata._setMetadata(metadata);
}
// log initialization params
emit Initialized(operator, proofHash, metadata);
}
// state functions
/// @notice Submit proofhash to add to feed
/// @dev Access Control: creator OR operator
/// State Machine: anytime
/// @param proofHash Proofhash (bytes32) sha256 hash of timestampled data
function submitHash(bytes32 proofHash) public {
// only operator or creator
require(Template.isCreator(msg.sender) || Operated.isOperator(msg.sender), "only operator or creator");
// submit proofHash
ProofHashes._submitHash(proofHash);
}
/// @notice Emit metadata event
/// @dev Access Control: creator OR operator
/// State Machine: anytime
/// @param metadata Data (any format) to emit as event
function setMetadata(bytes memory metadata) public {
// only operator or creator
require(Template.isCreator(msg.sender) || Operated.isOperator(msg.sender), "only operator or creator");
// set metadata
EventMetadata._setMetadata(metadata);
}
/// @notice Called by the operator to transfer control to new operator
/// @dev Access Control: operator
/// State Machine: anytime
/// @param operator Address of the new operator
function transferOperator(address operator) public {
// restrict access
require(Operated.isOperator(msg.sender), "only operator");
// transfer operator
Operated._transferOperator(operator);
}
/// @notice Called by the operator to renounce control
/// @dev Access Control: operator
/// State Machine: anytime
function renounceOperator() public {
// restrict access
require(Operated.isOperator(msg.sender), "only operator");
// renounce operator
Operated._renounceOperator();
}
}