MintableToken.sol 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. totalSupply_ = totalSupply_.add(_amount);
  37. balances[_to] = balances[_to].add(_amount);
  38. emit Mint(_to, _amount);
  39. emit Transfer(address(0), _to, _amount);
  40. return true;
  41. }
  42. /**
  43. * @dev Function to stop minting new tokens.
  44. * @return True if the operation was successful.
  45. */
  46. function finishMinting() public onlyOwner canMint returns (bool) {
  47. mintingFinished = true;
  48. emit MintFinished();
  49. return true;
  50. }
  51. }