diff options
author | chriseth <chris@ethereum.org> | 2017-07-12 21:46:33 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-07-12 21:55:11 +0800 |
commit | b1c1fb6c8314a8f756cb367bdaa73f4459f397f2 (patch) | |
tree | 7e9d18c3e48d0a90eb75cf3453354f3699d528d1 /test/compilationTests/gnosis/Tokens/StandardToken.sol | |
parent | 91f17a366202f5cac21a5a469c682ad86fe9ede8 (diff) | |
download | dexon-solidity-b1c1fb6c8314a8f756cb367bdaa73f4459f397f2.tar.gz dexon-solidity-b1c1fb6c8314a8f756cb367bdaa73f4459f397f2.tar.zst dexon-solidity-b1c1fb6c8314a8f756cb367bdaa73f4459f397f2.zip |
Gnosis compilation contracts.
Diffstat (limited to 'test/compilationTests/gnosis/Tokens/StandardToken.sol')
-rw-r--r-- | test/compilationTests/gnosis/Tokens/StandardToken.sol | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/test/compilationTests/gnosis/Tokens/StandardToken.sol b/test/compilationTests/gnosis/Tokens/StandardToken.sol new file mode 100644 index 00000000..fc899ca6 --- /dev/null +++ b/test/compilationTests/gnosis/Tokens/StandardToken.sol @@ -0,0 +1,102 @@ +pragma solidity ^0.4.11; +import "../Tokens/Token.sol"; +import "../Utils/Math.sol"; + + +/// @title Standard token contract with overflow protection +contract StandardToken is Token { + using Math for *; + + /* + * Storage + */ + mapping (address => uint) balances; + mapping (address => mapping (address => uint)) allowances; + uint totalTokens; + + /* + * Public functions + */ + /// @dev Transfers sender's tokens to a given address. Returns success + /// @param to Address of token receiver + /// @param value Number of tokens to transfer + /// @return Was transfer successful? + function transfer(address to, uint value) + public + returns (bool) + { + if ( !balances[msg.sender].safeToSub(value) + || !balances[to].safeToAdd(value)) + return false; + balances[msg.sender] -= value; + balances[to] += value; + Transfer(msg.sender, to, value); + return true; + } + + /// @dev Allows allowed third party to transfer tokens from one address to another. Returns success + /// @param from Address from where tokens are withdrawn + /// @param to Address to where tokens are sent + /// @param value Number of tokens to transfer + /// @return Was transfer successful? + function transferFrom(address from, address to, uint value) + public + returns (bool) + { + if ( !balances[from].safeToSub(value) + || !allowances[from][msg.sender].safeToSub(value) + || !balances[to].safeToAdd(value)) + return false; + balances[from] -= value; + allowances[from][msg.sender] -= value; + balances[to] += value; + Transfer(from, to, value); + return true; + } + + /// @dev Sets approved amount of tokens for spender. Returns success + /// @param spender Address of allowed account + /// @param value Number of approved tokens + /// @return Was approval successful? + function approve(address spender, uint value) + public + returns (bool) + { + allowances[msg.sender][spender] = value; + Approval(msg.sender, spender, value); + return true; + } + + /// @dev Returns number of allowed tokens for given address + /// @param owner Address of token owner + /// @param spender Address of token spender + /// @return Remaining allowance for spender + function allowance(address owner, address spender) + public + constant + returns (uint) + { + return allowances[owner][spender]; + } + + /// @dev Returns number of tokens owned by given address + /// @param owner Address of token owner + /// @return Balance of owner + function balanceOf(address owner) + public + constant + returns (uint) + { + return balances[owner]; + } + + /// @dev Returns total supply of tokens + /// @return Total supply + function totalSupply() + public + constant + returns (uint) + { + return totalTokens; + } +} |