Skip to content

Modifier Areas #623

@chriseth

Description

@chriseth

Especially in contracts that model a state machine, it would be convenient to group functions that can be called in a specific state. Currently, the modifiers have to be applied to all these functions individually. This enhancement proposes to provide a syntactic means to apply modifiers to several functions at the same time. This does not only apply to modifiers but also to visibility specifiers. Examples:

contract c {
   // ...
  modifier inState(state) { if (currentState != state) throw; _ }
  using modifier inState(State.transfer) {
    function f() { ... }
    function g() { ... }
  }
  using modifier inState(State.cleanup) {
    function h() { ... }
    function i() { ... }
  }
}

This is also convenient to disallow ether transfer using Emmy Noether's famous modifier (derived from Noether's theorem that describes the connection between preservation of ether and the symmetry of the blockchain):

contract c {
  modifier noether { if (msg.value > 0) throw; _ }
  using modifier noether {
    // put all functions in here that are not supposed to receive ether
    function f() { ... }
  }
}

If using modifier x; (i.e. without curly braces) is used, it applies to the whole contract (including functions before that statement).

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed due inactivityThe issue/PR was automatically closed due to inactivity.language design :rage4:Any changes to the language, e.g. new featuresstaleThe issue/PR was marked as stale because it has been open for too long.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions