Struct bitcoin_scripts::taproot::TaprootScriptTree
source · [−]pub struct TaprootScriptTree { /* private fields */ }
Expand description
Taproot script tree which keeps internal information in a tree data
structure, which can be modified by adding or removing parts of the tree
(subtrees). See Self::join
, Self::split
, Self::instill
,
Self::cut
operations.
The structure can be build out of (or converted into) TapTree
taproot
tree representation, which doesn’t have a modifiable tree structure.
Implementations
sourceimpl TaprootScriptTree
impl TaprootScriptTree
sourcepub fn with(root: TreeNode) -> Result<TaprootScriptTree, TaprootTreeError>
pub fn with(root: TreeNode) -> Result<TaprootScriptTree, TaprootTreeError>
Constructs new script tree from the root node.
Errors.
If any of the branches under the root node has non-consensus ordering of the child nodes (i.e. by lexicographic order of the node hash values).
sourcepub fn scripts(&self) -> TreeScriptIter<'_>ⓘNotable traits for TreeScriptIter<'tree>impl<'tree> Iterator for TreeScriptIter<'tree> type Item = (u8, &'tree LeafScript);
pub fn scripts(&self) -> TreeScriptIter<'_>ⓘNotable traits for TreeScriptIter<'tree>impl<'tree> Iterator for TreeScriptIter<'tree> type Item = (u8, &'tree LeafScript);
Returns iterator over known scripts stored in the tree.
NB: the iterator ignores scripts behind hidden nodes.
sourcepub fn nodes(&self) -> TreeNodeIter<'_>ⓘNotable traits for TreeNodeIter<'tree>impl<'tree> Iterator for TreeNodeIter<'tree> type Item = (&'tree TreeNode, DfsPath);
pub fn nodes(&self) -> TreeNodeIter<'_>ⓘNotable traits for TreeNodeIter<'tree>impl<'tree> Iterator for TreeNodeIter<'tree> type Item = (&'tree TreeNode, DfsPath);
Returns iterator over all known nodes of the tree.
sourcepub fn nodes_on_path<'node, 'path>(
&'node self,
path: &'path [DfsOrder]
) -> TreePathIter<'node, 'path>ⓘNotable traits for TreePathIter<'tree, 'path>impl<'tree, 'path> Iterator for TreePathIter<'tree, 'path> type Item = Result<&'tree TreeNode, DfsTraversalError>;
pub fn nodes_on_path<'node, 'path>(
&'node self,
path: &'path [DfsOrder]
) -> TreePathIter<'node, 'path>ⓘNotable traits for TreePathIter<'tree, 'path>impl<'tree, 'path> Iterator for TreePathIter<'tree, 'path> type Item = Result<&'tree TreeNode, DfsTraversalError>;
Returns iterator over all subnodes on a given path.
sourcepub fn node_at(
&self,
path: impl AsRef<[DfsOrder]>
) -> Result<&TreeNode, DfsTraversalError>
pub fn node_at(
&self,
path: impl AsRef<[DfsOrder]>
) -> Result<&TreeNode, DfsTraversalError>
Traverses tree using the provided path in DFS order and returns the node reference at the tip of the path.
Errors
Returns DfsTraversalError
if the path can’t be traversed.
sourcepub fn join(
self,
other_tree: TaprootScriptTree,
other_dfs_order: DfsOrder
) -> Result<TaprootScriptTree, MaxDepthExceeded>
pub fn join(
self,
other_tree: TaprootScriptTree,
other_dfs_order: DfsOrder
) -> Result<TaprootScriptTree, MaxDepthExceeded>
Joins two trees together under a new root.
Creates a new tree with the root node containing self
and other_tree
as its direct children. The other_tree
is put into other_dfs_order
side.
sourcepub fn split(
self
) -> Result<(TaprootScriptTree, TaprootScriptTree), UnsplittableTree>
pub fn split(
self
) -> Result<(TaprootScriptTree, TaprootScriptTree), UnsplittableTree>
Splits the tree into two subtrees. Errors if the tree root is hidden or a script leaf.
Returns
Two child nodes under the root of the original tree as a new taproot script trees in the original DFS ordering.
sourcepub fn instill(
&mut self,
other_tree: TaprootScriptTree,
path: impl AsRef<[DfsOrder]>,
dfs_order: DfsOrder
) -> Result<DfsPath, InstillError>
pub fn instill(
&mut self,
other_tree: TaprootScriptTree,
path: impl AsRef<[DfsOrder]>,
dfs_order: DfsOrder
) -> Result<DfsPath, InstillError>
Instills other_tree
as a subtree under provided path
by creating a
new branch node at the path
and putting other_tree
on the dfs_side
of it.
Error
Returns InstillError
when the given path can’t be traversed or
the resulting tree depth exceeds taproot tree depth limit.
sourcepub fn cut(
self,
path: impl AsRef<[DfsOrder]>,
dfs_side: DfsOrder
) -> Result<(TaprootScriptTree, TaprootScriptTree), CutError>
pub fn cut(
self,
path: impl AsRef<[DfsOrder]>,
dfs_side: DfsOrder
) -> Result<(TaprootScriptTree, TaprootScriptTree), CutError>
Cuts subtree out of this tree at the path
, returning this tree without
the cut branch and the cut subtree as a new tree.
Returns
Modified original tree without the cut node and a new tree constructed out of the cut node.
Error
Returns DfsTraversalError
when the given path can’t be traversed or
points at an unsplittable node (leaf node or a hidden node).
sourcepub fn as_root_node(&self) -> &TreeNode
pub fn as_root_node(&self) -> &TreeNode
Returns reference to the root node of the tree.
sourcepub fn into_root_node(self) -> TreeNode
pub fn into_root_node(self) -> TreeNode
Consumes the tree and returns instance of the root node of the tree.
sourcepub fn to_root_node(&self) -> TreeNode
pub fn to_root_node(&self) -> TreeNode
Returns a cloned root node.
Trait Implementations
sourceimpl AsRef<TreeNode> for TaprootScriptTree
impl AsRef<TreeNode> for TaprootScriptTree
sourceimpl Borrow<TreeNode> for TaprootScriptTree
impl Borrow<TreeNode> for TaprootScriptTree
sourceimpl BorrowMut<TreeNode> for TaprootScriptTree
impl BorrowMut<TreeNode> for TaprootScriptTree
sourcefn borrow_mut(&mut self) -> &mut TreeNode
fn borrow_mut(&mut self) -> &mut TreeNode
Mutably borrows from an owned value. Read more
sourceimpl Clone for TaprootScriptTree
impl Clone for TaprootScriptTree
sourcefn clone(&self) -> TaprootScriptTree
fn clone(&self) -> TaprootScriptTree
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for TaprootScriptTree
impl Debug for TaprootScriptTree
sourceimpl Display for TaprootScriptTree
impl Display for TaprootScriptTree
sourceimpl From<&TaprootScriptTree> for TapTree
impl From<&TaprootScriptTree> for TapTree
sourcefn from(tree: &TaprootScriptTree) -> Self
fn from(tree: &TaprootScriptTree) -> Self
Converts to this type from the input type.
sourceimpl From<TapTree> for TaprootScriptTree
impl From<TapTree> for TaprootScriptTree
sourceimpl From<TaprootScriptTree> for TapTree
impl From<TaprootScriptTree> for TapTree
sourcefn from(tree: TaprootScriptTree) -> Self
fn from(tree: TaprootScriptTree) -> Self
Converts to this type from the input type.
sourceimpl Hash for TaprootScriptTree
impl Hash for TaprootScriptTree
sourceimpl<'tree> IntoIterator for &'tree TaprootScriptTree
impl<'tree> IntoIterator for &'tree TaprootScriptTree
type Item = (u8, &'tree LeafScript)
type Item = (u8, &'tree LeafScript)
The type of the elements being iterated over.
type IntoIter = TreeScriptIter<'tree>
type IntoIter = TreeScriptIter<'tree>
Which kind of iterator are we turning this into?
sourceimpl Ord for TaprootScriptTree
impl Ord for TaprootScriptTree
sourceimpl PartialEq<TaprootScriptTree> for TaprootScriptTree
impl PartialEq<TaprootScriptTree> for TaprootScriptTree
sourcefn eq(&self, other: &TaprootScriptTree) -> bool
fn eq(&self, other: &TaprootScriptTree) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &TaprootScriptTree) -> bool
fn ne(&self, other: &TaprootScriptTree) -> bool
This method tests for !=
.
sourceimpl PartialOrd<TaprootScriptTree> for TaprootScriptTree
impl PartialOrd<TaprootScriptTree> for TaprootScriptTree
sourcefn partial_cmp(&self, other: &TaprootScriptTree) -> Option<Ordering>
fn partial_cmp(&self, other: &TaprootScriptTree) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl StrictDecode for TaprootScriptTree
impl StrictDecode for TaprootScriptTree
sourcefn strict_decode<D: Read>(d: D) -> Result<Self, Error>
fn strict_decode<D: Read>(d: D) -> Result<Self, Error>
Decode with the given std::io::Read
instance; must either
construct an instance or return implementation-specific error type. Read more
sourcefn strict_deserialize(data: impl AsRef<[u8]>) -> Result<Self, Error>
fn strict_deserialize(data: impl AsRef<[u8]>) -> Result<Self, Error>
Tries to deserialize byte array into the current type using
StrictDecode::strict_decode
Read more
sourcefn strict_file_load(path: impl AsRef<Path>) -> Result<Self, Error>
fn strict_file_load(path: impl AsRef<Path>) -> Result<Self, Error>
Reads data from file at path
and reconstructs object from it. Fails
with Error::DataNotEntirelyConsumed
if file contains remaining
data after the object reconstruction. Read more
sourceimpl StrictEncode for TaprootScriptTree
impl StrictEncode for TaprootScriptTree
sourcefn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>
fn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>
Encode with the given std::io::Write
instance; must return result
with either amount of bytes encoded – or implementation-specific
error type. Read more
sourcefn strict_serialize(&self) -> Result<Vec<u8, Global>, Error>
fn strict_serialize(&self) -> Result<Vec<u8, Global>, Error>
Serializes data as a byte array using StrictEncode::strict_encode
function Read more
impl Eq for TaprootScriptTree
impl StructuralEq for TaprootScriptTree
impl StructuralPartialEq for TaprootScriptTree
Auto Trait Implementations
impl RefUnwindSafe for TaprootScriptTree
impl Send for TaprootScriptTree
impl Sync for TaprootScriptTree
impl Unpin for TaprootScriptTree
impl UnwindSafe for TaprootScriptTree
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more