Skip to content

Commit 8ebb556

Browse files
committed
Merge #390: Add the equivalent of ForEach::as_key() for PkPkh
9570d49 Add the equivalent of `ForEach::as_key()` for `PkPkh` (Alekos Filini) Pull request description: ACKs for top commit: apoelstra: ACK 9570d49 sanket1729: ACK 9570d49 Tree-SHA512: 8e82578b09d6d5c7016f0da3bb7b5f34807233e96e022899a6409276fe60801c35ba05da655cc6d0f27c688afda8add9fe31c72a6304da0849ad5225cfb0c177
2 parents d458312 + 9570d49 commit 8ebb556

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/miniscript/iter.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,16 @@ pub enum PkPkh<Pk: MiniscriptKey> {
368368
HashedPubkey(Pk::Hash),
369369
}
370370

371+
impl<Pk: MiniscriptKey<Hash = Pk>> PkPkh<Pk> {
372+
/// Convenience method to avoid distinguishing between keys and hashes when these are the same type
373+
pub fn as_key(self) -> Pk {
374+
match self {
375+
PkPkh::PlainPubkey(pk) => pk,
376+
PkPkh::HashedPubkey(pkh) => pkh,
377+
}
378+
}
379+
}
380+
371381
/// Iterator for traversing all [MiniscriptKey]'s and hashes, depending what data are present in AST,
372382
/// starting from some specific node which constructs the iterator via
373383
/// [Miniscript::iter_pk_pkh] method.

0 commit comments

Comments
 (0)