Pausable.sol 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.6.0;
  3. import "../GSN/Context.sol";
  4. /**
  5. * @dev Contract module which allows children to implement an emergency stop
  6. * mechanism that can be triggered by an authorized account.
  7. *
  8. * This module is used through inheritance. It will make available the
  9. * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
  10. * the functions of your contract. Note that they will not be pausable by
  11. * simply including this module, only once the modifiers are put in place.
  12. */
  13. contract Pausable is Context {
  14. /**
  15. * @dev Emitted when the pause is triggered by `account`.
  16. */
  17. event Paused(address account);
  18. /**
  19. * @dev Emitted when the pause is lifted by `account`.
  20. */
  21. event Unpaused(address account);
  22. bool private _paused;
  23. /**
  24. * @dev Initializes the contract in unpaused state.
  25. */
  26. constructor () internal {
  27. _paused = false;
  28. }
  29. /**
  30. * @dev Returns true if the contract is paused, and false otherwise.
  31. */
  32. function paused() public view returns (bool) {
  33. return _paused;
  34. }
  35. /**
  36. * @dev Modifier to make a function callable only when the contract is not paused.
  37. */
  38. modifier whenNotPaused() {
  39. require(!_paused, "Pausable: paused");
  40. _;
  41. }
  42. /**
  43. * @dev Modifier to make a function callable only when the contract is paused.
  44. */
  45. modifier whenPaused() {
  46. require(_paused, "Pausable: not paused");
  47. _;
  48. }
  49. /**
  50. * @dev Triggers stopped state.
  51. */
  52. function _pause() internal virtual whenNotPaused {
  53. _paused = true;
  54. emit Paused(_msgSender());
  55. }
  56. /**
  57. * @dev Returns to normal state.
  58. */
  59. function _unpause() internal virtual whenPaused {
  60. _paused = false;
  61. emit Unpaused(_msgSender());
  62. }
  63. }