Struct 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
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl 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>,
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
sourcefn cmp(&self, other: &TaprootBuilder) -> Ordering
fn cmp(&self, other: &TaprootBuilder) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl PartialEq<TaprootBuilder> for TaprootBuilder
impl PartialEq<TaprootBuilder> for TaprootBuilder
sourcefn eq(&self, other: &TaprootBuilder) -> bool
fn eq(&self, other: &TaprootBuilder) -> bool
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>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more