StandardToken first version
This commit is contained in:
57
contracts/StandardToken.sol
Normal file
57
contracts/StandardToken.sol
Normal file
@ -0,0 +1,57 @@
|
||||
pragma solidity ^0.4.0;
|
||||
|
||||
import './ERC20.sol';
|
||||
import './SafeMath.sol';
|
||||
|
||||
/**
|
||||
* ERC20 token
|
||||
*
|
||||
* https://github.com/ethereum/EIPs/issues/20
|
||||
* Based on code by FirstBlood:
|
||||
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
|
||||
*/
|
||||
contract StandardToken is ERC20, SafeMath {
|
||||
|
||||
mapping(address => uint256) balances;
|
||||
mapping (address => mapping (address => uint256)) allowed;
|
||||
uint256 public totalSupply;
|
||||
|
||||
function transfer(address _to, uint256 _value) returns (bool success) {
|
||||
if (balances[msg.sender] < _value) {
|
||||
throw;
|
||||
}
|
||||
balances[msg.sender] = safeSub(balances[msg.sender], _value);
|
||||
balances[_to] = safeAdd(balances[_to], _value);
|
||||
Transfer(msg.sender, _to, _value);
|
||||
return true;
|
||||
}
|
||||
|
||||
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
|
||||
var _allowance = allowed[_from][msg.sender];
|
||||
if (balances[_from] < _value ||
|
||||
_allowance < _value)) {
|
||||
throw;
|
||||
}
|
||||
|
||||
balances[_to] = safeAdd(balances[_to], _value);
|
||||
balances[_from] = safeSub(balances[_from], _value);
|
||||
allowed[_from][msg.sender] = safeSub(_allowance, _value);
|
||||
Transfer(_from, _to, _value);
|
||||
return true;
|
||||
}
|
||||
|
||||
function balanceOf(address _owner) constant returns (uint256 balance) {
|
||||
return balances[_owner];
|
||||
}
|
||||
|
||||
function approve(address _spender, uint256 _value) returns (bool success) {
|
||||
allowed[msg.sender][_spender] = _value;
|
||||
Approval(msg.sender, _spender, _value);
|
||||
return true;
|
||||
}
|
||||
|
||||
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
|
||||
return allowed[_owner][_spender];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user