Moving business logic preconditions to the beginning of the function.

This commit is contained in:
Dan Phifer
2017-09-23 11:57:29 +08:00
parent 158a7a881d
commit e70dd18734
3 changed files with 7 additions and 6 deletions

View File

@ -16,6 +16,9 @@ contract BurnableToken is StandardToken {
*/
function burn(uint256 _value) public {
require(_value > 0);
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);