solidity/std/StandardToken.sol

60 lines
1.5 KiB
Solidity
Raw Normal View History

pragma solidity ^0.4.22;
2016-11-02 11:32:55 +00:00
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 {
2017-01-20 18:41:25 +00:00
uint256 supply;
mapping (address => uint256) balance;
2016-08-17 14:53:21 +00:00
mapping (address =>
2017-01-20 18:41:25 +00:00
mapping (address => uint256)) m_allowance;
2016-08-17 14:53:21 +00:00
constructor(address _initialOwner, uint256 _supply) public {
2017-01-20 18:41:25 +00:00
supply = _supply;
balance[_initialOwner] = _supply;
}
function balanceOf(address _account) constant public returns (uint) {
2017-01-20 18:41:25 +00:00
return balance[_account];
}
function totalSupply() constant public returns (uint) {
2017-01-20 18:41:25 +00:00
return supply;
2016-08-17 14:53:21 +00:00
}
function transfer(address _to, uint256 _value) public returns (bool success) {
2017-05-02 12:33:54 +00:00
return doTransfer(msg.sender, _to, _value);
2017-01-23 13:58:07 +00:00
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
2017-01-23 13:58:07 +00:00
if (m_allowance[_from][msg.sender] >= _value) {
if (doTransfer(_from, _to, _value)) {
m_allowance[_from][msg.sender] -= _value;
}
2016-08-17 14:53:21 +00:00
return true;
2016-08-24 19:20:59 +00:00
} else {
2016-08-17 14:53:21 +00:00
return false;
}
}
2017-05-02 12:33:54 +00:00
function doTransfer(address _from, address _to, uint _value) internal returns (bool success) {
2017-01-23 13:58:07 +00:00
if (balance[_from] >= _value && balance[_to] + _value >= balance[_to]) {
balance[_from] -= _value;
2017-01-20 18:41:25 +00:00
balance[_to] += _value;
2018-02-16 16:32:30 +00:00
emit Transfer(_from, _to, _value);
2016-08-17 14:53:21 +00:00
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) public returns (bool success) {
2017-01-20 18:41:25 +00:00
m_allowance[msg.sender][_spender] = _value;
2018-02-16 16:32:30 +00:00
emit Approval(msg.sender, _spender, _value);
2016-08-17 14:53:21 +00:00
return true;
}
2017-01-20 18:41:25 +00:00
function allowance(address _owner, address _spender) constant public returns (uint256) {
2017-01-20 18:41:25 +00:00
return m_allowance[_owner][_spender];
}
2016-08-17 14:53:21 +00:00
}