mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
- Cleaned up imports - Moved ApiError and such to it's own error.rs - Obsoleted 'success_response' in favour of new async regular and json only flavours - Made ApiError work async and be derived from hyper errors - Added a check to ensure an error is thrown if a non-json encoding is requested on a json-only function - Made all the individual service functions return futures (only node and network for now)
40 lines
1.5 KiB
Rust
40 lines
1.5 KiB
Rust
use super::ApiResult;
|
|
use crate::helpers::*;
|
|
use crate::ApiError;
|
|
use beacon_chain::BeaconChainTypes;
|
|
use eth2_config::Eth2Config;
|
|
use hyper::{Body, Request};
|
|
use std::sync::Arc;
|
|
use types::EthSpec;
|
|
|
|
/// HTTP handler to return the full spec object.
|
|
pub fn get_spec<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult {
|
|
let (beacon_chain, _head_state) = get_beacon_chain_from_request::<T>(&req)?;
|
|
|
|
let json: String = serde_json::to_string(&beacon_chain.spec)
|
|
.map_err(|e| ApiError::ServerError(format!("Unable to serialize spec: {:?}", e)))?;
|
|
|
|
Ok(success_response_old(Body::from(json)))
|
|
}
|
|
|
|
/// HTTP handler to return the full Eth2Config object.
|
|
pub fn get_eth2_config<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult {
|
|
let eth2_config = req
|
|
.extensions()
|
|
.get::<Arc<Eth2Config>>()
|
|
.ok_or_else(|| ApiError::ServerError("Eth2Config extension missing".to_string()))?;
|
|
|
|
let json: String = serde_json::to_string(eth2_config.as_ref())
|
|
.map_err(|e| ApiError::ServerError(format!("Unable to serialize Eth2Config: {:?}", e)))?;
|
|
|
|
Ok(success_response_old(Body::from(json)))
|
|
}
|
|
|
|
/// HTTP handler to return the full spec object.
|
|
pub fn get_slots_per_epoch<T: BeaconChainTypes + 'static>(_req: Request<Body>) -> ApiResult {
|
|
let json: String = serde_json::to_string(&T::EthSpec::slots_per_epoch())
|
|
.map_err(|e| ApiError::ServerError(format!("Unable to serialize epoch: {:?}", e)))?;
|
|
|
|
Ok(success_response_old(Body::from(json)))
|
|
}
|