Struct 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§
source§impl 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§
source§impl Clone for TaprootSpendInfo
impl Clone for TaprootSpendInfo
source§fn clone(&self) -> TaprootSpendInfo
fn clone(&self) -> TaprootSpendInfo
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for TaprootSpendInfo
impl Debug for TaprootSpendInfo
source§impl<'de> Deserialize<'de> for TaprootSpendInfo
impl<'de> Deserialize<'de> for TaprootSpendInfo
source§fn 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>,
source§impl Hash for TaprootSpendInfo
impl Hash for TaprootSpendInfo
source§impl Ord for TaprootSpendInfo
impl Ord for TaprootSpendInfo
source§fn cmp(&self, other: &TaprootSpendInfo) -> Ordering
fn cmp(&self, other: &TaprootSpendInfo) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<TaprootSpendInfo> for TaprootSpendInfo
impl PartialEq<TaprootSpendInfo> for TaprootSpendInfo
source§fn eq(&self, other: &TaprootSpendInfo) -> bool
fn eq(&self, other: &TaprootSpendInfo) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<TaprootSpendInfo> for TaprootSpendInfo
impl PartialOrd<TaprootSpendInfo> for TaprootSpendInfo
source§fn partial_cmp(&self, other: &TaprootSpendInfo) -> Option<Ordering>
fn partial_cmp(&self, other: &TaprootSpendInfo) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more