Skip to content

Instantly share code, notes, and snippets.

@critesjosh
Last active January 15, 2018 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save critesjosh/a92c7b9da1876460e3c011069384a5d2 to your computer and use it in GitHub Desktop.
Save critesjosh/a92c7b9da1876460e3c011069384a5d2 to your computer and use it in GitHub Desktop.
Add pausability to a smart contract
pragma solidity ^0.4.10;
contract Pausable {
bool public stopped = false;
address private owner;
modifier isAdmin() {
if(msg.sender != owner) {
revert();
}
_;
}
function Pausable(){
owner = msg.sender;
}
function toggleContractActive() isAdmin public
{
// You can add an additional modifier that restricts stopping a contract to be based on another action, such as a vote of users
stopped = !stopped;
}
modifier stopInEmergency { require(!stopped); _; }
modifier onlyInEmergency { require(stopped); _; }
function deposit() stopInEmergency public
{
// some code
}
function withdraw() onlyInEmergency public
{
// some code
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment