0

Two Solidity functions foo and bar both calling modifier m which emits an event Called with a unique identifier for the calling function. It could be any identifier, but it has to be unique per contract.

The modifier m can’t be called with more arguments as part of the requirements.

contract MyContract {
    event Called(bytes functionID);

    function foo() private m {
        // ...
    }

    function bar() private m  {
        // ...
    }

    modifier m {
        emit Called( /*  TODO: unique identifier for "calling" function, ie. foo or bar */  );
        _;
    }
}

How can I identify the calling function from within the modifier?

1 Answer 1

1

You could try passing args to the modifier

contract MyContract {
    event Called(bytes functionID);

    function foo() private m('foo') {
        // ...
    }

    function bar() private m('bar')  {
        // ...
    }

    modifier m(string func) {
        emit Called(func);
        _;
    }
}

Hope it helps

1
  • I like this idea, I thought about adding a function selector as argument as well. Unfortunately one of the requirements would be to not pass any arguments to the modifier.
    – mattes
    Commented Apr 17, 2023 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.