Claimable

Ownable合约的增强扩展合约,需要下一个所有者主动声明自己,才能获得所有者权限的扩展。

pragma solidity ^0.4.11;


import './Ownable.sol';


/**
 * @title Claimable
 * @dev Extension for the Ownable contract, where the ownership needs to be claimed.
 * This allows the new owner to accept the transfer.
 */
contract Claimable is Ownable {
  address public pendingOwner;

  /**
   * @dev Modifier throws if called by any account other than the pendingOwner.
   */
  modifier onlyPendingOwner() {
    require(msg.sender == pendingOwner);
    _;
  }

  /**
   * @dev Allows the current owner to set the pendingOwner address.
   * @param newOwner The address to transfer ownership to.
   */
  function transferOwnership(address newOwner) onlyOwner {
    pendingOwner = newOwner;
  }

  /**
   * @dev Allows the pendingOwner address to finalize the transfer.
   */
  function claimOwnership() onlyPendingOwner {
    owner = pendingOwner;
    pendingOwner = 0x0;
  }

transfer(address newOwner) onlyOwner

设置传递的地址为待处理的下一个所有者(但这个所有者没有声明接受之前,所有者仍是原所有者)。

function transferOwnership(address newOwner) onlyOwner {
    pendingOwner = newOwner;
}

modifier onlyPendingOwner

限制只能是待处理的下一个所有者才能操作的修改器。

modifier onlyPendingOwner() {
    require(msg.sender == pendingOwner);
    _;
}

claimOwnership( ) onlyPendingOwner

因为设置了onlyPendingOwner修改器,所有只有被指定的下一个待处理的所有者,才有权限调用这个方法,并把自己设置为整个合约的所有者。

function claimOwnership() onlyPendingOwner {
    owner = pendingOwner;
    pendingOwner = 0x0;
}

 

发表评论

后才能评论