Function modifiers #195
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Created by: UlfNorell
From the Sophia discussion at the Sofia workshop.
Solidity lets you create modifiers that can wrap function bodies in arbitrary code.
Created by: UlfNorell
Currently you can achieve this as
We could conceivably add some nicer syntax for applying the modifier.
What modifiers are people interested in using? The Solidity documentation has
priced
,owned
, andnoReentrancy
. The latter is not needed in Sophia and the first two are simplerequire
checks at the top of the function. It's not obvious that adding special syntax for this is worthwhile.Created by: nikita-fuchs
Modifiers are highly useful in cases where you want to restrict the access to some functions to a specific set of users. E.g. 5 functions of the contract shall be only accessible if the user is "Rank A", owns a certain amount of value/tokens and also paid something to actually call this function. It makes a contract safer, smaller and more readable not to have to include all this logic multiple times everywhere.
Created by: UlfNorell
You are allowed to not copy-paste code even without special syntax for modifiers.
The only the difference is between (imaginary syntax)
and
Created by: nikita-fuchs
Almost, as a modifier wraps the function call, right now it would be something like
I forgot to mention the last part - sometimes you put sanity checks to double-check the outcome into the modifier or/and add some additional automation, which one might forget to perform when needing to add manually to function's end. If sophia improvements are decided to be done anyway, modifiers would be really nice, as they used to come really handy for not forgetting to implement safety checks in the past. Is the decorator syntax the one you'd propose, Ulf ? (I have no strong opinion here)
Created by: UlfNorell
That's why I asked for use cases which aren't simple access checks. What is a concrete example of
tidyUpAfterwards(..)
?Created by: UlfNorell
Closing for now. Reopen if needed with actual use cases.