mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 04:01:51 +00:00
Changes to rest_api (#480)
* Add half-finished rest api changes * Add basic, messy changes to rest api * Fix expect() in ApiRequest * Remove ApiRequest, add route for beacon state * Tidy rest api, add get state from root * Add api method for getting state roots by slot * Add test for URL helper * Simplify state_at_slot fn * Add tests for rest api helper fns * Add extra tests for parse root * Fix clippy lints * Fix compile error in rest api * Update test to new ethereum-types
This commit is contained in:
25
beacon_node/rest_api/src/node.rs
Normal file
25
beacon_node/rest_api/src/node.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use crate::{success_response, ApiResult};
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use hyper::{Body, Request};
|
||||
use std::sync::Arc;
|
||||
use version;
|
||||
|
||||
/// Read the version string from the current Lighthouse build.
|
||||
pub fn get_version(_req: Request<Body>) -> ApiResult {
|
||||
let body = Body::from(
|
||||
serde_json::to_string(&version::version())
|
||||
.expect("Version should always be serialializable as JSON."),
|
||||
);
|
||||
Ok(success_response(body))
|
||||
}
|
||||
|
||||
/// Read the genesis time from the current beacon chain state.
|
||||
pub fn get_genesis_time<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult {
|
||||
let beacon_chain = req.extensions().get::<Arc<BeaconChain<T>>>().unwrap();
|
||||
let gen_time: u64 = beacon_chain.head().beacon_state.genesis_time;
|
||||
let body = Body::from(
|
||||
serde_json::to_string(&gen_time)
|
||||
.expect("Genesis should time always have a valid JSON serialization."),
|
||||
);
|
||||
Ok(success_response(body))
|
||||
}
|
||||
Reference in New Issue
Block a user