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...

3

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;
        }
    }
}
  • This is exactly what I also came up with meanwhile :) – CodingYourLife Aug 24 '18 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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