Moved beacon chain from request functionality into its own function.
This commit is contained in:
parent
01b652ab0e
commit
eeba69cd0f
@ -109,10 +109,7 @@ pub fn get_block<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult
|
|||||||
|
|
||||||
/// HTTP handler to return a `BeaconBlock` root at a given `slot`.
|
/// HTTP handler to return a `BeaconBlock` root at a given `slot`.
|
||||||
pub fn get_block_root<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult {
|
pub fn get_block_root<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult {
|
||||||
let beacon_chain = req
|
let beacon_chain = get_beacon_chain_from_request::<T>(&req)?;
|
||||||
.extensions()
|
|
||||||
.get::<Arc<BeaconChain<T>>>()
|
|
||||||
.ok_or_else(|| ApiError::ServerError("Beacon chain extension missing".to_string()))?;
|
|
||||||
|
|
||||||
let slot_string = UrlQuery::from_request(&req)?.only_one("slot")?;
|
let slot_string = UrlQuery::from_request(&req)?.only_one("slot")?;
|
||||||
let target = parse_slot(&slot_string)?;
|
let target = parse_slot(&slot_string)?;
|
||||||
@ -163,10 +160,7 @@ pub struct StateResponse<T: EthSpec> {
|
|||||||
/// Will not return a state if the request slot is in the future. Will return states higher than
|
/// Will not return a state if the request slot is in the future. Will return states higher than
|
||||||
/// the current head by skipping slots.
|
/// the current head by skipping slots.
|
||||||
pub fn get_state<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult {
|
pub fn get_state<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult {
|
||||||
let beacon_chain = req
|
let beacon_chain = get_beacon_chain_from_request::<T>(&req)?;
|
||||||
.extensions()
|
|
||||||
.get::<Arc<BeaconChain<T>>>()
|
|
||||||
.ok_or_else(|| ApiError::ServerError("Beacon chain extension missing".to_string()))?;
|
|
||||||
|
|
||||||
let (key, value) = match UrlQuery::from_request(&req) {
|
let (key, value) = match UrlQuery::from_request(&req) {
|
||||||
Ok(query) => {
|
Ok(query) => {
|
||||||
@ -220,10 +214,7 @@ pub fn get_state<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult
|
|||||||
/// Will not return a state if the request slot is in the future. Will return states higher than
|
/// Will not return a state if the request slot is in the future. Will return states higher than
|
||||||
/// the current head by skipping slots.
|
/// the current head by skipping slots.
|
||||||
pub fn get_state_root<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult {
|
pub fn get_state_root<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult {
|
||||||
let beacon_chain = req
|
let beacon_chain = get_beacon_chain_from_request::<T>(&req)?;
|
||||||
.extensions()
|
|
||||||
.get::<Arc<BeaconChain<T>>>()
|
|
||||||
.ok_or_else(|| ApiError::ServerError("Beacon chain extension missing".to_string()))?;
|
|
||||||
|
|
||||||
let slot_string = UrlQuery::from_request(&req)?.only_one("slot")?;
|
let slot_string = UrlQuery::from_request(&req)?.only_one("slot")?;
|
||||||
let slot = parse_slot(&slot_string)?;
|
let slot = parse_slot(&slot_string)?;
|
||||||
@ -240,10 +231,7 @@ pub fn get_state_root<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiR
|
|||||||
pub fn get_current_finalized_checkpoint<T: BeaconChainTypes + 'static>(
|
pub fn get_current_finalized_checkpoint<T: BeaconChainTypes + 'static>(
|
||||||
req: Request<Body>,
|
req: Request<Body>,
|
||||||
) -> ApiResult {
|
) -> ApiResult {
|
||||||
let beacon_chain = req
|
let beacon_chain = get_beacon_chain_from_request::<T>(&req)?;
|
||||||
.extensions()
|
|
||||||
.get::<Arc<BeaconChain<T>>>()
|
|
||||||
.ok_or_else(|| ApiError::ServerError("Beacon chain extension missing".to_string()))?;
|
|
||||||
|
|
||||||
let checkpoint = beacon_chain
|
let checkpoint = beacon_chain
|
||||||
.head()
|
.head()
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
use crate::{success_response, ApiError, ApiResult, DBPath};
|
use crate::{helpers::*, success_response, ApiError, ApiResult, DBPath};
|
||||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
use beacon_chain::BeaconChainTypes;
|
||||||
use http::HeaderValue;
|
use http::HeaderValue;
|
||||||
use hyper::{Body, Request};
|
use hyper::{Body, Request};
|
||||||
use prometheus::{Encoder, TextEncoder};
|
use prometheus::{Encoder, TextEncoder};
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub use lighthouse_metrics::*;
|
pub use lighthouse_metrics::*;
|
||||||
|
|
||||||
@ -31,10 +30,7 @@ pub fn get_prometheus<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiR
|
|||||||
let mut buffer = vec![];
|
let mut buffer = vec![];
|
||||||
let encoder = TextEncoder::new();
|
let encoder = TextEncoder::new();
|
||||||
|
|
||||||
let beacon_chain = req
|
let beacon_chain = get_beacon_chain_from_request::<T>(&req)?;
|
||||||
.extensions()
|
|
||||||
.get::<Arc<BeaconChain<T>>>()
|
|
||||||
.ok_or_else(|| ApiError::ServerError("Beacon chain extension missing".to_string()))?;
|
|
||||||
let db_path = req
|
let db_path = req
|
||||||
.extensions()
|
.extensions()
|
||||||
.get::<DBPath>()
|
.get::<DBPath>()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use super::{success_response, ApiResult};
|
use super::{success_response, ApiResult};
|
||||||
|
use crate::helpers::*;
|
||||||
use crate::ApiError;
|
use crate::ApiError;
|
||||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
use beacon_chain::BeaconChainTypes;
|
||||||
use eth2_config::Eth2Config;
|
use eth2_config::Eth2Config;
|
||||||
use hyper::{Body, Request};
|
use hyper::{Body, Request};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -8,10 +9,7 @@ use types::EthSpec;
|
|||||||
|
|
||||||
/// HTTP handler to return the full spec object.
|
/// HTTP handler to return the full spec object.
|
||||||
pub fn get_spec<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult {
|
pub fn get_spec<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult {
|
||||||
let beacon_chain = req
|
let beacon_chain = get_beacon_chain_from_request::<T>(&req)?;
|
||||||
.extensions()
|
|
||||||
.get::<Arc<BeaconChain<T>>>()
|
|
||||||
.ok_or_else(|| ApiError::ServerError("Beacon chain extension missing".to_string()))?;
|
|
||||||
|
|
||||||
let json: String = serde_json::to_string(&beacon_chain.spec)
|
let json: String = serde_json::to_string(&beacon_chain.spec)
|
||||||
.map_err(|e| ApiError::ServerError(format!("Unable to serialize spec: {:?}", e)))?;
|
.map_err(|e| ApiError::ServerError(format!("Unable to serialize spec: {:?}", e)))?;
|
||||||
|
Loading…
Reference in New Issue
Block a user