@@ -192,19 +192,6 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
192192 }
193193 }
194194
195- /// Compile [`Policy::Or`] and [`Policy::Threshold`] according to odds
196- #[ cfg( feature = "compiler" ) ]
197- fn compile_tr_policy ( & self ) -> Result < TapTree < Pk > , Error > {
198- let leaf_compilations: Vec < _ > = self
199- . to_tapleaf_prob_vec ( 1.0 )
200- . into_iter ( )
201- . filter ( |x| x. 1 != Policy :: Unsatisfiable )
202- . map ( |( prob, ref policy) | ( OrdF64 ( prob) , compiler:: best_compilation ( policy) . unwrap ( ) ) )
203- . collect ( ) ;
204- let taptree = with_huffman_tree :: < Pk > ( leaf_compilations) . unwrap ( ) ;
205- Ok ( taptree)
206- }
207-
208195 /// Extract the internal_key from policy tree.
209196 #[ cfg( feature = "compiler" ) ]
210197 fn extract_key ( self , unspendable_key : Option < Pk > ) -> Result < ( Pk , Policy < Pk > ) , Error > {
@@ -261,7 +248,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
261248 /// the probabilitity of satisfaction for the respective branch in the TapTree.
262249 // TODO: We might require other compile errors for Taproot.
263250 #[ cfg( feature = "compiler" ) ]
264- pub fn compile_tr ( & self , unspendable_key : Option < Pk > ) -> Result < Descriptor < Pk > , Error > {
251+ pub fn compile_tr_private ( & self , unspendable_key : Option < Pk > ) -> Result < Descriptor < Pk > , Error > {
265252 self . is_valid ( ) ?; // Check for validity
266253 match self . is_safe_nonmalleable ( ) {
267254 ( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
@@ -274,7 +261,21 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
274261 internal_key,
275262 match policy {
276263 Policy :: Trivial => None ,
277- policy => Some ( policy. compile_tr_policy ( ) ?) ,
264+ policy => {
265+ let vec_policies: Vec < _ > = policy. to_tapleaf_prob_vec ( 1.0 ) ;
266+ let mut leaf_compilations: Vec < ( OrdF64 , Miniscript < Pk , Tap > ) > = vec ! [ ] ;
267+ for ( prob, pol) in vec_policies {
268+ // policy corresponding to the key (replaced by unsatisfiable) is skipped
269+ if pol == Policy :: Unsatisfiable {
270+ continue ;
271+ }
272+ let compilation = compiler:: best_compilation :: < Pk , Tap > ( & pol) ?;
273+ compilation. sanity_check ( ) ?;
274+ leaf_compilations. push ( ( OrdF64 ( prob) , compilation) ) ;
275+ }
276+ let taptree = with_huffman_tree :: < Pk > ( leaf_compilations) ?;
277+ Some ( taptree)
278+ }
278279 } ,
279280 ) ?;
280281 Ok ( tree)
0 commit comments