Superuser.sol 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. pragma solidity ^0.4.24;
  2. import "./Ownable.sol";
  3. import "../access/rbac/RBAC.sol";
  4. /**
  5. * @title Superuser
  6. * @dev The Superuser contract defines a single superuser who can transfer the ownership
  7. * of a contract to a new address, even if he is not the owner.
  8. * A superuser can transfer his role to a new address.
  9. */
  10. contract Superuser is Ownable, RBAC {
  11. string private 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. modifier onlyOwnerOrSuperuser() {
  23. require(msg.sender == owner() || isSuperuser(msg.sender));
  24. _;
  25. }
  26. /**
  27. * @dev getter to determine if an account has superuser role
  28. */
  29. function isSuperuser(address _account)
  30. public
  31. view
  32. returns (bool)
  33. {
  34. return hasRole(_account, ROLE_SUPERUSER);
  35. }
  36. /**
  37. * @dev Allows the current superuser to transfer his role to a newSuperuser.
  38. * @param _newSuperuser The address to transfer ownership to.
  39. */
  40. function transferSuperuser(address _newSuperuser) public onlySuperuser {
  41. require(_newSuperuser != address(0));
  42. _removeRole(msg.sender, ROLE_SUPERUSER);
  43. _addRole(_newSuperuser, ROLE_SUPERUSER);
  44. }
  45. /**
  46. * @dev Allows the current superuser or owner to transfer control of the contract to a newOwner.
  47. * @param _newOwner The address to transfer ownership to.
  48. */
  49. function transferOwnership(address _newOwner) public onlyOwnerOrSuperuser {
  50. _transferOwnership(_newOwner);
  51. }
  52. }