Merge rust-bitcoin/rust-bitcoin#4620: Add alternate print format to DerivationPath using 'h' suffix
4284deed29
DerivationPath: support 'h' in Display output for hardened components (vicjuma) Pull request description: DerivationPath now supports a display format using both 'h' a single quote (') to indicate hardened components. This aligns it with its ChildNumber's output style. Resolves: #4618 ACKs for top commit: apoelstra: ACK 4284deed29114c5e31ef7c29e28e352b860f74e7; successfully ran local tests tcharding: ACK4284deed29
Tree-SHA512: 24e053c22ec94b851935debbab83d15ad9f41ccfca0a7c34a061450989b176295512e8ffb187b2a54c6c6926f82ec7e4a4186ccdba2ec2616a6e0603d90d2a9b
This commit is contained in:
commit
f034367bbc
|
@ -482,12 +482,20 @@ impl fmt::Display for DerivationPath {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut iter = self.0.iter();
|
||||
if let Some(first_element) = iter.next() {
|
||||
if f.alternate() {
|
||||
write!(f, "{:#}", first_element)?;
|
||||
} else {
|
||||
write!(f, "{}", first_element)?;
|
||||
}
|
||||
}
|
||||
for cn in iter {
|
||||
f.write_str("/")?;
|
||||
if f.alternate() {
|
||||
write!(f, "{:#}", cn)?;
|
||||
} else {
|
||||
write!(f, "{}", cn)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -1108,6 +1116,13 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_derivation_path_display() {
|
||||
let path = DerivationPath::from_str("m/84'/0'/0'/0/0").unwrap();
|
||||
assert_eq!(format!("{}", path), "84'/0'/0'/0/0");
|
||||
assert_eq!(format!("{:#}", path), "84h/0h/0h/0/0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_derivation_path_out_of_range() {
|
||||
let invalid_path = "2147483648";
|
||||
|
|
Loading…
Reference in New Issue