Addressed Paul's comments regarding head_state.

This commit is contained in:
Luke Anderson
2019-09-13 18:58:08 +10:00
parent c254ac8c2e
commit b0e3ce7885
5 changed files with 21 additions and 24 deletions

View File

@@ -1,4 +1,5 @@
use crate::helpers::*;
use crate::response_builder::ResponseBuilder;
use crate::{success_response, ApiResult};
use beacon_chain::BeaconChainTypes;
use hyper::{Body, Request};
@@ -16,11 +17,5 @@ pub fn get_version(_req: Request<Body>) -> ApiResult {
/// Read the genesis time from the current beacon chain state.
pub fn get_genesis_time<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult {
let beacon_chain = get_beacon_chain_from_request::<T>(&req)?;
let head_state = get_head_state(beacon_chain)?;
let gen_time: u64 = head_state.genesis_time;
let body = Body::from(
serde_json::to_string(&gen_time)
.expect("Genesis should time always have a valid JSON serialization."),
);
Ok(success_response(body))
ResponseBuilder::new(&req).body(&beacon_chain.head().beacon_state.genesis_time)
}