Skip to content

Commit a3c7105

Browse files
sgeislerdarosior
authored andcommitted
Implement ToPublicKey for DescriptorKey
1 parent 4bc5358 commit a3c7105

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/descriptor/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,27 @@ impl MiniscriptKey for DescriptorPublicKey {
231231
type Hash = hash160::Hash;
232232

233233
fn to_pubkeyhash(&self) -> Self::Hash {
234+
self.to_public_key().to_pubkeyhash()
235+
}
236+
}
237+
238+
impl ToPublicKey for DescriptorPublicKey {
239+
fn to_public_key(&self) -> bitcoin::PublicKey {
234240
match *self {
235-
DescriptorPublicKey::PubKey(ref pk) => pk.to_pubkeyhash(),
241+
DescriptorPublicKey::PubKey(ref pk) => *pk,
236242
DescriptorPublicKey::XPub(ref xpub) => {
237243
let ctx = secp256k1::Secp256k1::verification_only();
238244
xpub.xpub
239245
.derive_pub(&ctx, &xpub.derivation_path)
240-
.expect("Won't fail, only normal derivations")
246+
.expect("Shouldn't fail, only normal derivations")
241247
.public_key
242-
.to_pubkeyhash()
243248
}
244249
}
245250
}
251+
252+
fn hash_to_hash160(hash: &Self::Hash) -> hash160::Hash {
253+
*hash
254+
}
246255
}
247256

248257
impl<Pk: MiniscriptKey> Descriptor<Pk> {

0 commit comments

Comments
 (0)