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

Creates a new instance of TaprootBuilder.

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.

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.

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.

Checks if the builder has finalized building a tree.

Checks if the builder has hidden nodes.

Creates a TaprootSpendInfo with the given internal key.

Returns the unmodified builder as Err if the builder is not finalizable. See also TaprootBuilder::is_finalizable

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Serialize this value into the given Serde serializer. Read more

Constructs TapTree from a TaprootBuilder if it is complete binary tree.

Returns

A TapTree iff the builder is complete, otherwise return IncompleteTapTree error with the content of incomplete builder instance.

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.