Skip to content

Commit ae90d19

Browse files
committed
Merge rust-bitcoin#2909: bip32: add From<&'a [u32]> for DerivationPath
a7731b2 api: Run just check-api (Marko Bencun) 47cba7a 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: ACK a7731b2 tcharding: ACK a7731b2 Tree-SHA512: 2db94ee035e686102b8201f637422bb96bd79858aeffdb007594d722902d31a20f27e61b88fae8c854c80f785d9e7837b0158a046639ff8cc2d20d8883391842
2 parents 7ca7128 + a7731b2 commit ae90d19

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

api/bitcoin/all-features.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7584,6 +7584,7 @@ pub fn bitcoin::bip32::DerivationPath::from(numbers: &'a [bitcoin::bip32::ChildN
75847584
pub fn bitcoin::bip32::DerivationPath::from(numbers: alloc::vec::Vec<bitcoin::bip32::ChildNumber>) -> Self
75857585
pub fn bitcoin::bip32::DerivationPath::from_iter<T>(iter: T) -> Self where T: core::iter::traits::collect::IntoIterator<Item = bitcoin::bip32::ChildNumber>
75867586
pub fn bitcoin::bip32::DerivationPath::from_str(path: &str) -> core::result::Result<bitcoin::bip32::DerivationPath, bitcoin::bip32::Error>
7587+
pub fn bitcoin::bip32::DerivationPath::from_u32_slice(numbers: &[u32]) -> Self
75877588
pub fn bitcoin::bip32::DerivationPath::hardened_children(&self) -> bitcoin::bip32::DerivationPathIterator<'_>
75887589
pub fn bitcoin::bip32::DerivationPath::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
75897590
pub fn bitcoin::bip32::DerivationPath::index(&self, index: I) -> &Self::Output

api/bitcoin/default-features.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7237,6 +7237,7 @@ pub fn bitcoin::bip32::DerivationPath::from(numbers: &'a [bitcoin::bip32::ChildN
72377237
pub fn bitcoin::bip32::DerivationPath::from(numbers: alloc::vec::Vec<bitcoin::bip32::ChildNumber>) -> Self
72387238
pub fn bitcoin::bip32::DerivationPath::from_iter<T>(iter: T) -> Self where T: core::iter::traits::collect::IntoIterator<Item = bitcoin::bip32::ChildNumber>
72397239
pub fn bitcoin::bip32::DerivationPath::from_str(path: &str) -> core::result::Result<bitcoin::bip32::DerivationPath, bitcoin::bip32::Error>
7240+
pub fn bitcoin::bip32::DerivationPath::from_u32_slice(numbers: &[u32]) -> Self
72407241
pub fn bitcoin::bip32::DerivationPath::hardened_children(&self) -> bitcoin::bip32::DerivationPathIterator<'_>
72417242
pub fn bitcoin::bip32::DerivationPath::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
72427243
pub fn bitcoin::bip32::DerivationPath::index(&self, index: I) -> &Self::Output

api/bitcoin/no-features.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6596,6 +6596,7 @@ pub fn bitcoin::bip32::DerivationPath::from(numbers: &'a [bitcoin::bip32::ChildN
65966596
pub fn bitcoin::bip32::DerivationPath::from(numbers: alloc::vec::Vec<bitcoin::bip32::ChildNumber>) -> Self
65976597
pub fn bitcoin::bip32::DerivationPath::from_iter<T>(iter: T) -> Self where T: core::iter::traits::collect::IntoIterator<Item = bitcoin::bip32::ChildNumber>
65986598
pub fn bitcoin::bip32::DerivationPath::from_str(path: &str) -> core::result::Result<bitcoin::bip32::DerivationPath, bitcoin::bip32::Error>
6599+
pub fn bitcoin::bip32::DerivationPath::from_u32_slice(numbers: &[u32]) -> Self
65996600
pub fn bitcoin::bip32::DerivationPath::hardened_children(&self) -> bitcoin::bip32::DerivationPathIterator<'_>
66006601
pub fn bitcoin::bip32::DerivationPath::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
66016602
pub fn bitcoin::bip32::DerivationPath::index(&self, index: I) -> &Self::Output

bitcoin/src/bip32.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,19 @@ impl DerivationPath {
452452
/// assert_eq!(path.to_u32_vec(), vec![84 + HARDENED, HARDENED, HARDENED, 0, 1]);
453453
/// ```
454454
pub fn to_u32_vec(&self) -> Vec<u32> { self.into_iter().map(|&el| el.into()).collect() }
455+
456+
/// Creates a derivation path from a slice of u32s.
457+
/// ```
458+
/// use bitcoin::bip32::DerivationPath;
459+
///
460+
/// const HARDENED: u32 = 0x80000000;
461+
/// let expected = vec![84 + HARDENED, HARDENED, HARDENED, 0, 1];
462+
/// let path = DerivationPath::from_u32_slice(expected.as_slice());
463+
/// assert_eq!(path.to_u32_vec(), expected);
464+
/// ```
465+
pub fn from_u32_slice(numbers: &[u32]) -> Self {
466+
numbers.iter().map(|&n| ChildNumber::from(n)).collect()
467+
}
455468
}
456469

457470
impl fmt::Display for DerivationPath {

0 commit comments

Comments
 (0)