ERC20Mintable.sol 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. pragma solidity ^0.4.24;
  2. import "./ERC20.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 ERC20Mintable is ERC20, Ownable {
  10. event Mint(address indexed to, uint256 amount);
  11. event MintFinished();
  12. bool private mintingFinished_ = false;
  13. modifier onlyBeforeMintingFinished() {
  14. require(!mintingFinished_);
  15. _;
  16. }
  17. modifier onlyMinter() {
  18. require(isOwner());
  19. _;
  20. }
  21. /**
  22. * @return true if the minting is finished.
  23. */
  24. function mintingFinished() public view returns(bool) {
  25. return mintingFinished_;
  26. }
  27. /**
  28. * @dev Function to mint tokens
  29. * @param _to The address that will receive the minted tokens.
  30. * @param _amount The amount of tokens to mint.
  31. * @return A boolean that indicates if the operation was successful.
  32. */
  33. function mint(
  34. address _to,
  35. uint256 _amount
  36. )
  37. public
  38. onlyMinter
  39. onlyBeforeMintingFinished
  40. returns (bool)
  41. {
  42. _mint(_to, _amount);
  43. emit Mint(_to, _amount);
  44. return true;
  45. }
  46. /**
  47. * @dev Function to stop minting new tokens.
  48. * @return True if the operation was successful.
  49. */
  50. function finishMinting()
  51. public
  52. onlyOwner
  53. onlyBeforeMintingFinished
  54. returns (bool)
  55. {
  56. mintingFinished_ = true;
  57. emit MintFinished();
  58. return true;
  59. }
  60. }