Skip to content

feat: backend API endpoints — admin market ops, users, bets, and market filters - #1158

Merged
Ehonrie merged 7 commits into
Netwalls:mainfrom
augustinemartins:feat/backend-api-endpoints
Jul 27, 2026
Merged

feat: backend API endpoints — admin market ops, users, bets, and market filters#1158
Ehonrie merged 7 commits into
Netwalls:mainfrom
augustinemartins:feat/backend-api-endpoints

Conversation

@augustinemartins

@augustinemartins augustinemartins commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Closes #1077
Closes #1078
Closes #1089
Closes #1090

Summary

This PR implements 4 backend API endpoint groups for the BOXMEOUT prediction market:

1. Admin Market Resolution Endpoints

POST /api/admin/markets/:marketId/resolve, /cancel, /dispute-resolve

  • All routes gated by requireAdmin middleware (x-admin-api-key header)
  • Body validation for outcome/source/overrideOutcome fields
  • Every action writes an AdminLog entry for audit trail
  • Service layer handles Prisma updates atomically

2. User Profile Endpoints

GET /api/users/:address, PUT /api/users/:address

  • GET returns profile data aggregated from bet history
  • PUT requires Stellar wallet-signature verification via requireWalletAuth middleware
  • Wallet auth uses x-wallet-signature and x-wallet-message headers with 5-min timestamp replay protection

3. Bets by Wallet Address

GET /api/bets/:address

  • Returns all bets placed by a wallet address across markets
  • Indexed on bettor for efficient queries
  • Supports optional ?marketId filter

4. Market Bets with Outcome Filter

GET /api/markets/:id/bets

  • Returns all bets for a market with optional ?outcome=yes|no filter
  • Yes maps to FighterA, No maps to FighterB

Files Changed

File Description
backend/src/api/middleware/auth.ts Added requireWalletAuth middleware
backend/src/api/routes/market.routes.ts Added 3 admin :marketId routes
backend/src/api/routes/user.routes.ts New: GET/PUT /users/:address
backend/src/api/controllers/market.controller.ts Added admin handlers + getMarketBetsHandler
backend/src/api/controllers/bet.controller.ts Implemented getBetsByAddressHandler
backend/src/api/controllers/user.controller.ts New: getUserHandler, updateUserHandler
backend/src/services/market.service.ts Added resolveMarket, cancelMarket, resolveMarketDispute
backend/src/services/bet.service.ts Implemented getBetsByAddress, getBetsByMarket
backend/src/services/user.service.ts New: getUserByAddress, updateUser

Commits

  1. aacf0dd feat: implement admin market service functions with audit logging
  2. b34716e feat: wire admin market resolution endpoints with input validation
  3. 3c557ff feat: implement bets-by-address and market-bets endpoints
  4. 92cf285 feat: add user profile endpoints with wallet-signature authentication

augustinemartins and others added 7 commits July 26, 2026 12:27
- Add resolveMarket: updates market status to Resolved + AdminLog entry
- Add cancelMarket: cancels market with optional reason + AdminLog entry
- Add resolveMarketDispute: resolves disputed market with override + AdminLog entry
- All actions write AdminLog entries for audit trail
- Add POST /admin/markets/:marketId/resolve with outcome/source validation
- Add POST /admin/markets/:marketId/cancel with optional reason
- Add POST /admin/markets/:marketId/dispute-resolve with overrideOutcome validation
- Implement getMarketBetsHandler supporting ?outcome=yes|no filter
- All admin routes gated by requireAdmin middleware
- All handlers validate required fields before calling service layer
- Implement getBetsByAddress: query all bets by bettor address with optional marketId filter
- Implement getBetsByMarket: query bets by market with ?outcome=yes|no side filter
- Yes maps to FighterA, No maps to FighterB
- Implement getBetsByAddressHandler in controller with error handling
- Indexed on bettor for efficient wallet-level queries
- Add GET /api/users/:address to fetch user profile by wallet address
- Add PUT /api/users/:address gated by requireWalletAuth middleware
- requireWalletAuth verifies Stellar wallet signature via x-wallet-signature/x-wallet-message headers
- Includes replay protection with 5-minute timestamp expiry
- User service aggregates profile data from existing bet records
@Ehonrie
Ehonrie merged commit 3e36061 into Netwalls:main Jul 27, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant