Skip to content

Commit 61389dc

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 44c0e4b commit 61389dc

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
@@ -116,7 +116,7 @@ impl<Pk: MiniscriptKey> TapTree<Pk> {
116116
TapTree::Tree(ref left_tree, ref right_tree) => {
117117
1 + max(left_tree.taptree_height(), right_tree.taptree_height())
118118
}
119-
TapTree::Leaf(..) => 1,
119+
TapTree::Leaf(..) => 0,
120120
}
121121
}
122122

@@ -420,11 +420,7 @@ impl_from_tree!(
420420
key.args.len()
421421
)));
422422
}
423-
Ok(Tr {
424-
internal_key: expression::terminal(key, Pk::from_str)?,
425-
tree: None,
426-
spend_info: Mutex::new(None),
427-
})
423+
Tr::new(expression::terminal(key, Pk::from_str)?, None)
428424
}
429425
2 => {
430426
let key = &top.args[0];
@@ -436,11 +432,7 @@ impl_from_tree!(
436432
}
437433
let tree = &top.args[1];
438434
let ret = Self::parse_tr_script_spend(tree)?;
439-
Ok(Tr {
440-
internal_key: expression::terminal(key, Pk::from_str)?,
441-
tree: Some(ret),
442-
spend_info: Mutex::new(None),
443-
})
435+
Tr::new(expression::terminal(key, Pk::from_str)?, Some(ret))
444436
}
445437
_ => {
446438
return Err(Error::Unexpected(format!(

0 commit comments

Comments
 (0)