MarmottoshisWLbyRpGmAx
unknown
javascript
3 years ago
3.4 kB
15
Indexable
contract MarmottoshisWLbyRpGmAx is ERC721, Ownable {
constructor() ERC721("MarmottoshisWLbyRpGmAx", "MWL") {}
struct Player {
string twitter;
uint tokenID;
bool exists;
}
struct TokenMeta {
uint tokenID;
bool isWL;
}
uint constant maxWLSupply = 10;
mapping (address => Player) Players;
mapping (uint => TokenMeta) Tokens;
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
Counters.Counter private _winners;
function alreadyPlayed(address _address) public view returns(bool exists) {
return Players[_address].exists;
}
function play(string memory Twitter, string memory Q1, string memory Q2, string memory Q3, string memory Q4, string memory Q5) public {
bool isWL = true;
if (keccak256(bytes(Q1)) != keccak256(bytes("alpha"))) { isWL = false; }
if (keccak256(bytes(Q2)) != keccak256(bytes("beta"))) { isWL = false; }
if (keccak256(bytes(Q3)) != keccak256(bytes("gamma"))) { isWL = false; }
if (keccak256(bytes(Q4)) != keccak256(bytes("beta"))) { isWL = false; }
if (keccak256(bytes(Q5)) != keccak256(bytes("alpha"))) { isWL = false; }
uint totalMinted = _tokenIds.current();
uint totalWinners = _winners.current();
require(totalWinners < maxWLSupply, "Nombre de WL max atteint");
require(keccak256(bytes(Twitter)) != keccak256(bytes("")), "Compte Twitter manquant");
require(!alreadyPlayed(msg.sender), "Une seule participation par personne");
_mint(msg.sender, totalMinted);
_tokenIds.increment();
if (isWL == true) { _winners.increment(); }
Players[msg.sender].tokenID = totalMinted;
Players[msg.sender].twitter = Twitter;
Tokens[totalMinted].isWL = isWL;
Players[msg.sender].exists = true;
}
function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) {
require(_exists(_tokenId), "Ce token n'existe pas !");
bool isWL = Tokens[_tokenId].isWL;
string memory json_output;
if (isWL == true) { // WL
json_output = Base64.encode(
bytes(
string(
abi.encodePacked('{"id":', Strings.toString(_tokenId), ', "name": "WL obtenue", "description": "Bravo :)", "image": "ipfs://bafybeielkcdabtfm4t6hkdcxvefdvew3y3nfw4feyevlebka45quof74ei"}')
)
)
);
} else { // NO WL
json_output = Base64.encode(
bytes(
string(
abi.encodePacked('{"id":', Strings.toString(_tokenId), ', "name": "WL non obtenue", "description": "Petit lot de consolation ;)", "image": "ipfs://bafkreidqyuu2m33kg76jyxatiyyh3pajqjf3lnkjibtibynl44x2jcfd4a"}')
)
)
);
}
return string(abi.encodePacked('data:application/json;base64,', json_output));
}
function getPlayerInfos(address _address) view public onlyOwner returns(string memory){
require (Players[_address].exists, "Joueur inexistant");
return(Players[_address].twitter);
}
function getTotalWinners() view public returns(uint){
return _winners.current();
}
}Editor is loading...