Pausable.sol 1.8 KB

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