@@ -153,8 +153,10 @@ pub trait MiniscriptKey: Clone + Eq + Ord + fmt::Debug + fmt::Display + hash::Ha
153
153
}
154
154
155
155
/// 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 ;
158
160
159
161
/// The associated [`sha256::Hash`] for this [`MiniscriptKey`],
160
162
/// used in the hash256 fragment.
@@ -165,15 +167,15 @@ pub trait MiniscriptKey: Clone + Eq + Ord + fmt::Debug + fmt::Display + hash::Ha
165
167
type Hash256 : Clone + Eq + Ord + fmt:: Display + fmt:: Debug + hash:: Hash ;
166
168
167
169
/// Converts this key to the associated pubkey hash.
168
- fn to_pubkeyhash ( & self ) -> Self :: Hash ;
170
+ fn to_pubkeyhash ( & self ) -> Self :: RawPkHash ;
169
171
}
170
172
171
173
impl MiniscriptKey for bitcoin:: secp256k1:: PublicKey {
172
- type Hash = hash160:: Hash ;
174
+ type RawPkHash = hash160:: Hash ;
173
175
type Sha256 = sha256:: Hash ;
174
176
type Hash256 = hash256:: Hash ;
175
177
176
- fn to_pubkeyhash ( & self ) -> Self :: Hash {
178
+ fn to_pubkeyhash ( & self ) -> Self :: RawPkHash {
177
179
hash160:: Hash :: hash ( & self . serialize ( ) )
178
180
}
179
181
}
@@ -184,21 +186,21 @@ impl MiniscriptKey for bitcoin::PublicKey {
184
186
!self . compressed
185
187
}
186
188
187
- type Hash = hash160:: Hash ;
189
+ type RawPkHash = hash160:: Hash ;
188
190
type Sha256 = sha256:: Hash ;
189
191
type Hash256 = hash256:: Hash ;
190
192
191
- fn to_pubkeyhash ( & self ) -> Self :: Hash {
193
+ fn to_pubkeyhash ( & self ) -> Self :: RawPkHash {
192
194
hash160:: Hash :: hash ( & self . to_bytes ( ) )
193
195
}
194
196
}
195
197
196
198
impl MiniscriptKey for bitcoin:: secp256k1:: XOnlyPublicKey {
197
- type Hash = hash160:: Hash ;
199
+ type RawPkHash = hash160:: Hash ;
198
200
type Sha256 = sha256:: Hash ;
199
201
type Hash256 = hash256:: Hash ;
200
202
201
- fn to_pubkeyhash ( & self ) -> Self :: Hash {
203
+ fn to_pubkeyhash ( & self ) -> Self :: RawPkHash {
202
204
hash160:: Hash :: hash ( & self . serialize ( ) )
203
205
}
204
206
@@ -208,11 +210,11 @@ impl MiniscriptKey for bitcoin::secp256k1::XOnlyPublicKey {
208
210
}
209
211
210
212
impl MiniscriptKey for String {
211
- type Hash = String ;
213
+ type RawPkHash = String ;
212
214
type Sha256 = String ; // specify hashes as string
213
215
type Hash256 = String ;
214
216
215
- fn to_pubkeyhash ( & self ) -> Self :: Hash {
217
+ fn to_pubkeyhash ( & self ) -> Self :: RawPkHash {
216
218
( & self ) . to_string ( )
217
219
}
218
220
}
@@ -234,7 +236,7 @@ pub trait ToPublicKey: MiniscriptKey {
234
236
/// that calling `MiniscriptKey::to_pubkeyhash` followed by this function
235
237
/// should give the same result as calling `to_public_key` and hashing
236
238
/// 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 ;
238
240
239
241
/// Converts the generic associated [`MiniscriptKey::Sha256`] to [`sha256::Hash`]
240
242
fn to_sha256 ( hash : & <Self as MiniscriptKey >:: Sha256 ) -> sha256:: Hash ;
@@ -322,11 +324,11 @@ impl str::FromStr for DummyKey {
322
324
}
323
325
324
326
impl MiniscriptKey for DummyKey {
325
- type Hash = DummyKeyHash ;
327
+ type RawPkHash = DummyKeyHash ;
326
328
type Sha256 = DummySha256Hash ;
327
329
type Hash256 = DummyHash256 ;
328
330
329
- fn to_pubkeyhash ( & self ) -> Self :: Hash {
331
+ fn to_pubkeyhash ( & self ) -> Self :: RawPkHash {
330
332
DummyKeyHash
331
333
}
332
334
}
@@ -457,7 +459,7 @@ where
457
459
fn pk ( & mut self , pk : & P ) -> Result < Q , E > ;
458
460
459
461
/// 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 > ;
461
463
462
464
/// Provides the translation from P::Sha256 -> Q::Sha256
463
465
fn sha256 ( & mut self , sha256 : & P :: Sha256 ) -> Result < Q :: Sha256 , E > ;
@@ -478,7 +480,7 @@ where
478
480
fn pk ( & mut self , pk : & P ) -> Result < Q , E > ;
479
481
480
482
/// 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 > ;
482
484
}
483
485
484
486
impl < P , Q , E , T > Translator < P , Q , E > for T
@@ -491,7 +493,10 @@ where
491
493
<Self as PkTranslator < P , Q , E > >:: pk ( self , pk)
492
494
}
493
495
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 > {
495
500
<Self as PkTranslator < P , Q , E > >:: pkh ( self , pkh)
496
501
}
497
502
@@ -538,14 +543,14 @@ pub trait ForEachKey<Pk: MiniscriptKey> {
538
543
fn for_each_key < ' a , F : FnMut ( & ' a Pk ) -> bool > ( & ' a self , pred : F ) -> bool
539
544
where
540
545
Pk : ' a ,
541
- Pk :: Hash : ' a ;
546
+ Pk :: RawPkHash : ' a ;
542
547
543
548
/// Run a predicate on every key in the descriptor, returning whether
544
549
/// the predicate returned true for any key
545
550
fn for_any_key < ' a , F : FnMut ( & ' a Pk ) -> bool > ( & ' a self , mut pred : F ) -> bool
546
551
where
547
552
Pk : ' a ,
548
- Pk :: Hash : ' a ,
553
+ Pk :: RawPkHash : ' a ,
549
554
{
550
555
!self . for_each_key ( |key| !pred ( key) )
551
556
}
0 commit comments