You are viewing a single comment's thread from:

RE: Solidity实用笔记

in #starnote4 years ago

使用修饰器modifier可以轻松改变函数的行为。 例如,它们可以在执行函数之前自动检查某个条件。

contract owned {
  address owner;
  
  //修饰器所修饰的函数体会被插入到特殊符号 _; 的位置。
  modifier onlyOwner {
      require(
          msg.sender == owner,
          "Only owner can call this function."
      );
      _;
  }

  //只有合约的创建者才能销毁合约
  function destroy() public onlyOwner {
        selfdestruct(owner);
 }
}

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63470.48
ETH 2544.22
USDT 1.00
SBD 2.72