MintableToken.sol 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. pragma solidity ^0.4.8;
  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/zeppelin-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, uint value);
  12. event MintFinished();
  13. bool public mintingFinished = false;
  14. uint public totalSupply = 0;
  15. modifier canMint() {
  16. if(mintingFinished) throw;
  17. _;
  18. }
  19. /**
  20. * @dev Function to mint tokens
  21. * @param _to The address that will recieve the minted tokens.
  22. * @param _amount The amount of tokens to mint.
  23. * @return A boolean that indicates if the operation was successful.
  24. */
  25. function mint(address _to, uint _amount) onlyOwner canMint returns (bool) {
  26. totalSupply = totalSupply.add(_amount);
  27. balances[_to] = balances[_to].add(_amount);
  28. Mint(_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 returns (bool) {
  36. mintingFinished = true;
  37. MintFinished();
  38. return true;
  39. }
  40. }