diff --git a/contracts/mocks/ERC827TokenMock.sol b/contracts/mocks/ERC827TokenMock.sol index 1bc91174e..fbba4b5a5 100644 --- a/contracts/mocks/ERC827TokenMock.sol +++ b/contracts/mocks/ERC827TokenMock.sol @@ -1,11 +1,11 @@ pragma solidity ^0.4.13; -import '../token/ERC827.sol'; +import '../token/ERC827Token.sol'; // mock class using ERC827 Token -contract ERC827TokenMock is ERC827 { +contract ERC827TokenMock is ERC827Token { function ERC827TokenMock(address initialAccount, uint256 initialBalance) { balances[initialAccount] = initialBalance; diff --git a/contracts/token/ERC827.sol b/contracts/token/ERC827.sol index 472b82b07..6bd217e4f 100644 --- a/contracts/token/ERC827.sol +++ b/contracts/token/ERC827.sol @@ -1,125 +1,26 @@ pragma solidity ^0.4.13; -import "./StandardToken.sol"; +import "./ERC20.sol"; /** - @title ERC827, an extension of ERC20 token standard + @title ERC827 interface, an extension of ERC20 token standard - Implementation the ERC827, following the ERC20 standard with extra + Interface of a ERC827 token, following the ERC20 standard with extra methods to transfer value and data and execute calls in transfers and approvals. - Uses OpenZeppelin StandardToken. */ -contract ERC827 is StandardToken { +contract ERC827 is ERC20 { - /** - @dev Addition to ERC20 token methods. It allows to - approve the transfer of value and execute a call with the sent data. + function approve( + address _spender, uint256 _value, bytes _data + ) public returns (bool); - Beware that changing an allowance with this method brings the risk that - someone may use both the old and the new allowance by unfortunate - transaction ordering. One possible solution to mitigate this race condition - is to first reduce the spender's allowance to 0 and set the desired value - afterwards: - https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + function transfer( + address _to, uint256 _value, bytes _data + ) public returns (bool); - @param _spender The address that will spend the funds. - @param _value The amount of tokens to be spent. - @param _data ABI-encoded contract call to call `_to` address. - - @return true if the call function was executed successfully - */ - function approve(address _spender, uint256 _value, bytes _data) public returns (bool) { - require(_spender != address(this)); - - super.approve(_spender, _value); - - require(_spender.call(_data)); - - return true; - } - - /** - @dev Addition to ERC20 token methods. Transfer tokens to a specified - address and execute a call with the sent data on the same transaction - - @param _to address The address which you want to transfer to - @param _value uint256 the amout of tokens to be transfered - @param _data ABI-encoded contract call to call `_to` address. - - @return true if the call function was executed successfully - */ - function transfer(address _to, uint256 _value, bytes _data) public returns (bool) { - require(_to != address(this)); - - super.transfer(_to, _value); - - require(_to.call(_data)); - return true; - } - - /** - @dev Addition to ERC20 token methods. Transfer tokens from one address to - another and make a contract call on the same transaction - - @param _from The address which you want to send tokens from - @param _to The address which you want to transfer to - @param _value The amout of tokens to be transferred - @param _data ABI-encoded contract call to call `_to` address. - - @return true if the call function was executed successfully - */ - function transferFrom(address _from, address _to, uint256 _value, bytes _data) public returns (bool) { - require(_to != address(this)); - - super.transferFrom(_from, _to, _value); - - require(_to.call(_data)); - return true; - } - - /** - * @dev Addition to StandardToken methods. Increase the amount of tokens that - * an owner allowed to a spender and execute a call with the sent data. - * - * approve should be called when allowed[_spender] == 0. To increment - * allowed value is better to use this function to avoid 2 calls (and wait until - * the first transaction is mined) - * From MonolithDAO Token.sol - * @param _spender The address which will spend the funds. - * @param _addedValue The amount of tokens to increase the allowance by. - * @param _data ABI-encoded contract call to call `_spender` address. - */ - function increaseApproval(address _spender, uint _addedValue, bytes _data) public returns (bool) { - require(_spender != address(this)); - - super.approve(_spender, _addedValue); - - require(_spender.call(_data)); - - return true; - } - - /** - * @dev Addition to StandardToken methods. Decrease the amount of tokens that - * an owner allowed to a spender and execute a call with the sent data. - * - * approve should be called when allowed[_spender] == 0. To decrement - * allowed value is better to use this function to avoid 2 calls (and wait until - * the first transaction is mined) - * From MonolithDAO Token.sol - * @param _spender The address which will spend the funds. - * @param _subtractedValue The amount of tokens to decrease the allowance by. - * @param _data ABI-encoded contract call to call `_spender` address. - */ - function decreaseApproval(address _spender, uint _subtractedValue, bytes _data) public returns (bool) { - require(_spender != address(this)); - - super.decreaseApproval(_spender, _subtractedValue); - - require(_spender.call(_data)); - - return true; - } + function transferFrom( + address _from, address _to, uint256 _value, bytes _data + ) public returns (bool); } diff --git a/contracts/token/ERC827Token.sol b/contracts/token/ERC827Token.sol new file mode 100644 index 000000000..3cb22943d --- /dev/null +++ b/contracts/token/ERC827Token.sol @@ -0,0 +1,126 @@ +pragma solidity ^0.4.13; + +import "./ERC827.sol"; +import "./StandardToken.sol"; + +/** + @title ERC827, an extension of ERC20 token standard + + Implementation the ERC827, following the ERC20 standard with extra + methods to transfer value and data and execute calls in transfers and + approvals. + Uses OpenZeppelin StandardToken. + */ +contract ERC827Token is ERC827, StandardToken { + + /** + @dev Addition to ERC20 token methods. It allows to + approve the transfer of value and execute a call with the sent data. + + Beware that changing an allowance with this method brings the risk that + someone may use both the old and the new allowance by unfortunate + transaction ordering. One possible solution to mitigate this race condition + is to first reduce the spender's allowance to 0 and set the desired value + afterwards: + https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + + @param _spender The address that will spend the funds. + @param _value The amount of tokens to be spent. + @param _data ABI-encoded contract call to call `_to` address. + + @return true if the call function was executed successfully + */ + function approve(address _spender, uint256 _value, bytes _data) public returns (bool) { + require(_spender != address(this)); + + super.approve(_spender, _value); + + require(_spender.call(_data)); + + return true; + } + + /** + @dev Addition to ERC20 token methods. Transfer tokens to a specified + address and execute a call with the sent data on the same transaction + + @param _to address The address which you want to transfer to + @param _value uint256 the amout of tokens to be transfered + @param _data ABI-encoded contract call to call `_to` address. + + @return true if the call function was executed successfully + */ + function transfer(address _to, uint256 _value, bytes _data) public returns (bool) { + require(_to != address(this)); + + super.transfer(_to, _value); + + require(_to.call(_data)); + return true; + } + + /** + @dev Addition to ERC20 token methods. Transfer tokens from one address to + another and make a contract call on the same transaction + + @param _from The address which you want to send tokens from + @param _to The address which you want to transfer to + @param _value The amout of tokens to be transferred + @param _data ABI-encoded contract call to call `_to` address. + + @return true if the call function was executed successfully + */ + function transferFrom(address _from, address _to, uint256 _value, bytes _data) public returns (bool) { + require(_to != address(this)); + + super.transferFrom(_from, _to, _value); + + require(_to.call(_data)); + return true; + } + + /** + * @dev Addition to StandardToken methods. Increase the amount of tokens that + * an owner allowed to a spender and execute a call with the sent data. + * + * approve should be called when allowed[_spender] == 0. To increment + * allowed value is better to use this function to avoid 2 calls (and wait until + * the first transaction is mined) + * From MonolithDAO Token.sol + * @param _spender The address which will spend the funds. + * @param _addedValue The amount of tokens to increase the allowance by. + * @param _data ABI-encoded contract call to call `_spender` address. + */ + function increaseApproval(address _spender, uint _addedValue, bytes _data) public returns (bool) { + require(_spender != address(this)); + + super.approve(_spender, _addedValue); + + require(_spender.call(_data)); + + return true; + } + + /** + * @dev Addition to StandardToken methods. Decrease the amount of tokens that + * an owner allowed to a spender and execute a call with the sent data. + * + * approve should be called when allowed[_spender] == 0. To decrement + * allowed value is better to use this function to avoid 2 calls (and wait until + * the first transaction is mined) + * From MonolithDAO Token.sol + * @param _spender The address which will spend the funds. + * @param _subtractedValue The amount of tokens to decrease the allowance by. + * @param _data ABI-encoded contract call to call `_spender` address. + */ + function decreaseApproval(address _spender, uint _subtractedValue, bytes _data) public returns (bool) { + require(_spender != address(this)); + + super.decreaseApproval(_spender, _subtractedValue); + + require(_spender.call(_data)); + + return true; + } + +}