diff --git a/beacon_node/rest_api/src/lib.rs b/beacon_node/rest_api/src/lib.rs index 2062d4e03..a5f62360d 100644 --- a/beacon_node/rest_api/src/lib.rs +++ b/beacon_node/rest_api/src/lib.rs @@ -14,13 +14,14 @@ mod spec; mod url_query; mod validator; -use error::{ApiError, ApiResult}; use beacon_chain::{BeaconChain, BeaconChainTypes}; use client_network::NetworkMessage; use client_network::Service as NetworkService; +use error::{ApiError, ApiResult}; use eth2_config::Eth2Config; use hyper::rt::Future; -use hyper::service::{Service, MakeService}; +use hyper::server::conn::AddrStream; +use hyper::service::{MakeService, Service}; use hyper::{Body, Method, Request, Response, Server, StatusCode}; use parking_lot::RwLock; use response_builder::ResponseBuilder; @@ -31,7 +32,6 @@ use std::sync::Arc; use tokio::runtime::TaskExecutor; use tokio::sync::mpsc; use url_query::UrlQuery; -use hyper::server::conn::AddrStream; pub use beacon::{BlockResponse, HeadResponse, StateResponse}; pub use config::Config as ApiConfig; @@ -40,35 +40,6 @@ use serde::export::PhantomData; type BoxFut = Box, Error = ApiError> + Send>; -pub struct ApiMaker { - log: slog::Logger, - beacon_chain: Arc>, - db_path: DBPath, - network_service: Arc>, - network_channel: Arc>>, - eth2_config: Arc, -} - -impl MakeService for ApiMaker { - type ReqBody = Body; - type ResBody = Body; - type Error = ApiError; - type Service = ApiService; - type Future = futures::future::FutureResult; - type MakeError = String; - - fn make_service(&mut self, _ctx: AddrStream) -> Self::Future { - futures::future::ok(ApiService { - log: self.log.clone(), - beacon_chain: self.beacon_chain.clone(), - db_path: self.db_path.clone(), - network_service: self.network_service.clone(), - network_channel: self.network_channel.clone(), - eth2_config: self.eth2_config.clone(), - }) - } -} - pub struct ApiService { log: slog::Logger, beacon_chain: Arc>, @@ -201,7 +172,6 @@ impl Service for ApiService { metrics::stop_timer(timer); Box::new(futures::future::ok(response)) - } } @@ -236,16 +206,17 @@ pub fn start_server( let server_bc = beacon_chain.clone(); let eth2_config = Arc::new(eth2_config); - let service = move || ApiMaker { - log: log.clone(), - beacon_chain: beacon_chain.clone(), - db_path: db_path.clone(), - network_service: network_service.clone(), - network_channel: Arc::new(RwLock::new(network_chan.clone())), - eth2_config: eth2_config.clone(), + let service = move || -> futures::future::FutureResult, String> { + futures::future::ok(ApiService { + log: log.clone(), + beacon_chain: beacon_chain.clone(), + db_path: db_path.clone(), + network_service: network_service.clone(), + network_channel: Arc::new(RwLock::new(network_chan.clone())), + eth2_config: eth2_config.clone(), + }) }; - let log_clone = log.clone(); let server = Server::bind(&bind_addr) .serve(service)