Created
November 7, 2018 05:32
-
-
Save daviddao/ec5ff14f9dab95a9391f34b386e5ab33 to your computer and use it in GitHub Desktop.
Useful modifiers for solidity
This file contains hidden or 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
// 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