Created
December 20, 2016 13:59
-
-
Save AnthonyAkentiev/14791dee17996c852ecd510ff3cdc066 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Mixing safe math (that throws) with return true/false is not a good coding style | |
// This is your version: | |
function transfer(address _to, uint _value) returns (bool success) { | |
if ((msg.sender == owner) || (tradeable == true)) { | |
balances[msg.sender] = safeSub(balances[msg.sender], _value); | |
balances[_to] = safeAdd(balances[_to], _value); | |
// calling an event | |
Transfer(msg.sender, _to, _value); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
// This is how it should be rewritten: | |
function transfer(address _to, uint256 _value) returns (bool success) { | |
// checking for wraps (useful only if token count can be more than 2^256 - 1) | |
if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) { | |
balances[msg.sender] -= _value; | |
balances[_to] += _value; | |
Transfer(msg.sender, _to, _value); | |
return true; | |
} else { return false; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment