ERC20 internal transfer method (#1370)

(cherry picked from commit 43ebb4fc43)
This commit is contained in:
Anton Bukov
2018-10-03 00:15:59 +03:00
committed by Nicolás Venturo
parent 38ca422170
commit ffeae0d83e

View File

@ -59,12 +59,7 @@ contract ERC20 is IERC20 {
* @param value The amount to be transferred. * @param value The amount to be transferred.
*/ */
function transfer(address to, uint256 value) public returns (bool) { function transfer(address to, uint256 value) public returns (bool) {
require(value <= _balances[msg.sender]); _transfer(msg.sender, to, value);
require(to != address(0));
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true; return true;
} }
@ -99,14 +94,10 @@ contract ERC20 is IERC20 {
public public
returns (bool) returns (bool)
{ {
require(value <= _balances[from]);
require(value <= _allowed[from][msg.sender]); 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); _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
emit Transfer(from, to, value); _transfer(from, to, value);
return true; return true;
} }
@ -158,6 +149,21 @@ contract ERC20 is IERC20 {
return true; 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 * @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 * an account. This encapsulates the modification of balances such that the