Merge rust-bitcoin/rust-bitcoin#2909: bip32: add From<&'a [u32]> for DerivationPath
a7731b2f33
api: Run just check-api (Marko Bencun)47cba7a655
bip32: add from_32_slice method to DerivationPath (Marko Bencun) Pull request description: ChildNumber already has a `From<u32>` impl, but converting `&[u32]` to a `DerivationPath` was still difficult. ACKs for top commit: Kixunil: ACKa7731b2f33
tcharding: ACKa7731b2f33
Tree-SHA512: 2db94ee035e686102b8201f637422bb96bd79858aeffdb007594d722902d31a20f27e61b88fae8c854c80f785d9e7837b0158a046639ff8cc2d20d8883391842
This commit is contained in:
commit
ae90d1930b
|
@ -7584,6 +7584,7 @@ pub fn bitcoin::bip32::DerivationPath::from(numbers: &'a [bitcoin::bip32::ChildN
|
|||
pub fn bitcoin::bip32::DerivationPath::from(numbers: alloc::vec::Vec<bitcoin::bip32::ChildNumber>) -> Self
|
||||
pub fn bitcoin::bip32::DerivationPath::from_iter<T>(iter: T) -> Self where T: core::iter::traits::collect::IntoIterator<Item = bitcoin::bip32::ChildNumber>
|
||||
pub fn bitcoin::bip32::DerivationPath::from_str(path: &str) -> core::result::Result<bitcoin::bip32::DerivationPath, bitcoin::bip32::Error>
|
||||
pub fn bitcoin::bip32::DerivationPath::from_u32_slice(numbers: &[u32]) -> Self
|
||||
pub fn bitcoin::bip32::DerivationPath::hardened_children(&self) -> bitcoin::bip32::DerivationPathIterator<'_>
|
||||
pub fn bitcoin::bip32::DerivationPath::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
|
||||
pub fn bitcoin::bip32::DerivationPath::index(&self, index: I) -> &Self::Output
|
||||
|
|
|
@ -7237,6 +7237,7 @@ pub fn bitcoin::bip32::DerivationPath::from(numbers: &'a [bitcoin::bip32::ChildN
|
|||
pub fn bitcoin::bip32::DerivationPath::from(numbers: alloc::vec::Vec<bitcoin::bip32::ChildNumber>) -> Self
|
||||
pub fn bitcoin::bip32::DerivationPath::from_iter<T>(iter: T) -> Self where T: core::iter::traits::collect::IntoIterator<Item = bitcoin::bip32::ChildNumber>
|
||||
pub fn bitcoin::bip32::DerivationPath::from_str(path: &str) -> core::result::Result<bitcoin::bip32::DerivationPath, bitcoin::bip32::Error>
|
||||
pub fn bitcoin::bip32::DerivationPath::from_u32_slice(numbers: &[u32]) -> Self
|
||||
pub fn bitcoin::bip32::DerivationPath::hardened_children(&self) -> bitcoin::bip32::DerivationPathIterator<'_>
|
||||
pub fn bitcoin::bip32::DerivationPath::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
|
||||
pub fn bitcoin::bip32::DerivationPath::index(&self, index: I) -> &Self::Output
|
||||
|
|
|
@ -6596,6 +6596,7 @@ pub fn bitcoin::bip32::DerivationPath::from(numbers: &'a [bitcoin::bip32::ChildN
|
|||
pub fn bitcoin::bip32::DerivationPath::from(numbers: alloc::vec::Vec<bitcoin::bip32::ChildNumber>) -> Self
|
||||
pub fn bitcoin::bip32::DerivationPath::from_iter<T>(iter: T) -> Self where T: core::iter::traits::collect::IntoIterator<Item = bitcoin::bip32::ChildNumber>
|
||||
pub fn bitcoin::bip32::DerivationPath::from_str(path: &str) -> core::result::Result<bitcoin::bip32::DerivationPath, bitcoin::bip32::Error>
|
||||
pub fn bitcoin::bip32::DerivationPath::from_u32_slice(numbers: &[u32]) -> Self
|
||||
pub fn bitcoin::bip32::DerivationPath::hardened_children(&self) -> bitcoin::bip32::DerivationPathIterator<'_>
|
||||
pub fn bitcoin::bip32::DerivationPath::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
|
||||
pub fn bitcoin::bip32::DerivationPath::index(&self, index: I) -> &Self::Output
|
||||
|
|
|
@ -452,6 +452,19 @@ impl DerivationPath {
|
|||
/// 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() }
|
||||
|
||||
/// Creates a derivation path from a slice of u32s.
|
||||
/// ```
|
||||
/// use bitcoin::bip32::DerivationPath;
|
||||
///
|
||||
/// const HARDENED: u32 = 0x80000000;
|
||||
/// let expected = vec![84 + HARDENED, HARDENED, HARDENED, 0, 1];
|
||||
/// let path = DerivationPath::from_u32_slice(expected.as_slice());
|
||||
/// assert_eq!(path.to_u32_vec(), expected);
|
||||
/// ```
|
||||
pub fn from_u32_slice(numbers: &[u32]) -> Self {
|
||||
numbers.iter().map(|&n| ChildNumber::from(n)).collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for DerivationPath {
|
||||
|
|
Loading…
Reference in New Issue