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 9, 2022
1 parent ea76eb1 commit aeebccd
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 @@ -115,7 +115,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 @@ -433,11 +433,7 @@ where
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 @@ -449,11 +445,7 @@ where
}
let tree = &top.args[1];
let ret = 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 aeebccd

Please sign in to comment.