feat: Four market backend enhancements - #1161
Merged
Merged
Conversation
- Clean up merge conflict artifacts in market.service.ts - getMarketById returns Market or null, not thrown error - Consolidated getAllMarkets, getMarketById, createMarketRecord - Switched from prisma client to shared db instance
- Add createMarketOptimistic to market.service.ts uses txHash as temp id - Update createMarketRecord to reconcile optimistic rows matched by txHash - Add Zod validation schema for optimistic create payload - Add POST /api/markets/optimistic endpoint - Add reconcileMarketHandler for admin force-refresh (task 1) - Add getMarketsByCreatorHandler with paginated response (task 3)
- Add reconcileMarketFromChain in market.service.ts using simulateTransaction - Properly build TransactionBuilder for read-only contract simulation - Parse Soroban ScVal return with scValToNative - Add POST /api/admin/markets/:id/reconcile admin-protected route - Clean up duplicate route definitions - Add /by-creator/:address and /optimistic routes
- Add getMarketsByCreator to market.service.ts - Add @@index([createdBy]) on Market model - Create migration for Market_createdBy_idx B-tree index - Add GET /api/markets/by-creator/:address with pagination
feat: Four market backend enhancements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1073
Closes #1074
Closes #1075
Closes #1076
Summary
Implements four backend enhancements for the BOXMEOUT market service:
1. Fallback reconciliation from Soroban RPC (Task 1)
reconcileMarketFromChain(marketId)reads market state directly from on-chain viasimulateTransactioncallingget_market_info()TransactionBuilderwith a throwaway keypair for read-only simulationscValToNativePOST /api/admin/markets/:id/reconcile(adminAuth-protected)2. Optimistic row insertion on create_market tx (Task 2)
createMarketOptimistic(txHash, marketData)inserts an optimistic row immediately after tx submissiontxHashas temporary ID so row can be matched when the real event arrivescreateMarketRecord()now runs an interactive Prisma transaction to atomically reconcile:POST /api/markets/optimisticendpoint3. List markets created by a given address (Task 3)
getMarketsByCreator(createdBy, pagination)uses indexedcreatedBycolumn{ data: Market[], total: number }with page/limit pagination@@index([createdBy])on the Market modelCREATE INDEX Market_createdBy_idx ON Market (createdBy)GET /api/markets/by-creator/:address?page=&limit=4. Single-market lookup by marketId (Task 4)
getMarketById()returnsMarket | nullfor unknown IDs (not a thrown error)market.service.ts:getAllMarkets,getMarketById,createMarketRecordPrismaClientto shareddbinstanceFiles Changed
backend/src/services/market.service.tsbackend/src/api/controllers/market.controller.tsbackend/src/api/routes/market.routes.tsbackend/prisma/schema.prisma@@index([createdBy])on Marketbackend/prisma/migrations/.../migration.sqlTesting