Pausable.sol 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. pragma solidity ^0.4.24;
  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();
  9. event Unpaused();
  10. bool private _paused = false;
  11. /**
  12. * @return true if the contract is paused, false otherwise.
  13. */
  14. function paused() public view returns(bool) {
  15. return _paused;
  16. }
  17. /**
  18. * @dev Modifier to make a function callable only when the contract is not paused.
  19. */
  20. modifier whenNotPaused() {
  21. require(!_paused);
  22. _;
  23. }
  24. /**
  25. * @dev Modifier to make a function callable only when the contract is paused.
  26. */
  27. modifier whenPaused() {
  28. require(_paused);
  29. _;
  30. }
  31. /**
  32. * @dev called by the owner to pause, triggers stopped state
  33. */
  34. function pause() public onlyPauser whenNotPaused {
  35. _paused = true;
  36. emit Paused();
  37. }
  38. /**
  39. * @dev called by the owner to unpause, returns to normal state
  40. */
  41. function unpause() public onlyPauser whenPaused {
  42. _paused = false;
  43. emit Unpaused();
  44. }
  45. }