Created
June 17, 2018 01:41
-
-
Save microchipgnu/d457621ac8594f3b2e715f65e0a2789c 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; | |
} | |
} | |
/** | |
* @title Pausable | |
* @dev Base contract which allows children to implement an emergency stop mechanism. | |
*/ | |
contract Pausable is Ownable { | |
event Pause(); | |
event Unpause(); | |
bool public paused = false; | |
/** | |
* @dev Modifier to make a function callable only when the contract is not paused. | |
*/ | |
modifier whenNotPaused() { | |
require(!paused); | |
_; | |
} | |
/** | |
* @dev Modifier to make a function callable only when the contract is paused. | |
*/ | |
modifier whenPaused() { | |
require(paused); | |
_; | |
} | |
/** | |
* @dev called by the owner to pause, triggers stopped state | |
*/ | |
function pause() onlyOwner whenNotPaused public { | |
paused = true; | |
emit Pause(); | |
} | |
/** | |
* @dev called by the owner to unpause, returns to normal state | |
*/ | |
function unpause() onlyOwner whenPaused public { | |
paused = false; | |
emit Unpause(); | |
} | |
} | |
/** | |
* @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 Administrable. */ | |
contract Administrable is Ownable, Pausable{ | |
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); | |
} | |
} | |
contract MarketplaceManager is Administrable { | |
} | |
contract Marketplace is Administrable{ | |
string public name; | |
MarketplaceManager public managerAddress; | |
constructor(string _name, address _managerAddress) public { | |
require(_managerAddress != 0); | |
name = _name; | |
MarketplaceManager candidateContract = MarketplaceManager(_managerAddress); | |
managerAddress = candidateContract; | |
} | |
struct Store{ | |
StoreOwner owner; | |
} | |
struct StoreOwner{ | |
address ownerAddress; | |
} | |
modifier onlyStoreOwner(uint256 storeId){ | |
/*verificar se é dono da loja storeId*/ | |
_; | |
} | |
function setName(string _name) public onlyAdmins { | |
name = _name; | |
} | |
function setManagerAddress(address _managerAddress) public onlyAdmins{ | |
require(_managerAddress != 0); | |
MarketplaceManager candidateContract = MarketplaceManager(_managerAddress); | |
managerAddress = candidateContract; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment