Skip to content

Commit

Permalink
Fix tr tree checking bug
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sanket1729 committed Jun 10, 2022
1 parent 44c0e4b commit 61389dc
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/descriptor/tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<Pk: MiniscriptKey> TapTree<Pk> {
TapTree::Tree(ref left_tree, ref right_tree) => {
1 + max(left_tree.taptree_height(), right_tree.taptree_height())
}
TapTree::Leaf(..) => 1,
TapTree::Leaf(..) => 0,
}
}

Expand Down Expand Up @@ -420,11 +420,7 @@ impl_from_tree!(
key.args.len()
)));
}
Ok(Tr {
internal_key: expression::terminal(key, Pk::from_str)?,
tree: None,
spend_info: Mutex::new(None),
})
Tr::new(expression::terminal(key, Pk::from_str)?, None)
}
2 => {
let key = &top.args[0];
Expand All @@ -436,11 +432,7 @@ impl_from_tree!(
}
let tree = &top.args[1];
let ret = Self::parse_tr_script_spend(tree)?;
Ok(Tr {
internal_key: expression::terminal(key, Pk::from_str)?,
tree: Some(ret),
spend_info: Mutex::new(None),
})
Tr::new(expression::terminal(key, Pk::from_str)?, Some(ret))
}
_ => {
return Err(Error::Unexpected(format!(
Expand Down

0 comments on commit 61389dc

Please sign in to comment.