pub struct Witness { /* private fields */ }
alloc
only.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_slice<T: AsRef<[u8]>>(slice: &[T]) -> Self
pub fn from_slice<T: AsRef<[u8]>>(slice: &[T]) -> Self
Constructs a new Witness
object from a slice of bytes slices where each slice is a witness item.
Sourcepub fn to_vec(&self) -> Vec<Vec<u8>>
pub fn to_vec(&self) -> Vec<Vec<u8>>
Convenience method to create an array of byte-arrays from this witness.
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Returns the number of bytes this witness contributes to a transactions total size.
Sourcepub fn push<T: AsRef<[u8]>>(&mut self, new_element: T)
pub fn push<T: AsRef<[u8]>>(&mut self, new_element: T)
Push 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 third_to_last(&self) -> Option<&[u8]>
pub fn third_to_last(&self) -> Option<&[u8]>
Returns the third-to-last element in the witness, if any.
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Witness
Available on crate feature arbitrary
only.
impl<'a> Arbitrary<'a> for Witness
arbitrary
only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self
from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self
from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured
this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured
this type
needs to construct itself. Read moreSource§impl<'de> Deserialize<'de> for Witness
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for Witness
serde
only.