Pausable.sol 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. pragma solidity ^0.5.0;
  2. import "../access/roles/PauserRole.sol";
  3. /**
  4. * @title Pausable
  5. * @dev Base contract which allows children to implement an emergency stop mechanism.
  6. */
  7. contract Pausable is PauserRole {
  8. event Paused(address account);
  9. event Unpaused(address account);
  10. bool private _paused;
  11. constructor () internal {
  12. _paused = false;
  13. }
  14. /**
  15. * @return true if the contract is paused, false otherwise.
  16. */
  17. function paused() public view returns (bool) {
  18. return _paused;
  19. }
  20. /**
  21. * @dev Modifier to make a function callable only when the contract is not paused.
  22. */
  23. modifier whenNotPaused() {
  24. require(!_paused);
  25. _;
  26. }
  27. /**
  28. * @dev Modifier to make a function callable only when the contract is paused.
  29. */
  30. modifier whenPaused() {
  31. require(_paused);
  32. _;
  33. }
  34. /**
  35. * @dev called by the owner to pause, triggers stopped state
  36. */
  37. function pause() public onlyPauser whenNotPaused {
  38. _paused = true;
  39. emit Paused(msg.sender);
  40. }
  41. /**
  42. * @dev called by the owner to unpause, returns to normal state
  43. */
  44. function unpause() public onlyPauser whenPaused {
  45. _paused = false;
  46. emit Unpaused(msg.sender);
  47. }
  48. }