This commit is contained in:
Sewmina (server) 2024-09-30 16:53:39 +08:00
parent 9b66a61eea
commit 4a6ad8b68c

View File

@ -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);