123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- /* solium-disable security/no-low-level-calls */
- pragma solidity ^0.4.23;
- import "./ERC827.sol";
- import "../ERC20/StandardToken.sol";
- /**
- * @title ERC827, an extension of ERC20 token standard
- *
- * @dev Implementation the ERC827, following the ERC20 standard with extra
- * @dev methods to transfer value and data and execute calls in transfers and
- * @dev approvals.
- *
- * @dev Uses OpenZeppelin StandardToken.
- */
- contract ERC827Token is ERC827, StandardToken {
- /**
- * @dev Addition to ERC20 token methods. It allows to
- * @dev approve the transfer of value and execute a call with the sent data.
- *
- * @dev Beware that changing an allowance with this method brings the risk that
- * @dev someone may use both the old and the new allowance by unfortunate
- * @dev transaction ordering. One possible solution to mitigate this race condition
- * @dev is to first reduce the spender's allowance to 0 and set the desired value
- * @dev afterwards:
- * @dev 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 approveAndCall(
- address _spender,
- uint256 _value,
- bytes _data
- )
- public
- payable
- returns (bool)
- {
- require(_spender != address(this));
- super.approve(_spender, _value);
- // solium-disable-next-line security/no-call-value
- require(_spender.call.value(msg.value)(_data));
- return true;
- }
- /**
- * @dev Addition to ERC20 token methods. Transfer tokens to a specified
- * @dev 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 transferAndCall(
- address _to,
- uint256 _value,
- bytes _data
- )
- public
- payable
- returns (bool)
- {
- require(_to != address(this));
- super.transfer(_to, _value);
- // solium-disable-next-line security/no-call-value
- require(_to.call.value(msg.value)(_data));
- return true;
- }
- /**
- * @dev Addition to ERC20 token methods. Transfer tokens from one address to
- * @dev 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 transferFromAndCall(
- address _from,
- address _to,
- uint256 _value,
- bytes _data
- )
- public payable returns (bool)
- {
- require(_to != address(this));
- super.transferFrom(_from, _to, _value);
- // solium-disable-next-line security/no-call-value
- require(_to.call.value(msg.value)(_data));
- return true;
- }
- /**
- * @dev Addition to StandardToken methods. Increase the amount of tokens that
- * @dev an owner allowed to a spender and execute a call with the sent data.
- *
- * @dev approve should be called when allowed[_spender] == 0. To increment
- * @dev allowed value is better to use this function to avoid 2 calls (and wait until
- * @dev the first transaction is mined)
- * @dev 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 increaseApprovalAndCall(
- address _spender,
- uint _addedValue,
- bytes _data
- )
- public
- payable
- returns (bool)
- {
- require(_spender != address(this));
- super.increaseApproval(_spender, _addedValue);
- // solium-disable-next-line security/no-call-value
- require(_spender.call.value(msg.value)(_data));
- return true;
- }
- /**
- * @dev Addition to StandardToken methods. Decrease the amount of tokens that
- * @dev an owner allowed to a spender and execute a call with the sent data.
- *
- * @dev approve should be called when allowed[_spender] == 0. To decrement
- * @dev allowed value is better to use this function to avoid 2 calls (and wait until
- * @dev the first transaction is mined)
- * @dev 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 decreaseApprovalAndCall(
- address _spender,
- uint _subtractedValue,
- bytes _data
- )
- public
- payable
- returns (bool)
- {
- require(_spender != address(this));
- super.decreaseApproval(_spender, _subtractedValue);
- // solium-disable-next-line security/no-call-value
- require(_spender.call.value(msg.value)(_data));
- return true;
- }
- }
|