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