Further restructuring futures API.

- Adding try_future! macros where necessary
 - Returning ApiResult and mapping it to future instead
 - Upgrading POST publish block to return a future directly
This commit is contained in:
Luke Anderson
2019-09-11 18:02:00 +10:00
parent ebd97730d5
commit 2739ee83f9
5 changed files with 68 additions and 60 deletions

View File

@@ -5,19 +5,13 @@ use hyper::{Body, Request};
use version;
/// Read the version string from the current Lighthouse build.
pub fn get_version(req: Request<Body>) -> BoxFut {
success_response_json(req, &version::version())
pub fn get_version(req: Request<Body>) -> ApiResult {
success_response_2_json(req, &version::version())
}
/// Read the genesis time from the current beacon chain state.
pub fn get_genesis_time<T: BeaconChainTypes + 'static>(req: Request<Body>) -> BoxFut {
let bc = get_beacon_chain_from_request::<T>(&req);
let (_beacon_chain, head_state) = match bc {
Ok((bc, hs)) => (bc, hs),
Err(e) => {
return e.into();
}
};
pub fn get_genesis_time<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult {
let (_beacon_chain, head_state) = get_beacon_chain_from_request::<T>(&req)?;
let gen_time: u64 = head_state.genesis_time;
success_response(req, &gen_time)
success_response_2(req, &gen_time)
}