File tree 1 file changed +23
-4
lines changed
1 file changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -275,8 +275,13 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
275
275
compilation. sanity_check ( ) ?;
276
276
leaf_compilations. push ( ( OrdF64 ( prob) , compilation) ) ;
277
277
}
278
- let tap_tree = with_huffman_tree :: < Pk > ( leaf_compilations) ?;
279
- Some ( tap_tree)
278
+ if !leaf_compilations. is_empty ( ) {
279
+ let tap_tree = with_huffman_tree :: < Pk > ( leaf_compilations) ?;
280
+ Some ( tap_tree)
281
+ } else {
282
+ // no policies remaining once the extracted key is skipped
283
+ None
284
+ }
280
285
}
281
286
} ,
282
287
) ?;
@@ -330,8 +335,14 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
330
335
)
331
336
} )
332
337
. collect ( ) ;
333
- let tap_tree = with_huffman_tree :: < Pk > ( leaf_compilations) . unwrap ( ) ;
334
- Some ( tap_tree)
338
+
339
+ if !leaf_compilations. is_empty ( ) {
340
+ let tap_tree = with_huffman_tree :: < Pk > ( leaf_compilations) . unwrap ( ) ;
341
+ Some ( tap_tree)
342
+ } else {
343
+ // no policies remaining once the extracted key is skipped
344
+ None
345
+ }
335
346
}
336
347
} ,
337
348
) ?;
@@ -1119,6 +1130,14 @@ mod compiler_tests {
1119
1130
. collect :: < Vec < _ > > ( ) ;
1120
1131
assert_eq ! ( combinations, expected_comb) ;
1121
1132
}
1133
+
1134
+ #[ test]
1135
+ fn test_tr_pk_only ( ) {
1136
+ let policy: Policy < String > = policy_str ! ( "pk(A)" ) ;
1137
+ let desc = policy. compile_tr ( None ) . unwrap ( ) ;
1138
+ // pk(A) promoted to the internal key, leaving the script tree empty
1139
+ assert_eq ! ( desc. to_string( ) , "tr(A)#xyg3grex" ) ;
1140
+ }
1122
1141
}
1123
1142
1124
1143
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments