Skip to content

Instantly share code, notes, and snippets.

@michielmulders
Created August 5, 2018 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michielmulders/11d1e7cf40774c6237bd278415f1f54b to your computer and use it in GitHub Desktop.
Save michielmulders/11d1e7cf40774c6237bd278415f1f54b to your computer and use it in GitHub Desktop.
Circuit Breaker Solidity Ethereum smart contract example
bool private stopped = false;
address private owner;
modifier isAdmin() {
if(msg.sender != owner) {
throw;
}
_
}
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 { if (!stopped) _ }
modifier onlyInEmergency { if (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