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:
parent
8f7cc4d6b3
commit
1384330029
|
@ -693,6 +693,9 @@ impl TapTree {
|
||||||
/// Returns [`TapTreeIter<'_>`] iterator for a taproot script tree, operating in DFS order over
|
/// Returns [`TapTreeIter<'_>`] iterator for a taproot script tree, operating in DFS order over
|
||||||
/// tree [`ScriptLeaf`]s.
|
/// tree [`ScriptLeaf`]s.
|
||||||
pub fn script_leaves(&self) -> ScriptLeaves { ScriptLeaves { leaf_iter: self.0.leaf_nodes() } }
|
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 {
|
impl TryFrom<TaprootBuilder> for TapTree {
|
||||||
|
@ -842,6 +845,9 @@ impl NodeInfo {
|
||||||
|
|
||||||
/// Creates an iterator over all leaves (including hidden leaves) in the tree.
|
/// Creates an iterator over all leaves (including hidden leaves) in the tree.
|
||||||
pub fn leaf_nodes(&self) -> LeafNodes { LeafNodes { leaf_iter: self.leaves.iter() } }
|
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 {
|
impl TryFrom<TaprootBuilder> for NodeInfo {
|
||||||
|
|
Loading…
Reference in New Issue