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

@@ -29,6 +29,7 @@ pub enum Error {
UnknownBlockSlot(Hash256),
UnknownJustifiedBlock(Hash256),
UnknownJustifiedState(Hash256),
UnableToJsonEncode(String),
}
pub struct ForkChoice<T: BeaconChainTypes> {
@@ -230,6 +231,10 @@ impl<T: BeaconChainTypes> ForkChoice<T> {
self.backend.maybe_prune(finalized_root).map_err(Into::into)
}
pub fn as_json(&self) -> Result<String> {
self.backend.as_json().map_err(Error::UnableToJsonEncode)
}
/// Returns a `SszForkChoice` which contains the current state of `Self`.
pub fn as_ssz_container(&self) -> SszForkChoice {
SszForkChoice {