MintableToken.sol 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. pragma solidity ^0.4.18;
  2. import "./StandardToken.sol";
  3. import "../../ownership/Ownable.sol";
  4. /**
  5. * @title Mintable token
  6. * @dev Simple ERC20 Token example, with mintable token creation
  7. * @dev Issue: * https://github.com/OpenZeppelin/openzeppelin-solidity/issues/120
  8. * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol
  9. */
  10. contract MintableToken is StandardToken, Ownable {
  11. event Mint(address indexed to, uint256 amount);
  12. event MintFinished();
  13. bool public mintingFinished = false;
  14. modifier canMint() {
  15. require(!mintingFinished);
  16. _;
  17. }
  18. /**
  19. * @dev Function to mint tokens
  20. * @param _to The address that will receive the minted tokens.
  21. * @param _amount The amount of tokens to mint.
  22. * @return A boolean that indicates if the operation was successful.
  23. */
  24. function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
  25. totalSupply_ = totalSupply_.add(_amount);
  26. balances[_to] = balances[_to].add(_amount);
  27. Mint(_to, _amount);
  28. Transfer(address(0), _to, _amount);
  29. return true;
  30. }
  31. /**
  32. * @dev Function to stop minting new tokens.
  33. * @return True if the operation was successful.
  34. */
  35. function finishMinting() onlyOwner canMint public returns (bool) {
  36. mintingFinished = true;
  37. MintFinished();
  38. return true;
  39. }
  40. }