Files
lighthouse/crypto/eth2_wallet/src/validator_path.rs
Eitan Seri-Levi 01ec42e75a Fix Rust beta compiler errors 1.78.0-beta.1 (#5439)
* remove redundant imports

* fix test

* contains key

* fmt

* Merge branch 'unstable' into fix-beta-compiler
2024-03-20 05:17:02 +00:00

41 lines
777 B
Rust

use std::fmt;
pub const PURPOSE: u32 = 12381;
pub const COIN_TYPE: u32 = 3600;
pub enum KeyType {
Voting,
Withdrawal,
}
pub struct ValidatorPath(Vec<u32>);
impl ValidatorPath {
pub fn new(index: u32, key_type: KeyType) -> Self {
let mut vec = vec![PURPOSE, COIN_TYPE, index, 0];
match key_type {
KeyType::Voting => vec.push(0),
KeyType::Withdrawal => {}
}
Self(vec)
}
pub fn iter_nodes(&self) -> impl Iterator<Item = &u32> {
self.0.iter()
}
}
impl fmt::Display for ValidatorPath {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "m")?;
for node in self.iter_nodes() {
write!(f, "/{}", node)?;
}
Ok(())
}
}