ERC827Token.sol 4.4 KB

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