Skip to content

Commit aeebccd

Browse files
committed
Fix tr tree checking bug
There are two bugs fixed in this commit 1) Not checking height while creating tree from from_str/from_tree 2) Fix height calculation bugs with root at 0
1 parent ea76eb1 commit aeebccd

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

src/descriptor/tr.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<Pk: MiniscriptKey> TapTree<Pk> {
115115
TapTree::Tree(ref left_tree, ref right_tree) => {
116116
1 + max(left_tree.taptree_height(), right_tree.taptree_height())
117117
}
118-
TapTree::Leaf(..) => 1,
118+
TapTree::Leaf(..) => 0,
119119
}
120120
}
121121

@@ -433,11 +433,7 @@ where
433433
key.args.len()
434434
)));
435435
}
436-
Ok(Tr {
437-
internal_key: expression::terminal(key, Pk::from_str)?,
438-
tree: None,
439-
spend_info: Mutex::new(None),
440-
})
436+
Tr::new(expression::terminal(key, Pk::from_str)?, None)
441437
}
442438
2 => {
443439
let key = &top.args[0];
@@ -449,11 +445,7 @@ where
449445
}
450446
let tree = &top.args[1];
451447
let ret = parse_tr_script_spend(tree)?;
452-
Ok(Tr {
453-
internal_key: expression::terminal(key, Pk::from_str)?,
454-
tree: Some(ret),
455-
spend_info: Mutex::new(None),
456-
})
448+
Tr::new(expression::terminal(key, Pk::from_str)?, Some(ret))
457449
}
458450
_ => {
459451
return Err(Error::Unexpected(format!(

0 commit comments

Comments
 (0)