Pausable.sol 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. * Requirements:
  38. *
  39. * - The contract must not be paused.
  40. */
  41. modifier whenNotPaused() {
  42. require(!_paused, "Pausable: paused");
  43. _;
  44. }
  45. /**
  46. * @dev Modifier to make a function callable only when the contract is paused.
  47. *
  48. * Requirements:
  49. *
  50. * - The contract must be paused.
  51. */
  52. modifier whenPaused() {
  53. require(_paused, "Pausable: not paused");
  54. _;
  55. }
  56. /**
  57. * @dev Triggers stopped state.
  58. *
  59. * Requirements:
  60. *
  61. * - The contract must not be paused.
  62. */
  63. function _pause() internal virtual whenNotPaused {
  64. _paused = true;
  65. emit Paused(_msgSender());
  66. }
  67. /**
  68. * @dev Returns to normal state.
  69. *
  70. * Requirements:
  71. *
  72. * - The contract must be paused.
  73. */
  74. function _unpause() internal virtual whenPaused {
  75. _paused = false;
  76. emit Unpaused(_msgSender());
  77. }
  78. }