diff --git a/beacon_node/rest_api/src/error.rs b/beacon_node/rest_api/src/error.rs index f3eb597a0..b6b1bbfb5 100644 --- a/beacon_node/rest_api/src/error.rs +++ b/beacon_node/rest_api/src/error.rs @@ -1,7 +1,7 @@ use hyper::{Body, Method, Request, Response, Server, StatusCode}; use std::error::Error as StdError; -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Debug, Clone)] pub enum ApiError { MethodNotAllowed(String), ServerError(String), @@ -14,7 +14,7 @@ pub enum ApiError { pub type ApiResult = Result, ApiError>; impl ApiError { - pub fn status_code(&self) -> (StatusCode, &String) { + pub fn status_code(self) -> (StatusCode, String) { match self { ApiError::MethodNotAllowed(desc) => (StatusCode::METHOD_NOT_ALLOWED, desc), ApiError::ServerError(desc) => (StatusCode::INTERNAL_SERVER_ERROR, desc), @@ -30,10 +30,10 @@ impl Into> for ApiError { fn into(self) -> Response { let status_code = self.status_code(); Response::builder() - .status(status_code.0) - .header("content-type", "text/plain") - .body(Body::from(*status_code.1)) - .expect("Response should always be created.") + .status(status_code.0) + .header("content-type", "text/plain") + .body(Body::from(status_code.1)) + .expect("Response should always be created.") } } @@ -63,7 +63,7 @@ impl StdError for ApiError { impl std::fmt::Display for ApiError { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - let status = self.status_code(); + let status = self.clone().status_code(); write!(f, "{:?}: {:?}", status.0, status.1) } } diff --git a/beacon_node/rest_api/src/lib.rs b/beacon_node/rest_api/src/lib.rs index a5f62360d..0852dd1a3 100644 --- a/beacon_node/rest_api/src/lib.rs +++ b/beacon_node/rest_api/src/lib.rs @@ -79,7 +79,6 @@ impl Service for ApiService { let result = match (req.method(), path.as_ref()) { // Methods for Client (&Method::GET, "/node/version") => node::get_version(req), - /* (&Method::GET, "/node/genesis_time") => node::get_genesis_time::(req), (&Method::GET, "/node/syncing") => helpers::implementation_pending_response(req), @@ -89,9 +88,7 @@ impl Service for ApiService { (&Method::GET, "/network/peer_id") => network::get_peer_id::(req), (&Method::GET, "/network/peers") => network::get_peer_list::(req), (&Method::GET, "/network/listen_port") => network::get_listen_port::(req), - (&Method::GET, "/network/listen_addresses") => { - network::get_listen_addresses::(req) - } + (&Method::GET, "/network/listen_addresses") => network::get_listen_addresses::(req), // Methods for Beacon Node (&Method::GET, "/beacon/head") => beacon::get_head::(req), @@ -99,9 +96,7 @@ impl Service for ApiService { (&Method::GET, "/beacon/block_root") => beacon::get_block_root::(req), (&Method::GET, "/beacon/blocks") => helpers::implementation_pending_response(req), (&Method::GET, "/beacon/fork") => beacon::get_fork::(req), - (&Method::GET, "/beacon/attestations") => { - helpers::implementation_pending_response(req) - } + (&Method::GET, "/beacon/attestations") => helpers::implementation_pending_response(req), (&Method::GET, "/beacon/attestations/pending") => { helpers::implementation_pending_response(req) } @@ -115,15 +110,9 @@ impl Service for ApiService { } // Methods for Validator - (&Method::GET, "/beacon/validator/duties") => { - validator::get_validator_duties::(req) - } - (&Method::GET, "/beacon/validator/block") => { - validator::get_new_beacon_block::(req) - } - (&Method::POST, "/beacon/validator/block") => { - validator::publish_beacon_block::(req) - } + (&Method::GET, "/beacon/validator/duties") => validator::get_validator_duties::(req), + (&Method::GET, "/beacon/validator/block") => validator::get_new_beacon_block::(req), + //(&Method::POST, "/beacon/validator/block") => validator::publish_beacon_block::(req), (&Method::GET, "/beacon/validator/attestation") => { validator::get_new_attestation::(req) } @@ -149,7 +138,6 @@ impl Service for ApiService { (&Method::GET, "/metrics") => metrics::get_prometheus::(req), - */ _ => Err(ApiError::NotFound( "Request path and/or method not found.".to_owned(), )), @@ -208,8 +196,8 @@ pub fn start_server( let service = move || -> futures::future::FutureResult, String> { futures::future::ok(ApiService { - log: log.clone(), - beacon_chain: beacon_chain.clone(), + log: server_log.clone(), + beacon_chain: server_bc.clone(), db_path: db_path.clone(), network_service: network_service.clone(), network_channel: Arc::new(RwLock::new(network_chan.clone())), diff --git a/beacon_node/rest_api/src/validator.rs b/beacon_node/rest_api/src/validator.rs index 2ead55d14..8b2bbd2ac 100644 --- a/beacon_node/rest_api/src/validator.rs +++ b/beacon_node/rest_api/src/validator.rs @@ -203,7 +203,9 @@ pub fn get_new_beacon_block(req: Request) - Ok(success_response(body)) } -/// HTTP Handler to publish a BeaconBlock, which has been signed by a validator. +/* + + HTTP Handler to publish a BeaconBlock, which has been signed by a validator. pub fn publish_beacon_block(req: Request) -> ApiResult { let _ = check_content_type_for_json(&req)?; let log = get_logger_from_request(&req); @@ -232,11 +234,8 @@ pub fn publish_beacon_block(req: Request) - )) }); block_result - }) - .unwrap() - .unwrap(); + }); - /* .map_err(|e| ApiError::ServerError(format!("Unable parse request body: {:?}", e))) .and_then(|body| { trace!(log, "parsing json"); @@ -251,7 +250,6 @@ pub fn publish_beacon_block(req: Request) - }); tokio::run(block_future); let block = block_future.wait()?; - */ trace!(log, "BeaconBlock successfully parsed from JSON"; "block" => serde_json::to_string(&block).expect("We should always be able to serialize a block that we just created.")); match beacon_chain.process_block(block.clone()) { Ok(BlockProcessingOutcome::Processed { block_root }) => { @@ -277,6 +275,7 @@ pub fn publish_beacon_block(req: Request) - Ok(success_response(Body::empty())) } + */ /// HTTP Handler to produce a new Attestation from the current state, ready to be signed by a validator. pub fn get_new_attestation(req: Request) -> ApiResult {