Init
This commit is contained in:
72
src/app.ts
Normal file
72
src/app.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import express from 'express';
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
import { GetSolBalance, GetTicketsAccount, GetTicketsBalanceByTA, GetTokenAccount, GetTokenBalanceByTA } from "./sol";
|
||||
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const app = express();
|
||||
const port = process.env.EXPRESS_PORT;
|
||||
|
||||
app.get("/status", (req,res)=>{
|
||||
res.status(200).json({status:"Working"})
|
||||
})
|
||||
|
||||
app.get("/getSolBalance", async(req,res)=>{
|
||||
const {wallet} = req.query;
|
||||
|
||||
if(!wallet){res.status(403).json({error:"Wallet should be present"}); return;}
|
||||
|
||||
const balance = await GetSolBalance(wallet);
|
||||
|
||||
const response = {
|
||||
address: wallet,
|
||||
balance: balance
|
||||
};
|
||||
|
||||
res.status(200).json(response);
|
||||
})
|
||||
|
||||
app.get("/getTokenBalance", async(req,res)=>{
|
||||
const{ wallet } = req.query;
|
||||
if(!wallet){res.status(403).json({error:"Wallet should be present"}); return;}
|
||||
|
||||
const tokenAddress = await GetTokenAccount(wallet);
|
||||
const result = await GetTokenBalanceByTA(tokenAddress);
|
||||
const balance = result <0 ? 0 : result;
|
||||
|
||||
const response = {
|
||||
tokenAccount:tokenAddress,
|
||||
balance:balance
|
||||
}
|
||||
|
||||
res.status(200).json(response);
|
||||
})
|
||||
|
||||
app.get("/getTicketsBalance", async(req,res)=>{
|
||||
const{ wallet } = req.query;
|
||||
if(!wallet){res.status(403).json({error:"Wallet should be present"}); return;}
|
||||
|
||||
const tokenAddress = await GetTicketsAccount(wallet);
|
||||
const result = await GetTicketsBalanceByTA(tokenAddress);
|
||||
const balance = result <0 ? 0 : result;
|
||||
|
||||
const response = {
|
||||
tokenAccount:tokenAddress,
|
||||
balance:balance
|
||||
}
|
||||
|
||||
res.status(200).json(response);
|
||||
})
|
||||
|
||||
app.get("/purchaseTickets", async(req,res)=>{
|
||||
const {amount} = req.query;
|
||||
if(!amount){
|
||||
res.status(403).json({error:"Enter an amount"}); return;
|
||||
}
|
||||
})
|
||||
|
||||
app.listen(port, ()=>{
|
||||
console.log(`Mhunt Solana Brdige listening to port ${port}`)
|
||||
})
|
||||
Reference in New Issue
Block a user