mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 05:44:44 +00:00
Directory Restructure (#1163)
* Move tests -> testing * Directory restructure * Update Cargo.toml during restructure * Update Makefile during restructure * Fix arbitrary path
This commit is contained in:
41
crypto/eth2_wallet/src/validator_path.rs
Normal file
41
crypto/eth2_wallet/src/validator_path.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use std::fmt;
|
||||
use std::iter::Iterator;
|
||||
|
||||
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(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user