关于合约某些方法开关的使用
// 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,否则每个人都可以开关,这很危险
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!