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

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

`// 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,否则每个人都可以开关,这很危险

  • 发表于 2022-09-27 11:29
  • 阅读 ( 121 )
  • 学分 ( 0 )
  • 分类:智能合约

评论