ERC20Mintable.sol 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 canMint() {
  14. require(!mintingFinished_);
  15. _;
  16. }
  17. modifier hasMintPermission() {
  18. require(msg.sender == owner());
  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. hasMintPermission
  39. canMint
  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() public onlyOwner canMint returns (bool) {
  51. mintingFinished_ = true;
  52. emit MintFinished();
  53. return true;
  54. }
  55. }