mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-19 12:56:12 +00:00
Move active_validators into own crate
This commit is contained in:
26
beacon_chain/utils/active-validators/src/lib.rs
Normal file
26
beacon_chain/utils/active-validators/src/lib.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
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) {
|
||||
Some(i)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
Reference in New Issue
Block a user