CORIONplatform / solidity

GNU General Public License v3.0
12 stars 9 forks source link

token _transfer(...) when amount<balanceOf(from)<(amount + fee) #156

Closed gundas closed 7 years ago

gundas commented 7 years ago

token.sol on rc branch:

_transfer(...) function handles the cases when balanceOf(from) == amount by decreasing the amount by _fee. However, it does not handle the case when amount < balanceOf(from) < amount + fee - it simply fails the require check:

 require( db.balanceOf(from) >= safeAdd(amount, _fee) );

Looks kind of inconsistent to me.

iFA88 commented 7 years ago

You need equal or greater balance as the sending amount with fee. I don't see any problem there. You mean like this:

        if( fee ) {
            (_success, _fee) = getTransactionFee(amount);
            require( _success );
            if ( db.balanceOf(from) == amount ) {
                _amount = safeSub(amount, _fee);
            }
        }
        require( db.balanceOf(from) >= safeAdd(_amount, _fee) );
gundas commented 7 years ago

I agree. Thus, my question is why the code additionally handles a special case when balance == amount, but not the case when balance is greater than amount but lower than amount + fee

iFA88 commented 7 years ago

If the address owner want to send her/his balance to an another address, then the fee is subtracted from the sending amount. If we don't have this, the users can not empty an address. :)

gundas commented 7 years ago

So, if I want to transfer amount=100 COR and the fee=5 COR, then:

iFA88 commented 7 years ago

yes, this is correct. I dont think that schould be weird. This IF is only when the sender want send all of his/her balance. If the balance is 1514717841 ION then he/she need to send 1514717841 ION. If he/she send1514717840 ION would be failed.

gundas commented 7 years ago

The code works as intended - so, I am closing this issue.