Moved beacon chain from request functionality into its own function.

This commit is contained in:
Luke Anderson
2019-09-04 22:03:55 +10:00
parent 01b652ab0e
commit eeba69cd0f
3 changed files with 10 additions and 28 deletions

View File

@@ -1,9 +1,8 @@
use crate::{success_response, ApiError, ApiResult, DBPath};
use beacon_chain::{BeaconChain, BeaconChainTypes};
use crate::{helpers::*, success_response, ApiError, ApiResult, DBPath};
use beacon_chain::BeaconChainTypes;
use http::HeaderValue;
use hyper::{Body, Request};
use prometheus::{Encoder, TextEncoder};
use std::sync::Arc;
pub use lighthouse_metrics::*;
@@ -31,10 +30,7 @@ pub fn get_prometheus<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiR
let mut buffer = vec![];
let encoder = TextEncoder::new();
let beacon_chain = req
.extensions()
.get::<Arc<BeaconChain<T>>>()
.ok_or_else(|| ApiError::ServerError("Beacon chain extension missing".to_string()))?;
let beacon_chain = get_beacon_chain_from_request::<T>(&req)?;
let db_path = req
.extensions()
.get::<DBPath>()