Merge rust-bitcoin/rust-bitcoin#1946: bitcoin/bip32: add DerivationPath::to_u32_vec
6640074d34
bitcoin/bip32: add DerivationPath::to_u32_vec (Marko Bencun) Pull request description: This is useful to pass the keypath to other libraries which expect it to be represented with a list of u32 ints. Fixes #1944 ACKs for top commit: apoelstra: ACK6640074d34
RCasatta: ACK6640074d34
Tree-SHA512: c2327716370558dd9d7e0419f898707ba5e56555284ea7ca746c973080061aae53674b41d8fe7c68a00d7c4bec1e4bb53e8991141749a87dfa40febe9f456369
This commit is contained in:
commit
63a09649f7
|
@ -412,6 +412,20 @@ impl DerivationPath {
|
||||||
new_path.0.extend_from_slice(path.as_ref());
|
new_path.0.extend_from_slice(path.as_ref());
|
||||||
new_path
|
new_path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the derivation path as a vector of u32 integers.
|
||||||
|
/// Unhardened elements are copied as is.
|
||||||
|
/// 0x80000000 is added to the hardened elements.
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use bitcoin::bip32::DerivationPath;
|
||||||
|
/// use std::str::FromStr;
|
||||||
|
///
|
||||||
|
/// let path = DerivationPath::from_str("m/84'/0'/0'/0/1").unwrap();
|
||||||
|
/// const HARDENED: u32 = 0x80000000;
|
||||||
|
/// assert_eq!(path.to_u32_vec(), vec![84 + HARDENED, HARDENED, HARDENED, 0, 1]);
|
||||||
|
/// ```
|
||||||
|
pub fn to_u32_vec(&self) -> Vec<u32> { self.into_iter().map(|&el| el.into()).collect() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for DerivationPath {
|
impl fmt::Display for DerivationPath {
|
||||||
|
|
Loading…
Reference in New Issue