Last active
January 15, 2018 16:39
-
-
Save critesjosh/a92c7b9da1876460e3c011069384a5d2 to your computer and use it in GitHub Desktop.
Add pausability to a smart contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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