diff --git a/backend/src/api/routes.ts b/backend/src/api/routes.ts index 88533b5..e52af66 100644 --- a/backend/src/api/routes.ts +++ b/backend/src/api/routes.ts @@ -1,6 +1,7 @@ import { Router, Request, Response } from "express"; import { getFeeStats } from "../services/horizon"; import { stellarConfig, CONTRACT_IDS } from "../config/stellar"; +import { requireAuth } from "../middleware/auth"; import campaignRoutes from "../routes/campaigns"; import publisherRoutes from "../routes/publishers"; import auctionRoutes from "../routes/auctions"; @@ -55,8 +56,41 @@ router.get("/network", async (_req: Request, res: Response) => { } }); -// List deployed contract IDs -router.get("/contracts", (_req: Request, res: Response) => { +// Account details +router.get("/account/:address", async (req: Request, res: Response) => { + try { + const { address } = req.params; + const account = await getAccountDetails(address as string); + if (!account) { + return res.status(404).json({ error: "Account not found or not funded" }); + } + res.json(account); + } catch (err: any) { + req.log?.error({ err }, 'Failed to fetch account details'); + const details = process.env.NODE_ENV === 'development' ? err.message : undefined; + res.status(500).json({ error: 'Failed to fetch account details', ...(details && { details }) }); + } +}); + +// Account transaction history +router.get( + "/account/:address/transactions", + async (req: Request, res: Response) => { + try { + const { address } = req.params; + const limit = Math.min(parseInt(req.query.limit as string) || 20, 200); + const txs = await getAccountTransactions(address as string, limit); + res.json({ transactions: txs, count: txs.length }); + } catch (err: any) { + req.log?.error({ err }, 'Failed to fetch account transactions'); + const details = process.env.NODE_ENV === 'development' ? err.message : undefined; + res.status(500).json({ error: 'Failed to fetch account transactions', ...(details && { details }) }); + } + }, +); + +// List deployed contract IDs (auth required) +router.get("/contracts", requireAuth, (_req: Request, res: Response) => { res.json({ contracts: CONTRACT_IDS }); });