-
Notifications
You must be signed in to change notification settings - Fork 21
/
Pausable.sol
55 lines (46 loc) · 1.29 KB
/
Pausable.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.4;
import "../ownership/Ownable.sol";
/**
* @title Pausable
* @dev Base contract that can be paused by the owner to stop all normal functionality.
*/
contract Pausable is Ownable {
bool private _paused;
event Paused(address account);
event Unpaused(address account);
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused, "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused, "Pausable: not paused");
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() external view returns (bool) {
return _paused;
}
/**
* @dev Called by the owner to pause, triggers stopped state.
*/
function pause() external onlyOwner whenNotPaused {
_paused = true;
emit Paused(msg.sender);
}
/**
* @dev Called by the owner to unpause, returns to normal state.
*/
function unpause() external onlyOwner whenPaused {
_paused = false;
emit Unpaused(msg.sender);
}
}