Created
July 21, 2017 22:16
-
-
Save danfinlay/df49513822d3be36afa90c47c6c1aa4c to your computer and use it in GitHub Desktop.
A sample restricted token, that respects an owner's whitelist.
This file contains hidden or 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 RestrictedToken { | |
address owner; | |
mapping (address => uint) balances; | |
mapping (address => bool) whitelist; | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
function RestrictedToken() { | |
balances[tx.origin] = 10000; | |
owner = tx.origin; | |
} | |
modifier only_owner() | |
{ | |
require(msg.sender == owner); | |
// Do not forget the "_;"! It will | |
// be replaced by the actual function | |
// body when the modifier is used. | |
_; | |
} | |
function reviseWhitelistEntry(address receiver, bool permission) only_owner { | |
whitelist[receiver] = permission; | |
} | |
function sendCoin(address receiver, uint amount) returns(bool sufficient) { | |
if (balances[msg.sender] < amount) return false; | |
if (whitelist[receiver] == false) return false; | |
balances[msg.sender] -= amount; | |
balances[receiver] += amount; | |
Transfer(msg.sender, receiver, amount); | |
return true; | |
} | |
function getBalance(address addr) returns(uint) { | |
return balances[addr]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment