Make API friendly to block explorers (#702)

* Add validator index to duties response

* Add `get_state` method to beacon chain

* Improve /beacon/validators endpoint

* Add validators/all and validators/active endpoints

* Start refactor of HTTP docs

* Document /beacon/heads endpoint

* Remove some unused API endpoints

* Improve API docs

* Add methods to get all validator duties

* Improve docs

* Remove dead links

* Make tables left-justified

* Add /consensus/vote_count endpoint

* Add /consensus/individual_votes endpoint

* Update formatting

* Tidy

* Add committees endpoint

* Strictly require 0x prefix for serde in BLS

* Update docs to have 0x prefix

* Fix failing tests

* Add unfinished code

* Improve testing, fix bugs

* Tidy, ensure all beacon endpoints smoke tested

* Fix pubkey cache error

* Address comments with docs
This commit is contained in:
Paul Hauner
2019-12-19 11:45:28 +11:00
committed by GitHub
parent d756bc9ecd
commit 251aea645c
28 changed files with 1831 additions and 268 deletions

View File

@@ -388,6 +388,19 @@ impl<T: EthSpec> BeaconState<T> {
cache.get_beacon_committees_at_slot(slot)
}
/// Get all of the Beacon committees at a given relative epoch.
///
/// Utilises the committee cache.
///
/// Spec v0.9.1
pub fn get_beacon_committees_at_epoch(
&self,
relative_epoch: RelativeEpoch,
) -> Result<Vec<BeaconCommittee>, Error> {
let cache = self.committee_cache(relative_epoch)?;
cache.get_all_beacon_committees()
}
/// Compute the proposer (not necessarily for the Beacon chain) from a list of indices.
///
/// Spec v0.9.1

View File

@@ -141,6 +141,21 @@ impl CommitteeCache {
.collect()
}
/// Returns all committees for `self.initialized_epoch`.
pub fn get_all_beacon_committees(&self) -> Result<Vec<BeaconCommittee>, Error> {
let initialized_epoch = self
.initialized_epoch
.ok_or_else(|| Error::CommitteeCacheUninitialized(None))?;
initialized_epoch.slot_iter(self.slots_per_epoch).try_fold(
Vec::with_capacity(self.slots_per_epoch as usize),
|mut vec, slot| {
vec.append(&mut self.get_beacon_committees_at_slot(slot)?);
Ok(vec)
},
)
}
/// Returns the `AttestationDuty` for the given `validator_index`.
///
/// Returns `None` if the `validator_index` does not exist, does not have duties or `Self` is