Skip to content

Commit f034367

Browse files
committed
Merge rust-bitcoin#4620: Add alternate print format to DerivationPath using 'h' suffix
4284dee 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: rust-bitcoin#4618 ACKs for top commit: apoelstra: ACK 4284dee; successfully ran local tests tcharding: ACK 4284dee Tree-SHA512: 24e053c22ec94b851935debbab83d15ad9f41ccfca0a7c34a061450989b176295512e8ffb187b2a54c6c6926f82ec7e4a4186ccdba2ec2616a6e0603d90d2a9b
2 parents 1fee075 + 4284dee commit f034367

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

bitcoin/src/bip32.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,19 @@ impl fmt::Display for DerivationPath {
482482
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
483483
let mut iter = self.0.iter();
484484
if let Some(first_element) = iter.next() {
485-
write!(f, "{}", first_element)?;
485+
if f.alternate() {
486+
write!(f, "{:#}", first_element)?;
487+
} else {
488+
write!(f, "{}", first_element)?;
489+
}
486490
}
487491
for cn in iter {
488492
f.write_str("/")?;
489-
write!(f, "{}", cn)?;
493+
if f.alternate() {
494+
write!(f, "{:#}", cn)?;
495+
} else {
496+
write!(f, "{}", cn)?;
497+
}
490498
}
491499
Ok(())
492500
}
@@ -1108,6 +1116,13 @@ mod tests {
11081116
}
11091117
}
11101118

1119+
#[test]
1120+
fn test_derivation_path_display() {
1121+
let path = DerivationPath::from_str("m/84'/0'/0'/0/0").unwrap();
1122+
assert_eq!(format!("{}", path), "84'/0'/0'/0/0");
1123+
assert_eq!(format!("{:#}", path), "84h/0h/0h/0/0");
1124+
}
1125+
11111126
#[test]
11121127
fn parse_derivation_path_out_of_range() {
11131128
let invalid_path = "2147483648";

0 commit comments

Comments
 (0)