add method to determine validator status
This commit is contained in:
parent
86e5ce9ed8
commit
d3681e876a
@ -42,6 +42,10 @@ impl ValidatorRecord {
|
||||
};
|
||||
(s, keypair)
|
||||
}
|
||||
|
||||
pub fn status_is(&self, status: ValidatorStatus) -> bool {
|
||||
self.status == status as u8
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -2,28 +2,29 @@ extern crate types;
|
||||
|
||||
use types::{ValidatorRecord, ValidatorStatus};
|
||||
|
||||
pub fn validator_is_active(v: &ValidatorRecord) -> bool {
|
||||
v.status == ValidatorStatus::Active as u8
|
||||
}
|
||||
|
||||
/// Returns the indicies of each active validator in a given vec of validators.
|
||||
pub fn active_validator_indices(validators: &[ValidatorRecord]) -> Vec<usize> {
|
||||
validators
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, validator)| {
|
||||
if validator_is_active(&validator) {
|
||||
if validator.status_is(ValidatorStatus::Active) {
|
||||
Some(i)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
pub fn validator_is_active(v: &ValidatorRecord) -> bool {
|
||||
v.status_is(ValidatorStatus::Active)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_active_validator() {
|
||||
let mut validators = vec![];
|
||||
|
Loading…
Reference in New Issue
Block a user