Created
August 17, 2017 17:59
-
-
Save thiagodelgado111/99cb6edeb4d5e64605d2e1576cb76d8e to your computer and use it in GitHub Desktop.
Modifiers
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.15; | |
contract Example { | |
address public owner; | |
function Example () { | |
owner = msg.sender; | |
} | |
modifier throwForInvalidAddress (address target) { | |
if (target == 0x0) revert(); | |
_; | |
} | |
modifier isAllowed () { | |
assert(msg.sender == owner); // contract state | |
_; | |
} | |
modifier isValueBiggerThanZero(uint value) { | |
require(value > 0); | |
_; | |
} | |
function isOwner(address target) constant returns (bool) { | |
return target == owner; | |
} | |
function simpleFunction(address target) | |
throwForInvalidAddress(target) | |
isValueBiggerThanZero(msg.value) | |
isAllowed // omitted parenthesis for parameterless modifiers | |
payable | |
{ | |
// do something | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment