feat(api): add v2 /chain/globals endpoint - #37
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fetches a single post from HAFSQL with the same column shape, children count and vote aggregation as the feed, then runs it through dealiasSoftPosts so lite-user (@skateuser) identity is preserved. Serves edge-cached (s-maxage=300) so post pages, OG images and Farcaster frames stop hitting Hive RPC directly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Covers the happy path (single post by author/permlink) and the 404 (nonexistent permlink) in the existing status-code smoke suite. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Introduces vitest (+ test/test:watch scripts and a config that mirrors the '@/*' tsconfig alias) as the unit-test framework for API routes. Unit tests live in tests/unit/ so route folders with literal-bracket segments (e.g. [author]) don't break glob includes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Covers 200 (normalized shape + 300s edge-cache headers), query parameterization, soft-post de-alias delegation, 404 (short cache), and 500 (no cache). HAFSQL and dealiasSoftPosts are mocked so the suite runs with no live DB. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Bundles the chain-wide constants clients need for HP and vote-value math: dynamic global properties (VESTS<->HP ratio), the post reward fund (reward_balance / recent_claims) and the HIVE/USD median price. Follows a HAFSQL-first, dhive-fallback pattern: global properties come from the HAFSQL dynamic_global_properties view (normalized from raw integers) and fall back to dhive RPC if the view is unavailable/empty. Reward fund and median price are dhive-only (HAFSQL doesn't expose them). Edge-cached at s-maxage=300 since these are identical per-user and slow-moving. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Covers the HAFSQL path (no DGPO RPC), RPC fallback on both HAFSQL throw and empty rows, number normalization parity between sources, the post reward-fund request, and the 500 path. HAFSQL and HiveClient are mocked. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 24 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Part of #38 (read-through-API tracking issue). |
What
Adds
GET /api/v2/chain/globals— the chain-wide constants clients need for HP and vote-value math, in one edge-cached read.Third in the series of small PRs closing API read gaps for the "read-through-API" migration.
Why
useHivePoweron the webapp fires three RPC calls per user, per page to compute HP and "$ per vote":reward_balance / recent_claimsfrom the post reward fundThese are identical for every user and slow-moving, so one cached endpoint replaces N per-user RPC bursts.
How — HAFSQL-first, dhive fallback
Following the principle that reads should prefer HAFSQL and use dhive as the resilience layer:
dynamic_global_propertiesview, newest row byblock_num), dhive RPC fallback if the view is unavailable/empty. HAFSQL stores raw integers and RPC returns asset strings, so both are normalized to a single numeric shape (with asourcefield so consumers can see which path served it).operation_*_reward_table/operation_feed_publish_tablelogs exist, not current pool/median state). Verified directly against our HAFSQL instance.s-maxage=300, stale-while-revalidate=150.Response shape
{ "success": true, "data": { "globalProperties": { "total_vesting_fund_hive": 212276626.544, "total_vesting_shares": 343888772092.4087, "vests_per_hive": 1620.003, "head_block_number": 107803905, "source": "hafsql" }, "rewardFund": { "reward_balance": "1086575.137 HIVE", "recent_claims": "763634274937908862", "...": "..." }, "medianPrice": { "base": "0.050 HBD", "quote": "1.000 HIVE" } } }Testing
tests/unit/chain-globals.route.test.ts, 5 tests, no live DB — HAFSQL + HiveClient mocked): HAFSQL path (asserts no DGPO RPC), RPC fallback on both HAFSQL throw and empty rows, cross-source number-normalization parity, theget_reward_fund(['post'])request, and the 500 path.source: hafsqlat the current head block,shares/fundmatchesvests_per_hiveexactly, reward fund + median populated.tests/test-api-endpoints.sh): chain globals check added.pnpm lintclean;pnpm buildcompiles the route as dynamic.Notes
🤖 Generated with Claude Code