eth-owned

EIP-173 interface and tools for chainlib-eth
git clone git://holbrook.no/eth-owned.git
Info | Log | Files | Refs

Owned.sol (884B)


      1 pragma solidity >= 0.6.11;
      2 
      3 // SPDX-License-Identifier: GPL-3.0-or-later
      4 
      5 contract Owned {
      6 
      7 	// EIP173
      8 	address public owner;
      9 
     10 	address newOwner;
     11 
     12 	uint8 finalOwner; 
     13 
     14 	// EIP173
     15 	event OwnershipTransferred(address indexed _previousOwner, address indexed _newOwner);
     16 
     17 	constructor() public {
     18 		owner = msg.sender;
     19 	}
     20 
     21 	// EIP173
     22 	function transferOwnership(address _newOwner) public returns (bool) {
     23 		require(owner == msg.sender);
     24 		require(finalOwner < 2);
     25 		newOwner = _newOwner;
     26 	}
     27 
     28 	function transferOwnershipFinal(address _newOwner) public returns (bool) {
     29 		this.transferOwnership(_newOwner);
     30 		finalOwner = 1;
     31 	}
     32 
     33 	function acceptOwnership() public returns (bool) {
     34 		address oldOwner;
     35 
     36 		require(newOwner == msg.sender);
     37 		oldOwner = owner;
     38 		owner = newOwner;
     39 		emit OwnershipTransferred(oldOwner, owner);
     40 		if (finalOwner == 1) {
     41 			finalOwner = 2;
     42 		}
     43 		return true;
     44 	}
     45 }