-
-
Save grepruby/038c228ecd12bc9b18967a3e7ff23571 to your computer and use it in GitHub Desktop.
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.11; | |
/** | |
* @title SafeMath | |
* @dev Math operations with safety checks that throw on error | |
*/ | |
library SafeMath { | |
function mul(uint256 a, uint256 b) internal constant returns (uint256) { | |
uint256 c = a * b; | |
require(a == 0 || c / a == b); | |
return c; | |
} | |
function div(uint256 a, uint256 b) internal constant returns (uint256) { | |
// require(b > 0); // Solidity automatically throws when dividing by 0 | |
uint256 c = a / b; | |
// require(a == b * c + a % b); // There is no case in which this doesn't hold | |
return c; | |
} | |
function sub(uint256 a, uint256 b) internal constant returns (uint256) { | |
require(b <= a); | |
return a - b; | |
} | |
function add(uint256 a, uint256 b) internal constant returns (uint256) { | |
uint256 c = a + b; | |
require(c >= a); | |
return c; | |
} | |
} | |
/** | |
* @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 OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
/** | |
* @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
* account. | |
*/ | |
function Ownable() 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 transfer control of the contract to a newOwner. | |
* @param newOwner The address to transfer ownership to. | |
*/ | |
function transferOwnership(address newOwner) public onlyOwner { | |
require(newOwner != address(0)); | |
OwnershipTransferred(owner, newOwner); | |
owner = newOwner; | |
} | |
} | |
// ERC20 Token Standard Interface | |
// https://github.com/ethereum/EIPs/issues/20 | |
interface IERC20 { | |
function balanceOf(address _owner) public constant returns (uint256); | |
function totalSupply() public constant returns (uint256); | |
function transfer(address _spender, uint256 _value) public returns (bool); | |
event Transfer(address indexed from, address indexed to, uint value); | |
} | |
contract DataCentre is Ownable { | |
uint256 internal totalSupply; | |
mapping(address => uint256) internal balances; | |
mapping(address => mapping (address => uint)) internal allowances; | |
function DataCentre() { | |
balances[msg.sender] = 10000; | |
totalSupply = 10000; | |
} | |
function getBalanceOf(address _owner) public constant returns (uint256) { | |
return balances[_owner]; | |
} | |
function setBalanceOf(address _owner, uint256 _value) public onlyOwner { | |
balances[_owner] = _value; | |
} | |
function getTotalSupply() public constant returns (uint256) { | |
return totalSupply; | |
} | |
function setTotalSupply(uint256 _value) public onlyOwner { | |
totalSupply = _value; | |
} | |
} | |
contract Token is IERC20, Ownable { | |
using SafeMath for uint; | |
address public dataCentre; | |
function Token (address _dataCentre) public { | |
dataCentre = _dataCentre; | |
} | |
// setting up the dataCentre functions as internal for ease of user | |
function setBalance(address _owner, uint256 _value) internal { | |
DataCentre(dataCentre).setBalanceOf(_owner, _value); | |
} | |
function balanceOf(address _owner) public constant returns (uint256) { | |
return DataCentre(dataCentre).getBalanceOf(_owner); | |
} | |
function setTotalSupply(uint256 _value) internal { | |
DataCentre(dataCentre).setTotalSupply(_value); | |
} | |
function totalSupply() public constant returns (uint256) { | |
return DataCentre(dataCentre).getTotalSupply(); | |
} | |
function transfer(address _spender, uint256 _value) public returns (bool) { | |
setBalance(msg.sender, balanceOf(msg.sender).sub(_value)); | |
setBalance(_spender, balanceOf(_spender).add(_value)); | |
Transfer(msg.sender, _spender, _value); | |
} | |
// This handles the upgradeability part | |
function kill(address _newTokenContract) public onlyOwner { | |
if (dataCentre != address(0)) { | |
Ownable(dataCentre).transferOwnership(_newTokenContract); | |
} | |
selfdestruct(_newTokenContract); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment