Created
June 17, 2018 00:58
-
-
Save microchipgnu/9dd607acd2499d15f6d768b115b61eeb to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
/** | |
* @title Ownable | |
* @dev The Ownable contract has an owner address, and provides basic authorization control | |
* functions, this simplifies the implementation of "user permissions". | |
*/ | |
contract Ownable { | |
address public owner; | |
event OwnershipRenounced(address indexed previousOwner); | |
event OwnershipTransferred( | |
address indexed previousOwner, | |
address indexed newOwner | |
); | |
/** | |
* @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
* account. | |
*/ | |
constructor() public { | |
owner = msg.sender; | |
} | |
/** | |
* @dev Throws if called by any account other than the owner. | |
*/ | |
modifier onlyOwner() { | |
require(msg.sender == owner); | |
_; | |
} | |
/** | |
* @dev Allows the current owner to relinquish control of the contract. | |
* @notice Renouncing to ownership will leave the contract without an owner. | |
* It will not be possible to call the functions with the `onlyOwner` | |
* modifier anymore. | |
*/ | |
function renounceOwnership() public onlyOwner { | |
emit OwnershipRenounced(owner); | |
owner = address(0); | |
} | |
/** | |
* @dev Allows the current owner to transfer control of the contract to a newOwner. | |
* @param _newOwner The address to transfer ownership to. | |
*/ | |
function transferOwnership(address _newOwner) public onlyOwner { | |
_transferOwnership(_newOwner); | |
} | |
/** | |
* @dev Transfers control of the contract to a newOwner. | |
* @param _newOwner The address to transfer ownership to. | |
*/ | |
function _transferOwnership(address _newOwner) internal { | |
require(_newOwner != address(0)); | |
emit OwnershipTransferred(owner, _newOwner); | |
owner = _newOwner; | |
} | |
} | |
pragma solidity ^0.4.24; | |
/** | |
* @title SafeMath | |
* @dev Math operations with safety checks that throw on error | |
*/ | |
library SafeMath { | |
/** | |
* @dev Multiplies two numbers, throws on overflow. | |
*/ | |
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { | |
// Gas optimization: this is cheaper than asserting 'a' not being zero, but the | |
// benefit is lost if 'b' is also tested. | |
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 | |
if (a == 0) { | |
return 0; | |
} | |
c = a * b; | |
assert(c / a == b); | |
return c; | |
} | |
/** | |
* @dev Integer division of two numbers, truncating the quotient. | |
*/ | |
function div(uint256 a, uint256 b) internal pure returns (uint256) { | |
// assert(b > 0); // Solidity automatically throws when dividing by 0 | |
// uint256 c = a / b; | |
// assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
return a / b; | |
} | |
/** | |
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). | |
*/ | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b <= a); | |
return a - b; | |
} | |
/** | |
* @dev Adds two numbers, throws on overflow. | |
*/ | |
function add(uint256 a, uint256 b) internal pure returns (uint256 c) { | |
c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
} | |
/** @title Admin. */ | |
contract Admin is Ownable{ | |
using SafeMath for uint256; | |
/** @dev Number of added admin addresses to the admins mapping. */ | |
uint256 public totalAdmins; | |
/** @dev Number of added admin address to the super admins mapping. */ | |
uint256 public totalSuperAdmins; | |
mapping(uint256 => address) public idToAdminAddress; | |
mapping(uint256 => address) public idToSuperAdminAddress; | |
mapping(address => bool) public admins; | |
mapping(address => bool) public superAdmins; | |
mapping(address => bool) public processedAdmin; | |
mapping(address => bool) public processedSuperAdmin; | |
event AddAdmin(address indexed admin); | |
event RemoveAdmin(address indexed admin); | |
event AddSuperAdmin(address indexed admin); | |
event RemoveSuperAdmin(address indexed admin); | |
modifier onlyAdmins { | |
if (msg.sender != owner && !superAdmins[msg.sender] && !admins[msg.sender]) revert(); | |
_; | |
} | |
modifier onlySuperAdmins { | |
if (msg.sender != owner && !superAdmins[msg.sender]) revert(); | |
_; | |
} | |
/** @dev Gives an address super admin privileges. | |
@param admin The address to give admin privileges. | |
*/ | |
function addSuperAdmin(address admin) public onlyOwner { | |
superAdmins[admin] = true; | |
if (!processedSuperAdmin[admin]) { | |
processedSuperAdmin[admin] = true; | |
idToSuperAdminAddress[totalSuperAdmins] = admin; | |
totalSuperAdmins = totalSuperAdmins.add(1); | |
} | |
emit AddSuperAdmin(admin); | |
} | |
/** @dev Removes super admin privileges from an address. | |
@param admin The address to remove super admin privileges from. | |
*/ | |
function removeSuperAdmin(address admin) public onlyOwner { | |
superAdmins[admin] = false; | |
emit RemoveSuperAdmin(admin); | |
} | |
function addAdmin(address admin) public onlySuperAdmins { | |
admins[admin] = true; | |
if (!processedAdmin[admin]) { | |
processedAdmin[admin] = true; | |
idToAdminAddress[totalAdmins] = admin; | |
totalAdmins = totalAdmins.add(1); | |
} | |
emit AddAdmin(admin); | |
} | |
function removeAdmin(address admin) public onlySuperAdmins { | |
admins[admin] = false; | |
emit RemoveAdmin(admin); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment