BaseToken.sol 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 original code by FirstBlood:
  9. * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
  10. */
  11. contract BaseToken is ERC20 {
  12. function transfer(address _to, uint256 _value) returns (bool success) {
  13. if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
  14. balances[msg.sender] -= _value;
  15. balances[_to] += _value;
  16. Transfer(msg.sender, _to, _value);
  17. return true;
  18. } else { return false; }
  19. }
  20. function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
  21. if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
  22. balances[_to] += _value;
  23. balances[_from] -= _value;
  24. allowed[_from][msg.sender] -= _value;
  25. Transfer(_from, _to, _value);
  26. return true;
  27. } else { return false; }
  28. }
  29. function balanceOf(address _owner) constant returns (uint256 balance) {
  30. return balances[_owner];
  31. }
  32. function approve(address _spender, uint256 _value) returns (bool success) {
  33. allowed[msg.sender][_spender] = _value;
  34. Approval(msg.sender, _spender, _value);
  35. return true;
  36. }
  37. function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
  38. return allowed[_owner][_spender];
  39. }
  40. mapping(address => uint256) balances;
  41. mapping (address => mapping (address => uint256)) allowed;
  42. uint256 public totalSupply;
  43. }