Solidity__合约销毁

selfdestruct(minter); // 销毁合约

/*
+------------------------------------------------------------------------------+
|                                                                              |
|      XX               XXXXX XXXXXX          XXXXXXXXXXX        XXXXXXXXXX    |
|     XX XX           XXX   XXX   XXX         X         X        X        X    |
|    XX   XX          X      X      X         XXXXXXXXXXX        X        X    |
|   XXXXXXXXX         X             X         X                  X        X    |
|  XX       XX        X             X         X                  X        X    |
| XX          X       X             X         XXXXXXXXXXX        X        X    |
|                                                                              |
|                                                                              |
+------------------------------------------------------------------------------+
*/
pragma solidity ^0.4.21;

contract Coin {
    // 关键字“public”让这些变量可以从外部读取
    address public minter;
    mapping (address => uint) public balances;

    // 轻客户端可以通过事件针对变化作出高效的反应
    event Sent(address from, address to, uint amount);

    // 这是构造函数,只有当合约创建时运行
    function Coin() public {
        minter = msg.sender;
    }

    function mint(address receiver, uint amount) public {
        if (msg.sender != minter) return;
        balances[receiver] += amount;
    }

    function send(address receiver, uint amount) public {
        if (balances[msg.sender] < amount) return;
        balances[msg.sender] -= amount;
        balances[receiver] += amount;
        emit Sent(msg.sender, receiver, amount);
    }
    function kill() {
       if (minter == msg.sender) { // 权限检查
          selfdestruct(minter); // 销毁合约
       }
    }
}

你可能感兴趣的:(Solidity__合约销毁)