Files
openzeppelin-contracts/contracts/ownership/Superuser.sol
Leo Arias 45c0c072d1 Improve encapsulation on lifecycle, ownership and payments (#1269)
* Improve encapsulation on Pausable

* add the underscore

* Improve encapsulation on ownership

* fix rebase

* fix ownership

* Improve encapsulation on payments

* Add missing tests

* add missing test

* Do not prefix getters

* Fix tests.

* revert pending owner reset

* add missing underscore

* Add missing underscore
2018-09-05 16:11:29 -03:00

63 lines
1.6 KiB
Solidity

pragma solidity ^0.4.24;
import "./Ownable.sol";
import "../access/rbac/RBAC.sol";
/**
* @title Superuser
* @dev The Superuser contract defines a single superuser who can transfer the ownership
* of a contract to a new address, even if he is not the owner.
* A superuser can transfer his role to a new address.
*/
contract Superuser is Ownable, RBAC {
string private constant ROLE_SUPERUSER = "superuser";
constructor () public {
_addRole(msg.sender, ROLE_SUPERUSER);
}
/**
* @dev Throws if called by any account that's not a superuser.
*/
modifier onlySuperuser() {
checkRole(msg.sender, ROLE_SUPERUSER);
_;
}
modifier onlyOwnerOrSuperuser() {
require(msg.sender == owner() || isSuperuser(msg.sender));
_;
}
/**
* @dev getter to determine if an account has superuser role
*/
function isSuperuser(address _account)
public
view
returns (bool)
{
return hasRole(_account, ROLE_SUPERUSER);
}
/**
* @dev Allows the current superuser to transfer his role to a newSuperuser.
* @param _newSuperuser The address to transfer ownership to.
*/
function transferSuperuser(address _newSuperuser) public onlySuperuser {
require(_newSuperuser != address(0));
_removeRole(msg.sender, ROLE_SUPERUSER);
_addRole(_newSuperuser, ROLE_SUPERUSER);
}
/**
* @dev Allows the current superuser or owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) public onlyOwnerOrSuperuser {
_transferOwnership(_newOwner);
}
}