ERC721Mintable.sol 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. pragma solidity ^0.4.24;
  2. import "./ERC721.sol";
  3. import "../../access/roles/MinterRole.sol";
  4. /**
  5. * @title ERC721Mintable
  6. * @dev ERC721 minting logic
  7. */
  8. contract ERC721Mintable is ERC721, MinterRole {
  9. event Minted(address indexed to, uint256 tokenId);
  10. event MintingFinished();
  11. bool private mintingFinished_ = false;
  12. modifier onlyBeforeMintingFinished() {
  13. require(!mintingFinished_);
  14. _;
  15. }
  16. /**
  17. * @return true if the minting is finished.
  18. */
  19. function mintingFinished() public view returns(bool) {
  20. return mintingFinished_;
  21. }
  22. /**
  23. * @dev Function to mint tokens
  24. * @param _to The address that will receive the minted tokens.
  25. * @param _tokenId The token id to mint.
  26. * @return A boolean that indicates if the operation was successful.
  27. */
  28. function mint(
  29. address _to,
  30. uint256 _tokenId
  31. )
  32. public
  33. onlyMinter
  34. onlyBeforeMintingFinished
  35. returns (bool)
  36. {
  37. _mint(_to, _tokenId);
  38. emit Minted(_to, _tokenId);
  39. return true;
  40. }
  41. function mintWithTokenURI(
  42. address _to,
  43. uint256 _tokenId,
  44. string _tokenURI
  45. )
  46. public
  47. onlyMinter
  48. onlyBeforeMintingFinished
  49. returns (bool)
  50. {
  51. mint(_to, _tokenId);
  52. _setTokenURI(_tokenId, _tokenURI);
  53. return true;
  54. }
  55. /**
  56. * @dev Function to stop minting new tokens.
  57. * @return True if the operation was successful.
  58. */
  59. function finishMinting()
  60. public
  61. onlyMinter
  62. onlyBeforeMintingFinished
  63. returns (bool)
  64. {
  65. mintingFinished_ = true;
  66. emit MintingFinished();
  67. return true;
  68. }
  69. }