{"content":{"title":"关于合约某些方法开关的使用","body":"```\r\n// SPDX-License-Identifier: MIT\r\npragma solidity ^0.8.9;\r\ncontract lockFunction{\r\n    address private owner;\r\n    bool private openFunction = true;\r\n    uint num=1;\r\n\r\n     /// @custom:oz-upgrades-unsafe-allow constructor\r\n    constructor() {\r\n        owner = payable(msg.sender);\r\n    }\r\n    //手动开启\r\n    function unlock() public onlyOwner{\r\n        openFunction = true;\r\n    }\r\n    //手动关闭\r\n    function lock() public onlyOwner{\r\n        openFunction = false;\r\n    }\r\n\r\n    function getNumber(string memory thisThing)public view returns(string memory){\r\n        require(openFunction,\"close\");\r\n        string memory setRecord = thisThing;\r\n        return setRecord;\r\n    }\r\n\r\n\r\n    modifier onlyOwner() {\r\n        require(isOwner());\r\n        _;\r\n    }\r\n\r\n    function isOwner() internal view returns (bool) {\r\n        return msg.sender == owner;\r\n    }\r\n}\r\n```\r\n之前提问过这个问题，特地为各位做个总结，`require(openFunction,\"close\");`是需要加在每个方法的第一列，记住lock需要用onlyowner，否则每个人都可以开关，这很危险"},"author":{"user":"https://learnblockchain.cn/people/7148","address":null},"history":"QmZDV5WAbtnmstJZ5sPsoFFQ4k66sE9ez6F5xQQypFegQw","timestamp":1668156576,"version":1}