Add StandardBurnableToken implementation (#870)
* Add StandardBurnableToken implementation BurnableToken that extends from StandardToken and adds a burnFrom method that decrements allowance. Equivalent to a transferFrom plus burn in a single operation. * Return event object from expectEvent helper * Add comment on Approval event in burnFrom function * Improvements on burnable token tests - Inject initial balance as a parameter to the behaviour - Use expectEvent helper for assertions on events - Use chai bignumber for numbers - Change to bdd-style assertions
This commit is contained in:
committed by
GitHub
parent
9e1c934ffd
commit
0926729c8f
@ -16,14 +16,17 @@ contract BurnableToken is BasicToken {
|
||||
* @param _value The amount of token to be burned.
|
||||
*/
|
||||
function burn(uint256 _value) public {
|
||||
require(_value <= balances[msg.sender]);
|
||||
_burn(msg.sender, _value);
|
||||
}
|
||||
|
||||
function _burn(address _who, uint256 _value) internal {
|
||||
require(_value <= balances[_who]);
|
||||
// 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);
|
||||
balances[_who] = balances[_who].sub(_value);
|
||||
totalSupply_ = totalSupply_.sub(_value);
|
||||
emit Burn(burner, _value);
|
||||
emit Transfer(burner, address(0), _value);
|
||||
emit Burn(_who, _value);
|
||||
emit Transfer(_who, address(0), _value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user