Skip to content

Commit 787c701

Browse files
committed
feat(compile): shorten internal key in tr descriptor for pretty output
1 parent c3da068 commit 787c701

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/handlers.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ pub(crate) fn handle_compile_subcommand(
905905
let taproot_policy: Miniscript<String, Tap> = policy.compile()?;
906906

907907
let mut r = None;
908+
let mut shorten_descriptor = None;
908909

909910
let descriptor = match script_type.as_str() {
910911
"sh" => Descriptor::new_sh(legacy_policy),
@@ -926,6 +927,12 @@ pub(crate) fn handle_compile_subcommand(
926927
let (xonly_internal_key, _) = internal_key_point.x_only_public_key();
927928

928929
let tree = TapTree::Leaf(Arc::new(taproot_policy));
930+
931+
shorten_descriptor = Some(Descriptor::new_tr(
932+
shorten(xonly_internal_key, 4, 4),
933+
Some(tree.clone()),
934+
)?);
935+
929936
Descriptor::new_tr(xonly_internal_key.to_string(), Some(tree))
930937
}
931938
_ => {
@@ -936,10 +943,12 @@ pub(crate) fn handle_compile_subcommand(
936943
}?;
937944

938945
if pretty {
946+
let descriptor = shorten_descriptor.unwrap_or(descriptor);
947+
939948
let mut rows = vec![vec!["Descriptor".cell().bold(true), descriptor.cell()]];
940949

941950
if let Some(r_value) = &r {
942-
rows.push(vec!["r".cell().bold(true), r_value.cell()]);
951+
rows.push(vec!["r".cell().bold(true), shorten(r_value, 4, 4).cell()]);
943952
}
944953

945954
let table = rows

0 commit comments

Comments
 (0)