SmartToken.sol 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. pragma solidity ^0.4.13;
  2. import "./StandardToken.sol";
  3. /**
  4. @title SmartToken, an extension of ERC20 token standard
  5. Implementation the SmartToken, following the ERC20 standard with extra
  6. methods to transfer value and data and execute calls in transfers and
  7. approvals.
  8. Uses OpenZeppelin StandardToken.
  9. */
  10. contract SmartToken is StandardToken {
  11. /**
  12. @dev `approveData` is an addition to ERC20 token methods. It allows to
  13. approve the transfer of value and execute a call with the sent data.
  14. Beware that changing an allowance with this method brings the risk that
  15. someone may use both the old and the new allowance by unfortunate
  16. transaction ordering. One possible solution to mitigate this race condition
  17. is to first reduce the spender's allowance to 0 and set the desired value
  18. afterwards:
  19. https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
  20. @param _spender The address that will spend the funds.
  21. @param _value The amount of tokens to be spent.
  22. @param _data ABI-encoded contract call to call `_to` address.
  23. @return true if the call function was executed successfully
  24. */
  25. function approveData(address _spender, uint256 _value, bytes _data) public returns (bool) {
  26. require(_spender != address(this));
  27. super.approve(_spender, _value);
  28. require(_spender.call(_data));
  29. return true;
  30. }
  31. /**
  32. @dev Addition to ERC20 token methods. Transfer tokens to a specified
  33. address and execute a call with the sent data on the same transaction
  34. @param _to address The address which you want to transfer to
  35. @param _value uint256 the amout of tokens to be transfered
  36. @param _data ABI-encoded contract call to call `_to` address.
  37. @return true if the call function was executed successfully
  38. */
  39. function transferData(address _to, uint256 _value, bytes _data) public returns (bool) {
  40. require(_to != address(this));
  41. require(_to.call(_data));
  42. super.transfer(_to, _value);
  43. return true;
  44. }
  45. /**
  46. @dev Addition to ERC20 token methods. Transfer tokens from one address to
  47. another and make a contract call on the same transaction
  48. @param _from The address which you want to send tokens from
  49. @param _to The address which you want to transfer to
  50. @param _value The amout of tokens to be transferred
  51. @param _data ABI-encoded contract call to call `_to` address.
  52. @return true if the call function was executed successfully
  53. */
  54. function transferDataFrom(address _from, address _to, uint256 _value, bytes _data) public returns (bool) {
  55. require(_to != address(this));
  56. require(_to.call(_data));
  57. super.transferFrom(_from, _to, _value);
  58. return true;
  59. }
  60. }