pub struct ControlBlock {
pub leaf_version: LeafVersion,
pub output_key_parity: Parity,
pub internal_key: UntweakedPublicKey,
pub merkle_branch: TaprootMerkleBranch,
}
Expand description
Control block data structure used in Tapscript satisfaction.
Fields
leaf_version: LeafVersion
The tapleaf version.
output_key_parity: Parity
The parity of the output key (NOT THE INTERNAL KEY WHICH IS ALWAYS XONLY).
internal_key: UntweakedPublicKey
The internal key.
merkle_branch: TaprootMerkleBranch
The merkle proof of a script associated with this leaf.
Implementations
sourceimpl ControlBlock
impl ControlBlock
sourcepub fn from_slice(sl: &[u8]) -> Result<ControlBlock, TaprootError>
pub fn from_slice(sl: &[u8]) -> Result<ControlBlock, TaprootError>
Constructs a ControlBlock
from slice. This is an extra witness element that provides the
proof that taproot script pubkey is correctly computed with some specified leaf hash. This
is the last element in taproot witness when spending a output via script path.
Errors
TaprootError::InvalidControlBlockSize
ifsl
is not of size 1 + 32 + 32N for any N >= 0.TaprootError::InvalidParity
if first byte ofsl
is not a valid output key parity.TaprootError::InvalidTaprootLeafVersion
if first byte ofsl
is not a valid leaf version.TaprootError::InvalidInternalKey
if internal key is invalid (first 32 bytes after the parity byte).TaprootError::InvalidMerkleTreeDepth
if merkle tree is too deep (more than 128 levels).
sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Returns the size of control block. Faster and more efficient than calling
Self::serialize().len()
. Can be handy for fee estimation.
sourcepub fn serialize(&self) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn serialize(&self) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
Serializes the control block.
This would be required when using ControlBlock
as a witness element while spending an
output via script path. This serialization does not include the crate::VarInt
prefix that would
be applied when encoding this element as a witness.
sourcepub fn verify_taproot_commitment<C: Verification>(
&self,
secp: &Secp256k1<C>,
output_key: XOnlyPublicKey,
script: &Script
) -> bool
pub fn verify_taproot_commitment<C: Verification>(
&self,
secp: &Secp256k1<C>,
output_key: XOnlyPublicKey,
script: &Script
) -> bool
Verifies that a control block is correct proof for a given output key and script.
Only checks that script is contained inside the taptree described by output key. Full verification must also execute the script with witness data.
Trait Implementations
sourceimpl Clone for ControlBlock
impl Clone for ControlBlock
sourcefn clone(&self) -> ControlBlock
fn clone(&self) -> ControlBlock
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl Debug for ControlBlock
impl Debug for ControlBlock
sourceimpl<'de> Deserialize<'de> for ControlBlock
impl<'de> Deserialize<'de> for ControlBlock
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 Deserialize for ControlBlock
impl Deserialize for ControlBlock
sourcefn deserialize(bytes: &[u8]) -> Result<Self, Error>
fn deserialize(bytes: &[u8]) -> Result<Self, Error>
sourceimpl Hash for ControlBlock
impl Hash for ControlBlock
sourceimpl Ord for ControlBlock
impl Ord for ControlBlock
sourcefn cmp(&self, other: &ControlBlock) -> Ordering
fn cmp(&self, other: &ControlBlock) -> Ordering
1.21.0 · sourceconst fn max(self, other: Self) -> Selfwhere
Self: Sized,
const fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourceconst fn min(self, other: Self) -> Selfwhere
Self: Sized,
const fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourceconst fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
const fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl PartialEq<ControlBlock> for ControlBlock
impl PartialEq<ControlBlock> for ControlBlock
sourcefn eq(&self, other: &ControlBlock) -> bool
fn eq(&self, other: &ControlBlock) -> bool
sourceimpl PartialOrd<ControlBlock> for ControlBlock
impl PartialOrd<ControlBlock> for ControlBlock
sourcefn partial_cmp(&self, other: &ControlBlock) -> Option<Ordering>
fn partial_cmp(&self, other: &ControlBlock) -> Option<Ordering>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more