ERC827.sol 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. pragma solidity ^0.4.13;
  2. import "./StandardToken.sol";
  3. /**
  4. @title ERC827, an extension of ERC20 token standard
  5. Implementation the ERC827, 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 ERC827 is StandardToken {
  11. /**
  12. @dev 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 approve(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 transfer(address _to, uint256 _value, bytes _data) public returns (bool) {
  40. require(_to != address(this));
  41. super.transfer(_to, _value);
  42. require(_to.call(_data));
  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 transferFrom(address _from, address _to, uint256 _value, bytes _data) public returns (bool) {
  55. require(_to != address(this));
  56. super.transferFrom(_from, _to, _value);
  57. require(_to.call(_data));
  58. return true;
  59. }
  60. /**
  61. * @dev Addition to StandardToken methods. Increase the amount of tokens that
  62. * an owner allowed to a spender and execute a call with the sent data.
  63. *
  64. * approve should be called when allowed[_spender] == 0. To increment
  65. * allowed value is better to use this function to avoid 2 calls (and wait until
  66. * the first transaction is mined)
  67. * From MonolithDAO Token.sol
  68. * @param _spender The address which will spend the funds.
  69. * @param _addedValue The amount of tokens to increase the allowance by.
  70. * @param _data ABI-encoded contract call to call `_spender` address.
  71. */
  72. function increaseApproval(address _spender, uint _addedValue, bytes _data) public returns (bool) {
  73. require(_spender != address(this));
  74. super.approve(_spender, _addedValue);
  75. require(_spender.call(_data));
  76. return true;
  77. }
  78. /**
  79. * @dev Addition to StandardToken methods. Decrease the amount of tokens that
  80. * an owner allowed to a spender and execute a call with the sent data.
  81. *
  82. * approve should be called when allowed[_spender] == 0. To decrement
  83. * allowed value is better to use this function to avoid 2 calls (and wait until
  84. * the first transaction is mined)
  85. * From MonolithDAO Token.sol
  86. * @param _spender The address which will spend the funds.
  87. * @param _subtractedValue The amount of tokens to decrease the allowance by.
  88. * @param _data ABI-encoded contract call to call `_spender` address.
  89. */
  90. function decreaseApproval(address _spender, uint _subtractedValue, bytes _data) public returns (bool) {
  91. require(_spender != address(this));
  92. super.decreaseApproval(_spender, _subtractedValue);
  93. require(_spender.call(_data));
  94. return true;
  95. }
  96. }