solidity/std/StandardToken.sol

42 lines
1.2 KiB
Solidity
Raw Normal View History

2016-08-19 14:51:40 +00:00
import "./Token.sol";
2016-08-17 14:53:21 +00:00
2016-08-19 14:49:50 +00:00
contract StandardToken is Token {
2016-08-19 15:21:54 +00:00
uint256 public totalSupply;
mapping (address => uint256) public balanceOf;
2016-08-17 14:53:21 +00:00
mapping (address =>
2016-08-19 15:21:54 +00:00
mapping (address => uint256)) public allowance;
2016-08-17 14:53:21 +00:00
2016-08-19 14:49:50 +00:00
function StandardToken(address _initialOwner, uint256 _supply) {
2016-08-19 15:21:54 +00:00
totalSupply = _supply;
balanceOf[_initialOwner] = _supply;
2016-08-17 14:53:21 +00:00
}
function transfer(address _to, uint256 _value) returns (bool success) {
2016-08-24 19:06:54 +00:00
if (balanceOf[msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]) {
2016-08-19 15:21:54 +00:00
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
2016-08-17 14:53:21 +00:00
Transfer(msg.sender, _to, _value);
return true;
2016-08-24 19:20:59 +00:00
} else {
2016-08-17 14:53:21 +00:00
return false;
}
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
2016-08-24 19:06:54 +00:00
if (allowance[_from][msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]) {
2016-08-19 15:21:54 +00:00
allowance[_from][msg.sender] -= _value;
balanceOf[_to] += _value;
2016-08-17 14:53:21 +00:00
Transfer(_from, _to, _value);
return true;
2016-08-24 19:20:59 +00:00
} else {
2016-08-17 14:53:21 +00:00
return false;
}
}
function approve(address _spender, uint256 _value) returns (bool success) {
2016-08-19 15:21:54 +00:00
allowance[msg.sender][_spender] = _value;
2016-08-17 14:53:21 +00:00
Approval(msg.sender, _spender, _value);
return true;
}
}