21
21
core:: cmp:: Reverse ,
22
22
} ;
23
23
24
- use super :: ENTAILMENT_MAX_TERMINALS ;
25
24
use crate :: expression:: { self , FromTree } ;
26
25
use crate :: iter:: { Tree , TreeLike } ;
27
26
use crate :: miniscript:: types:: extra_props:: TimelockInfo ;
@@ -80,12 +79,6 @@ pub enum PolicyError {
80
79
NonBinaryArgAnd ,
81
80
/// `Or` fragments only support two args.
82
81
NonBinaryArgOr ,
83
- /// Semantic Policy Error: `And` `Or` fragments must take args: `k > 1`.
84
- InsufficientArgsforAnd ,
85
- /// Semantic policy error: `And` `Or` fragments must take args: `k > 1`.
86
- InsufficientArgsforOr ,
87
- /// Entailment max terminals exceeded.
88
- EntailmentMaxTerminals ,
89
82
/// Cannot lift policies that have a combination of height and timelocks.
90
83
HeightTimelockCombination ,
91
84
/// Duplicate Public Keys.
@@ -114,15 +107,6 @@ impl fmt::Display for PolicyError {
114
107
f. write_str ( "And policy fragment must take 2 arguments" )
115
108
}
116
109
PolicyError :: NonBinaryArgOr => f. write_str ( "Or policy fragment must take 2 arguments" ) ,
117
- PolicyError :: InsufficientArgsforAnd => {
118
- f. write_str ( "Semantic Policy 'And' fragment must have at least 2 args " )
119
- }
120
- PolicyError :: InsufficientArgsforOr => {
121
- f. write_str ( "Semantic Policy 'Or' fragment must have at least 2 args " )
122
- }
123
- PolicyError :: EntailmentMaxTerminals => {
124
- write ! ( f, "Policy entailment only supports {} terminals" , ENTAILMENT_MAX_TERMINALS )
125
- }
126
110
PolicyError :: HeightTimelockCombination => {
127
111
f. write_str ( "Cannot lift policies that have a heightlock and timelock combination" )
128
112
}
@@ -137,13 +121,7 @@ impl error::Error for PolicyError {
137
121
use self :: PolicyError :: * ;
138
122
139
123
match self {
140
- NonBinaryArgAnd
141
- | NonBinaryArgOr
142
- | InsufficientArgsforAnd
143
- | InsufficientArgsforOr
144
- | EntailmentMaxTerminals
145
- | HeightTimelockCombination
146
- | DuplicatePubKeys => None ,
124
+ NonBinaryArgAnd | NonBinaryArgOr | HeightTimelockCombination | DuplicatePubKeys => None ,
147
125
}
148
126
}
149
127
}
@@ -252,7 +230,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
252
230
// TODO: We might require other compile errors for Taproot.
253
231
#[ cfg( feature = "compiler" ) ]
254
232
pub fn compile_tr ( & self , unspendable_key : Option < Pk > ) -> Result < Descriptor < Pk > , Error > {
255
- self . is_valid ( ) ? ; // Check for validity
233
+ self . is_valid ( ) . map_err ( Error :: ConcretePolicy ) ? ;
256
234
match self . is_safe_nonmalleable ( ) {
257
235
( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
258
236
( _, false ) => Err ( Error :: from ( CompilerError :: ImpossibleNonMalleableCompilation ) ) ,
@@ -308,7 +286,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
308
286
& self ,
309
287
unspendable_key : Option < Pk > ,
310
288
) -> Result < Descriptor < Pk > , Error > {
311
- self . is_valid ( ) ? ; // Check for validity
289
+ self . is_valid ( ) . map_err ( Error :: ConcretePolicy ) ? ;
312
290
match self . is_safe_nonmalleable ( ) {
313
291
( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
314
292
( _, false ) => Err ( Error :: from ( CompilerError :: ImpossibleNonMalleableCompilation ) ) ,
@@ -355,7 +333,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
355
333
& self ,
356
334
desc_ctx : DescriptorCtx < Pk > ,
357
335
) -> Result < Descriptor < Pk > , Error > {
358
- self . is_valid ( ) ?;
336
+ self . is_valid ( ) . map_err ( Error :: ConcretePolicy ) ?;
359
337
match self . is_safe_nonmalleable ( ) {
360
338
( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
361
339
( _, false ) => Err ( Error :: from ( CompilerError :: ImpossibleNonMalleableCompilation ) ) ,
@@ -869,7 +847,7 @@ impl<Pk: FromStrKey> str::FromStr for Policy<Pk> {
869
847
870
848
let tree = expression:: Tree :: from_str ( s) ?;
871
849
let policy: Policy < Pk > = FromTree :: from_tree ( & tree) ?;
872
- policy. check_timelocks ( ) ?;
850
+ policy. check_timelocks ( ) . map_err ( Error :: ConcretePolicy ) ?;
873
851
Ok ( policy)
874
852
}
875
853
}
@@ -934,7 +912,7 @@ impl<Pk: FromStrKey> Policy<Pk> {
934
912
} ) ,
935
913
( "and" , _) => {
936
914
if top. args . len ( ) != 2 {
937
- return Err ( Error :: PolicyError ( PolicyError :: NonBinaryArgAnd ) ) ;
915
+ return Err ( Error :: ConcretePolicy ( PolicyError :: NonBinaryArgAnd ) ) ;
938
916
}
939
917
let mut subs = Vec :: with_capacity ( top. args . len ( ) ) ;
940
918
for arg in & top. args {
@@ -944,7 +922,7 @@ impl<Pk: FromStrKey> Policy<Pk> {
944
922
}
945
923
( "or" , _) => {
946
924
if top. args . len ( ) != 2 {
947
- return Err ( Error :: PolicyError ( PolicyError :: NonBinaryArgOr ) ) ;
925
+ return Err ( Error :: ConcretePolicy ( PolicyError :: NonBinaryArgOr ) ) ;
948
926
}
949
927
let mut subs = Vec :: with_capacity ( top. args . len ( ) ) ;
950
928
for arg in & top. args {
0 commit comments