taproot: add TapNodeHash getter method on TapTree and NodeInfo

Fixes a gap in the API of the taproot module. Callers can now use
TapTree::root_hash or NodeInfo::node_hash to extract the taproot
tree merkle root hash for fast validation without any ECC overhead.
This commit is contained in:
conduition 2024-02-11 17:14:13 +00:00
parent 8f7cc4d6b3
commit 1384330029
No known key found for this signature in database
GPG Key ID: 78296CED84F6B3C5
1 changed files with 6 additions and 0 deletions

View File

@ -693,6 +693,9 @@ impl TapTree {
/// Returns [`TapTreeIter<'_>`] iterator for a taproot script tree, operating in DFS order over
/// tree [`ScriptLeaf`]s.
pub fn script_leaves(&self) -> ScriptLeaves { ScriptLeaves { leaf_iter: self.0.leaf_nodes() } }
/// Returns the root [`TapNodeHash`] of this tree.
pub fn root_hash(&self) -> TapNodeHash { self.0.hash }
}
impl TryFrom<TaprootBuilder> for TapTree {
@ -842,6 +845,9 @@ impl NodeInfo {
/// Creates an iterator over all leaves (including hidden leaves) in the tree.
pub fn leaf_nodes(&self) -> LeafNodes { LeafNodes { leaf_iter: self.leaves.iter() } }
/// Returns the root [`TapNodeHash`] of this node info.
pub fn node_hash(&self) -> TapNodeHash { self.hash }
}
impl TryFrom<TaprootBuilder> for NodeInfo {