-
-
Save ilyar/a3b1348c197db670aa958a3ec026a01b to your computer and use it in GitHub Desktop.
ShardedToken
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 ShardedToken { | |
using SafeMath for uint256; | |
address owner = msg.sender; | |
uint256 private _totalSupply; | |
mapping(address => ShardedToken.Extension) private extensions; | |
function register() public { | |
extensions[msg.sender] = new Token.Extension(); | |
} | |
function mint(address to, uint256 amount) public { | |
require(msg.sender == owner, "Access denied"); | |
_totalSupply = _totalSupply.add(amount); | |
ShardedToken.Extension(to).receive(address(0), amount); | |
} | |
library Extension { | |
uint256 private _balance; | |
mapping(address => uint256) private _allowance; | |
function balance() public view returns(uint256) { | |
return _balance; | |
} | |
function transfer(address to, uint256 amount) public { | |
_balance = _balance.sub(amount, "Not enough balance"); | |
ShardedToken.Extension(to).receive(this, amount); | |
} | |
function receive(address from, uint256 amount) protected { | |
_balance = _balance.add(amount); | |
} | |
// | |
function allowance(address to) public view returns(uint256) { | |
return _allowance[to]; | |
} | |
function approve(address to, uint256 amount) public { | |
require(_allowance[to] == 0 || amount == 0); | |
_allowance[to] = amount; | |
} | |
function transferFrom(address to, uint256 amount) public { | |
_allowance[msg.sender] = _allowance[msg.sender].sub(amount); | |
transfer(to, amount); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment