Pausable.sol 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. pragma solidity ^0.5.0;
  2. import "../GSN/Context.sol";
  3. import "../access/roles/PauserRole.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, PauserRole {
  14. /**
  15. * @dev Emitted when the pause is triggered by a pauser (`account`).
  16. */
  17. event Paused(address account);
  18. /**
  19. * @dev Emitted when the pause is lifted by a pauser (`account`).
  20. */
  21. event Unpaused(address account);
  22. bool private _paused;
  23. /**
  24. * @dev Initializes the contract in unpaused state. Assigns the Pauser role
  25. * to the deployer.
  26. */
  27. constructor () internal {
  28. _paused = false;
  29. }
  30. /**
  31. * @dev Returns true if the contract is paused, and false otherwise.
  32. */
  33. function paused() public view returns (bool) {
  34. return _paused;
  35. }
  36. /**
  37. * @dev Modifier to make a function callable only when the contract is not paused.
  38. */
  39. modifier whenNotPaused() {
  40. require(!_paused, "Pausable: paused");
  41. _;
  42. }
  43. /**
  44. * @dev Modifier to make a function callable only when the contract is paused.
  45. */
  46. modifier whenPaused() {
  47. require(_paused, "Pausable: not paused");
  48. _;
  49. }
  50. /**
  51. * @dev Called by a pauser to pause, triggers stopped state.
  52. */
  53. function pause() public onlyPauser whenNotPaused {
  54. _paused = true;
  55. emit Paused(_msgSender());
  56. }
  57. /**
  58. * @dev Called by a pauser to unpause, returns to normal state.
  59. */
  60. function unpause() public onlyPauser whenPaused {
  61. _paused = false;
  62. emit Unpaused(_msgSender());
  63. }
  64. }