关于合约某些方法开关的使用

  • ? or ?
  • 更新于 2022-09-27 11:29
  • 阅读 797

关于合约某些方法开关的使用

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
contract lockFunction{
    address private owner;
    bool private openFunction = true;
    uint num=1;

     /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        owner = payable(msg.sender);
    }
    //手动开启
    function unlock() public onlyOwner{
        openFunction = true;
    }
    //手动关闭
    function lock() public onlyOwner{
        openFunction = false;
    }

    function getNumber(string memory thisThing)public view returns(string memory){
        require(openFunction,"close");
        string memory setRecord = thisThing;
        return setRecord;
    }

    modifier onlyOwner() {
        require(isOwner());
        _;
    }

    function isOwner() internal view returns (bool) {
        return msg.sender == owner;
    }
}

之前提问过这个问题,特地为各位做个总结,require(openFunction,"close");是需要加在每个方法的第一列,记住lock需要用onlyowner,否则每个人都可以开关,这很危险

点赞 0
收藏 0
分享

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
? or ?
? or ?
0x34e6...BA9C
江湖只有他的大名,没有他的介绍。