1 Star 0 Fork 0

zhupeng911/solidity

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
20-test_Modifier.sol 1.61 KB
一键复制 编辑 原始数据 按行查看 历史
朱鹏 提交于 2018-11-12 16:55 +08:00 . 函数修饰器
pragma solidity ^0.4.25;
/*
1、函数修改器modifier
//定义一个函数修改器,可以被继承;
//修饰时,函数提被插入到“_;”处
//不符合条件,将抛出异常
2、理解函数修改器的执行流:
如果修改器或者函数内部有return语句,
仅仅跳出当前的修改器或者函数,“_”后继续执行
*/
contract Mutex{
bool public locked;
//防止递归调用
modifier noReettrancy(){
require(!locked);
locked=true;
_;
locked=false;
}
//return 7之后,locked=false仍然会执行
function f() public noReettrancy() returns(uint){
return 7;
}
}
//Exp1:
contract Exp1{
uint public a=0;
modifier mf1(){
a=1;
_;
a=2;
}
modifier mf2(){
a=3;
_;
a=4;
}
function test1() mf1 mf2 public{
a=100;
}
}
// a=1; mf2(a=3; _;(a=100;) a=4;) a=2;
/*
contract owned{
address owner;
constructor() public{
owner=msg.sender;//本合约的地址
}
//1、不带参数的函数修改器
modifier onlyOwner(){
require(owner==msg.sender) ;
_;
}
//2、带参数的函数修改器
modifier mustOver18(uint age){
require(age>=18);
_;
}
}
contract testModifier is owned{//进行继承is
function kill(uint age) public onlyOwner mustOver18(age){//销毁本合约
selfdestruct(owner);
}
//用于验证合约是否被销毁
function hello() public view returns(string){
return "hello";
}
}
*/
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhupeng911/solidity.git
git@gitee.com:zhupeng911/solidity.git
zhupeng911
solidity
solidity
master

搜索帮助