BurnableToken.sol 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. pragma solidity ^0.4.24;
  2. import "./StandardToken.sol";
  3. /**
  4. * @title Burnable Token
  5. * @dev Token that can be irreversibly burned (destroyed).
  6. */
  7. contract BurnableToken is StandardToken {
  8. event Burn(address indexed burner, uint256 value);
  9. /**
  10. * @dev Burns a specific amount of tokens.
  11. * @param _value The amount of token to be burned.
  12. */
  13. function burn(uint256 _value) public {
  14. _burn(msg.sender, _value);
  15. }
  16. /**
  17. * @dev Burns a specific amount of tokens from the target address and decrements allowance
  18. * @param _from address The address which you want to send tokens from
  19. * @param _value uint256 The amount of token to be burned
  20. */
  21. function burnFrom(address _from, uint256 _value) public {
  22. require(_value <= allowed[_from][msg.sender]);
  23. // Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted,
  24. // this function needs to emit an event with the updated approval.
  25. allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
  26. _burn(_from, _value);
  27. }
  28. function _burn(address _who, uint256 _value) internal {
  29. require(_value <= balances[_who]);
  30. // no need to require value <= totalSupply, since that would imply the
  31. // sender's balance is greater than the totalSupply, which *should* be an assertion failure
  32. balances[_who] = balances[_who].sub(_value);
  33. totalSupply_ = totalSupply_.sub(_value);
  34. emit Burn(_who, _value);
  35. emit Transfer(_who, address(0), _value);
  36. }
  37. }