Add API endpoint for fork choice

This commit is contained in:
Paul Hauner
2020-01-27 12:51:28 +11:00
parent cc11e52f78
commit 8a61904d83
9 changed files with 81 additions and 2 deletions

View File

@@ -5,6 +5,7 @@
use eth2_config::Eth2Config;
use futures::{future, Future, IntoFuture};
use proto_array_fork_choice::core::ProtoArray;
use reqwest::{
r#async::{Client, ClientBuilder, Response},
StatusCode,
@@ -101,6 +102,10 @@ impl<E: EthSpec> HttpClient<E> {
Node(self.clone())
}
pub fn advanced(&self) -> Advanced<E> {
Advanced(self.clone())
}
fn url(&self, path: &str) -> Result<Url, Error> {
self.url.join(path).map_err(|e| e.into())
}
@@ -536,6 +541,27 @@ impl<E: EthSpec> Node<E> {
}
}
/// Provides the functions on the `/advanced` endpoint of the node.
#[derive(Clone)]
pub struct Advanced<E>(HttpClient<E>);
impl<E: EthSpec> Advanced<E> {
fn url(&self, path: &str) -> Result<Url, Error> {
self.0
.url("advanced/")
.and_then(move |url| url.join(path).map_err(Error::from))
.map_err(Into::into)
}
/// Gets the core `ProtoArray` struct from the node.
pub fn get_fork_choice(&self) -> impl Future<Item = ProtoArray, Error = Error> {
let client = self.0.clone();
self.url("fork_choice")
.into_future()
.and_then(move |url| client.json_get(url, vec![]))
}
}
#[derive(Deserialize)]
#[serde(bound = "T: EthSpec")]
pub struct BlockResponse<T: EthSpec> {