MintableToken.sol 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol
  8. */
  9. contract MintableToken is StandardToken, Ownable {
  10. event Mint(address indexed to, uint256 amount);
  11. event MintFinished();
  12. bool public mintingFinished = false;
  13. modifier canMint() {
  14. require(!mintingFinished);
  15. _;
  16. }
  17. modifier hasMintPermission() {
  18. require(msg.sender == owner);
  19. _;
  20. }
  21. /**
  22. * @dev Function to mint tokens
  23. * @param _to The address that will receive the minted tokens.
  24. * @param _amount The amount of tokens to mint.
  25. * @return A boolean that indicates if the operation was successful.
  26. */
  27. function mint(
  28. address _to,
  29. uint256 _amount
  30. )
  31. public
  32. hasMintPermission
  33. canMint
  34. returns (bool)
  35. {
  36. _mint(_to, _amount);
  37. emit Mint(_to, _amount);
  38. return true;
  39. }
  40. /**
  41. * @dev Function to stop minting new tokens.
  42. * @return True if the operation was successful.
  43. */
  44. function finishMinting() public onlyOwner canMint returns (bool) {
  45. mintingFinished = true;
  46. emit MintFinished();
  47. return true;
  48. }
  49. }