Superuser.sol 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. pragma solidity ^0.4.23;
  2. import "./Ownable.sol";
  3. import "./rbac/RBAC.sol";
  4. /**
  5. * @title Superuser
  6. * @dev The Superuser contract defines a single superuser who can transfer the ownership
  7. * @dev of a contract to a new address, even if he is not the owner.
  8. * @dev A superuser can transfer his role to a new address.
  9. */
  10. contract Superuser is Ownable, RBAC {
  11. string public constant ROLE_SUPERUSER = "superuser";
  12. constructor () public {
  13. addRole(msg.sender, ROLE_SUPERUSER);
  14. }
  15. /**
  16. * @dev Throws if called by any account that's not a superuser.
  17. */
  18. modifier onlySuperuser() {
  19. checkRole(msg.sender, ROLE_SUPERUSER);
  20. _;
  21. }
  22. /**
  23. * @dev getter to determine if address has superuser role
  24. */
  25. function isSuperuser(address _addr)
  26. public
  27. view
  28. returns (bool)
  29. {
  30. return hasRole(_addr, ROLE_SUPERUSER);
  31. }
  32. /**
  33. * @dev Allows the current superuser to transfer his role to a newSuperuser.
  34. * @param _newSuperuser The address to transfer ownership to.
  35. */
  36. function transferSuperuser(address _newSuperuser)
  37. onlySuperuser
  38. public
  39. {
  40. require(_newSuperuser != address(0));
  41. removeRole(msg.sender, ROLE_SUPERUSER);
  42. addRole(_newSuperuser, ROLE_SUPERUSER);
  43. }
  44. /**
  45. * @dev Allows the current superuser to transfer control of the contract to a newOwner.
  46. * @param _newOwner The address to transfer ownership to.
  47. */
  48. function transferOwnership(address _newOwner) public onlySuperuser {
  49. require(_newOwner != address(0));
  50. owner = _newOwner;
  51. emit OwnershipTransferred(owner, _newOwner);
  52. }
  53. }