mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Add network routes to API
This commit is contained in:
@@ -48,7 +48,7 @@ pub struct Client<T: BeaconChainTypes> {
|
||||
|
||||
impl<T> Client<T>
|
||||
where
|
||||
T: BeaconChainTypes + InitialiseBeaconChain<T> + Clone + 'static,
|
||||
T: BeaconChainTypes + InitialiseBeaconChain<T> + Clone + Send + Sync + 'static,
|
||||
{
|
||||
/// Generate an instance of the client. Spawn and link all internal sub-processes.
|
||||
pub fn new(
|
||||
@@ -122,6 +122,7 @@ where
|
||||
&client_config.rest_api,
|
||||
executor,
|
||||
beacon_chain.clone(),
|
||||
network.clone(),
|
||||
client_config.db_path().expect("unable to read datadir"),
|
||||
&log,
|
||||
) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use eth2_libp2p::Enr;
|
||||
use reqwest::{Error as HttpError, Url};
|
||||
use types::{BeaconBlock, BeaconState, Checkpoint, EthSpec, Slot};
|
||||
|
||||
@@ -18,6 +19,7 @@ pub struct BootstrapParams<T: EthSpec> {
|
||||
pub finalized_state: BeaconState<T>,
|
||||
pub genesis_block: BeaconBlock<T>,
|
||||
pub genesis_state: BeaconState<T>,
|
||||
pub enr: Enr,
|
||||
}
|
||||
|
||||
impl<T: EthSpec> BootstrapParams<T> {
|
||||
@@ -37,6 +39,7 @@ impl<T: EthSpec> BootstrapParams<T> {
|
||||
.map_err(|e| format!("Unable to get genesis block: {:?}", e))?,
|
||||
genesis_state: get_state(url.clone(), genesis_slot)
|
||||
.map_err(|e| format!("Unable to get genesis state: {:?}", e))?,
|
||||
enr: get_enr(url.clone()).map_err(|e| format!("Unable to get ENR: {:?}", e))?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -97,3 +100,16 @@ fn get_block<T: EthSpec>(mut url: Url, slot: Slot) -> Result<BeaconBlock<T>, Err
|
||||
.json()
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
fn get_enr(mut url: Url) -> Result<Enr, Error> {
|
||||
url.path_segments_mut()
|
||||
.map(|mut url| {
|
||||
url.push("node").push("network").push("enr");
|
||||
})
|
||||
.map_err(|_| Error::UrlCannotBeBase)?;
|
||||
|
||||
reqwest::get(url)?
|
||||
.error_for_status()?
|
||||
.json()
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user