2121 core:: cmp:: Reverse ,
2222} ;
2323
24- use super :: ENTAILMENT_MAX_TERMINALS ;
2524use crate :: expression:: { self , FromTree } ;
2625use crate :: iter:: { Tree , TreeLike } ;
2726use crate :: miniscript:: types:: extra_props:: TimelockInfo ;
@@ -80,12 +79,6 @@ pub enum PolicyError {
8079 NonBinaryArgAnd ,
8180 /// `Or` fragments only support two args.
8281 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 ,
8982 /// Cannot lift policies that have a combination of height and timelocks.
9083 HeightTimelockCombination ,
9184 /// Duplicate Public Keys.
@@ -114,15 +107,6 @@ impl fmt::Display for PolicyError {
114107 f. write_str ( "And policy fragment must take 2 arguments" )
115108 }
116109 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- }
126110 PolicyError :: HeightTimelockCombination => {
127111 f. write_str ( "Cannot lift policies that have a heightlock and timelock combination" )
128112 }
@@ -137,13 +121,7 @@ impl error::Error for PolicyError {
137121 use self :: PolicyError :: * ;
138122
139123 match self {
140- NonBinaryArgAnd
141- | NonBinaryArgOr
142- | InsufficientArgsforAnd
143- | InsufficientArgsforOr
144- | EntailmentMaxTerminals
145- | HeightTimelockCombination
146- | DuplicatePubKeys => None ,
124+ NonBinaryArgAnd | NonBinaryArgOr | HeightTimelockCombination | DuplicatePubKeys => None ,
147125 }
148126 }
149127}
@@ -252,7 +230,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
252230 // TODO: We might require other compile errors for Taproot.
253231 #[ cfg( feature = "compiler" ) ]
254232 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 ) ? ;
256234 match self . is_safe_nonmalleable ( ) {
257235 ( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
258236 ( _, false ) => Err ( Error :: from ( CompilerError :: ImpossibleNonMalleableCompilation ) ) ,
@@ -308,7 +286,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
308286 & self ,
309287 unspendable_key : Option < Pk > ,
310288 ) -> Result < Descriptor < Pk > , Error > {
311- self . is_valid ( ) ? ; // Check for validity
289+ self . is_valid ( ) . map_err ( Error :: ConcretePolicy ) ? ;
312290 match self . is_safe_nonmalleable ( ) {
313291 ( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
314292 ( _, false ) => Err ( Error :: from ( CompilerError :: ImpossibleNonMalleableCompilation ) ) ,
@@ -355,7 +333,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
355333 & self ,
356334 desc_ctx : DescriptorCtx < Pk > ,
357335 ) -> Result < Descriptor < Pk > , Error > {
358- self . is_valid ( ) ?;
336+ self . is_valid ( ) . map_err ( Error :: ConcretePolicy ) ?;
359337 match self . is_safe_nonmalleable ( ) {
360338 ( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
361339 ( _, false ) => Err ( Error :: from ( CompilerError :: ImpossibleNonMalleableCompilation ) ) ,
@@ -869,7 +847,7 @@ impl<Pk: FromStrKey> str::FromStr for Policy<Pk> {
869847
870848 let tree = expression:: Tree :: from_str ( s) ?;
871849 let policy: Policy < Pk > = FromTree :: from_tree ( & tree) ?;
872- policy. check_timelocks ( ) ?;
850+ policy. check_timelocks ( ) . map_err ( Error :: ConcretePolicy ) ?;
873851 Ok ( policy)
874852 }
875853}
@@ -934,7 +912,7 @@ impl<Pk: FromStrKey> Policy<Pk> {
934912 } ) ,
935913 ( "and" , _) => {
936914 if top. args . len ( ) != 2 {
937- return Err ( Error :: PolicyError ( PolicyError :: NonBinaryArgAnd ) ) ;
915+ return Err ( Error :: ConcretePolicy ( PolicyError :: NonBinaryArgAnd ) ) ;
938916 }
939917 let mut subs = Vec :: with_capacity ( top. args . len ( ) ) ;
940918 for arg in & top. args {
@@ -944,7 +922,7 @@ impl<Pk: FromStrKey> Policy<Pk> {
944922 }
945923 ( "or" , _) => {
946924 if top. args . len ( ) != 2 {
947- return Err ( Error :: PolicyError ( PolicyError :: NonBinaryArgOr ) ) ;
925+ return Err ( Error :: ConcretePolicy ( PolicyError :: NonBinaryArgOr ) ) ;
948926 }
949927 let mut subs = Vec :: with_capacity ( top. args . len ( ) ) ;
950928 for arg in & top. args {
0 commit comments