Pull Eth2Config during bootstrap

This commit is contained in:
Paul Hauner
2019-08-27 00:04:15 +10:00
parent 81c898586e
commit 6875ae8af5
7 changed files with 63 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
use eth2_config::Eth2Config;
use eth2_libp2p::{
multiaddr::{Multiaddr, Protocol},
Enr,
@@ -74,6 +75,11 @@ impl Bootstrapper {
}
}
/// Returns the servers Eth2Config.
pub fn eth2_config(&self) -> Result<Eth2Config, String> {
get_eth2_config(self.url.clone()).map_err(|e| format!("Unable to get Eth2Config: {:?}", e))
}
/// Returns the servers ENR address.
pub fn enr(&self) -> Result<Enr, String> {
get_enr(self.url.clone()).map_err(|e| format!("Unable to get ENR: {:?}", e))
@@ -129,6 +135,19 @@ fn get_slots_per_epoch(mut url: Url) -> Result<Slot, Error> {
.map_err(Into::into)
}
fn get_eth2_config(mut url: Url) -> Result<Eth2Config, Error> {
url.path_segments_mut()
.map(|mut url| {
url.push("spec").push("eth2_config");
})
.map_err(|_| Error::InvalidUrl)?;
reqwest::get(url)?
.error_for_status()?
.json()
.map_err(Into::into)
}
fn get_finalized_slot(mut url: Url, slots_per_epoch: u64) -> Result<Slot, Error> {
url.path_segments_mut()
.map(|mut url| {