From e5e0fb256267d943b28190b2962d6c7c695926c6 Mon Sep 17 00:00:00 2001 From: rtroncosogar Date: Thu, 1 Nov 2018 22:04:16 -0300 Subject: [PATCH 1/3] Updated TransferFrom function It seems more logical than before, cause makes more sense if first we discount the value available and then that value is transferred --- contracts/eip20/EIP20.sol | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/contracts/eip20/EIP20.sol b/contracts/eip20/EIP20.sol index d5e510e6..69ba4088 100644 --- a/contracts/eip20/EIP20.sol +++ b/contracts/eip20/EIP20.sol @@ -45,15 +45,13 @@ contract EIP20 is EIP20Interface { } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { - uint256 allowance = allowed[_from][msg.sender]; - require(balances[_from] >= _value && allowance >= _value); - balances[_to] += _value; - balances[_from] -= _value; - if (allowance < MAX_UINT256) { - allowed[_from][msg.sender] -= _value; - } - emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars - return true; + uint256 allowance = allowed[_from][msg.sender]; + require(balances[_from] >= _value && allowance >= _value && allowed < MAX_UINT256); + allowed[_from][msg.sender] -= _value; + balances[_from] -= _value; + balances[_to] += _value; + emit Transfer(_from, _to, _value); + return true; } function balanceOf(address _owner) public view returns (uint256 balance) { From 081c5fff6688c0145a33d54c830ecd342dc6cdb6 Mon Sep 17 00:00:00 2001 From: rtroncosogar Date: Thu, 1 Nov 2018 22:05:46 -0300 Subject: [PATCH 2/3] Added comments in the emit sentence --- contracts/eip20/EIP20.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/eip20/EIP20.sol b/contracts/eip20/EIP20.sol index 69ba4088..267fcc01 100644 --- a/contracts/eip20/EIP20.sol +++ b/contracts/eip20/EIP20.sol @@ -50,7 +50,7 @@ contract EIP20 is EIP20Interface { allowed[_from][msg.sender] -= _value; balances[_from] -= _value; balances[_to] += _value; - emit Transfer(_from, _to, _value); + emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars return true; } From ec81633017349934aff23a84a96cb0db15648473 Mon Sep 17 00:00:00 2001 From: rtroncosogar Date: Thu, 1 Nov 2018 23:32:06 -0300 Subject: [PATCH 3/3] Improved logic in "TransferFrom" --- contracts/eip20/EIP20.sol | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/eip20/EIP20.sol b/contracts/eip20/EIP20.sol index 267fcc01..ccc09ec1 100644 --- a/contracts/eip20/EIP20.sol +++ b/contracts/eip20/EIP20.sol @@ -45,13 +45,13 @@ contract EIP20 is EIP20Interface { } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { - uint256 allowance = allowed[_from][msg.sender]; - require(balances[_from] >= _value && allowance >= _value && allowed < MAX_UINT256); - allowed[_from][msg.sender] -= _value; - balances[_from] -= _value; - balances[_to] += _value; - emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars - return true; + uint256 allowance = allowed[_from][msg.sender]; + require(balances[_from] >= _value && allowance >= _value && allowance < MAX_UINT256); + allowed[_from][msg.sender] -= _value; + balances[_from] -= _value; + balances[_to] += _value; + emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars + return true; } function balanceOf(address _owner) public view returns (uint256 balance) {