Skip to content

Instantly share code, notes, and snippets.

@grepruby
Created July 4, 2018 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grepruby/19e320337056581a0287061f2e8adfc3 to your computer and use it in GitHub Desktop.
Save grepruby/19e320337056581a0287061f2e8adfc3 to your computer and use it in GitHub Desktop.
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 ControlCentre is Ownable {
using SafeMath for uint;
address public dataCentre;
address public token;
function ControlCentre (address _token, address _dataCentre) public {
token = _token;
dataCentre = _dataCentre;
}
// These functions remain the same, setting up the dataCentre functions as internal for ease of user
function setBalance(address _owner, uint256 _value) internal {
DataCentre(dataCentre).setBalanceOf(_owner, _value);
}
function getBalanceOf(address _owner) public constant returns (uint256) {
return DataCentre(dataCentre).getBalanceOf(_owner);
}
function setTotalSupply(uint256 _value) internal {
DataCentre(dataCentre).setTotalSupply(_value);
}
function getTotalSupply() public constant returns (uint256) {
return DataCentre(dataCentre).getTotalSupply();
}
// this function will take in an additional sender parameter.
function transfer(address _sender, address _spender, uint256 _value) public returns (bool) {
setBalance(_sender, getBalanceOf(_sender).sub(_value));
setBalance(_spender, getBalanceOf(_spender).add(_value));
}
// This handles the upgradeability part
function kill(address _newController) public onlyOwner {
if(dataCentre != address(0)) {
Ownable(dataCentre).transferOwnership(msg.sender);
}
if(token != address(0)) {
Ownable(token).transferOwnership(msg.sender);
}
selfdestruct(_newController);
}
}
contract SkeletalToken is IERC20, Ownable {
using SafeMath for uint;
function balanceOf(address _owner) public constant returns (uint256) {
return ControlCentre(owner).getBalanceOf(_owner);
}
function totalSupply() public constant returns (uint256) {
return ControlCentre(owner).getTotalSupply();
}
function transfer(address _spender, uint256 _value) public returns (bool) {
ControlCentre(owner).transfer(msg.sender, _spender, _value);
Transfer(msg.sender, _spender, _value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment