Struct bitcoin::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>
pub fn with_huffman_tree<C, I>( secp: &Secp256k1<C>, internal_key: UntweakedPublicKey, script_weights: I, ) -> Result<Self, TaprootBuilderError>
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<TapNodeHash>,
) -> Self
pub fn new_key_spend<C: Verification>( secp: &Secp256k1<C>, internal_key: UntweakedPublicKey, merkle_root: Option<TapNodeHash>, ) -> 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<TapNodeHash>
pub fn merkle_root(&self) -> Option<TapNodeHash>
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 script_map(
&self,
) -> &BTreeMap<(ScriptBuf, LeafVersion), BTreeSet<TaprootMerkleBranch>>
pub fn script_map( &self, ) -> &BTreeMap<(ScriptBuf, LeafVersion), BTreeSet<TaprootMerkleBranch>>
Returns a reference to the internal script map.
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 control_block(
&self,
script_ver: &(ScriptBuf, LeafVersion),
) -> Option<ControlBlock>
pub fn control_block( &self, script_ver: &(ScriptBuf, 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 From<&TaprootSpendInfo> for TapTweakHash
impl From<&TaprootSpendInfo> for TapTweakHash
source§fn from(spend_info: &TaprootSpendInfo) -> TapTweakHash
fn from(spend_info: &TaprootSpendInfo) -> TapTweakHash
source§impl From<TaprootSpendInfo> for TapTweakHash
impl From<TaprootSpendInfo> for TapTweakHash
source§fn from(spend_info: TaprootSpendInfo) -> TapTweakHash
fn from(spend_info: TaprootSpendInfo) -> TapTweakHash
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 for TaprootSpendInfo
impl PartialEq 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 for TaprootSpendInfo
impl PartialOrd 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 moreimpl Eq for TaprootSpendInfo
impl StructuralPartialEq for TaprootSpendInfo
Auto Trait Implementations§
impl Freeze for TaprootSpendInfo
impl RefUnwindSafe for TaprootSpendInfo
impl Send for TaprootSpendInfo
impl Sync for TaprootSpendInfo
impl Unpin for TaprootSpendInfo
impl UnwindSafe for TaprootSpendInfo
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)