Created
February 18, 2018 01:49
-
-
Save mikec/b457ed7fa6b587ff5a729275a7b095cc 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
contract TokenDelegate is StorageStateful { | |
using SafeMath for uint256; | |
function transfer(address to, uint256 value) public returns (bool) { | |
require(to != address(0)); | |
require(value <= getBalance(msg.sender)); | |
subBalance(msg.sender, value); | |
addBalance(to, value); | |
return true; | |
} | |
function balanceOf(address owner) public view returns (uint256 balance) { | |
return getBalance(owner); | |
} | |
function getBalance(address balanceHolder) public view returns (uint256) { | |
return _storage.getUint(keccak256("balances", balanceHolder)); | |
} | |
function totalSupply() public view returns (uint256) { | |
return _storage.getUint("totalSupply"); | |
} | |
function addSupply(uint256 amount) internal { | |
_storage.setUint("totalSupply", totalSupply().add(amount)); | |
} | |
function addBalance(address balanceHolder, uint256 amount) internal { | |
setBalance(balanceHolder, getBalance(balanceHolder).add(amount)); | |
} | |
function subBalance(address balanceHolder, uint256 amount) internal { | |
setBalance(balanceHolder, getBalance(balanceHolder).sub(amount)); | |
} | |
function setBalance(address balanceHolder, uint256 amount) internal { | |
_storage.setUint(keccak256("balances", balanceHolder), amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment