Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation of pk()-only policies into tr() descriptors #677

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/policy/concrete.rs
Original file line number Diff line number Diff line change
@@ -247,8 +247,13 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
.expect("compiler produces sane output");
leaf_compilations.push((OrdF64(prob), compilation));
}
let tap_tree = with_huffman_tree::<Pk>(leaf_compilations).unwrap();
Some(tap_tree)
if !leaf_compilations.is_empty() {
let tap_tree = with_huffman_tree::<Pk>(leaf_compilations).unwrap();
Some(tap_tree)
} else {
// no policies remaining once the extracted key is skipped
None
}
}
},
)
@@ -303,8 +308,14 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
)
})
.collect();
let tap_tree = with_huffman_tree::<Pk>(leaf_compilations).unwrap();
Some(tap_tree)

if !leaf_compilations.is_empty() {
let tap_tree = with_huffman_tree::<Pk>(leaf_compilations).unwrap();
Some(tap_tree)
} else {
// no policies remaining once the extracted key is skipped
None
}
}
},
)?;
@@ -1109,6 +1120,14 @@ mod compiler_tests {
.collect::<Vec<_>>();
assert_eq!(combinations, expected_comb);
}

#[test]
fn test_tr_pk_only() {
let policy: Policy<String> = policy_str!("pk(A)");
let desc = policy.compile_tr(None).unwrap();
// pk(A) promoted to the internal key, leaving the script tree empty
assert_eq!(desc.to_string(), "tr(A)#xyg3grex");
}
}

#[cfg(test)]