Skip to content

Commit

Permalink
taproot: add TapNodeHash getter method on TapTree and NodeInfo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
conduition committed Feb 12, 2024
1 parent 8f7cc4d commit 1384330
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bitcoin/src/taproot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1384330

Please sign in to comment.