2017-07-12 13:46:33 +00:00
|
|
|
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;
|
2018-06-27 08:35:38 +00:00
|
|
|
emit Transfer(msg.sender, to, value);
|
2017-07-12 13:46:33 +00:00
|
|
|
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;
|
2018-06-27 08:35:38 +00:00
|
|
|
emit Transfer(from, to, value);
|
2017-07-12 13:46:33 +00:00
|
|
|
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;
|
2018-06-27 08:35:38 +00:00
|
|
|
emit Approval(msg.sender, spender, value);
|
2017-07-12 13:46:33 +00:00
|
|
|
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
|
2018-07-02 09:14:28 +00:00
|
|
|
view
|
2017-07-12 13:46:33 +00:00
|
|
|
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
|
2018-07-02 09:14:28 +00:00
|
|
|
view
|
2017-07-12 13:46:33 +00:00
|
|
|
returns (uint)
|
|
|
|
{
|
|
|
|
return balances[owner];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @dev Returns total supply of tokens
|
|
|
|
/// @return Total supply
|
|
|
|
function totalSupply()
|
|
|
|
public
|
2018-07-02 09:14:28 +00:00
|
|
|
view
|
2017-07-12 13:46:33 +00:00
|
|
|
returns (uint)
|
|
|
|
{
|
|
|
|
return totalTokens;
|
|
|
|
}
|
|
|
|
}
|