Skip to content

Commit b25dc96

Browse files
feat: make explorer realtime updates honest and broader
Drive live UI from real WebSocket events (transaction-confirmed, mempool top-N), widen query invalidation, tighten poll fallback to 4s, and improve peers/masternodes UX so the explorer stays accurate without pretending every feed is push-live. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 053b10f commit b25dc96

32 files changed

Lines changed: 897 additions & 368 deletions

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ WEBSOCKET_ENABLED=true
1919
# Networks the realtime monitor polls (comma-separated: mainnet,testnet).
2020
# Only list networks you actually run a node for.
2121
WEBSOCKET_NETWORKS=mainnet
22-
BLOCKCHAIN_POLL_INTERVAL=10000
22+
# Block + mempool poll interval (ms). Default 4000.
23+
BLOCKCHAIN_POLL_INTERVAL=4000
2324
WEBSOCKET_HEARTBEAT_INTERVAL=30000
2425
WEBSOCKET_MAX_CONNECTIONS_PER_IP=5
2526
WEBSOCKET_MAX_PAYLOAD_BYTES=65536

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Modern, responsive block explorer for **FairCoin**. Vite + React SPA frontend with an Express API server (run with Bun) that talks JSON-RPC to a FairCoin node and caches responses in MongoDB. Real-time updates are pushed over WebSocket.
44

5+
## Realtime model
6+
7+
WebSocket (`WS /api/ws`) pushes **change notifications** (new blocks, mempool updates, network stats, transaction confirmations). Canonical blockchain data is always loaded over **HTTP** (`GET /api/*`) via React Query: the client invalidates (and optionally paints) caches on push, then refetches the full API shape. When the socket is down, live hooks fall back to a 30s HTTP poll. In local dev, Vite proxies `/api` with `ws: true` so the browser can upgrade `/api/ws` to the API server.
8+
59
## Stack
610

711
- **Frontend**: Vite, React 18, TypeScript, TanStack Query, Tailwind CSS 4, shadcn/Radix UI, react-router
@@ -62,7 +66,7 @@ MONGODB_URI=mongodb://localhost:27017/faircoin-explorer
6266
# WebSocket / realtime monitor
6367
WEBSOCKET_ENABLED=true
6468
WEBSOCKET_NETWORKS=mainnet # comma-separated; add testnet if you run a testnet node
65-
BLOCKCHAIN_POLL_INTERVAL=10000
69+
BLOCKCHAIN_POLL_INTERVAL=4000 # block/mempool poll (ms); default 4s
6670
WEBSOCKET_HEARTBEAT_INTERVAL=30000
6771
WEBSOCKET_MAX_CONNECTIONS_PER_IP=5
6872
WEBSOCKET_MAX_PAYLOAD_BYTES=65536
@@ -88,7 +92,7 @@ The Express server exposes a read-only JSON API under `/api`:
8892
- `GET /api/validate-address?address=`, `/api/fee-estimate`
8993
- `GET /api/price`, `/api/price/history`, `/api/stats/history`
9094
- `GET /api/bridge/reserves` (proxied WFAIR bridge reserves)
91-
- `WS /api/ws` (new blocks, mempool updates, network stats)
95+
- `WS /api/ws` — push of chain changes (`new-block`, `block-count`, `mempool-update` with top-N txs, `transaction-confirmed`, `network-stats`). Canonical data still comes from HTTP `/api/*`; the socket tells the client when to refetch.
9296

9397
## MCP server (for AI assistants)
9498

@@ -149,5 +153,6 @@ Only key generation is done in-process (using the audited `@noble/curves` secp25
149153

150154
## Notes
151155

156+
- Realtime model: the server polls the FairCoin RPC (default every 4s) and pushes change events on `WS /api/ws`. Clients should treat HTTP `/api/*` as the source of truth and use the socket to invalidate/refetch.
152157
- Address balances/history require a FairCoin node with `addressindex=1`; without it the explorer degrades gracefully to validation-only data.
153-
- The MongoDB cache populates on demand; `npm run sync-db` (full historical sync) is optional.
158+
- The MongoDB cache populates on demand; `bun run sync-db` (full historical sync) is optional.

0 commit comments

Comments
 (0)