ERC721Mintable.sol 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. pragma solidity ^0.4.24;
  2. import "./ERC721Full.sol";
  3. import "../../access/roles/MinterRole.sol";
  4. /**
  5. * @title ERC721Mintable
  6. * @dev ERC721 minting logic
  7. */
  8. contract ERC721Mintable is ERC721Full, 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 tokenId The token id to mint.
  25. * @return A boolean that indicates if the operation was successful.
  26. */
  27. function mint(
  28. address to,
  29. uint256 tokenId
  30. )
  31. public
  32. onlyMinter
  33. onlyBeforeMintingFinished
  34. returns (bool)
  35. {
  36. _mint(to, tokenId);
  37. return true;
  38. }
  39. function mintWithTokenURI(
  40. address to,
  41. uint256 tokenId,
  42. string tokenURI
  43. )
  44. public
  45. onlyMinter
  46. onlyBeforeMintingFinished
  47. returns (bool)
  48. {
  49. mint(to, tokenId);
  50. _setTokenURI(tokenId, tokenURI);
  51. return true;
  52. }
  53. /**
  54. * @dev Function to stop minting new tokens.
  55. * @return True if the operation was successful.
  56. */
  57. function finishMinting()
  58. public
  59. onlyMinter
  60. onlyBeforeMintingFinished
  61. returns (bool)
  62. {
  63. _mintingFinished = true;
  64. emit MintingFinished();
  65. return true;
  66. }
  67. }