BaseToken.sol 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. pragma solidity ^0.4.0;
  2. // Everything throws instead of returning false on failure.
  3. import './ERC20.sol';
  4. /**
  5. * ERC 20 token
  6. *
  7. * https://github.com/ethereum/EIPs/issues/20
  8. * Based on code by FirstBlood:
  9. * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
  10. */
  11. contract BaseToken is ERC20 {
  12. mapping(address => uint256) balances;
  13. mapping (address => mapping (address => uint256)) allowed;
  14. uint256 public totalSupply;
  15. function transfer(address _to, uint256 _value) returns (bool success) {
  16. if (balances[msg.sender] >= _value &&
  17. balances[_to] + _value > balances[_to]) {
  18. balances[msg.sender] -= _value;
  19. balances[_to] += _value;
  20. Transfer(msg.sender, _to, _value);
  21. return true;
  22. } else { return false; }
  23. }
  24. function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
  25. if (balances[_from] >= _value &&
  26. allowed[_from][msg.sender] >= _value &&
  27. balances[_to] + _value > balances[_to]) {
  28. balances[_to] += _value;
  29. balances[_from] -= _value;
  30. allowed[_from][msg.sender] -= _value;
  31. Transfer(_from, _to, _value);
  32. return true;
  33. } else { return false; }
  34. }
  35. function balanceOf(address _owner) constant returns (uint256 balance) {
  36. return balances[_owner];
  37. }
  38. function approve(address _spender, uint256 _value) returns (bool success) {
  39. allowed[msg.sender][_spender] = _value;
  40. Approval(msg.sender, _spender, _value);
  41. return true;
  42. }
  43. function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
  44. return allowed[_owner][_spender];
  45. }
  46. }