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§
Source§impl 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<'_> ⓘ
pub fn scripts(&self) -> TreeScriptIter<'_> ⓘ
Returns iterator over known bitcoin_scripts stored in the tree.
NB: the iterator ignores bitcoin_scripts behind hidden nodes. It iterates the bitcoin_scripts in DFS (and not consensus) order.
Sourcepub fn nodes(&self) -> TreeNodeIter<'_> ⓘ
pub fn nodes(&self) -> TreeNodeIter<'_> ⓘ
Returns iterator over all known nodes of the tree in DFS order.
Sourcepub fn nodes_on_path<'node, 'path>(
&'node self,
path: &'path [DfsOrder],
) -> TreePathIter<'node, 'path> ⓘ
pub fn nodes_on_path<'node, 'path>( &'node self, path: &'path [DfsOrder], ) -> TreePathIter<'node, 'path> ⓘ
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§
Source§impl AsRef<TreeNode> for TaprootScriptTree
impl AsRef<TreeNode> for TaprootScriptTree
Source§impl Borrow<TreeNode> for TaprootScriptTree
impl Borrow<TreeNode> for TaprootScriptTree
Source§impl BorrowMut<TreeNode> for TaprootScriptTree
impl BorrowMut<TreeNode> for TaprootScriptTree
Source§fn borrow_mut(&mut self) -> &mut TreeNode
fn borrow_mut(&mut self) -> &mut TreeNode
Source§impl Clone for TaprootScriptTree
impl Clone for TaprootScriptTree
Source§fn clone(&self) -> TaprootScriptTree
fn clone(&self) -> TaprootScriptTree
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TaprootScriptTree
impl Debug for TaprootScriptTree
Source§impl Display for TaprootScriptTree
impl Display for TaprootScriptTree
Source§impl From<&TaprootScriptTree> for TapTree
impl From<&TaprootScriptTree> for TapTree
Source§fn from(tree: &TaprootScriptTree) -> Self
fn from(tree: &TaprootScriptTree) -> Self
Source§impl From<TapTree> for TaprootScriptTree
impl From<TapTree> for TaprootScriptTree
Source§impl From<TaprootScriptTree> for TapTree
impl From<TaprootScriptTree> for TapTree
Source§fn from(tree: TaprootScriptTree) -> Self
fn from(tree: TaprootScriptTree) -> Self
Source§impl Hash for TaprootScriptTree
impl Hash for TaprootScriptTree
Source§impl<'tree> IntoIterator for &'tree TaprootScriptTree
impl<'tree> IntoIterator for &'tree TaprootScriptTree
Source§impl Ord for TaprootScriptTree
impl Ord for TaprootScriptTree
Source§fn cmp(&self, other: &TaprootScriptTree) -> Ordering
fn cmp(&self, other: &TaprootScriptTree) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for TaprootScriptTree
impl PartialEq for TaprootScriptTree
Source§impl PartialOrd for TaprootScriptTree
impl PartialOrd for TaprootScriptTree
Source§impl StrictDecode for TaprootScriptTree
impl StrictDecode for TaprootScriptTree
Source§fn strict_decode<D: Read>(d: D) -> Result<Self, Error>
fn strict_decode<D: Read>(d: D) -> Result<Self, Error>
std::io::Read instance; must either
construct an instance or return implementation-specific error type.Source§fn strict_deserialize(data: impl AsRef<[u8]>) -> Result<Self, Error>
fn strict_deserialize(data: impl AsRef<[u8]>) -> Result<Self, Error>
StrictDecode::strict_decode. If there are some data remains in the
buffer once deserialization is completed, fails with
Error::DataNotEntirelyConsumed. Use io::Cursor over the buffer and
StrictDecode::strict_decode to avoid such failures.Source§fn strict_file_load(path: impl AsRef<Path>) -> Result<Self, Error>
fn strict_file_load(path: impl AsRef<Path>) -> Result<Self, Error>
path and reconstructs object from it. Fails
with Error::DataNotEntirelyConsumed if file contains remaining
data after the object reconstruction.Source§impl StrictEncode for TaprootScriptTree
impl StrictEncode for TaprootScriptTree
Source§fn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>
fn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>
std::io::Write instance; must return result
with either amount of bytes encoded – or implementation-specific
error type.Source§fn strict_serialize(&self) -> Result<Vec<u8>, Error>
fn strict_serialize(&self) -> Result<Vec<u8>, Error>
StrictEncode::strict_encode
function