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 AliasService * The AliasService provides basic alias service * namespaced by owner's address. * Access to aliases can be granted to contracts * via permission once a fee is paid to the alias owner. * Alias contract owner takes a 10%, or less, cut. */ contract AliasService is Ownable { uint256 public fee; mapping (address => uint256) private priceList; mapping (address => mapping(address => bool)) private permissions; mapping (address => mapping(bytes32 => address)) private aliases; event AliasSet( address _namespace, address _address, bytes32 _alias ); event PriceChanged( address _namespace, uint256 _price ); event FeeChanged( uint256 _fee ); event PermissionGranted( address _namespace, address _grantee ); /** * @dev Throws if address 0x0. */ modifier notNull(address _address) { require(_address != address(0)); _; } constructor() public { priceList[msg.sender] = 1000000000000000; //0.001 Ether permissions[msg.sender][msg.sender] = true; fee = 90; } /** * @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; } /* * Setting the alias for an address. * No duplicates allowed. If the alias exists the address is overwritten. * Minimum length for alias set to 4 characters. Maximum is 32 (because bytes32). */ function setAlias(address _address, bytes32 _alias) public notNull(_address) { if (_alias.length < 4) return; aliases[msg.sender][_alias] = _address; if (permissions[msg.sender][msg.sender] == false) { permissions[msg.sender][msg.sender] = true; } emit AliasSet(msg.sender, _address, _alias); } function getAddress(address _namespace, bytes32 _alias) public notNull(_namespace) view returns (address _address) { if (permissions[_namespace][msg.sender] == true) { return aliases[_namespace][_alias]; } } function() public payable { } function approveAddress(address _namespace) public notNull(_namespace) payable { require(msg.value >= priceList[_namespace]); permissions[_namespace][msg.sender] = true; _namespace.transfer(div(mul(msg.value,fee),100)); emit PermissionGranted(_namespace, msg.sender); } function removeAddress(address _namespace) public notNull(_namespace) { permissions[_namespace][msg.sender] = false; } /** * Setting price in wei for accessing namespace. * Only prices lower that 1 Ether allowed */ function setPrice(uint256 _price) public { if (_price > 1000000000000000000) revert(); priceList[msg.sender] = _price; emit PriceChanged(msg.sender, _price); } /* * Fee for accessing namespace. Max fee 10% can be set. */ function setFee(uint256 _fee) onlyOwner public { if (_fee < 90) revert(); fee = _fee; emit FeeChanged(fee); } function transfer() onlyOwner public { msg.sender.transfer(address(this).balance); } }
0.4.18