Skip to content

Instantly share code, notes, and snippets.

@daviddao
Created November 7, 2018 05:32
Show Gist options
  • Save daviddao/ec5ff14f9dab95a9391f34b386e5ab33 to your computer and use it in GitHub Desktop.
Save daviddao/ec5ff14f9dab95a9391f34b386e5ab33 to your computer and use it in GitHub Desktop.
Useful modifiers for solidity
// preventing from sending to useless addresses
modifier validDestination( address to ) {
require(to != address(0x0));
require(to != address(this) );
_;
}
// making contract inactive
bool private stopped = false;
address private owner;
modifier isAdmin() {
require(msg.sender == owner);
_;
}
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;
}
// automatic deprecation
modifier isActive() {
require(block.number <= SOME_BLOCK_NUMBER);
_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment