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