Struct sapio_bitcoin::util::taproot::TaprootBuilder
source · [−]pub struct TaprootBuilder { /* private fields */ }Expand description
Builder for building taproot iteratively. Users can specify tap leaf or omitted/hidden branches in a depth-first search (DFS) walk order to construct this tree.
See Wikipedia for more details on DFS.
Implementations
sourceimpl TaprootBuilder
impl TaprootBuilder
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of TaprootBuilder.
sourcepub fn with_huffman_tree<I>(
script_weights: I
) -> Result<Self, TaprootBuilderError> where
I: IntoIterator<Item = (u32, Script)>,
pub fn with_huffman_tree<I>(
script_weights: I
) -> Result<Self, TaprootBuilderError> where
I: IntoIterator<Item = (u32, Script)>,
Creates a new TaprootSpendInfo from a list of scripts (with default script version) and
weights of satisfaction for that script.
The weights represent the probability of each branch being taken. If probabilities/weights
for each condition are known, constructing the tree as a Huffman Tree is the optimal way to
minimize average case satisfaction cost. This function takes as input an iterator of
tuple(u32, &Script) where u32 represents the satisfaction weights of the branch. For
example, [(3, S1), (2, S2), (5, S3)] would construct a TapTree that has optimal
satisfaction weight when probability for S1 is 30%, S2 is 20% and S3 is 50%.
Errors:
- When the optimal Huffman Tree has a depth more than 128.
- If the provided list of script weights is empty.
Edge Cases:
If the script weight calculations overflow, a sub-optimal tree may be generated. This should not happen unless you are dealing with billions of branches with weights close to 2^32.
sourcepub fn add_leaf_with_ver(
self,
depth: u8,
script: Script,
ver: LeafVersion
) -> Result<Self, TaprootBuilderError>
pub fn add_leaf_with_ver(
self,
depth: u8,
script: Script,
ver: LeafVersion
) -> Result<Self, TaprootBuilderError>
Adds a leaf script at depth to the builder with script version ver. Errors if the leaves
are not provided in DFS walk order. The depth of the root node is 0.
sourcepub fn add_leaf(
self,
depth: u8,
script: Script
) -> Result<Self, TaprootBuilderError>
pub fn add_leaf(
self,
depth: u8,
script: Script
) -> Result<Self, TaprootBuilderError>
Adds a leaf script at depth to the builder with default script version. Errors if the
leaves are not provided in DFS walk order. The depth of the root node is 0.
See TaprootBuilder::add_leaf_with_ver for adding a leaf with specific version.
Adds a hidden/omitted node at depth to the builder. Errors if the leaves are not provided
in DFS walk order. The depth of the root node is 0.
sourcepub fn is_finalized(&self) -> bool
pub fn is_finalized(&self) -> bool
Checks if the builder has finalized building a tree.
Checks if the builder has hidden nodes.
sourcepub fn finalize<C: Verification>(
self,
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey
) -> Result<TaprootSpendInfo, TaprootBuilderError>
pub fn finalize<C: Verification>(
self,
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey
) -> Result<TaprootSpendInfo, TaprootBuilderError>
Creates a TaprootSpendInfo with the given internal key.
Trait Implementations
sourceimpl Clone for TaprootBuilder
impl Clone for TaprootBuilder
sourcefn clone(&self) -> TaprootBuilder
fn clone(&self) -> TaprootBuilder
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 TaprootBuilder
impl Debug for TaprootBuilder
sourceimpl<'de> Deserialize<'de> for TaprootBuilder
impl<'de> Deserialize<'de> for TaprootBuilder
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl From<TapTree> for TaprootBuilder
impl From<TapTree> for TaprootBuilder
sourceimpl Hash for TaprootBuilder
impl Hash for TaprootBuilder
sourceimpl Ord for TaprootBuilder
impl Ord for TaprootBuilder
sourceimpl PartialEq<TaprootBuilder> for TaprootBuilder
impl PartialEq<TaprootBuilder> for TaprootBuilder
sourcefn eq(&self, other: &TaprootBuilder) -> bool
fn eq(&self, other: &TaprootBuilder) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &TaprootBuilder) -> bool
fn ne(&self, other: &TaprootBuilder) -> bool
This method tests for !=.
sourceimpl PartialOrd<TaprootBuilder> for TaprootBuilder
impl PartialOrd<TaprootBuilder> for TaprootBuilder
sourcefn partial_cmp(&self, other: &TaprootBuilder) -> Option<Ordering>
fn partial_cmp(&self, other: &TaprootBuilder) -> 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 Serialize for TaprootBuilder
impl Serialize for TaprootBuilder
impl Eq for TaprootBuilder
impl StructuralEq for TaprootBuilder
impl StructuralPartialEq for TaprootBuilder
Auto Trait Implementations
impl RefUnwindSafe for TaprootBuilder
impl Send for TaprootBuilder
impl Sync for TaprootBuilder
impl Unpin for TaprootBuilder
impl UnwindSafe for TaprootBuilder
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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more