API service
Location:src/services/api.ts
The API service provides a REST API and Prometheus metrics endpoint.
Class: ApiService
Singleton service that manages an Express server.
Endpoints
Root endpoint
- GET
/- Returns ”🐮 Moooo!”
Metrics
- GET
/metrics- Prometheus metrics
Health check
- GET
/health- Returns health status of all chains - Response includes overall health and per-chain status
Configuration
- GET
/config- Returns current watch-tower configuration - Shows chain IDs, contracts, deployment blocks, and filter policies
API endpoints
- GET
/api/version- Version information - GET
/api/dump/:chainId- Dumps registry for specified chain ID
Usage
Configuration
The API server can be disabled with the--disable-api flag:
Chain service
Location:src/services/chain.ts
The chain service manages blockchain interactions and order monitoring for each network.
Class: ChainContext
Represents a single blockchain network being monitored.
Initialization
Warm-up phase
The warm-up phase synchronizes historical blocks:- Loads last processed block from database
- Fetches events from
deploymentBlockto current block - Processes events in pages (configurable size)
- Updates registry with new conditional orders
- Transitions to
IN_SYNCstate
Block watching
After warm-up, subscribes to new blocks:- Fetches
ConditionalOrderCreatedevents - Processes new conditional orders
- Polls existing orders for discrete order creation
- Updates database atomically
Health monitoring
Sync states
- SYNCING: Catching up with historical blocks
- IN_SYNC: Caught up, watching new blocks
- UNKNOWN: Watchdog timeout exceeded (may indicate RPC issues)
Provider support
Supports both HTTP and WebSocket providers:Storage service
Location:src/services/storage.ts
The storage service provides database operations using LevelDB.
Class: DBService
Singleton service for database operations.
Configuration
Database options:Usage
Default location
Default database path:./database
Can be configured:
ACID guarantees
LevelDB provides:- Atomicity: Batch operations are atomic
- Consistency: Schema validation on read/write
- Isolation: Single-threaded Node.js
- Durability: Writes are persisted to disk
Service initialization order
- DBService: Initialize database connection
- ApiService: Start REST API server (if enabled)
- ChainContext: Initialize per network
- Create provider
- Load registry from database
- Start chain monitoring