如何使用带有修饰符的条件?

How to use conditionals with modifiers?

我需要完成此任务才能让函数仅在修饰符(应该 正确)如图所示工作时工作。基本上 compPurch 必须始终为真,并且 realBuyer 或 timeBought 必须为真。

    modifier compPurch() {
        require(state == State.Locked, "it's not locked");
        _;
        time = block.timestamp;
    }

    modifier realBuyer() {
        require(msg.sender == buyer, "you're not the buyer");
        _;
    }

    modifier timeBought() {
        require(block.timestamp >= time + 5, "wait 5 mins fro purchase");
        _;
    }
}

I created all modifiers, but I don't know how to use AND & OR conditionals to make them work as intended in the task

多个修饰符总是用 AND 运算符连接。

因此您可以对第一个条件使用一个修饰符,对第二个条件使用一个修饰符。第二个条件中的子条件需要在同一个修饰符中。

modifier compPurch() {
    // ...
}

modifier realBuyerOrTimeBought() {
    // explicit OR in the condition
    require(msg.sender == buyer || block.timestamp >= time + 5);
    // ...
}

// implicitly joined with the AND operator
function foo() public compPurch realBuyerOrTimeBought {
}