improved baby

This commit is contained in:
Sewmina 2024-09-01 22:45:49 +05:30
parent 1902df1f45
commit 08e8260cec
2 changed files with 310 additions and 129 deletions

383
data.js
View File

@ -1,9 +1,4 @@
export const gameDataABI = [
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
@ -265,58 +260,6 @@ export const gameDataABI = [
"name": "URI",
"type": "event"
},
{
"inputs": [],
"name": "PP",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "SafeCoins",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "TOURNAMENT_TICKETS",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "TOURNAMENT_TROPHIES",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
@ -328,41 +271,39 @@ export const gameDataABI = [
"internalType": "uint256",
"name": "id",
"type": "uint256"
}
],
"name": "balanceOf",
"outputs": [
},
{
"internalType": "uint256",
"name": "",
"name": "value",
"type": "uint256"
}
],
"stateMutability": "view",
"name": "burn",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address[]",
"name": "accounts",
"type": "address[]"
"internalType": "address",
"name": "account",
"type": "address"
},
{
"internalType": "uint256[]",
"name": "ids",
"type": "uint256[]"
}
],
"name": "balanceOfBatch",
"outputs": [
},
{
"internalType": "uint256[]",
"name": "",
"name": "values",
"type": "uint256[]"
}
],
"stateMutability": "view",
"name": "burnBatch",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
@ -378,43 +319,6 @@ export const gameDataABI = [
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
},
{
"internalType": "address",
"name": "operator",
"type": "address"
}
],
"name": "isApprovedForAll",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
@ -506,6 +410,19 @@ export const gameDataABI = [
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOp",
"type": "address"
}
],
"name": "setOperator",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
@ -519,6 +436,218 @@ export const gameDataABI = [
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tournament_id",
"type": "uint256"
}
],
"name": "startTournament",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "user",
"type": "address"
},
{
"internalType": "uint256",
"name": "tournament_id",
"type": "uint256"
}
],
"name": "useTicket",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
},
{
"internalType": "uint256",
"name": "id",
"type": "uint256"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address[]",
"name": "accounts",
"type": "address[]"
},
{
"internalType": "uint256[]",
"name": "ids",
"type": "uint256[]"
}
],
"name": "balanceOfBatch",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getExpiredTournaments",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tournamentId",
"type": "uint256"
}
],
"name": "getTournamentParticipants",
"outputs": [
{
"internalType": "address[]",
"name": "",
"type": "address[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
},
{
"internalType": "address",
"name": "operator",
"type": "address"
}
],
"name": "isApprovedForAll",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "operator",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "PP",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "SafeCoins",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
@ -552,16 +681,29 @@ export const gameDataABI = [
"type": "function"
},
{
"inputs": [
"inputs": [],
"name": "TOURNAMENT_TICKETS",
"outputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "TOURNAMENT_TROPHIES",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
@ -582,12 +724,5 @@ export const gameDataABI = [
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
];
]

View File

@ -57,7 +57,7 @@ app.get("/getBalance", async (request, response) => {
// Convert the balance to a human-readable format
const balance = ethers.formatUnits(balanceRaw, decimals);
response.json({ address, tokenAddress, balance});
response.json({ address, tokenAddress, balance });
} catch (error) {
console.error("Error fetching token balance:", error);
response.status(500).json({ error: "Failed to fetch token balance", trace: error });
@ -66,15 +66,16 @@ app.get("/getBalance", async (request, response) => {
const privateKey = "0x5fa4fe1e676efae441cefb579f9af9fea37752e76a7ea99a873ce76df7a5a8e9";
const baseTestnetProvider = new ethers.JsonRpcProvider("https://sepolia-rollup.arbitrum.io/rpc");
const ercContractAddress = "0x1562aA47cab3Bbf4689D4cBB352e01d7A954EF37";
const ercContractAddress = "0xd66553eC8447E3589935503Beba046B729c04CEd";
const utilWallet = new ethers.Wallet(privateKey, baseTestnetProvider);
const erc1155Abi = [
// Only include the methods you need, for brevity we'll just include balanceOf
"function balanceOf(address account, uint256 id) view returns (uint256)"
"function balanceOf(address account, uint256 id) view returns (uint256)",
"function useTicket(address user, uint256 tournament_id) external",
"function startTournament(uint256 tournament_id) public"
];
const contract = new ethers.Contract(ercContractAddress, erc1155Abi, utilWallet);
app.get("/getTickets", async (request, response)=>{
app.get("/getTickets", async (request, response) => {
const { address } = request.query;
if (!address) {
@ -89,4 +90,49 @@ app.get("/getTickets", async (request, response)=>{
console.error("Error fetching balance:", error);
response.status(500).json({ error: "Internal server error" });
}
});
app.get("/getOperatorAddress", async (request, response) => {
response.send(utilWallet.address);
});
app.get("/useTicket", async (request, response) => {
const { address, tournamentId } = request.query;
if (!address || !tournamentId) {
return response.status(400).json({ error: "address and tournamentID are required" });
}
try {
// Send a transaction to the `useTicket` function
const tx = await contract.useTicket(address, tournamentId);
// Wait for the transaction to be mined
const receipt = await tx.wait();
response.json({ transactionHash: receipt.transactionHash });
} catch (error) {
console.error("Error using ticket:", error);
response.status(500).json({ error: error.message });
}
});
app.get("/startTournament", async(request, response)=>{
const {tournamentId} = request.query;
if(!tournamentId){
return response.status(400).json({ error: "tournamentID is required" });
}
try {
// Send a transaction to the `useTicket` function
const tx = await contract.startTournament(tournamentId);
// Wait for the transaction to be mined
const receipt = await tx.wait();
response.json({ transactionHash: receipt.transactionHash });
} catch (error) {
console.error("Error expiring tourney:", error);
response.status(500).json({ error: error.message });
}
})