ERC827Token.sol 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* solium-disable security/no-low-level-calls */
  2. pragma solidity ^0.4.21;
  3. import "./ERC827.sol";
  4. import "../ERC20/StandardToken.sol";
  5. /**
  6. * @title ERC827, an extension of ERC20 token standard
  7. *
  8. * @dev Implementation the ERC827, following the ERC20 standard with extra
  9. * @dev methods to transfer value and data and execute calls in transfers and
  10. * @dev approvals.
  11. *
  12. * @dev Uses OpenZeppelin StandardToken.
  13. */
  14. contract ERC827Token is ERC827, StandardToken {
  15. /**
  16. * @dev Addition to ERC20 token methods. It allows to
  17. * @dev approve the transfer of value and execute a call with the sent data.
  18. *
  19. * @dev Beware that changing an allowance with this method brings the risk that
  20. * @dev someone may use both the old and the new allowance by unfortunate
  21. * @dev transaction ordering. One possible solution to mitigate this race condition
  22. * @dev is to first reduce the spender's allowance to 0 and set the desired value
  23. * @dev afterwards:
  24. * @dev https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
  25. *
  26. * @param _spender The address that will spend the funds.
  27. * @param _value The amount of tokens to be spent.
  28. * @param _data ABI-encoded contract call to call `_to` address.
  29. *
  30. * @return true if the call function was executed successfully
  31. */
  32. function approve(address _spender, uint256 _value, bytes _data) public returns (bool) {
  33. require(_spender != address(this));
  34. super.approve(_spender, _value);
  35. require(_spender.call(_data));
  36. return true;
  37. }
  38. /**
  39. * @dev Addition to ERC20 token methods. Transfer tokens to a specified
  40. * @dev address and execute a call with the sent data on the same transaction
  41. *
  42. * @param _to address The address which you want to transfer to
  43. * @param _value uint256 the amout of tokens to be transfered
  44. * @param _data ABI-encoded contract call to call `_to` address.
  45. *
  46. * @return true if the call function was executed successfully
  47. */
  48. function transfer(address _to, uint256 _value, bytes _data) public returns (bool) {
  49. require(_to != address(this));
  50. super.transfer(_to, _value);
  51. require(_to.call(_data));
  52. return true;
  53. }
  54. /**
  55. * @dev Addition to ERC20 token methods. Transfer tokens from one address to
  56. * @dev another and make a contract call on the same transaction
  57. *
  58. * @param _from The address which you want to send tokens from
  59. * @param _to The address which you want to transfer to
  60. * @param _value The amout of tokens to be transferred
  61. * @param _data ABI-encoded contract call to call `_to` address.
  62. *
  63. * @return true if the call function was executed successfully
  64. */
  65. function transferFrom(
  66. address _from,
  67. address _to,
  68. uint256 _value,
  69. bytes _data
  70. )
  71. public returns (bool)
  72. {
  73. require(_to != address(this));
  74. super.transferFrom(_from, _to, _value);
  75. require(_to.call(_data));
  76. return true;
  77. }
  78. /**
  79. * @dev Addition to StandardToken methods. Increase the amount of tokens that
  80. * @dev an owner allowed to a spender and execute a call with the sent data.
  81. *
  82. * @dev approve should be called when allowed[_spender] == 0. To increment
  83. * @dev allowed value is better to use this function to avoid 2 calls (and wait until
  84. * @dev the first transaction is mined)
  85. * @dev From MonolithDAO Token.sol
  86. *
  87. * @param _spender The address which will spend the funds.
  88. * @param _addedValue The amount of tokens to increase the allowance by.
  89. * @param _data ABI-encoded contract call to call `_spender` address.
  90. */
  91. function increaseApproval(address _spender, uint _addedValue, bytes _data) public returns (bool) {
  92. require(_spender != address(this));
  93. super.increaseApproval(_spender, _addedValue);
  94. require(_spender.call(_data));
  95. return true;
  96. }
  97. /**
  98. * @dev Addition to StandardToken methods. Decrease the amount of tokens that
  99. * @dev an owner allowed to a spender and execute a call with the sent data.
  100. *
  101. * @dev approve should be called when allowed[_spender] == 0. To decrement
  102. * @dev allowed value is better to use this function to avoid 2 calls (and wait until
  103. * @dev the first transaction is mined)
  104. * @dev From MonolithDAO Token.sol
  105. *
  106. * @param _spender The address which will spend the funds.
  107. * @param _subtractedValue The amount of tokens to decrease the allowance by.
  108. * @param _data ABI-encoded contract call to call `_spender` address.
  109. */
  110. function decreaseApproval(address _spender, uint _subtractedValue, bytes _data) public returns (bool) {
  111. require(_spender != address(this));
  112. super.decreaseApproval(_spender, _subtractedValue);
  113. require(_spender.call(_data));
  114. return true;
  115. }
  116. }