Indexer
The WeedSwap indexer is an observational service. It does not authorize or settle protocol actions.
#Inputs
The service refuses to start unless it receives a PostgreSQL URL, chain ID, HTTP(S) RPC URL, start block, confirmation depth, one or more unique nonzero contract addresses, and a valid port. Integer syntax and address lists are validated before PostgreSQL or RPC connections open. There are no production defaults and an empty address list is an error.
DATABASE_URL=postgresql://weedswap:<percent-encoded-password>@postgres:5432/weedswap
CHAIN_ID=31337
RPC_URL=http://127.0.0.1:8545
START_BLOCK=0
CONFIRMATION_DEPTH=0
INDEX_ADDRESSES=<comma-separated-local-deployment-addresses>
PORT=4201The local launcher replaces INDEX_ADDRESSES in its process after deploying the local contracts. Production Compose consumes DATABASE_URL from the same external environment file that the deployment preflight validates; it does not replace that URL. Reserved password characters in a PostgreSQL URL must be percent-encoded.
#Block loop
The service validates the RPC chain ID once, finds a safe head after confirmation depth, reads up to 200 blocks per range, stores block identity, fetches logs for configured addresses, and advances a durable cursor.
#Reorg handling
Before applying a block, the indexer compares the saved parent block hash. A mismatch rewinds up to 20 blocks, deletes affected events and block records inside a transaction, resets the cursor, and replays canonical data.
#Storage model
| Table | Purpose |
|---|---|
| chain_blocks | Chain ID, block number, hash, and parent hash |
| protocol_events | Raw topic, data payload, address, event name, and block identity |
| indexer_cursors | Next block and last finalized hash per chain |
#Health and metrics
The HTTP service exposes /health with chain ID and last indexed block, and /metrics with a basic healthy flag and last block gauge. These endpoints show service progress, not protocol solvency or market health.
