@@ -27,8 +27,7 @@ use crate::miniscript::context::ScriptContext;
27
27
use crate :: policy:: { semantic, Liftable } ;
28
28
use crate :: util:: { varint_len, witness_to_scriptsig} ;
29
29
use crate :: {
30
- BareCtx , Error , ForEach , ForEachKey , Miniscript , MiniscriptKey , Satisfier , ToPublicKey ,
31
- TranslatePk ,
30
+ BareCtx , Error , ForEach , ForEachKey , Key , Miniscript , Satisfier , ToPublicKey , TranslatePk ,
32
31
} ;
33
32
34
33
use super :: {
@@ -39,12 +38,12 @@ use super::{
39
38
/// Create a Bare Descriptor. That is descriptor that is
40
39
/// not wrapped in sh or wsh. This covers the Pk descriptor
41
40
#[ derive( Clone , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
42
- pub struct Bare < Pk : MiniscriptKey > {
41
+ pub struct Bare < Pk : Key > {
43
42
/// underlying miniscript
44
43
ms : Miniscript < Pk , BareCtx > ,
45
44
}
46
45
47
- impl < Pk : MiniscriptKey > Bare < Pk > {
46
+ impl < Pk : Key > Bare < Pk > {
48
47
/// Create a new raw descriptor
49
48
pub fn new ( ms : Miniscript < Pk , BareCtx > ) -> Result < Self , Error > {
50
49
// do the top-level checks
@@ -63,7 +62,7 @@ impl<Pk: MiniscriptKey> Bare<Pk> {
63
62
}
64
63
}
65
64
66
- impl < Pk : MiniscriptKey + ToPublicKey > Bare < Pk > {
65
+ impl < Pk : Key + ToPublicKey > Bare < Pk > {
67
66
/// Obtain the corresponding script pubkey for this descriptor
68
67
/// Non failing verion of [`DescriptorTrait::script_pubkey`] for this descriptor
69
68
pub fn spk ( & self ) -> Script {
@@ -83,32 +82,32 @@ impl<Pk: MiniscriptKey + ToPublicKey> Bare<Pk> {
83
82
}
84
83
}
85
84
86
- impl < Pk : MiniscriptKey > fmt:: Debug for Bare < Pk > {
85
+ impl < Pk : Key > fmt:: Debug for Bare < Pk > {
87
86
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
88
87
write ! ( f, "{:?}" , self . ms)
89
88
}
90
89
}
91
90
92
- impl < Pk : MiniscriptKey > fmt:: Display for Bare < Pk > {
91
+ impl < Pk : Key > fmt:: Display for Bare < Pk > {
93
92
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
94
93
let desc = format ! ( "{}" , self . ms) ;
95
94
let checksum = desc_checksum ( & desc) . map_err ( |_| fmt:: Error ) ?;
96
95
write ! ( f, "{}#{}" , & desc, & checksum)
97
96
}
98
97
}
99
98
100
- impl < Pk : MiniscriptKey > Liftable < Pk > for Bare < Pk > {
99
+ impl < Pk : Key > Liftable < Pk > for Bare < Pk > {
101
100
fn lift ( & self ) -> Result < semantic:: Policy < Pk > , Error > {
102
101
self . ms . lift ( )
103
102
}
104
103
}
105
104
106
105
impl < Pk > FromTree for Bare < Pk >
107
106
where
108
- Pk : MiniscriptKey + FromStr ,
107
+ Pk : Key + FromStr ,
109
108
Pk :: Hash : FromStr ,
110
109
<Pk as FromStr >:: Err : ToString ,
111
- <<Pk as MiniscriptKey >:: Hash as FromStr >:: Err : ToString ,
110
+ <<Pk as Key >:: Hash as FromStr >:: Err : ToString ,
112
111
{
113
112
fn from_tree ( top : & expression:: Tree ) -> Result < Self , Error > {
114
113
let sub = Miniscript :: < Pk , BareCtx > :: from_tree ( & top) ?;
@@ -119,10 +118,10 @@ where
119
118
120
119
impl < Pk > FromStr for Bare < Pk >
121
120
where
122
- Pk : MiniscriptKey + FromStr ,
121
+ Pk : Key + FromStr ,
123
122
Pk :: Hash : FromStr ,
124
123
<Pk as FromStr >:: Err : ToString ,
125
- <<Pk as MiniscriptKey >:: Hash as FromStr >:: Err : ToString ,
124
+ <<Pk as Key >:: Hash as FromStr >:: Err : ToString ,
126
125
{
127
126
type Err = Error ;
128
127
@@ -133,7 +132,7 @@ where
133
132
}
134
133
}
135
134
136
- impl < Pk : MiniscriptKey > DescriptorTrait < Pk > for Bare < Pk > {
135
+ impl < Pk : Key > DescriptorTrait < Pk > for Bare < Pk > {
137
136
fn sanity_check ( & self ) -> Result < ( ) , Error > {
138
137
self . ms . sanity_check ( ) ?;
139
138
Ok ( ( ) )
@@ -202,7 +201,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
202
201
}
203
202
}
204
203
205
- impl < Pk : MiniscriptKey > ForEachKey < Pk > for Bare < Pk > {
204
+ impl < Pk : Key > ForEachKey < Pk > for Bare < Pk > {
206
205
fn for_each_key < ' a , F : FnMut ( ForEach < ' a , Pk > ) -> bool > ( & ' a self , pred : F ) -> bool
207
206
where
208
207
Pk : ' a ,
@@ -212,7 +211,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Bare<Pk> {
212
211
}
213
212
}
214
213
215
- impl < P : MiniscriptKey , Q : MiniscriptKey > TranslatePk < P , Q > for Bare < P > {
214
+ impl < P : Key , Q : Key > TranslatePk < P , Q > for Bare < P > {
216
215
type Output = Bare < Q > ;
217
216
218
217
fn translate_pk < Fpk , Fpkh , E > (
@@ -223,7 +222,7 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Bare<P> {
223
222
where
224
223
Fpk : FnMut ( & P ) -> Result < Q , E > ,
225
224
Fpkh : FnMut ( & P :: Hash ) -> Result < Q :: Hash , E > ,
226
- Q : MiniscriptKey ,
225
+ Q : Key ,
227
226
{
228
227
Ok ( Bare :: new (
229
228
self . ms
@@ -235,12 +234,12 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Bare<P> {
235
234
236
235
/// A bare PkH descriptor at top level
237
236
#[ derive( Clone , Ord , PartialOrd , Eq , PartialEq , Hash ) ]
238
- pub struct Pkh < Pk : MiniscriptKey > {
237
+ pub struct Pkh < Pk : Key > {
239
238
/// underlying publickey
240
239
pk : Pk ,
241
240
}
242
241
243
- impl < Pk : MiniscriptKey > Pkh < Pk > {
242
+ impl < Pk : Key > Pkh < Pk > {
244
243
/// Create a new Pkh descriptor
245
244
pub fn new ( pk : Pk ) -> Self {
246
245
// do the top-level checks
@@ -258,7 +257,7 @@ impl<Pk: MiniscriptKey> Pkh<Pk> {
258
257
}
259
258
}
260
259
261
- impl < Pk : MiniscriptKey + ToPublicKey > Pkh < Pk > {
260
+ impl < Pk : Key + ToPublicKey > Pkh < Pk > {
262
261
/// Obtain the corresponding script pubkey for this descriptor
263
262
/// Non failing verion of [`DescriptorTrait::script_pubkey`] for this descriptor
264
263
pub fn spk ( & self ) -> Script {
@@ -285,32 +284,32 @@ impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
285
284
}
286
285
}
287
286
288
- impl < Pk : MiniscriptKey > fmt:: Debug for Pkh < Pk > {
287
+ impl < Pk : Key > fmt:: Debug for Pkh < Pk > {
289
288
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
290
289
write ! ( f, "pkh({:?})" , self . pk)
291
290
}
292
291
}
293
292
294
- impl < Pk : MiniscriptKey > fmt:: Display for Pkh < Pk > {
293
+ impl < Pk : Key > fmt:: Display for Pkh < Pk > {
295
294
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
296
295
let desc = format ! ( "pkh({})" , self . pk) ;
297
296
let checksum = desc_checksum ( & desc) . map_err ( |_| fmt:: Error ) ?;
298
297
write ! ( f, "{}#{}" , & desc, & checksum)
299
298
}
300
299
}
301
300
302
- impl < Pk : MiniscriptKey > Liftable < Pk > for Pkh < Pk > {
301
+ impl < Pk : Key > Liftable < Pk > for Pkh < Pk > {
303
302
fn lift ( & self ) -> Result < semantic:: Policy < Pk > , Error > {
304
303
Ok ( semantic:: Policy :: KeyHash ( self . pk . to_pubkeyhash ( ) ) )
305
304
}
306
305
}
307
306
308
307
impl < Pk > FromTree for Pkh < Pk >
309
308
where
310
- Pk : MiniscriptKey + FromStr ,
309
+ Pk : Key + FromStr ,
311
310
Pk :: Hash : FromStr ,
312
311
<Pk as FromStr >:: Err : ToString ,
313
- <<Pk as MiniscriptKey >:: Hash as FromStr >:: Err : ToString ,
312
+ <<Pk as Key >:: Hash as FromStr >:: Err : ToString ,
314
313
{
315
314
fn from_tree ( top : & expression:: Tree ) -> Result < Self , Error > {
316
315
if top. name == "pkh" && top. args . len ( ) == 1 {
@@ -329,10 +328,10 @@ where
329
328
330
329
impl < Pk > FromStr for Pkh < Pk >
331
330
where
332
- Pk : MiniscriptKey + FromStr ,
331
+ Pk : Key + FromStr ,
333
332
Pk :: Hash : FromStr ,
334
333
<Pk as FromStr >:: Err : ToString ,
335
- <<Pk as MiniscriptKey >:: Hash as FromStr >:: Err : ToString ,
334
+ <<Pk as Key >:: Hash as FromStr >:: Err : ToString ,
336
335
{
337
336
type Err = Error ;
338
337
@@ -343,7 +342,7 @@ where
343
342
}
344
343
}
345
344
346
- impl < Pk : MiniscriptKey > DescriptorTrait < Pk > for Pkh < Pk > {
345
+ impl < Pk : Key > DescriptorTrait < Pk > for Pkh < Pk > {
347
346
fn sanity_check ( & self ) -> Result < ( ) , Error > {
348
347
Ok ( ( ) )
349
348
}
@@ -414,7 +413,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
414
413
}
415
414
}
416
415
417
- impl < Pk : MiniscriptKey > ForEachKey < Pk > for Pkh < Pk > {
416
+ impl < Pk : Key > ForEachKey < Pk > for Pkh < Pk > {
418
417
fn for_each_key < ' a , F : FnMut ( ForEach < ' a , Pk > ) -> bool > ( & ' a self , mut pred : F ) -> bool
419
418
where
420
419
Pk : ' a ,
@@ -424,7 +423,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Pkh<Pk> {
424
423
}
425
424
}
426
425
427
- impl < P : MiniscriptKey , Q : MiniscriptKey > TranslatePk < P , Q > for Pkh < P > {
426
+ impl < P : Key , Q : Key > TranslatePk < P , Q > for Pkh < P > {
428
427
type Output = Pkh < Q > ;
429
428
430
429
fn translate_pk < Fpk , Fpkh , E > (
@@ -435,7 +434,7 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Pkh<P> {
435
434
where
436
435
Fpk : FnMut ( & P ) -> Result < Q , E > ,
437
436
Fpkh : FnMut ( & P :: Hash ) -> Result < Q :: Hash , E > ,
438
- Q : MiniscriptKey ,
437
+ Q : Key ,
439
438
{
440
439
Ok ( Pkh :: new ( translatefpk ( & self . pk ) ?) )
441
440
}
0 commit comments