Skip to content

Commit

Permalink
Add stats fields for GET /colors API
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamaguchi committed Mar 25, 2024
1 parent 3aa81f5 commit 7c71bb8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,17 @@ fn handle_request(
ColorIdentifier::from_hex(hex).ok()
});
let colors: Vec<(ColorIdentifier, u32)> = query.get_colors(color_id, COLOR_IDS_PER_PAGE);
json_response(colors, TTL_SHORT)
info!("colors: {:?}", colors);
let values: Vec<_> = colors.into_iter().map(|(color_id, height)| {
let stats = query.get_colored_stats(&color_id);
json!({
"color_id": color_id,
"height": height,
"chain_stats": ColoredStatsValue::from(stats.0),
"mempool_stats": ColoredStatsValue::from(stats.1)
})
}).collect();
json_response(values, TTL_SHORT)
}

(&Method::GET, Some(&"color"), Some(color_id), None, None, None) => {
Expand Down

0 comments on commit 7c71bb8

Please sign in to comment.