diff --git a/beacon_node/rest_api/src/beacon.rs b/beacon_node/rest_api/src/beacon.rs index 302061395f..7828898e82 100644 --- a/beacon_node/rest_api/src/beacon.rs +++ b/beacon_node/rest_api/src/beacon.rs @@ -55,10 +55,7 @@ pub fn get_head(req: Request) -> ApiResult previous_justified_block_root: chain_head.beacon_state.previous_justified_checkpoint.root, }; - let json: String = serde_json::to_string(&head) - .map_err(|e| ApiError::ServerError(format!("Unable to serialize HeadResponse: {:?}", e)))?; - - Ok(success_response_old(Body::from(json))) + ResponseBuilder::new(&req).body(&head) } #[derive(Serialize, Encode)] @@ -119,10 +116,7 @@ pub fn get_block_root(req: Request) -> ApiR ApiError::NotFound(format!("Unable to find BeaconBlock for slot {:?}", target)) })?; - let json: String = serde_json::to_string(&root) - .map_err(|e| ApiError::ServerError(format!("Unable to serialize root: {:?}", e)))?; - - Ok(success_response_old(Body::from(json))) + ResponseBuilder::new(&req).body(&root) } /// HTTP handler to return the `Fork` of the current head. @@ -231,10 +225,7 @@ pub fn get_state_root(req: Request) -> ApiR let root = state_root_at_slot(&beacon_chain, slot)?; - let json: String = serde_json::to_string(&root) - .map_err(|e| ApiError::ServerError(format!("Unable to serialize root: {:?}", e)))?; - - Ok(success_response_old(Body::from(json))) + ResponseBuilder::new(&req).body(&root) } /// HTTP handler to return the highest finalized slot. @@ -246,10 +237,7 @@ pub fn get_current_finalized_checkpoint( let checkpoint = head_state.finalized_checkpoint.clone(); - let json: String = serde_json::to_string(&checkpoint) - .map_err(|e| ApiError::ServerError(format!("Unable to serialize checkpoint: {:?}", e)))?; - - Ok(success_response_old(Body::from(json))) + ResponseBuilder::new(&req).body(&checkpoint) } /// HTTP handler to return a `BeaconState` at the genesis block. diff --git a/beacon_node/rest_api/src/metrics.rs b/beacon_node/rest_api/src/metrics.rs index 09d361b8a2..d50e4a98ca 100644 --- a/beacon_node/rest_api/src/metrics.rs +++ b/beacon_node/rest_api/src/metrics.rs @@ -1,5 +1,5 @@ use crate::response_builder::ResponseBuilder; -use crate::{helpers::*, success_response, ApiError, ApiResult, DBPath}; +use crate::{helpers::*, ApiError, ApiResult, DBPath}; use beacon_chain::BeaconChainTypes; use http::HeaderValue; use hyper::{Body, Request}; diff --git a/beacon_node/rest_api/src/validator.rs b/beacon_node/rest_api/src/validator.rs index c665a0b1f6..05ae6b8c99 100644 --- a/beacon_node/rest_api/src/validator.rs +++ b/beacon_node/rest_api/src/validator.rs @@ -149,11 +149,7 @@ pub fn get_validator_duties(req: Request) - duties.append(&mut vec![duty]); } - let body = Body::from( - serde_json::to_string(&duties) - .expect("We should always be able to serialize the duties we created."), - ); - Ok(success_response_old(body)) + ResponseBuilder::new(&req).body_json(&duties) } /// HTTP Handler to produce a new BeaconBlock from the current state, ready to be signed by a validator. @@ -189,10 +185,6 @@ pub fn get_new_beacon_block(req: Request) - )) })?; - let body = Body::from( - serde_json::to_string(&new_block) - .expect("We should always be able to serialize a new block that we produced."), - ); ResponseBuilder::new(&req).body(&new_block) } @@ -359,9 +351,5 @@ pub fn get_new_attestation(req: Request) -> signature: AggregateSignature::new(), }; - let body = Body::from( - serde_json::to_string(&attestation) - .expect("We should always be able to serialize a new attestation that we produced."), - ); - Ok(success_response_old(body)) + ResponseBuilder::new(&req).body(&attestation) }