|
19 | 19 | core::cmp::Reverse,
|
20 | 20 | };
|
21 | 21 |
|
22 |
| -#[cfg(feature = "compiler")] |
23 |
| -use crate::errstr; |
24 | 22 | use crate::expression::{self, FromTree};
|
25 | 23 | use crate::iter::{Tree, TreeLike};
|
26 | 24 | use crate::miniscript::types::extra_props::TimelockInfo;
|
@@ -249,7 +247,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
|
249 | 247 | leaf_compilations.push((OrdF64(prob), compilation));
|
250 | 248 | }
|
251 | 249 | if !leaf_compilations.is_empty() {
|
252 |
| - let tap_tree = with_huffman_tree::<Pk>(leaf_compilations).unwrap(); |
| 250 | + let tap_tree = with_huffman_tree::<Pk>(leaf_compilations); |
253 | 251 | Some(tap_tree)
|
254 | 252 | } else {
|
255 | 253 | // no policies remaining once the extracted key is skipped
|
@@ -311,7 +309,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
|
311 | 309 | .collect();
|
312 | 310 |
|
313 | 311 | if !leaf_compilations.is_empty() {
|
314 |
| - let tap_tree = with_huffman_tree::<Pk>(leaf_compilations).unwrap(); |
| 312 | + let tap_tree = with_huffman_tree::<Pk>(leaf_compilations); |
315 | 313 | Some(tap_tree)
|
316 | 314 | } else {
|
317 | 315 | // no policies remaining once the extracted key is skipped
|
@@ -957,30 +955,25 @@ impl<Pk: FromStrKey> expression::FromTree for Policy<Pk> {
|
957 | 955 |
|
958 | 956 | /// Creates a Huffman Tree from compiled [`Miniscript`] nodes.
|
959 | 957 | #[cfg(feature = "compiler")]
|
960 |
| -fn with_huffman_tree<Pk: MiniscriptKey>( |
961 |
| - ms: Vec<(OrdF64, Miniscript<Pk, Tap>)>, |
962 |
| -) -> Result<TapTree<Pk>, Error> { |
| 958 | +fn with_huffman_tree<Pk: MiniscriptKey>(ms: Vec<(OrdF64, Miniscript<Pk, Tap>)>) -> TapTree<Pk> { |
963 | 959 | let mut node_weights = BinaryHeap::<(Reverse<OrdF64>, TapTree<Pk>)>::new();
|
964 | 960 | for (prob, script) in ms {
|
965 | 961 | node_weights.push((Reverse(prob), TapTree::Leaf(Arc::new(script))));
|
966 | 962 | }
|
967 |
| - if node_weights.is_empty() { |
968 |
| - return Err(errstr("Empty Miniscript compilation")); |
969 |
| - } |
| 963 | + assert_ne!(node_weights.len(), 0, "empty Miniscript compilation"); |
970 | 964 | while node_weights.len() > 1 {
|
971 |
| - let (p1, s1) = node_weights.pop().expect("len must atleast be two"); |
972 |
| - let (p2, s2) = node_weights.pop().expect("len must atleast be two"); |
| 965 | + let (p1, s1) = node_weights.pop().expect("len must at least be two"); |
| 966 | + let (p2, s2) = node_weights.pop().expect("len must at least be two"); |
973 | 967 |
|
974 | 968 | let p = (p1.0).0 + (p2.0).0;
|
975 | 969 | node_weights.push((Reverse(OrdF64(p)), TapTree::combine(s1, s2)));
|
976 | 970 | }
|
977 | 971 |
|
978 | 972 | debug_assert!(node_weights.len() == 1);
|
979 |
| - let node = node_weights |
| 973 | + node_weights |
980 | 974 | .pop()
|
981 | 975 | .expect("huffman tree algorithm is broken")
|
982 |
| - .1; |
983 |
| - Ok(node) |
| 976 | + .1 |
984 | 977 | }
|
985 | 978 |
|
986 | 979 | /// Enumerates a [`Policy::Thresh(k, ..n..)`] into `n` different thresh's.
|
|
0 commit comments