2024-05-21 12:41:34 -07:00
|
|
|
use crate::http_util::not_found_err;
|
|
|
|
|
use crate::http_util::rpc_err;
|
|
|
|
|
use crate::model::app_state::AppState;
|
|
|
|
|
use crate::model::block_selector_extended::BlockSelectorExtended;
|
2024-05-09 11:01:53 -07:00
|
|
|
use axum::extract::Path;
|
|
|
|
|
use axum::extract::State;
|
|
|
|
|
use axum::response::Json;
|
|
|
|
|
use axum::response::Response;
|
2024-05-10 17:04:11 -07:00
|
|
|
use neptune_core::models::blockchain::block::block_info::BlockInfo;
|
2024-05-09 11:01:53 -07:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
use tarpc::context;
|
|
|
|
|
|
|
|
|
|
#[axum::debug_handler]
|
|
|
|
|
pub async fn block_info(
|
2024-05-21 12:41:34 -07:00
|
|
|
Path(selector): Path<BlockSelectorExtended>,
|
2024-05-09 11:01:53 -07:00
|
|
|
State(state): State<Arc<AppState>>,
|
|
|
|
|
) -> Result<Json<BlockInfo>, Response> {
|
2024-05-21 12:41:34 -07:00
|
|
|
let block_info = state
|
2024-05-25 19:16:36 -07:00
|
|
|
.read()
|
|
|
|
|
.await
|
2024-05-09 11:01:53 -07:00
|
|
|
.rpc_client
|
2024-05-21 12:41:34 -07:00
|
|
|
.block_info(context::current(), selector.into())
|
2024-05-09 11:01:53 -07:00
|
|
|
.await
|
|
|
|
|
.map_err(rpc_err)?
|
2024-05-21 12:41:34 -07:00
|
|
|
.ok_or_else(not_found_err)?;
|
|
|
|
|
|
|
|
|
|
Ok(Json(block_info))
|
2024-05-09 11:01:53 -07:00
|
|
|
}
|