@@ -192,19 +192,6 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
192
192
}
193
193
}
194
194
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
-
208
195
/// Extract the internal_key from policy tree.
209
196
#[ cfg( feature = "compiler" ) ]
210
197
fn extract_key ( self , unspendable_key : Option < Pk > ) -> Result < ( Pk , Policy < Pk > ) , Error > {
@@ -261,7 +248,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
261
248
/// the probabilitity of satisfaction for the respective branch in the TapTree.
262
249
// TODO: We might require other compile errors for Taproot.
263
250
#[ 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 > {
265
252
self . is_valid ( ) ?; // Check for validity
266
253
match self . is_safe_nonmalleable ( ) {
267
254
( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
@@ -274,7 +261,21 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
274
261
internal_key,
275
262
match policy {
276
263
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
+ }
278
279
} ,
279
280
) ?;
280
281
Ok ( tree)
0 commit comments