@@ -40,7 +40,7 @@ use self::checksum::verify_checksum;
40
40
use crate :: extensions:: { CovExtArgs , ExtParam , NoExtParam } ;
41
41
use crate :: miniscript:: { Legacy , Miniscript , Segwitv0 } ;
42
42
use crate :: {
43
- expression, miniscript, BareCtx , CovenantExt , Error , ExtTranslator , ForEach , ForEachKey ,
43
+ expression, miniscript, BareCtx , CovenantExt , Error , Extension , ExtTranslator , ForEach , ForEachKey ,
44
44
MiniscriptKey , NoExt , Satisfier , ToPublicKey , TranslateExt , TranslatePk , Translator ,
45
45
} ;
46
46
@@ -202,7 +202,7 @@ impl DescriptorInfo {
202
202
/// of the type [DescriptorSecretKey]. If the descriptor contains secret, users
203
203
/// should use the method [DescriptorPublicKey::parse_descriptor] to obtain the
204
204
/// Descriptor and a secret key to public key mapping
205
- pub fn from_desc_str < T : ExtParam > ( s : & str ) -> Result < Self , Error > {
205
+ pub fn from_desc_str < T : Extension > ( s : & str ) -> Result < Self , Error > {
206
206
// Parse as a string descriptor
207
207
let descriptor = Descriptor :: < String , T > :: from_str ( s) ?;
208
208
let has_secret = descriptor. for_any_key ( |pk| match pk {
@@ -225,7 +225,7 @@ impl DescriptorInfo {
225
225
226
226
/// Script descriptor
227
227
#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord ) ]
228
- pub enum Descriptor < Pk : MiniscriptKey , T : ExtParam = CovExtArgs > {
228
+ pub enum Descriptor < Pk : MiniscriptKey , T : Extension = CovenantExt < CovExtArgs > > {
229
229
/// A raw scriptpubkey (including pay-to-pubkey) under Legacy context
230
230
Bare ( Bare < Pk > ) ,
231
231
/// Pay-to-PubKey-Hash
@@ -239,57 +239,57 @@ pub enum Descriptor<Pk: MiniscriptKey, T: ExtParam = CovExtArgs> {
239
239
/// Pay-to-Taproot
240
240
Tr ( Tr < Pk , NoExt > ) ,
241
241
/// Pay-to-Taproot
242
- TrExt ( Tr < Pk , CovenantExt < T > > ) ,
242
+ TrExt ( Tr < Pk , T > ) ,
243
243
/// Covenant descriptor with all known extensions
244
244
/// Downstream implementations of extensions should implement directly use descriptor API
245
- LegacyCSFSCov ( LegacyCSFSCov < Pk , CovenantExt < T > > ) ,
245
+ LegacyCSFSCov ( LegacyCSFSCov < Pk , T > ) ,
246
246
}
247
247
248
- impl < Pk : MiniscriptKey > From < Bare < Pk > > for Descriptor < Pk , NoExtParam > {
248
+ impl < Pk : MiniscriptKey > From < Bare < Pk > > for Descriptor < Pk , CovenantExt < NoExtParam > > {
249
249
#[ inline]
250
250
fn from ( inner : Bare < Pk > ) -> Self {
251
251
Descriptor :: Bare ( inner)
252
252
}
253
253
}
254
254
255
- impl < Pk : MiniscriptKey > From < Pkh < Pk > > for Descriptor < Pk , NoExtParam > {
255
+ impl < Pk : MiniscriptKey > From < Pkh < Pk > > for Descriptor < Pk , CovenantExt < NoExtParam > > {
256
256
#[ inline]
257
257
fn from ( inner : Pkh < Pk > ) -> Self {
258
258
Descriptor :: Pkh ( inner)
259
259
}
260
260
}
261
261
262
- impl < Pk : MiniscriptKey > From < Wpkh < Pk > > for Descriptor < Pk , NoExtParam > {
262
+ impl < Pk : MiniscriptKey > From < Wpkh < Pk > > for Descriptor < Pk , CovenantExt < NoExtParam > > {
263
263
#[ inline]
264
264
fn from ( inner : Wpkh < Pk > ) -> Self {
265
265
Descriptor :: Wpkh ( inner)
266
266
}
267
267
}
268
268
269
- impl < Pk : MiniscriptKey > From < Sh < Pk > > for Descriptor < Pk , NoExtParam > {
269
+ impl < Pk : MiniscriptKey > From < Sh < Pk > > for Descriptor < Pk , CovenantExt < NoExtParam > > {
270
270
#[ inline]
271
271
fn from ( inner : Sh < Pk > ) -> Self {
272
272
Descriptor :: Sh ( inner)
273
273
}
274
274
}
275
275
276
- impl < Pk : MiniscriptKey > From < Wsh < Pk > > for Descriptor < Pk , NoExtParam > {
276
+ impl < Pk : MiniscriptKey > From < Wsh < Pk > > for Descriptor < Pk , CovenantExt < NoExtParam > > {
277
277
#[ inline]
278
278
fn from ( inner : Wsh < Pk > ) -> Self {
279
279
Descriptor :: Wsh ( inner)
280
280
}
281
281
}
282
282
283
- impl < Pk : MiniscriptKey > From < Tr < Pk , NoExt > > for Descriptor < Pk , NoExtParam > {
283
+ impl < Pk : MiniscriptKey > From < Tr < Pk , NoExt > > for Descriptor < Pk , CovenantExt < NoExtParam > > {
284
284
#[ inline]
285
285
fn from ( inner : Tr < Pk , NoExt > ) -> Self {
286
286
Descriptor :: Tr ( inner)
287
287
}
288
288
}
289
289
290
- impl < Pk : MiniscriptKey , T : ExtParam > From < LegacyCSFSCov < Pk , CovenantExt < T > > > for Descriptor < Pk , T > {
290
+ impl < Pk : MiniscriptKey , Arg : ExtParam > From < LegacyCSFSCov < Pk , CovenantExt < Arg > > > for Descriptor < Pk , CovenantExt < Arg > > {
291
291
#[ inline]
292
- fn from ( inner : LegacyCSFSCov < Pk , CovenantExt < T > > ) -> Self {
292
+ fn from ( inner : LegacyCSFSCov < Pk , CovenantExt < Arg > > ) -> Self {
293
293
Descriptor :: LegacyCSFSCov ( inner)
294
294
}
295
295
}
@@ -313,7 +313,7 @@ impl DescriptorType {
313
313
}
314
314
}
315
315
316
- impl < Pk : MiniscriptKey , T : ExtParam > Descriptor < Pk , T > {
316
+ impl < Pk : MiniscriptKey , Arg : ExtParam > Descriptor < Pk , CovenantExt < Arg > > {
317
317
// Keys
318
318
319
319
/// Create a new pk descriptor
@@ -419,7 +419,7 @@ impl<Pk: MiniscriptKey, T: ExtParam> Descriptor<Pk, T> {
419
419
/// Errors when miniscript exceeds resource limits under Tap context
420
420
pub fn new_tr_ext (
421
421
key : Pk ,
422
- script : Option < tr:: TapTree < Pk , CovenantExt < T > > > ,
422
+ script : Option < tr:: TapTree < Pk , CovenantExt < Arg > > > ,
423
423
) -> Result < Self , Error > {
424
424
Ok ( Descriptor :: TrExt ( Tr :: new ( key, script) ?) )
425
425
}
@@ -499,19 +499,19 @@ impl<Pk: MiniscriptKey, T: ExtParam> Descriptor<Pk, T> {
499
499
}
500
500
}
501
501
502
- impl < Pk : MiniscriptKey , T : ExtParam > Descriptor < Pk , T > {
502
+ impl < Pk : MiniscriptKey , Arg : ExtParam > Descriptor < Pk , CovenantExt < Arg > > {
503
503
/// Create a new covenant descriptor
504
504
// All extensions are supported in wsh descriptor
505
505
pub fn new_cov_wsh (
506
506
pk : Pk ,
507
- ms : Miniscript < Pk , Segwitv0 , CovenantExt < T > > ,
507
+ ms : Miniscript < Pk , Segwitv0 , CovenantExt < Arg > > ,
508
508
) -> Result < Self , Error > {
509
509
let cov = LegacyCSFSCov :: new ( pk, ms) ?;
510
510
Ok ( Descriptor :: LegacyCSFSCov ( cov) )
511
511
}
512
512
513
513
/// Tries to convert descriptor as a covenant descriptor
514
- pub fn as_cov ( & self ) -> Result < & LegacyCSFSCov < Pk , CovenantExt < T > > , Error > {
514
+ pub fn as_cov ( & self ) -> Result < & LegacyCSFSCov < Pk , CovenantExt < Arg > > , Error > {
515
515
if let Descriptor :: LegacyCSFSCov ( cov) = self {
516
516
Ok ( cov)
517
517
} else {
@@ -520,7 +520,7 @@ impl<Pk: MiniscriptKey, T: ExtParam> Descriptor<Pk, T> {
520
520
}
521
521
}
522
522
523
- impl < Pk : MiniscriptKey + ToPublicKey > Descriptor < Pk , CovExtArgs > {
523
+ impl < Pk : MiniscriptKey + ToPublicKey > Descriptor < Pk , CovenantExt < CovExtArgs > > {
524
524
///
525
525
/// Obtains the blinded address for this descriptor
526
526
///
@@ -693,13 +693,13 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk, CovExtArgs> {
693
693
}
694
694
}
695
695
696
- impl < P , Q , Arg > TranslatePk < P , Q > for Descriptor < P , Arg >
696
+ impl < P , Q , Ext > TranslatePk < P , Q > for Descriptor < P , Ext >
697
697
where
698
698
P : MiniscriptKey ,
699
699
Q : MiniscriptKey ,
700
- Arg : ExtParam ,
700
+ Ext : Extension ,
701
701
{
702
- type Output = Descriptor < Q , Arg > ;
702
+ type Output = Descriptor < Q , Ext > ;
703
703
704
704
/// Converts a descriptor using abstract keys to one using specific keys.
705
705
fn translate_pk < T , E > ( & self , t : & mut T ) -> Result < Self :: Output , E >
@@ -720,22 +720,20 @@ where
720
720
}
721
721
}
722
722
723
- impl < PArg , QArg , Pk > TranslateExt < CovenantExt < PArg > , CovenantExt < QArg > , PArg , QArg >
724
- for Descriptor < Pk , PArg >
723
+ impl < PExt , QExt , Pk > TranslateExt < PExt , QExt >
724
+ for Descriptor < Pk , PExt >
725
725
where
726
- PArg : ExtParam ,
727
- QArg : ExtParam ,
726
+ PExt : Extension + TranslateExt < PExt , QExt , Output = QExt > ,
727
+ QExt : Extension ,
728
728
Pk : MiniscriptKey ,
729
- // PExt: TranslateExt<PExt, QExt, PArg, QArg, Output = QExt>,
730
- // Tr<Pk, CovenantExt<PArg>>: TranslateExt<PExt, QExt, PArg, QArg,>
731
729
{
732
- type Output = Descriptor < Pk , QArg > ;
730
+ type Output = Descriptor < Pk , QExt > ;
733
731
734
732
/// Converts a descriptor using abstract keys to one using specific keys.
735
733
#[ rustfmt:: skip]
736
734
fn translate_ext < T , E > ( & self , t : & mut T ) -> Result < Self :: Output , E >
737
735
where
738
- T : ExtTranslator < PArg , QArg , E > ,
736
+ T : ExtTranslator < PExt , QExt , E > ,
739
737
{
740
738
let desc = match * self {
741
739
Descriptor :: Bare ( ref bare) => Descriptor :: Bare ( bare. clone ( ) ) ,
@@ -745,10 +743,10 @@ where
745
743
Descriptor :: Wsh ( ref wsh) => Descriptor :: Wsh ( wsh. clone ( ) ) ,
746
744
Descriptor :: Tr ( ref tr) => Descriptor :: Tr ( tr. clone ( ) ) ,
747
745
Descriptor :: TrExt ( ref tr) => Descriptor :: TrExt (
748
- TranslateExt :: < CovenantExt < PArg > , CovenantExt < QArg > , _ , _ > :: translate_ext ( tr, t) ?,
746
+ TranslateExt :: < PExt , QExt > :: translate_ext ( tr, t) ?,
749
747
) ,
750
748
Descriptor :: LegacyCSFSCov ( ref cov) => {
751
- Descriptor :: LegacyCSFSCov ( TranslateExt :: < CovenantExt < PArg > , CovenantExt < QArg > , _ , _ > :: translate_ext (
749
+ Descriptor :: LegacyCSFSCov ( TranslateExt :: < PExt , QExt > :: translate_ext (
752
750
cov, t,
753
751
) ?)
754
752
}
@@ -757,7 +755,7 @@ where
757
755
}
758
756
}
759
757
760
- impl < Pk : MiniscriptKey , T : ExtParam > ForEachKey < Pk > for Descriptor < Pk , T > {
758
+ impl < Pk : MiniscriptKey , T : Extension > ForEachKey < Pk > for Descriptor < Pk , T > {
761
759
fn for_each_key < ' a , F : FnMut ( ForEach < ' a , Pk > ) -> bool > ( & ' a self , pred : F ) -> bool
762
760
where
763
761
Pk : ' a ,
@@ -962,7 +960,7 @@ impl Descriptor<DescriptorPublicKey> {
962
960
}
963
961
}
964
962
965
- impl Descriptor < DescriptorPublicKey , CovExtArgs > {
963
+ impl Descriptor < DescriptorPublicKey , CovenantExt < CovExtArgs > > {
966
964
/// Utility method for deriving the descriptor at each index in a range to find one matching
967
965
/// `script_pubkey`.
968
966
///
@@ -975,7 +973,7 @@ impl Descriptor<DescriptorPublicKey, CovExtArgs> {
975
973
secp : & secp256k1_zkp:: Secp256k1 < C > ,
976
974
script_pubkey : & Script ,
977
975
range : Range < u32 > ,
978
- ) -> Result < Option < ( u32 , Descriptor < bitcoin:: PublicKey , CovExtArgs > ) > , ConversionError > {
976
+ ) -> Result < Option < ( u32 , Descriptor < bitcoin:: PublicKey , CovenantExt < CovExtArgs > > ) > , ConversionError > {
979
977
let range = if self . is_deriveable ( ) { range } else { 0 ..1 } ;
980
978
981
979
for i in range {
@@ -991,7 +989,7 @@ impl Descriptor<DescriptorPublicKey, CovExtArgs> {
991
989
}
992
990
993
991
impl_from_tree ! (
994
- ; T ; ExtParam ,
992
+ ; T ; Extension ,
995
993
Descriptor <Pk , T >,
996
994
/// Parse an expression tree into a descriptor.
997
995
fn from_tree( top: & expression:: Tree ) -> Result <Descriptor <Pk , T >, Error > {
@@ -1008,7 +1006,7 @@ impl_from_tree!(
1008
1006
) ;
1009
1007
1010
1008
impl_from_str ! (
1011
- ; T ; ExtParam ,
1009
+ ; T ; Extension ,
1012
1010
Descriptor <Pk , T >,
1013
1011
type Err = Error ; ,
1014
1012
fn from_str( s: & str ) -> Result <Descriptor <Pk , T >, Error > {
@@ -1026,7 +1024,7 @@ impl_from_str!(
1026
1024
Ok ( tr) => Ok ( Descriptor :: Tr ( tr) ) ,
1027
1025
Err ( _) => {
1028
1026
// Try parsing with extensions
1029
- let tr = Tr :: <Pk , CovenantExt < T > >:: from_str( s) ?;
1027
+ let tr = Tr :: <Pk , T >:: from_str( s) ?;
1030
1028
Ok ( Descriptor :: TrExt ( tr) )
1031
1029
}
1032
1030
}
@@ -1038,7 +1036,7 @@ impl_from_str!(
1038
1036
}
1039
1037
) ;
1040
1038
1041
- impl < Pk : MiniscriptKey , T : ExtParam > fmt:: Debug for Descriptor < Pk , T > {
1039
+ impl < Pk : MiniscriptKey , T : Extension > fmt:: Debug for Descriptor < Pk , T > {
1042
1040
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1043
1041
match * self {
1044
1042
Descriptor :: Bare ( ref sub) => write ! ( f, "{:?}" , sub) ,
@@ -1053,7 +1051,7 @@ impl<Pk: MiniscriptKey, T: ExtParam> fmt::Debug for Descriptor<Pk, T> {
1053
1051
}
1054
1052
}
1055
1053
1056
- impl < Pk : MiniscriptKey , T : ExtParam > fmt:: Display for Descriptor < Pk , T > {
1054
+ impl < Pk : MiniscriptKey , T : Extension > fmt:: Display for Descriptor < Pk , T > {
1057
1055
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1058
1056
match * self {
1059
1057
Descriptor :: Bare ( ref sub) => write ! ( f, "{}" , sub) ,
@@ -1068,7 +1066,7 @@ impl<Pk: MiniscriptKey, T: ExtParam> fmt::Display for Descriptor<Pk, T> {
1068
1066
}
1069
1067
}
1070
1068
1071
- serde_string_impl_pk ! ( Descriptor , "a script descriptor" , T ; ExtParam ) ;
1069
+ serde_string_impl_pk ! ( Descriptor , "a script descriptor" , T ; Extension ) ;
1072
1070
1073
1071
#[ cfg( test) ]
1074
1072
mod tests {
@@ -1095,7 +1093,7 @@ mod tests {
1095
1093
use crate :: policy;
1096
1094
use crate :: { hex_script, Descriptor , DummyKey , Error , Miniscript , Satisfier } ;
1097
1095
1098
- type StdDescriptor = Descriptor < PublicKey , CovExtArgs > ;
1096
+ type StdDescriptor = Descriptor < PublicKey , CovenantExt < CovExtArgs > > ;
1099
1097
const TEST_PK : & ' static str =
1100
1098
"elpk(020000000000000000000000000000000000000000000000000000000000000002)" ;
1101
1099
@@ -1910,7 +1908,7 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
1910
1908
let res_policy: policy:: concrete:: Policy < DescriptorPublicKey > =
1911
1909
res_descriptor_str. parse ( ) . unwrap ( ) ;
1912
1910
let res_descriptor =
1913
- Descriptor :: < DescriptorPublicKey , NoExtParam > :: new_sh ( res_policy. compile ( ) . unwrap ( ) )
1911
+ Descriptor :: < DescriptorPublicKey , CovenantExt < NoExtParam > > :: new_sh ( res_policy. compile ( ) . unwrap ( ) )
1914
1912
. unwrap ( ) ;
1915
1913
1916
1914
assert_eq ! ( res_descriptor. to_string( ) , derived_descriptor. to_string( ) ) ;
0 commit comments