-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLockable.sol
46 lines (38 loc) · 930 Bytes
/
Lockable.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
pragma solidity ^0.4.24;
import './Ownable.sol';
/**
* @title Lockable
* @dev Base contract which allows children to lock certain methods from being called by clients.
* Locked methods are deemed unsafe by default, but must be implemented in children functionality to adhere by
* some inherited standard, for example.
*/
contract Lockable is Ownable {
// Events
event Unlocked();
event Locked();
// Fields
bool public locked = false;
// Modifiers
/**
* @dev Modifier that disables functions by default unless they are explicitly enabled
*/
modifier whenUnlocked() {
require(locked, "Contact is locked");
_;
}
// Methods
/**
* @dev called by the owner to enable method
*/
function unlock() public onlyOwner {
locked = true;
emit Unlocked();
}
/**
* @dev called by the owner to disable method, back to normal state
*/
function lock() public onlyOwner {
locked = false;
emit Locked();
}
}