@@ -187,7 +187,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
187
187
188
188
/// Extracts the internal_key from this policy tree.
189
189
#[ cfg( feature = "compiler" ) ]
190
- fn extract_key ( self , unspendable_key : Option < Pk > ) -> Result < ( Pk , Policy < Pk > ) , Error > {
190
+ fn extract_key ( self , unspendable_key : Option < Pk > ) -> Result < ( Pk , Policy < Pk > ) , CompilerError > {
191
191
let internal_key = self
192
192
. tapleaf_probability_iter ( )
193
193
. filter_map ( |( prob, ref pol) | match pol {
@@ -200,7 +200,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
200
200
match ( internal_key, unspendable_key) {
201
201
( Some ( ref key) , _) => Ok ( ( key. clone ( ) , self . translate_unsatisfiable_pk ( key) ) ) ,
202
202
( _, Some ( key) ) => Ok ( ( key, self ) ) ,
203
- _ => Err ( errstr ( "No viable internal key found." ) ) ,
203
+ _ => Err ( CompilerError :: NoInternalKey ) ,
204
204
}
205
205
}
206
206
@@ -222,11 +222,11 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
222
222
/// is also *cost-efficient*.
223
223
// TODO: We might require other compile errors for Taproot.
224
224
#[ cfg( feature = "compiler" ) ]
225
- pub fn compile_tr ( & self , unspendable_key : Option < Pk > ) -> Result < Descriptor < Pk > , Error > {
226
- self . is_valid ( ) . map_err ( Error :: ConcretePolicy ) ?;
225
+ pub fn compile_tr ( & self , unspendable_key : Option < Pk > ) -> Result < Descriptor < Pk > , CompilerError > {
226
+ self . is_valid ( ) . map_err ( CompilerError :: PolicyError ) ?;
227
227
match self . is_safe_nonmalleable ( ) {
228
- ( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
229
- ( _, false ) => Err ( Error :: from ( CompilerError :: ImpossibleNonMalleableCompilation ) ) ,
228
+ ( false , _) => Err ( CompilerError :: TopLevelNonSafe ) ,
229
+ ( _, false ) => Err ( CompilerError :: ImpossibleNonMalleableCompilation ) ,
230
230
_ => {
231
231
let ( internal_key, policy) = self . clone ( ) . extract_key ( unspendable_key) ?;
232
232
policy. check_num_tapleaves ( ) ?;
@@ -337,7 +337,9 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
337
337
DescriptorCtx :: Sh => Descriptor :: new_sh ( compiler:: best_compilation ( self ) ?) ,
338
338
DescriptorCtx :: Wsh => Descriptor :: new_wsh ( compiler:: best_compilation ( self ) ?) ,
339
339
DescriptorCtx :: ShWsh => Descriptor :: new_sh_wsh ( compiler:: best_compilation ( self ) ?) ,
340
- DescriptorCtx :: Tr ( unspendable_key) => self . compile_tr ( unspendable_key) ,
340
+ DescriptorCtx :: Tr ( unspendable_key) => self
341
+ . compile_tr ( unspendable_key)
342
+ . map_err ( Error :: CompilerError ) ,
341
343
} ,
342
344
}
343
345
}
@@ -585,9 +587,10 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
585
587
586
588
/// Does checks on the number of `TapLeaf`s.
587
589
#[ cfg( feature = "compiler" ) ]
588
- fn check_num_tapleaves ( & self ) -> Result < ( ) , Error > {
589
- if self . num_tap_leaves ( ) > MAX_COMPILATION_LEAVES {
590
- return Err ( errstr ( "Too many Tapleaves" ) ) ;
590
+ fn check_num_tapleaves ( & self ) -> Result < ( ) , CompilerError > {
591
+ let n = self . num_tap_leaves ( ) ;
592
+ if n > MAX_COMPILATION_LEAVES {
593
+ return Err ( CompilerError :: TooManyTapleaves { n, max : MAX_COMPILATION_LEAVES } ) ;
591
594
}
592
595
Ok ( ( ) )
593
596
}
0 commit comments