Moved chain/cache building into separate function, and made sure that all REST API endpoints are using this function to get the state.

This commit is contained in:
Luke Anderson
2019-09-09 12:10:41 +10:00
parent a2267dc4d3
commit 99c673045c
6 changed files with 26 additions and 42 deletions

View File

@@ -1,7 +1,7 @@
use crate::helpers::get_beacon_chain_from_request;
use crate::{success_response, ApiResult};
use beacon_chain::{BeaconChain, BeaconChainTypes};
use beacon_chain::BeaconChainTypes;
use hyper::{Body, Request};
use std::sync::Arc;
use version;
/// Read the version string from the current Lighthouse build.
@@ -15,8 +15,8 @@ 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 = req.extensions().get::<Arc<BeaconChain<T>>>().unwrap();
let gen_time: u64 = beacon_chain.head().beacon_state.genesis_time;
let (_beacon_chain, head_state) = get_beacon_chain_from_request::<T>(&req)?;
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."),