This repository has been archived by the owner on Mar 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
EthereumForkArbiter.sol
134 lines (109 loc) · 3.16 KB
/
EthereumForkArbiter.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
pragma solidity 0.4.15;
import './AccessControl/AccessControlled.sol';
import './AccessRoles.sol';
import './Reclaimable.sol';
import './Standards/IEthereumForkArbiter.sol';
contract EthereumForkArbiter is
IEthereumForkArbiter,
AccessControlled,
AccessRoles,
Reclaimable
{
////////////////////////
// Mutable state
////////////////////////
string private _nextForkName;
string private _nextForkUrl;
uint256 private _nextForkBlockNumber;
uint256 private _lastSignedBlockNumber;
bytes32 private _lastSignedBlockHash;
uint256 private _lastSignedTimestamp;
////////////////////////
// Constructor
////////////////////////
function EthereumForkArbiter(IAccessPolicy accessPolicy)
AccessControlled(accessPolicy)
Reclaimable()
public
{
}
////////////////////////
// Public functions
////////////////////////
/// @notice Announce that a particular future Ethereum fork will the one taken by the contract. The contract on the other branch should be considered invalid. Once the fork has happened, it will additionally be confirmed by signing a block on the fork. Notice that forks may happen unannounced.
function announceFork(
string name,
string url,
uint256 blockNumber
)
public
only(ROLE_PLATFORM_OPERATOR_REPRESENTATIVE)
{
require(blockNumber == 0 || blockNumber > block.number);
// Store announcement
_nextForkName = name;
_nextForkUrl = url;
_nextForkBlockNumber = blockNumber;
// Log
LogForkAnnounced(_nextForkName, _nextForkUrl, _nextForkBlockNumber);
}
/// @notice Declare that the current fork (as identified by a blockhash) is the valid fork. The valid fork is always the one with the most recent signature.
function signFork(uint256 number, bytes32 hash)
public
only(ROLE_PLATFORM_OPERATOR_REPRESENTATIVE)
{
require(block.blockhash(number) == hash);
// Reset announcement
delete _nextForkName;
delete _nextForkUrl;
delete _nextForkBlockNumber;
// Store signature
_lastSignedBlockNumber = number;
_lastSignedBlockHash = hash;
_lastSignedTimestamp = block.timestamp;
// Log
LogForkSigned(_lastSignedBlockNumber, _lastSignedBlockHash);
}
function nextForkName()
public
constant
returns (string)
{
return _nextForkName;
}
function nextForkUrl()
public
constant
returns (string)
{
return _nextForkUrl;
}
function nextForkBlockNumber()
public
constant
returns (uint256)
{
return _nextForkBlockNumber;
}
function lastSignedBlockNumber()
public
constant
returns (uint256)
{
return _lastSignedBlockNumber;
}
function lastSignedBlockHash()
public
constant
returns (bytes32)
{
return _lastSignedBlockHash;
}
function lastSignedTimestamp()
public
constant
returns (uint256)
{
return _lastSignedTimestamp;
}
}