Struct sapio_bitcoin::util::taproot::TaprootSpendInfo
source · [−]pub struct TaprootSpendInfo { /* private fields */ }Expand description
Represents taproot spending information.
Taproot output corresponds to a combination of a single public key condition (known as the internal key), and zero or more general conditions encoded in scripts organized in the form of a binary tree.
Taproot can be spent by either:
- Spending using the key path i.e., with secret key corresponding to the tweaked
output_key. - By satisfying any of the scripts in the script spend path. Each script can be satisfied by providing a witness stack consisting of the script’s inputs, plus the script itself and the control block.
If one or more of the spending conditions consist of just a single key (after aggregation), the most likely key should be made the internal key. See BIP341 for more details on choosing internal keys for a taproot application.
Note: This library currently does not support annex.
Implementations
sourceimpl TaprootSpendInfo
impl TaprootSpendInfo
sourcepub fn with_huffman_tree<C, I>(
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey,
script_weights: I
) -> Result<Self, TaprootBuilderError> where
I: IntoIterator<Item = (u32, Script)>,
C: Verification,
pub fn with_huffman_tree<C, I>(
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey,
script_weights: I
) -> Result<Self, TaprootBuilderError> where
I: IntoIterator<Item = (u32, Script)>,
C: Verification,
Creates a new TaprootSpendInfo from a list of scripts (with default script version) and
weights of satisfaction for that script.
See TaprootBuilder::with_huffman_tree for more detailed documentation.
sourcepub fn new_key_spend<C: Verification>(
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey,
merkle_root: Option<TapBranchHash>
) -> Self
pub fn new_key_spend<C: Verification>(
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey,
merkle_root: Option<TapBranchHash>
) -> Self
Creates a new key spend with internal_key and merkle_root. Provide None for
the merkle_root if there is no script path.
Note: As per BIP341
When the merkle root is None, the output key commits to an unspendable script path
instead of having no script path. This is achieved by computing the output key point as
Q = P + int(hashTapTweak(bytes(P)))G. See also TaprootSpendInfo::tap_tweak.
Refer to BIP 341 footnote (‘Why should the output key always have a taproot commitment, even if there is no script path?’) for more details.
sourcepub fn tap_tweak(&self) -> TapTweakHash
pub fn tap_tweak(&self) -> TapTweakHash
Returns the TapTweakHash for this TaprootSpendInfo i.e., the tweak using internal_key
and merkle_root.
sourcepub fn internal_key(&self) -> UntweakedPublicKey
pub fn internal_key(&self) -> UntweakedPublicKey
Returns the internal key for this TaprootSpendInfo.
sourcepub fn merkle_root(&self) -> Option<TapBranchHash>
pub fn merkle_root(&self) -> Option<TapBranchHash>
Returns the merkle root for this TaprootSpendInfo.
sourcepub fn output_key(&self) -> TweakedPublicKey
pub fn output_key(&self) -> TweakedPublicKey
Returns the output key (the key used in script pubkey) for this TaprootSpendInfo.
sourcepub fn output_key_parity(&self) -> Parity
pub fn output_key_parity(&self) -> Parity
Returns the parity of the output key. See also TaprootSpendInfo::output_key.
sourcepub fn from_node_info<C: Verification>(
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey,
node: NodeInfo
) -> TaprootSpendInfo
pub fn from_node_info<C: Verification>(
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey,
node: NodeInfo
) -> TaprootSpendInfo
Computes the TaprootSpendInfo from internal_key and node.
This is useful when you want to manually build a taproot tree without using
TaprootBuilder.
sourcepub fn as_script_map(
&self
) -> &BTreeMap<(Script, LeafVersion), BTreeSet<TaprootMerkleBranch>>
pub fn as_script_map(
&self
) -> &BTreeMap<(Script, LeafVersion), BTreeSet<TaprootMerkleBranch>>
Returns the internal script map.
sourcepub fn control_block(
&self,
script_ver: &(Script, LeafVersion)
) -> Option<ControlBlock>
pub fn control_block(
&self,
script_ver: &(Script, LeafVersion)
) -> Option<ControlBlock>
Constructs a ControlBlock for particular script with the given version.
Returns
- If there are multiple control blocks possible, returns the shortest one.
- If the script is not contained in the
TaprootSpendInfo, returnsNone.
Trait Implementations
sourceimpl Clone for TaprootSpendInfo
impl Clone for TaprootSpendInfo
sourcefn clone(&self) -> TaprootSpendInfo
fn clone(&self) -> TaprootSpendInfo
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 TaprootSpendInfo
impl Debug for TaprootSpendInfo
sourceimpl<'de> Deserialize<'de> for TaprootSpendInfo
impl<'de> Deserialize<'de> for TaprootSpendInfo
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 Hash for TaprootSpendInfo
impl Hash for TaprootSpendInfo
sourceimpl Ord for TaprootSpendInfo
impl Ord for TaprootSpendInfo
sourceimpl PartialEq<TaprootSpendInfo> for TaprootSpendInfo
impl PartialEq<TaprootSpendInfo> for TaprootSpendInfo
sourcefn eq(&self, other: &TaprootSpendInfo) -> bool
fn eq(&self, other: &TaprootSpendInfo) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &TaprootSpendInfo) -> bool
fn ne(&self, other: &TaprootSpendInfo) -> bool
This method tests for !=.
sourceimpl PartialOrd<TaprootSpendInfo> for TaprootSpendInfo
impl PartialOrd<TaprootSpendInfo> for TaprootSpendInfo
sourcefn partial_cmp(&self, other: &TaprootSpendInfo) -> Option<Ordering>
fn partial_cmp(&self, other: &TaprootSpendInfo) -> 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 TaprootSpendInfo
impl Serialize for TaprootSpendInfo
impl Eq for TaprootSpendInfo
impl StructuralEq for TaprootSpendInfo
impl StructuralPartialEq for TaprootSpendInfo
Auto Trait Implementations
impl RefUnwindSafe for TaprootSpendInfo
impl Send for TaprootSpendInfo
impl Sync for TaprootSpendInfo
impl Unpin for TaprootSpendInfo
impl UnwindSafe for TaprootSpendInfo
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