Skip to content

Commit 934a05f

Browse files
sgeislerdarosior
authored andcommitted
Implement ToPublicKey for DescriptorKey
1 parent c732925 commit 934a05f

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
@@ -245,18 +245,27 @@ impl MiniscriptKey for DescriptorPublicKey {
245245
type Hash = hash160::Hash;
246246

247247
fn to_pubkeyhash(&self) -> Self::Hash {
248+
self.to_public_key().to_pubkeyhash()
249+
}
250+
}
251+
252+
impl ToPublicKey for DescriptorPublicKey {
253+
fn to_public_key(&self) -> bitcoin::PublicKey {
248254
match *self {
249-
DescriptorPublicKey::PubKey(ref pk) => pk.to_pubkeyhash(),
255+
DescriptorPublicKey::PubKey(ref pk) => *pk,
250256
DescriptorPublicKey::XPub(ref xpub) => {
251257
let ctx = secp256k1::Secp256k1::verification_only();
252258
xpub.xpub
253259
.derive_pub(&ctx, &xpub.derivation_path)
254-
.expect("Won't fail, only normal derivations")
260+
.expect("Shouldn't fail, only normal derivations")
255261
.public_key
256-
.to_pubkeyhash()
257262
}
258263
}
259264
}
265+
266+
fn hash_to_hash160(hash: &Self::Hash) -> hash160::Hash {
267+
*hash
268+
}
260269
}
261270

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

0 commit comments

Comments
 (0)