// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.20; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "@openzeppelin/contracts/utils/Base64.sol"; import "./BokkyPooBahsDateTimeLibrary.sol"; import "./TixSellLibraries.sol"; contract NftTemplateContractDesignTwoContract is Ownable,AccessControl { bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE"); using Strings for uint256; // Mappings modifier onlyFounders() { require( hasRole(ADMIN_ROLE, msg.sender), "Only founders can do that" ); _; } modifier onlyAdmin() { require(msg.sender == owner() || hasRole(ADMIN_ROLE, msg.sender), "Only admins can do that"); _; } constructor(address initialOwner, address[] memory _admins) Ownable(initialOwner) { for (uint256 i = 0; i < _admins.length; ++i) { _grantRole(ADMIN_ROLE, _admins[i]); _grantRole(DEFAULT_ADMIN_ROLE, _admins[i]); } } function buildImage(address _nftTixSellSmartContract, TixSellLibrary.NftTicketInfo memory _nftTicketInfo) external view returns (string memory){ //Infos clés // Event name // Event date and hour // Nom Lieu (voir si on met plan google map) // Ville // Nom du billet // Prix //Categorie // Id token // require que celui a l'orgine de la transaction soit _nftTixSellSmartContract (pour pas se fabriquer des billets en externe) require(msg.sender==_nftTixSellSmartContract || hasRole(ADMIN_ROLE, msg.sender),"Not authorized"); // convert date/hour in string string memory anneeToDisplay=''; string memory moisToDisplay= ''; string memory jourToDisplay= ''; string memory heureToDisplay= ''; string memory minuteToDisplay= ''; if (_nftTicketInfo.eventDate>0){ (uint annee,uint mois,uint jour,uint heure,uint minute,) = BokkyPooBahsDateTimeLibrary.timestampToDateTime(_nftTicketInfo.eventDate); anneeToDisplay = annee.toString(); moisToDisplay = mois.toString(); if (bytes(moisToDisplay).length==1){ moisToDisplay = string.concat("0",moisToDisplay); } jourToDisplay = jour.toString(); if (bytes(jourToDisplay).length==1){ jourToDisplay = string.concat("0",jourToDisplay); } heureToDisplay = heure.toString(); if (bytes(heureToDisplay).length==1){ heureToDisplay = string.concat("0",heureToDisplay); } minuteToDisplay = minute.toString(); if (bytes(minuteToDisplay).length==1){ minuteToDisplay = string.concat("0",minuteToDisplay); } } return Base64.encode( bytes( abi.encodePacked( '', '', '', '', '', '', '', '', '' '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'date', '.', ' ',jourToDisplay,'.',moisToDisplay,'.',anneeToDisplay,'', 'time', '.', ' ',heureToDisplay,':',minuteToDisplay,' GMT ',_nftTicketInfo.ticketDesignInfo.heureDisplay,' ', 'location.', ' ',_nftTicketInfo.ticketDesignInfo.venue,'', '', '', '', '', '', '', '', '',_nftTicketInfo.ticketDesignInfo.eventTitleOne,'',_nftTicketInfo.ticketDesignInfo.eventTitleTwo,'', '', '',_nftTicketInfo.ticketDesignInfo.price,'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',_nftTicketInfo.ticketDesignInfo.ticketType,'', '', '' ) ) ); } function weiToEtherString(uint256 amountInWei) internal pure returns (string memory) { uint256 amountInFinney = amountInWei / 1e15; // 1 finney == 1e15 return string( abi.encodePacked( Strings.toString(amountInFinney / 1000), //left of decimal ".", Strings.toString((amountInFinney % 1000) / 100), //first decimal Strings.toString(((amountInFinney % 1000) % 100) / 10) // first decimal ) ); } function addressToString(address x) internal pure returns (string memory) { bytes memory s = new bytes(40); for (uint256 i = 0; i < 20; i++) { bytes1 b = bytes1(uint8(uint256(uint160(x)) / (2**(8 * (19 - i))))); bytes1 hi = bytes1(uint8(b) / 16); bytes1 lo = bytes1(uint8(b) - 16 * uint8(hi)); s[2 * i] = char(hi); s[2 * i + 1] = char(lo); } return string(s); } function char(bytes1 b) internal pure returns (bytes1 c) { if (uint8(b) < 10) return bytes1(uint8(b) + 0x30); else return bytes1(uint8(b) + 0x57); } }