Skip to content

Instantly share code, notes, and snippets.

@Georgi87
Created October 27, 2016 15:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Georgi87/4db9ba0454b84f48919658a0d37e722e to your computer and use it in GitHub Desktop.
Save Georgi87/4db9ba0454b84f48919658a0d37e722e to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.0;
import "Tokens/AbstractToken.sol";
/// @title Standard token contract - Standard token interface implementation.
contract StandardToken is Token {
/*
* Data structures
*/
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply;
/*
* Read and write 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 success Returns success of function call.
function transfer(address _to, uint256 _value)
public
returns (bool success)
{
if (balances[msg.sender] < _value) {
// Balance too low
throw;
}
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 success Returns success of function call.
function transferFrom(address _from, address _to, uint256 _value)
public
returns (bool success)
{
if (balances[_from] < _value || allowed[_from][msg.sender] < _value) {
// Balance or allowance too low
throw;
}
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _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 success Returns success of function call.
function approve(address _spender, uint256 _value)
public
returns (bool success)
{
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/*
* Read functions
*/
/// @dev Returns number of allowed tokens for given address.
/// @param _owner Address of token owner.
/// @param _spender Address of token spender.
/// @return remaining Returns remaining allowance for spender.
function allowance(address _owner, address _spender)
constant
public
returns (uint256 remaining)
{
return allowed[_owner][_spender];
}
/// @dev Returns number of tokens owned by given address.
/// @param _owner Address of token owner.
/// @return balance Returns balance of owner.
function balanceOf(address _owner)
constant
public
returns (uint256 balance)
{
return balances[_owner];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment