4

I want to do the following:

contract Base {
    bool public active;

    modifier canSetMetadata() {
        require(active == false);
        _;
    }
}

contract BaseWithMetadataControl is Base {
    address public metadataControl;

    modifier canSetMetadata() {
        if(msg.sender != metadataControl) {
            super.canSetMetadata();
        }
        _;
    }
}

So the child class should call the parent's class modifier. It doesn't seem to be possible but I don't want to duplicate the modifier code because it's likely to change...

1 Answer 1

5

You could override an internal function that implements the check

pragma solidity 0.4.24;

contract Base {
    bool public active;

    modifier canSetMetadata() {
        require(canSetMetadata_());
        _;
    }

    function canSetMetadata_() internal view returns (bool) {
        return (active == false);
    }
}

contract BaseWithMetadataControl is Base {
    address public metadataControl;

    function canSetMetadata_() internal view returns (bool) {
        if(msg.sender != metadataControl) {
            return super.canSetMetadata_();
        } else {
            return true;
        }
    }
}
1
  • This is exactly what I also came up with meanwhile :) Aug 24, 2018 at 11:12

Your Answer

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

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