Skip to content

Commit 8dd1ae1

Browse files
author
Scott Robinson
committed
Extract DescriptorInnerKey trait
1 parent a6a3b82 commit 8dd1ae1

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

src/descriptor/key.rs

+34-22
Original file line numberDiff line numberDiff line change
@@ -531,15 +531,9 @@ impl error::Error for ConversionError {
531531
}
532532
}
533533

534-
impl DescriptorExtendedPublicKey {
534+
pub trait DescriptorInnerKey {
535535
/// The fingerprint of the master key associated with this key, `0x00000000` if none.
536-
pub fn master_fingerprint(&self) -> bip32::Fingerprint {
537-
if let Some((fingerprint, _)) = self.origin {
538-
fingerprint
539-
} else {
540-
self.xkey.fingerprint()
541-
}
542-
}
536+
fn master_fingerprint(&self) -> bip32::Fingerprint;
543537

544538
/// Full path, from the master key
545539
///
@@ -548,19 +542,10 @@ impl DescriptorExtendedPublicKey {
548542
/// to the wildcard type (hardened or normal).
549543
///
550544
/// For multipath extended keys, this returns `None`.
551-
pub fn full_derivation_path(&self) -> Option<bip32::DerivationPath> {
552-
let origin_path = if let Some((_, ref path)) = self.origin {
553-
path.clone()
554-
} else {
555-
bip32::DerivationPath::from(vec![])
556-
};
557-
Some(origin_path.extend(&self.derivation_path))
558-
}
545+
fn full_derivation_path(&self) -> Option<bip32::DerivationPath>;
559546

560547
/// Whether or not the key has a wildcard
561-
pub fn has_wildcard(&self) -> bool {
562-
self.wildcard != Wildcard::None
563-
}
548+
fn has_wildcard(&self) -> bool;
564549

565550
/// Replaces any wildcard (i.e. `/*`) in the key with a particular derivation index, turning it into a
566551
/// *definite* key (i.e. one where all the derivation paths are set).
@@ -574,7 +559,35 @@ impl DescriptorExtendedPublicKey {
574559
/// # Errors
575560
///
576561
/// - If `index` is hardened.
577-
pub fn at_derivation_index(self, index: u32) -> Result<DefiniteDescriptorKey, ConversionError> {
562+
fn at_derivation_index(self, index: u32) -> Result<DefiniteDescriptorKey, ConversionError>;
563+
564+
/// Whether or not this key has multiple derivation paths.
565+
fn is_multipath(&self) -> bool;
566+
}
567+
568+
impl DescriptorInnerKey for DescriptorExtendedPublicKey {
569+
fn master_fingerprint(&self) -> bip32::Fingerprint {
570+
if let Some((fingerprint, _)) = self.origin {
571+
fingerprint
572+
} else {
573+
self.xkey.fingerprint()
574+
}
575+
}
576+
577+
fn full_derivation_path(&self) -> Option<bip32::DerivationPath> {
578+
let origin_path = if let Some((_, ref path)) = self.origin {
579+
path.clone()
580+
} else {
581+
bip32::DerivationPath::from(vec![])
582+
};
583+
Some(origin_path.extend(&self.derivation_path))
584+
}
585+
586+
fn has_wildcard(&self) -> bool {
587+
self.wildcard != Wildcard::None
588+
}
589+
590+
fn at_derivation_index(self, index: u32) -> Result<DefiniteDescriptorKey, ConversionError> {
578591
let derivation_path = match self.wildcard {
579592
Wildcard::None => self.derivation_path,
580593
Wildcard::Unhardened => self.derivation_path.into_child(
@@ -599,8 +612,7 @@ impl DescriptorExtendedPublicKey {
599612
.expect("The key should not contain any wildcards at this point"))
600613
}
601614

602-
/// Whether or not this key has multiple derivation paths.
603-
pub fn is_multipath(&self) -> bool {
615+
fn is_multipath(&self) -> bool {
604616
false
605617
}
606618
}

0 commit comments

Comments
 (0)