feat: DB models (User, EventLog, Bet index) + Soroban RPC event subscription - #1163
Merged
Conversation
- Add User model to Prisma schema with address as primary key - Stellar address format validation regex (G...56 chars) - createdAt and updatedAt timestamps Task 1: Implement the DB table/migration for UserModel
- Add User model: address PK, createdAt, updatedAt - Add EventLog model: idempotent ingestion via @@unique(txHash, eventType), nullable processedAt with index for unprocessed queries - Add @@index([marketId, bettor]) on Bet for fast lookups - Migration SQL for all three schema changes Tasks 1-3: DB table/migration for UserModel, BetModel, EventLogModel
- Bootstraps the indexer by calling startIndexer() - Graceful crash handling with exit code 1 - Requires STELLAR_RPC_URL, MARKET_FACTORY_CONTRACT_ID, and DATABASE_URL Task 4 (part 1): Indexer entry point
… processing
- Subscribe to ALL contract events (no contractIds filter) so dynamically
deployed Market contract events are never missed across restarts
- Write raw events to EventLog table BEFORE downstream processing via
persistRawEvents() with idempotent upsert on (txHash, eventType)
- Mark events as processed after successful downstream processing via
markEventsProcessed() using nullable processedAt index
- Exponential backoff reconnection on RPC disconnect (existing behavior)
- Route known events through switch/case handlers, log warnings for unknowns
Task 4: Subscribe to Soroban RPC events for all three contracts
and persist raw events
…iption feat: DB models (User, EventLog, Bet index) + Soroban RPC event subscription
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 #1061
Closes #1062
Closes #1063
Closes #1064
Summary
This PR implements four tasks that add database models, indexes, and a multi-contract Soroban RPC event subscription system.
Commit 1: UserModel DB table (Task 1)
Usermodel withaddressas primary key (Stellar G…56 format)user.model.tscreatedAtandupdatedAttimestampsCommit 2: DB schema + migration (Tasks 2 & 3)
@@index([marketId, bettor])for fast lookups@@unique([txHash, eventType])guarantees idempotent ingestionprocessedAtnullableDateTimewith index for efficient "unprocessed" queriestxHash,eventType,contractId,ledger,ledgerClosedAt,body(JSON)Commits 3 & 4: Soroban RPC event subscription (Task 4)
src/indexer/index.ts): Bootstraps the long-lived event listenersrc/services/indexer.service.ts):persistRawEvents()with idempotent upsertmarkEventsProcessed()Acceptance Criteria
addressPK, validated as Stellar address