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