kabu_rpc_handler/handler/
blocks.rs1use crate::dto::block::BlockHeader;
2use axum::extract::State;
3use axum::http::StatusCode;
4use axum::Json;
5use kabu_rpc_state::AppState;
6use revm::{DatabaseCommit, DatabaseRef};
7
8#[utoipa::path(
12 get,
13 path = "latest_block",
14 tag = "block",
15 tags = [],
16 responses(
17 (status = 200, description = "Todo item created successfully", body = BlockHeader),
18 )
19)]
20pub async fn latest_block<DB: DatabaseRef + DatabaseCommit + Send + Sync + Clone + 'static>(
21 State(app_state): State<AppState<DB>>,
22) -> Result<Json<BlockHeader>, (StatusCode, String)> {
23 {
24 let block_header_opt = app_state.bc.latest_block().read().await.block_header.clone();
25 if let Some(block_header) = block_header_opt {
26 let ret = BlockHeader {
27 number: block_header.number,
28 timestamp: block_header.timestamp,
29 base_fee_per_gas: block_header.base_fee_per_gas,
30 next_block_base_fee: 0,
31 };
32 Ok(Json(ret))
33 } else {
34 Err((StatusCode::INTERNAL_SERVER_ERROR, "No block header found".to_string()))
35 }
36 }
37}