contract Contest is ERC721Full { using Counters for Counters.Counter; Counters.Counter private _tokenIds; /// original sponsor of this contest address public originalSponsor; /// minimum amount that must be supplied in order to make a submission uint256 public submissionFee; /// block timestamp at which this contest has officially ended uint256 public contestEnd; struct submission { // the creater of this stable diffusion image address submitter; // number of votes for this submission uint256 votes; } /// map between submissions and the number of votes received for that submission map(uint256 => submission) public submissions; /// address of contest factory address public factory; error InsufficientSubmissionFee(); error SenderNotJudge(address sender); /// @dev only submissions that meet the submission fee can enter the contest modifier validSubmission() { if (msg.value < submissionFee) { revert InsufficientSubmissionFee(); } _; } /// @dev only a judge will be able to vote on a submission modifier isJudge() { if !ContestFactory(factory).isJudge(msg.sender) { revert SenderNotJudge(msg.sender); } _; } /// construct this ERC721 minter, this sets the name, symbol, and contestEnd values constructor(string memory name, string memory symbol, string memory sponsor, uint64 contestDuration, uint256 _submissionFee) ERC721Full(name, symbol) public { originalSponsor = sponsor; submissionFee = _submissionFee; // the ContestFactory is assumed to created this contest factory = msg.sender; // update the contestEnd by adjusting by current timestamp unchecked { // unchecked to avoid overflow error contestEnd = block.timestamp + contestDuration; } } /// @dev Mints a new NFT for a submission to the contest, /// @param submitter, this is the address that should /// @param tokenURI, IPFS URI of the image associated with this NFT /// @return the id of the newly minted NFT function mint(address submitter, string memory tokenURI) public validSubmission returns (uint256) { _tokenIds.increment(); uint256 newItemId = _tokenIds.current(); // _mint(address(this), newItemId); // initialize this submission to zero votes votes[newItemId] = submission{ submitter: submitter, votes: 0, } _setTokenURI(newItemId, tokenURI); return newItemId; } }
0.4.18