ERC20Mintable.sol 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. pragma solidity ^0.4.24;
  2. import "./ERC20.sol";
  3. import "../../access/roles/MinterRole.sol";
  4. /**
  5. * @title ERC20Mintable
  6. * @dev ERC20 minting logic
  7. */
  8. contract ERC20Mintable is ERC20, MinterRole {
  9. event MintingFinished();
  10. bool private _mintingFinished = false;
  11. modifier onlyBeforeMintingFinished() {
  12. require(!_mintingFinished);
  13. _;
  14. }
  15. /**
  16. * @return true if the minting is finished.
  17. */
  18. function mintingFinished() public view returns(bool) {
  19. return _mintingFinished;
  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. onlyMinter
  33. onlyBeforeMintingFinished
  34. returns (bool)
  35. {
  36. _mint(to, amount);
  37. return true;
  38. }
  39. /**
  40. * @dev Function to stop minting new tokens.
  41. * @return True if the operation was successful.
  42. */
  43. function finishMinting()
  44. public
  45. onlyMinter
  46. onlyBeforeMintingFinished
  47. returns (bool)
  48. {
  49. _mintingFinished = true;
  50. emit MintingFinished();
  51. return true;
  52. }
  53. }