Skip to content

Commit

Permalink
Merge #492: DefiniteDescriptorKey: provide additional methods for con…
Browse files Browse the repository at this point in the history
…verting to a DescriptorPublicKey

1477dbb DefiniteDescriptorKey: provide additional methods for converting to a DescriptorPublicKey (Andrew Poelstra)

Pull request description:

  Fixes #491

  I didn't provide a mutable version of this. I'm not sure if we want to support this or not; generally public keys should be immutable after creation.

ACKs for top commit:
  sanket1729:
    ACK 1477dbb

Tree-SHA512: 8c06ac3b6c395c3805b8cbd958ce4f354025ee88b2915562662cb084216048c6543591c468112981e8afa72d89373a544965096227475f0c198af9194d826a7e
  • Loading branch information
sanket1729 committed Dec 30, 2022
2 parents 928e283 + 1477dbb commit 0ee470d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/descriptor/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,16 @@ impl DefiniteDescriptorKey {
pub fn full_derivation_path(&self) -> Option<bip32::DerivationPath> {
self.0.full_derivation_path()
}

/// Reference to the underlying `DescriptorPublicKey`
pub fn as_descriptor_public_key(&self) -> &DescriptorPublicKey {
&self.0
}

/// Converts the definite key into a generic one
pub fn into_descriptor_public_key(self) -> DescriptorPublicKey {
self.0
}
}

impl FromStr for DefiniteDescriptorKey {
Expand Down Expand Up @@ -1134,6 +1144,12 @@ impl From<DefiniteDescriptorKey> for DescriptorPublicKey {
}
}

impl Borrow<DescriptorPublicKey> for DefiniteDescriptorKey {
fn borrow(&self) -> &DescriptorPublicKey {
&self.0
}
}

#[cfg(test)]
mod test {
use core::str::FromStr;
Expand Down

0 comments on commit 0ee470d

Please sign in to comment.