@@ -195,19 +195,6 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
195
195
}
196
196
}
197
197
198
- /// Compile [`Policy::Or`] and [`Policy::Threshold`] according to odds
199
- #[ cfg( feature = "compiler" ) ]
200
- fn compile_tr_policy ( & self ) -> Result < TapTree < Pk > , Error > {
201
- let leaf_compilations: Vec < _ > = self
202
- . to_tapleaf_prob_vec ( 1.0 )
203
- . into_iter ( )
204
- . filter ( |x| x. 1 != Policy :: Unsatisfiable )
205
- . map ( |( prob, ref policy) | ( OrdF64 ( prob) , compiler:: best_compilation ( policy) . unwrap ( ) ) )
206
- . collect ( ) ;
207
- let taptree = Self :: with_huffman_tree ( leaf_compilations, |x| x) . unwrap ( ) ;
208
- Ok ( taptree)
209
- }
210
-
211
198
/// Extract the internal_key from policy tree.
212
199
#[ cfg( feature = "compiler" ) ]
213
200
fn extract_key ( self , unspendable_key : Option < Pk > ) -> Result < ( Pk , Policy < Pk > ) , Error > {
@@ -252,10 +239,15 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
252
239
}
253
240
}
254
241
255
- /// Compile the [`Tr`] descriptor into optimized [`TapTree`] implementation
256
- // TODO: We might require other compile errors for Taproot. Will discuss and update.
242
+ /// Compile [`Policy`] into a [`TapTree Descriptor`][`Descriptor::Tr`]
243
+ ///
244
+ /// We recursively expand the policy tree w.r.t root-level [`Policy::Or`]s and
245
+ /// [`Policy::Threshold`](1, ...) to obtain (sub)-policies. For example,
246
+ /// `thresh(1,and(or(A,B),C),or(or(D, E),and(F, G)),H)` is split into the list
247
+ /// [and(or(A,B),C), D,E, and(F, G), H] which are used for generating miniscript compilations
248
+ /// required for generating [`TapTree`].
257
249
#[ cfg( feature = "compiler" ) ]
258
- pub fn compile_tr ( & self , unspendable_key : Option < Pk > ) -> Result < Descriptor < Pk > , Error > {
250
+ pub fn compile_tr_private ( & self , unspendable_key : Option < Pk > ) -> Result < Descriptor < Pk > , Error > {
259
251
self . is_valid ( ) ?; // Check for validity
260
252
match self . is_safe_nonmalleable ( ) {
261
253
( false , _) => Err ( Error :: from ( CompilerError :: TopLevelNonSafe ) ) ,
@@ -268,7 +260,19 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
268
260
internal_key,
269
261
match policy {
270
262
Policy :: Trivial => None ,
271
- policy => Some ( policy. compile_tr_policy ( ) ?) ,
263
+ policy => {
264
+ let leaf_compilations: Vec < _ > = policy
265
+ . to_tapleaf_prob_vec ( 1.0 )
266
+ . into_iter ( )
267
+ . filter ( |x| x. 1 != Policy :: Unsatisfiable )
268
+ . map ( |( prob, ref pol) | {
269
+ ( OrdF64 ( prob) , compiler:: best_compilation ( pol) . unwrap ( ) )
270
+ } )
271
+ . collect ( ) ;
272
+ let taptree =
273
+ Self :: with_huffman_tree ( leaf_compilations, |x| x) . unwrap ( ) ;
274
+ Some ( taptree)
275
+ }
272
276
} ,
273
277
) ?;
274
278
Ok ( tree)
0 commit comments