Removing 'success_respons' in favour of 'ResponseBuilder'
This commit is contained in:
parent
09e11dd081
commit
91f5f17566
@ -55,10 +55,7 @@ pub fn get_head<T: BeaconChainTypes + 'static>(req: Request<Body>) -> 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<T: BeaconChainTypes + 'static>(req: Request<Body>) -> 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<T: BeaconChainTypes + 'static>(req: Request<Body>) -> 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<T: BeaconChainTypes + 'static>(
|
||||
|
||||
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.
|
||||
|
@ -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};
|
||||
|
@ -149,11 +149,7 @@ pub fn get_validator_duties<T: BeaconChainTypes + 'static>(req: Request<Body>) -
|
||||
|
||||
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<T: BeaconChainTypes + 'static>(req: Request<Body>) -
|
||||
))
|
||||
})?;
|
||||
|
||||
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<T: BeaconChainTypes + 'static>(req: Request<Body>) ->
|
||||
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user