Struct esplora_client::api::Witness
source · pub struct Witness { /* private fields */ }
Expand description
The Witness is the data used to unlock bitcoin since the segwit upgrade.
Can be logically seen as an array of bytestrings, i.e. Vec<Vec<u8>>
, and it is serialized on the wire
in that format. You can convert between this type and Vec<Vec<u8>>
by using Witness::from_slice
and Witness::to_vec
.
For serialization and deserialization performance it is stored internally as a single Vec
,
saving some allocations.
Implementations§
source§impl Witness
impl Witness
sourcepub fn from_vec(vec: Vec<Vec<u8, Global>, Global>) -> Witness
👎Deprecated since 0.30.0: use Witness::from_slice()
instead
pub fn from_vec(vec: Vec<Vec<u8, Global>, Global>) -> Witness
Witness::from_slice()
insteadCreates Witness
object from an array of byte-arrays
sourcepub fn from_slice<T>(slice: &[T]) -> Witnesswhere
T: AsRef<[u8]>,
pub fn from_slice<T>(slice: &[T]) -> Witnesswhere T: AsRef<[u8]>,
Creates a Witness
object from a slice of bytes slices where each slice is a witness item.
sourcepub fn to_vec(&self) -> Vec<Vec<u8, Global>, Global>
pub fn to_vec(&self) -> Vec<Vec<u8, Global>, Global>
Convenience method to create an array of byte-arrays from this witness.
sourcepub fn serialized_len(&self) -> usize
pub fn serialized_len(&self) -> usize
Returns the bytes required when this Witness is consensus encoded.
sourcepub fn push<T>(&mut self, new_element: T)where
T: AsRef<[u8]>,
pub fn push<T>(&mut self, new_element: T)where T: AsRef<[u8]>,
Push a new element on the witness, requires an allocation.
sourcepub fn push_bitcoin_signature(
&mut self,
signature: &SerializedSignature,
hash_type: EcdsaSighashType
)
pub fn push_bitcoin_signature( &mut self, signature: &SerializedSignature, hash_type: EcdsaSighashType )
Pushes a DER-encoded ECDSA signature with a signature hash type as a new element on the witness, requires an allocation.
sourcepub fn second_to_last(&self) -> Option<&[u8]>
pub fn second_to_last(&self) -> Option<&[u8]>
Returns the second-to-last element in the witness, if any.
sourcepub fn tapscript(&self) -> Option<&Script>
pub fn tapscript(&self) -> Option<&Script>
Get Tapscript following BIP341 rules regarding accounting for an annex.
This does not guarantee that this represents a P2TR Witness
. It
merely gets the second to last or third to last element depending on
the first byte of the last element being equal to 0x50. See
Script::is_v1_p2tr to
check whether this is actually a Taproot witness.
Trait Implementations§
source§impl Decodable for Witness
impl Decodable for Witness
source§impl<'de> Deserialize<'de> for Witness
impl<'de> Deserialize<'de> for Witness
source§fn deserialize<D>(
deserializer: D
) -> Result<Witness, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<Witness, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
source§impl<'a> IntoIterator for &'a Witness
impl<'a> IntoIterator for &'a Witness
source§impl Ord for Witness
impl Ord for Witness
source§impl PartialEq<Witness> for Witness
impl PartialEq<Witness> for Witness
source§impl PartialOrd<Witness> for Witness
impl PartialOrd<Witness> for Witness
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 moresource§impl Serialize for Witness
impl Serialize for Witness
source§fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,
impl Eq for Witness
impl StructuralEq for Witness
impl StructuralPartialEq for Witness
Auto Trait Implementations§
impl RefUnwindSafe for Witness
impl Send for Witness
impl Sync for Witness
impl Unpin for Witness
impl UnwindSafe for Witness
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<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.