Skip to content

Instantly share code, notes, and snippets.

@thiagodelgado111
Created August 17, 2017 17:59
Show Gist options
  • Save thiagodelgado111/99cb6edeb4d5e64605d2e1576cb76d8e to your computer and use it in GitHub Desktop.
Save thiagodelgado111/99cb6edeb4d5e64605d2e1576cb76d8e to your computer and use it in GitHub Desktop.
Modifiers
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