MintableToken.sol 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. pragma solidity ^0.4.24;
  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. modifier hasMintPermission() {
  19. require(msg.sender == owner);
  20. _;
  21. }
  22. /**
  23. * @dev Function to mint tokens
  24. * @param _to The address that will receive the minted tokens.
  25. * @param _amount The amount of tokens to mint.
  26. * @return A boolean that indicates if the operation was successful.
  27. */
  28. function mint(
  29. address _to,
  30. uint256 _amount
  31. )
  32. hasMintPermission
  33. canMint
  34. public
  35. returns (bool)
  36. {
  37. totalSupply_ = totalSupply_.add(_amount);
  38. balances[_to] = balances[_to].add(_amount);
  39. emit Mint(_to, _amount);
  40. emit Transfer(address(0), _to, _amount);
  41. return true;
  42. }
  43. /**
  44. * @dev Function to stop minting new tokens.
  45. * @return True if the operation was successful.
  46. */
  47. function finishMinting() onlyOwner canMint public returns (bool) {
  48. mintingFinished = true;
  49. emit MintFinished();
  50. return true;
  51. }
  52. }