MintableToken.sol 1.4 KB

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