Skip to content

Commit 905c5dc

Browse files
committed
Rename Pk::Hash to Pk::RawPkHash
1 parent 5d36f9b commit 905c5dc

19 files changed

+84
-77
lines changed

src/descriptor/bare.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Bare<Pk> {
167167
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool
168168
where
169169
Pk: 'a,
170-
Pk::Hash: 'a,
170+
Pk::RawPkHash: 'a,
171171
{
172172
self.ms.for_each_key(pred)
173173
}
@@ -329,7 +329,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Pkh<Pk> {
329329
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
330330
where
331331
Pk: 'a,
332-
Pk::Hash: 'a,
332+
Pk::RawPkHash: 'a,
333333
{
334334
pred(&self.pk)
335335
}

src/descriptor/key.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ impl<K: InnerXKey> DescriptorXKey<K> {
736736

737737
impl MiniscriptKey for DescriptorPublicKey {
738738
// This allows us to be able to derive public keys even for PkH s
739-
type Hash = Self;
739+
type RawPkHash = Self;
740740
type Sha256 = sha256::Hash;
741741
type Hash256 = hash256::Hash;
742742

@@ -803,7 +803,7 @@ impl fmt::Display for DerivedDescriptorKey {
803803

804804
impl MiniscriptKey for DerivedDescriptorKey {
805805
// This allows us to be able to derive public keys even for PkH s
806-
type Hash = Self;
806+
type RawPkHash = Self;
807807
type Sha256 = sha256::Hash;
808808
type Hash256 = hash256::Hash;
809809

src/descriptor/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Descriptor<Pk> {
498498
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool
499499
where
500500
Pk: 'a,
501-
Pk::Hash: 'a,
501+
Pk::RawPkHash: 'a,
502502
{
503503
match *self {
504504
Descriptor::Bare(ref bare) => bare.for_each_key(pred),

src/descriptor/segwitv0.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Wsh<Pk> {
249249
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool
250250
where
251251
Pk: 'a,
252-
Pk::Hash: 'a,
252+
Pk::RawPkHash: 'a,
253253
{
254254
match self.inner {
255255
WshInner::SortedMulti(ref smv) => smv.for_each_key(pred),
@@ -442,7 +442,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Wpkh<Pk> {
442442
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
443443
where
444444
Pk: 'a,
445-
Pk::Hash: 'a,
445+
Pk::RawPkHash: 'a,
446446
{
447447
pred(&self.pk)
448448
}

src/descriptor/sh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Sh<Pk> {
380380
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool
381381
where
382382
Pk: 'a,
383-
Pk::Hash: 'a,
383+
Pk::RawPkHash: 'a,
384384
{
385385
match self.inner {
386386
ShInner::Wsh(ref wsh) => wsh.for_each_key(pred),

src/descriptor/sortedmulti.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> ForEachKey<Pk> for SortedMultiVec<Pk
115115
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
116116
where
117117
Pk: 'a,
118-
Pk::Hash: 'a,
118+
Pk::RawPkHash: 'a,
119119
{
120120
self.pks.iter().all(|key| pred(key))
121121
}

src/descriptor/tr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Tr<Pk> {
581581
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
582582
where
583583
Pk: 'a,
584-
Pk::Hash: 'a,
584+
Pk::RawPkHash: 'a,
585585
{
586586
let script_keys_res = self
587587
.iter_scripts()

src/interpreter/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ impl TypedHash160 {
148148
}
149149

150150
impl MiniscriptKey for BitcoinKey {
151-
type Hash = TypedHash160;
151+
type RawPkHash = TypedHash160;
152152
type Sha256 = sha256::Hash;
153153
type Hash256 = hash256::Hash;
154154

155-
fn to_pubkeyhash(&self) -> Self::Hash {
155+
fn to_pubkeyhash(&self) -> Self::RawPkHash {
156156
match self {
157157
BitcoinKey::Fullkey(pk) => TypedHash160::FullKey(pk.to_pubkeyhash()),
158158
BitcoinKey::XOnlyPublicKey(pk) => TypedHash160::XonlyKey(pk.to_pubkeyhash()),

src/lib.rs

+24-19
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ pub trait MiniscriptKey: Clone + Eq + Ord + fmt::Debug + fmt::Display + hash::Ha
153153
}
154154

155155
/// The associated PublicKey Hash for this [`MiniscriptKey`],
156-
/// used in the pkh fragment
157-
type Hash: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
156+
/// used in the raw_pkh fragment
157+
/// This fragment is only internally used for representing partial descriptors when parsing from script
158+
/// The library does not support creating partial descriptors yet.
159+
type RawPkHash: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
158160

159161
/// The associated [`sha256::Hash`] for this [`MiniscriptKey`],
160162
/// used in the hash256 fragment.
@@ -165,15 +167,15 @@ pub trait MiniscriptKey: Clone + Eq + Ord + fmt::Debug + fmt::Display + hash::Ha
165167
type Hash256: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
166168

167169
/// Converts this key to the associated pubkey hash.
168-
fn to_pubkeyhash(&self) -> Self::Hash;
170+
fn to_pubkeyhash(&self) -> Self::RawPkHash;
169171
}
170172

171173
impl MiniscriptKey for bitcoin::secp256k1::PublicKey {
172-
type Hash = hash160::Hash;
174+
type RawPkHash = hash160::Hash;
173175
type Sha256 = sha256::Hash;
174176
type Hash256 = hash256::Hash;
175177

176-
fn to_pubkeyhash(&self) -> Self::Hash {
178+
fn to_pubkeyhash(&self) -> Self::RawPkHash {
177179
hash160::Hash::hash(&self.serialize())
178180
}
179181
}
@@ -184,21 +186,21 @@ impl MiniscriptKey for bitcoin::PublicKey {
184186
!self.compressed
185187
}
186188

187-
type Hash = hash160::Hash;
189+
type RawPkHash = hash160::Hash;
188190
type Sha256 = sha256::Hash;
189191
type Hash256 = hash256::Hash;
190192

191-
fn to_pubkeyhash(&self) -> Self::Hash {
193+
fn to_pubkeyhash(&self) -> Self::RawPkHash {
192194
hash160::Hash::hash(&self.to_bytes())
193195
}
194196
}
195197

196198
impl MiniscriptKey for bitcoin::secp256k1::XOnlyPublicKey {
197-
type Hash = hash160::Hash;
199+
type RawPkHash = hash160::Hash;
198200
type Sha256 = sha256::Hash;
199201
type Hash256 = hash256::Hash;
200202

201-
fn to_pubkeyhash(&self) -> Self::Hash {
203+
fn to_pubkeyhash(&self) -> Self::RawPkHash {
202204
hash160::Hash::hash(&self.serialize())
203205
}
204206

@@ -208,11 +210,11 @@ impl MiniscriptKey for bitcoin::secp256k1::XOnlyPublicKey {
208210
}
209211

210212
impl MiniscriptKey for String {
211-
type Hash = String;
213+
type RawPkHash = String;
212214
type Sha256 = String; // specify hashes as string
213215
type Hash256 = String;
214216

215-
fn to_pubkeyhash(&self) -> Self::Hash {
217+
fn to_pubkeyhash(&self) -> Self::RawPkHash {
216218
(&self).to_string()
217219
}
218220
}
@@ -234,7 +236,7 @@ pub trait ToPublicKey: MiniscriptKey {
234236
/// that calling `MiniscriptKey::to_pubkeyhash` followed by this function
235237
/// should give the same result as calling `to_public_key` and hashing
236238
/// the result directly.
237-
fn hash_to_hash160(hash: &<Self as MiniscriptKey>::Hash) -> hash160::Hash;
239+
fn hash_to_hash160(hash: &<Self as MiniscriptKey>::RawPkHash) -> hash160::Hash;
238240

239241
/// Converts the generic associated [`MiniscriptKey::Sha256`] to [`sha256::Hash`]
240242
fn to_sha256(hash: &<Self as MiniscriptKey>::Sha256) -> sha256::Hash;
@@ -322,11 +324,11 @@ impl str::FromStr for DummyKey {
322324
}
323325

324326
impl MiniscriptKey for DummyKey {
325-
type Hash = DummyKeyHash;
327+
type RawPkHash = DummyKeyHash;
326328
type Sha256 = DummySha256Hash;
327329
type Hash256 = DummyHash256;
328330

329-
fn to_pubkeyhash(&self) -> Self::Hash {
331+
fn to_pubkeyhash(&self) -> Self::RawPkHash {
330332
DummyKeyHash
331333
}
332334
}
@@ -457,7 +459,7 @@ where
457459
fn pk(&mut self, pk: &P) -> Result<Q, E>;
458460

459461
/// Translates public key hashes P::Hash -> Q::Hash.
460-
fn pkh(&mut self, pkh: &P::Hash) -> Result<Q::Hash, E>;
462+
fn pkh(&mut self, pkh: &P::RawPkHash) -> Result<Q::RawPkHash, E>;
461463

462464
/// Provides the translation from P::Sha256 -> Q::Sha256
463465
fn sha256(&mut self, sha256: &P::Sha256) -> Result<Q::Sha256, E>;
@@ -478,7 +480,7 @@ where
478480
fn pk(&mut self, pk: &P) -> Result<Q, E>;
479481

480482
/// Provides the translation public keys hashes P::Hash -> Q::Hash
481-
fn pkh(&mut self, pkh: &P::Hash) -> Result<Q::Hash, E>;
483+
fn pkh(&mut self, pkh: &P::RawPkHash) -> Result<Q::RawPkHash, E>;
482484
}
483485

484486
impl<P, Q, E, T> Translator<P, Q, E> for T
@@ -491,7 +493,10 @@ where
491493
<Self as PkTranslator<P, Q, E>>::pk(self, pk)
492494
}
493495

494-
fn pkh(&mut self, pkh: &<P as MiniscriptKey>::Hash) -> Result<<Q as MiniscriptKey>::Hash, E> {
496+
fn pkh(
497+
&mut self,
498+
pkh: &<P as MiniscriptKey>::RawPkHash,
499+
) -> Result<<Q as MiniscriptKey>::RawPkHash, E> {
495500
<Self as PkTranslator<P, Q, E>>::pkh(self, pkh)
496501
}
497502

@@ -538,14 +543,14 @@ pub trait ForEachKey<Pk: MiniscriptKey> {
538543
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool
539544
where
540545
Pk: 'a,
541-
Pk::Hash: 'a;
546+
Pk::RawPkHash: 'a;
542547

543548
/// Run a predicate on every key in the descriptor, returning whether
544549
/// the predicate returned true for any key
545550
fn for_any_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
546551
where
547552
Pk: 'a,
548-
Pk::Hash: 'a,
553+
Pk::RawPkHash: 'a,
549554
{
550555
!self.for_each_key(|key| !pred(key))
551556
}

src/macros.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ macro_rules! impl_from_tree {
2727
impl<Pk $(, $gen)*> $crate::expression::FromTree for $name
2828
where
2929
Pk: MiniscriptKey + core::str::FromStr,
30-
Pk::Hash: core::str::FromStr,
30+
Pk::RawPkHash: core::str::FromStr,
3131
Pk::Sha256: core::str::FromStr,
3232
Pk::Hash256: core::str::FromStr,
3333
<Pk as core::str::FromStr>::Err: $crate::prelude::ToString,
34-
<<Pk as MiniscriptKey>::Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
34+
<<Pk as MiniscriptKey>::RawPkHash as core::str::FromStr>::Err: $crate::prelude::ToString,
3535
<<Pk as MiniscriptKey>::Sha256 as core::str::FromStr>::Err: $crate::prelude::ToString,
3636
<<Pk as MiniscriptKey>::Hash256 as core::str::FromStr>::Err: $crate::prelude::ToString,
3737
$($gen : $gen_con,)*
@@ -57,11 +57,11 @@ macro_rules! impl_from_str {
5757
impl<Pk $(, $gen)*> core::str::FromStr for $name
5858
where
5959
Pk: MiniscriptKey + core::str::FromStr,
60-
Pk::Hash: core::str::FromStr,
60+
Pk::RawPkHash: core::str::FromStr,
6161
Pk::Sha256: core::str::FromStr,
6262
Pk::Hash256: core::str::FromStr,
6363
<Pk as core::str::FromStr>::Err: $crate::prelude::ToString,
64-
<<Pk as MiniscriptKey>::Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
64+
<<Pk as MiniscriptKey>::RawPkHash as core::str::FromStr>::Err: $crate::prelude::ToString,
6565
<<Pk as MiniscriptKey>::Sha256 as core::str::FromStr>::Err: $crate::prelude::ToString,
6666
<<Pk as MiniscriptKey>::Hash256 as core::str::FromStr>::Err: $crate::prelude::ToString,
6767
$($gen : $gen_con,)*
@@ -87,11 +87,11 @@ macro_rules! impl_block_str {
8787
impl<Pk $(, $gen)*> $name
8888
where
8989
Pk: MiniscriptKey + core::str::FromStr,
90-
Pk::Hash: core::str::FromStr,
90+
Pk::RawPkHash: core::str::FromStr,
9191
Pk::Sha256: core::str::FromStr,
9292
Pk::Hash256: core::str::FromStr,
9393
<Pk as core::str::FromStr>::Err: $crate::prelude::ToString,
94-
<<Pk as MiniscriptKey>::Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
94+
<<Pk as MiniscriptKey>::RawPkHash as core::str::FromStr>::Err: $crate::prelude::ToString,
9595
<<Pk as MiniscriptKey>::Sha256 as core::str::FromStr>::Err: $crate::prelude::ToString,
9696
<<Pk as MiniscriptKey>::Hash256 as core::str::FromStr>::Err: $crate::prelude::ToString,
9797
$($gen : $gen_con,)*
@@ -112,11 +112,11 @@ macro_rules! serde_string_impl_pk {
112112
impl<'de, Pk $(, $gen)*> $crate::serde::Deserialize<'de> for $name<Pk $(, $gen)*>
113113
where
114114
Pk: $crate::MiniscriptKey + core::str::FromStr,
115-
Pk::Hash: core::str::FromStr,
115+
Pk::RawPkHash: core::str::FromStr,
116116
Pk::Sha256: core::str::FromStr,
117117
Pk::Hash256: core::str::FromStr,
118118
<Pk as core::str::FromStr>::Err: core::fmt::Display,
119-
<<Pk as $crate::MiniscriptKey>::Hash as core::str::FromStr>::Err:
119+
<<Pk as $crate::MiniscriptKey>::RawPkHash as core::str::FromStr>::Err:
120120
core::fmt::Display,
121121
<<Pk as $crate::MiniscriptKey>::Sha256 as core::str::FromStr>::Err:
122122
core::fmt::Display,
@@ -137,11 +137,11 @@ macro_rules! serde_string_impl_pk {
137137
impl<'de, Pk $(, $gen)*> $crate::serde::de::Visitor<'de> for Visitor<Pk $(, $gen)*>
138138
where
139139
Pk: $crate::MiniscriptKey + core::str::FromStr,
140-
Pk::Hash: core::str::FromStr,
140+
Pk::RawPkHash: core::str::FromStr,
141141
Pk::Sha256: core::str::FromStr,
142142
Pk::Hash256: core::str::FromStr,
143143
<Pk as core::str::FromStr>::Err: core::fmt::Display,
144-
<<Pk as $crate::MiniscriptKey>::Hash as core::str::FromStr>::Err:
144+
<<Pk as $crate::MiniscriptKey>::RawPkHash as core::str::FromStr>::Err:
145145
core::fmt::Display,
146146
<<Pk as $crate::MiniscriptKey>::Sha256 as core::str::FromStr>::Err:
147147
core::fmt::Display,

src/miniscript/astelem.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
7979
pub(super) fn real_for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: &mut F) -> bool
8080
where
8181
Pk: 'a,
82-
Pk::Hash: 'a,
82+
Pk::RawPkHash: 'a,
8383
{
8484
match *self {
8585
Terminal::PkK(ref p) => pred(p),
@@ -200,7 +200,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> ForEachKey<Pk> for Terminal<Pk, Ctx>
200200
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
201201
where
202202
Pk: 'a,
203-
Pk::Hash: 'a,
203+
Pk::RawPkHash: 'a,
204204
{
205205
self.real_for_each_key(&mut pred)
206206
}

src/miniscript/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl fmt::Display for ScriptContextError {
191191
pub trait ScriptContext:
192192
fmt::Debug + Clone + Ord + PartialOrd + Eq + PartialEq + hash::Hash + private::Sealed
193193
where
194-
Self::Key: MiniscriptKey<Hash = hash160::Hash>,
194+
Self::Key: MiniscriptKey<RawPkHash = hash160::Hash>,
195195
Self::Key: MiniscriptKey<Sha256 = sha256::Hash>,
196196
Self::Key: MiniscriptKey<Hash256 = hash256::Hash>,
197197
{

src/miniscript/decode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub enum Terminal<Pk: MiniscriptKey, Ctx: ScriptContext> {
136136
/// `DUP HASH160 <keyhash> EQUALVERIFY`
137137
PkH(Pk),
138138
/// Only for parsing PkH for Script
139-
RawPkH(Pk::Hash),
139+
RawPkH(Pk::RawPkHash),
140140
// timelocks
141141
/// `n CHECKLOCKTIMEVERIFY`
142142
After(u32),

src/miniscript/iter.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
140140
/// NB: The function analyzes only single miniscript item and not any of its descendants in AST.
141141
/// To obtain a list of all public key hashes within AST use [Miniscript::iter_pkh()] function,
142142
/// for example `miniscript.iter_pubkey_hashes().collect()`.
143-
pub fn get_leapkh(&self) -> Vec<Pk::Hash> {
143+
pub fn get_leapkh(&self) -> Vec<Pk::RawPkHash> {
144144
match self.node {
145145
Terminal::RawPkH(ref hash) => vec![hash.clone()],
146146
Terminal::PkK(ref key) | Terminal::PkH(ref key) => vec![key.to_pubkeyhash()],
@@ -193,7 +193,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
193193
/// returns it cloned copy.
194194
///
195195
/// NB: The function analyzes only single miniscript item and not any of its descendants in AST.
196-
pub fn get_nth_pkh(&self, n: usize) -> Option<Pk::Hash> {
196+
pub fn get_nth_pkh(&self, n: usize) -> Option<Pk::RawPkHash> {
197197
match (&self.node, n) {
198198
(&Terminal::RawPkH(ref hash), 0) => Some(hash.clone()),
199199
(&Terminal::PkK(ref key), 0) | (&Terminal::PkH(ref key), 0) => {
@@ -348,7 +348,7 @@ impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> PkhIter<'a, Pk, Ctx> {
348348
}
349349

350350
impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> Iterator for PkhIter<'a, Pk, Ctx> {
351-
type Item = Pk::Hash;
351+
type Item = Pk::RawPkHash;
352352

353353
fn next(&mut self) -> Option<Self::Item> {
354354
loop {
@@ -376,10 +376,10 @@ pub enum PkPkh<Pk: MiniscriptKey> {
376376
/// Plain public key
377377
PlainPubkey(Pk),
378378
/// Hashed public key
379-
HashedPubkey(Pk::Hash),
379+
HashedPubkey(Pk::RawPkHash),
380380
}
381381

382-
impl<Pk: MiniscriptKey<Hash = Pk>> PkPkh<Pk> {
382+
impl<Pk: MiniscriptKey<RawPkHash = Pk>> PkPkh<Pk> {
383383
/// Convenience method to avoid distinguishing between keys and hashes when these are the same type
384384
pub fn as_key(self) -> Pk {
385385
match self {

0 commit comments

Comments
 (0)