Rename LeafInfo into ScriptLeaf

This commit is contained in:
Dr Maxim Orlovsky 2022-04-04 17:59:31 +02:00
parent 2b8d96581a
commit 7a5482d23a
No known key found for this signature in database
GPG Key ID: FFC0250947E5C6F7
2 changed files with 11 additions and 11 deletions

View File

@ -26,7 +26,7 @@ use util::psbt::map::Map;
use util::psbt::raw; use util::psbt::raw;
use util::psbt::Error; use util::psbt::Error;
use util::taproot::{LeafInfo, TapLeafHash}; use util::taproot::{ScriptLeaf, TapLeafHash};
use util::taproot::{NodeInfo, TaprootBuilder}; use util::taproot::{NodeInfo, TaprootBuilder};
@ -156,7 +156,7 @@ 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
/// leaf depth and leaf script pairs. /// tree [`ScriptLeaf`]s.
pub fn script_leaves(&self) -> TapTreeIter { pub fn script_leaves(&self) -> TapTreeIter {
self.into_iter() self.into_iter()
} }
@ -165,11 +165,11 @@ impl TapTree {
/// Iterator for a taproot script tree, operating in DFS order over leaf depth and /// Iterator for a taproot script tree, operating in DFS order over leaf depth and
/// leaf script pairs. /// leaf script pairs.
pub struct TapTreeIter<'tree> { pub struct TapTreeIter<'tree> {
leaf_iter: core::slice::Iter<'tree, LeafInfo>, leaf_iter: core::slice::Iter<'tree, ScriptLeaf>,
} }
impl<'tree> Iterator for TapTreeIter<'tree> { impl<'tree> Iterator for TapTreeIter<'tree> {
type Item = &'tree LeafInfo; type Item = &'tree ScriptLeaf;
#[inline] #[inline]
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -178,7 +178,7 @@ impl<'tree> Iterator for TapTreeIter<'tree> {
} }
impl<'tree> IntoIterator for &'tree TapTree { impl<'tree> IntoIterator for &'tree TapTree {
type Item = &'tree LeafInfo; type Item = &'tree ScriptLeaf;
type IntoIter = TapTreeIter<'tree>; type IntoIter = TapTreeIter<'tree>;
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter {

View File

@ -560,7 +560,7 @@ pub struct NodeInfo {
/// Merkle hash for this node. /// Merkle hash for this node.
pub(crate) hash: sha256::Hash, pub(crate) hash: sha256::Hash,
/// Information about leaves inside this node. /// Information about leaves inside this node.
pub(crate) leaves: Vec<LeafInfo>, pub(crate) leaves: Vec<ScriptLeaf>,
/// Tracks information on hidden nodes below this node. /// Tracks information on hidden nodes below this node.
pub(crate) has_hidden_nodes: bool, pub(crate) has_hidden_nodes: bool,
} }
@ -577,7 +577,7 @@ impl NodeInfo {
/// Creates a new leaf [`NodeInfo`] with given [`Script`] and [`LeafVersion`]. /// Creates a new leaf [`NodeInfo`] with given [`Script`] and [`LeafVersion`].
pub fn new_leaf_with_ver(script: Script, ver: LeafVersion) -> Self { pub fn new_leaf_with_ver(script: Script, ver: LeafVersion) -> Self {
let leaf = LeafInfo::new(script, ver); let leaf = ScriptLeaf::new(script, ver);
Self { Self {
hash: sha256::Hash::from_inner(leaf.leaf_hash().into_inner()), hash: sha256::Hash::from_inner(leaf.leaf_hash().into_inner()),
leaves: vec![leaf], leaves: vec![leaf],
@ -608,7 +608,7 @@ impl NodeInfo {
/// Store information about taproot leaf node. /// Store information about taproot leaf node.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct LeafInfo { pub struct ScriptLeaf {
/// The underlying script. /// The underlying script.
script: Script, script: Script,
/// The leaf version. /// The leaf version.
@ -617,8 +617,8 @@ pub struct LeafInfo {
merkle_branch: TaprootMerkleBranch, merkle_branch: TaprootMerkleBranch,
} }
impl LeafInfo { impl ScriptLeaf {
/// Creates an new [`LeafInfo`] from `script` and `ver` and no merkle branch. /// Creates an new [`ScriptLeaf`] from `script` and `ver` and no merkle branch.
fn new(script: Script, ver: LeafVersion) -> Self { fn new(script: Script, ver: LeafVersion) -> Self {
Self { Self {
script: script, script: script,
@ -635,7 +635,7 @@ impl LeafInfo {
self.merkle_branch.0.len() as u8 self.merkle_branch.0.len() as u8
} }
/// Computes a leaf hash for this [`LeafInfo`]. /// Computes a leaf hash for this [`ScriptLeaf`].
#[inline] #[inline]
pub fn leaf_hash(&self) -> TapLeafHash { pub fn leaf_hash(&self) -> TapLeafHash {
TapLeafHash::from_script(&self.script, self.ver) TapLeafHash::from_script(&self.script, self.ver)