-
-
Save chemonoworld/829fc96136bd0d208ae8e44bdc4da992 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
import "./KIP17Token.sol"; | |
contract RandomNumberGenerator is KIP17MetadataMintable { | |
uint[1000] remainingTokenList; // tokenId : 1~1000 | |
uint constant preSaleQuantity = 1000; | |
uint remainingTokenCount = preSaleQuantity; | |
function _generateRandomNumber (uint requiredSeed) public view returns (uint) { | |
require(remainingTokenCount > 0); | |
return uint(keccak256(abi.encodePacked(requiredSeed, blockhash(block.number), msg.sender))) % remainingTokenCount; | |
} | |
function draw (uint requiredSeed, address to, uint256 tokenId, string memory tokenURI) public returns (uint) { | |
require(remainingTokenCount > 0); | |
uint randNum = _generateRandomNumber(requiredSeed); | |
uint drawNum = remainingTokenList[randNum]; | |
remainingTokenList[randNum] = remainingTokenList[remainingTokenCount - 1]; | |
remainingTokenCount--; | |
mintWithTokenURI(to, tokenId, tokenURI);//from KIP17Token.sol | |
return (drawNum); | |
} | |
function _initiateRemainingTokenList () private { | |
for (uint i=0 ; i <preSaleQuantity ; i++) | |
{ | |
remainingTokenList[i] = i + 1; | |
} | |
} | |
constructor () public { | |
//initiate pre-sale nft tokenId | |
_initiateRemainingTokenList(); | |
} | |
} | |
contract KIP17TEST is | |
KIP17Full, | |
KIP17Mintable, | |
KIP17MetadataMintable, | |
KIP17Burnable, | |
KIP17Pausable, | |
RandomNumberGenerator | |
{ | |
constructor(string memory name, string memory symbol) | |
public | |
KIP17Full(name, symbol) | |
{} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment