all files / contracts/ CopyrightLYNFT.sol

100% Statements 15/15
100% Branches 8/8
100% Functions 6/6
100% Lines 18/18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69                                              4×           1× 1× 1× 1× 1× 1×       7× 7×   5×       5×   3×   1×             2×       7× 7× 5×     2×      
// SPDX-License-Identifier: GPL-3.0-or-later
 
pragma solidity ^0.8.6;
 
import "openzeppelin-solidity/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "openzeppelin-solidity/contracts/access/Ownable.sol";
import "openzeppelin-solidity/contracts/security/Pausable.sol";
import "./Manifestations.sol";
import "./Evidencable.sol";
import "./Stakable.sol";
 
/**
 * @title CopyrightLY NFTs for reuse licenses
 */
contract CopyrightLYNFT is Ownable, Pausable, ERC721URIStorage {
 
  address public manifestations;
  mapping(address => uint256) public amountMinted;
 
  event NFTMinted(address indexed minter, uint256 tokenId, string tokenUri,
    address manifestations, string manifestationHash);
 
  constructor(address _manifestations) ERC721("CopyrightLY NFT", "CLYNFT") {
    manifestations = _manifestations;
  }
 
  function mint(string memory manifestationHash, string memory metadataHash) public
  whenNotPaused() isAuthor(manifestationHash) isMintable(manifestationHash) returns (uint256)
  {
    uint256 tokenId = uint256(keccak256(abi.encodePacked(msg.sender, amountMinted[msg.sender])));
    _mint(msg.sender, tokenId);
    _setTokenURI(tokenId, metadataHash);
    amountMinted[msg.sender]++;
    emit NFTMinted(msg.sender, tokenId, ERC721URIStorage.tokenURI(tokenId), manifestations, manifestationHash);
    return tokenId;
  }
 
  modifier isAuthor(string memory manifestationHash) {
    ( , address[] memory authors, , )  = Manifestations(manifestations).getManifestation(manifestationHash);
    require(_contains(authors, msg.sender),
      "Only authors can mint NFTs for a manifestation");
    _;
  }
 
  modifier isMintable(string memory manifestationHash) {
    require(Stakable(manifestations).isStaked(manifestationHash),
      "NFT cannot be minted if manifestation without stake");
    require(!Evidencable(manifestations).isUnevidenced(manifestationHash),
      "NFT cannot be minted if manifestation without evidence");
    _;
  }
 
  /**
   * @dev Base URI for computing {tokenURI}.
   */
  function _baseURI() override internal view virtual returns (string memory) {
    return "ipfs://";
  }
 
  function _contains(address[] memory accounts, address account) private pure returns(bool) {
    for (uint i = 0; i < accounts.length; i++) {
      if (accounts[i] == account) {
        return true;
      }
    }
    return false;
  }
}