From 4a6ad8b68c51f8e5c33daa9f2bc5b6f60c44fe12 Mon Sep 17 00:00:00 2001 From: "Sewmina (server)" Date: Mon, 30 Sep 2024 16:53:39 +0800 Subject: [PATCH] prod v1 --- index.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/index.js b/index.js index 9fab3d0..291b4d9 100644 --- a/index.js +++ b/index.js @@ -71,6 +71,7 @@ const utilWallet = new ethers.Wallet(privateKey, baseTestnetProvider); const erc1155Abi = [ "function balanceOf(address account, uint256 id) view returns (uint256)", "function useTicket(address user, uint256 tournament_id) external", + "function ticketPrice() view returns (uint256)", "function startTournament(uint256 tournament_id) public", "function getUserTickets(address user) public view returns (uint256[] memory)", "function getTournamentParticipentsCount(uint256 tournamentId) public view returns(uint256)" @@ -78,6 +79,12 @@ const erc1155Abi = [ ]; const contract = new ethers.Contract(ercContractAddress, erc1155Abi, utilWallet); +const nftContractAddress="0x5F018178AC0BDa64A89A9C446365c8BeBCA8dcc2"; +const nftAbi = [ + "function mintNewUser(address user, uint256 newItemId, string calldata _uri) public returns (uint256)" +]; +const nftContract = new ethers.Contract(nftContractAddress, nftAbi, utilWallet); + app.get("/getTickets", async (request, response) => { const { address } = request.query; @@ -140,6 +147,19 @@ app.get("/startTournament", async(request, response)=>{ } }) +app.get("/getTicketPrice", async(request,response)=>{ + try{ + const tx = await contract.ticketPrice(); + response.json({ + wei: tx.toString(), + eth: ethers.formatEther(tx) + }); + }catch(err){ + console.error("Error reading tickets price:", err); + response.status(500).json({ error: err.message }); + } +}) + app.get("/getMyTickets", async(request,response)=>{ const {address} = request.query; if(!address){response.status(400).json({error:"address is required"})} @@ -164,3 +184,44 @@ app.get("/getTournamentParticipentsCount", async(request,response)=>{ response.status(500).json({ error: err.message }); } }) + +app.get("/mintUserToken", async(request,response)=>{ + const {id, address} = request.query; + if(!id || !address){response.status(400).json({error:"id and address is required"})} + + const tokenMetadataResponse = await fetch(`https://vps.playpoolstudios.com/metahunt/api/launcher/get_token_metadata.php?id=${id}`); + let dataJson = await tokenMetadataResponse.json(); + const randomPfpResposne = await fetch('http://vps.playpoolstudios.com:1854/getRandomLink'); + const randomPfpJson = await randomPfpResposne.json(); + + dataJson['image'] = randomPfpJson['localLink']; + console.log(dataJson); + const writeToFile = await fetch('http://linode.playpoolstudios.com/begula/nft_data/721/data_writer.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + id: id, + data: JSON.stringify(dataJson) + }) + }); + + const uri = `http://linode.playpoolstudios.com/begula/nft_data/721/${id}.json`; + try{ + const tx = await nftContract.mintNewUser(address, id, uri); + response.json({ newId: tx.toString() }); + }catch(err){ + console.error("Error reading participents for tourney:", err); + response.status(500).json({ error: err.message }); + } +}) + + +/* ------------------------------------------------------------------------------- */ + + +setInterval(async()=>{ + const idsResponse = await fetch(`https://vps.playpoolstudios.com/metahunt/api/launcher/update_metadata.php`); + console.log("Updated NFT metadata, response :" + await idsResponse.text()); +}, 120000); \ No newline at end of file