[Ethereum] Can Solidity function modifiers access function arguments

modifierssolidity

I would like to have a modifier that looks like this:

modifier restrictTargetType(uint contractType) {
    if (contractTypes[target] != contractType) { throw; }
    _
}

Where target is an address passed as a function argument. Simply naming the function argument target isn't sufficient, and gives me an Error: Undeclared identifier.

Best Answer

At the point where you use the modifier, the function arguments are already in scope. This means something like the following is possible:

contract C {
  modifier restrictTargetType(address target, uint contractType) {
    require(contractTypes[target] == contractType);
    _;
  }
  function f(address target, uint contractType) restrictTargetType(target, contractType) {
    ....
  }
}

There is no generic way to provide access to the function arguments, though.

Related Topic