-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCircuitBreaker.sol
More file actions
40 lines (33 loc) · 987 Bytes
/
CircuitBreaker.sol
File metadata and controls
40 lines (33 loc) · 987 Bytes
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
pragma solidity ^0.4.6;
/// @title Circuit Breaker Example
/// @author Adam Lemmon - <adamjlemmon@gmail.com>
contract CircuitBreaker {
/**
* Storage
*/
enum State { active, inactive }
State public state = State.active;
bool private stopped = false;
address private owner;
/**
* Public
*/
/// @dev Toggle the circuit breaker to enable / disable functionality
/// @param _state The state to transition to
function setState(State _state) public {
if(msg.sender != owner) throw;
state = _state;
}
/// @dev Disable method if circuit breaker set
modifier haltOnInactive {
if (state != State.inactive) _;
}
/// @dev In case of circuit breaker continue to allow method to function
modifier enableOnInactive {
if (state == State.inactive) _;
}
/// @dev Disable any transfer in case on emergency
function transfer() public haltOnInactive { }
/// @dev Only allow user's to withdraw funds in case of emergency
function withdraw() public enableOnInactive { }
}