diff --git a/contracts/token/ERC20/ERC20.sol b/contracts/token/ERC20/ERC20.sol index 8fd420a2909..3d18c1dec67 100644 --- a/contracts/token/ERC20/ERC20.sol +++ b/contracts/token/ERC20/ERC20.sol @@ -58,12 +58,7 @@ contract ERC20 is IERC20 { * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { - require(value <= _balances[msg.sender]); - require(to != address(0)); - - _balances[msg.sender] = _balances[msg.sender].sub(value); - _balances[to] = _balances[to].add(value); - emit Transfer(msg.sender, to, value); + _transfer(msg.sender, to, value); return true; } @@ -98,14 +93,10 @@ contract ERC20 is IERC20 { public returns (bool) { - require(value <= _balances[from]); require(value <= _allowed[from][msg.sender]); - require(to != address(0)); - _balances[from] = _balances[from].sub(value); - _balances[to] = _balances[to].add(value); _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); - emit Transfer(from, to, value); + _transfer(from, to, value); return true; } @@ -157,6 +148,21 @@ contract ERC20 is IERC20 { return true; } + /** + * @dev Transfer token for a specified addresses + * @param from The address to transfer from. + * @param to The address to transfer to. + * @param value The amount to be transferred. + */ + function _transfer(address from, address to, uint256 value) internal { + require(value <= _balances[from]); + require(to != address(0)); + + _balances[from] = _balances[from].sub(value); + _balances[to] = _balances[to].add(value); + emit Transfer(from, to, value); + } + /** * @dev Internal function that mints an amount of the token and assigns it to * an account. This encapsulates the modification of balances such that the