Skip to content

Commit 43ebb4f

Browse files
k06afrangio
authored andcommitted
ERC20 internal transfer method (#1370)
1 parent f4d6f40 commit 43ebb4f

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

contracts/token/ERC20/ERC20.sol

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@ contract ERC20 is IERC20 {
5858
* @param value The amount to be transferred.
5959
*/
6060
function transfer(address to, uint256 value) public returns (bool) {
61-
require(value <= _balances[msg.sender]);
62-
require(to != address(0));
63-
64-
_balances[msg.sender] = _balances[msg.sender].sub(value);
65-
_balances[to] = _balances[to].add(value);
66-
emit Transfer(msg.sender, to, value);
61+
_transfer(msg.sender, to, value);
6762
return true;
6863
}
6964

@@ -98,14 +93,10 @@ contract ERC20 is IERC20 {
9893
public
9994
returns (bool)
10095
{
101-
require(value <= _balances[from]);
10296
require(value <= _allowed[from][msg.sender]);
103-
require(to != address(0));
10497

105-
_balances[from] = _balances[from].sub(value);
106-
_balances[to] = _balances[to].add(value);
10798
_allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
108-
emit Transfer(from, to, value);
99+
_transfer(from, to, value);
109100
return true;
110101
}
111102

@@ -157,6 +148,21 @@ contract ERC20 is IERC20 {
157148
return true;
158149
}
159150

151+
/**
152+
* @dev Transfer token for a specified addresses
153+
* @param from The address to transfer from.
154+
* @param to The address to transfer to.
155+
* @param value The amount to be transferred.
156+
*/
157+
function _transfer(address from, address to, uint256 value) internal {
158+
require(value <= _balances[from]);
159+
require(to != address(0));
160+
161+
_balances[from] = _balances[from].sub(value);
162+
_balances[to] = _balances[to].add(value);
163+
emit Transfer(from, to, value);
164+
}
165+
160166
/**
161167
* @dev Internal function that mints an amount of the token and assigns it to
162168
* an account. This encapsulates the modification of balances such that the

0 commit comments

Comments
 (0)