Pausable.sol 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. pragma solidity ^0.4.24;
  2. import "../ownership/Ownable.sol";
  3. /**
  4. * @title Pausable
  5. * @dev Base contract which allows children to implement an emergency stop mechanism.
  6. */
  7. contract Pausable is Ownable {
  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 onlyOwner 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 onlyOwner whenPaused {
  42. paused_ = false;
  43. emit Unpaused();
  44. }
  45. }