Struct celestia_types::sample::Sample
source · pub struct Sample {
pub id: SampleId,
pub proof_type: AxisType,
pub share: Vec<u8>,
pub proof: NamespaceProof,
}Expand description
Represents Sample, with proof of its inclusion and location on EDS
Fields§
§id: SampleIdLocation of the sample in the EDS and associated block height
proof_type: AxisTypeIndication whether sampling was done row or column-wise
Share that is being sampled
proof: NamespaceProofProof of the inclusion of the share
Implementations§
source§impl Sample
impl Sample
sourcepub fn new(
row_index: u16,
column_index: u16,
proof_type: AxisType,
eds: &ExtendedDataSquare,
block_height: u64,
) -> Result<Self>
pub fn new( row_index: u16, column_index: u16, proof_type: AxisType, eds: &ExtendedDataSquare, block_height: u64, ) -> Result<Self>
Create a new Sample for the given index of the ExtendedDataSquare in a block.
row_index and column_index specifies the Share position in EDS.
proof_type determines whether proof of inclusion of the Share should be
constructed for its row or column.
§Errors
This function will return an error, if:
row_index/column_indexfalls outside the providedExtendedDataSquare.ExtendedDataSquareis incorrect (either data shares don’t have their namespace prefixed, orShares aren’t namespace ordered)- Block height is zero
§Example
use celestia_types::AxisType;
use celestia_types::sample::Sample;
let block_height = 15;
let eds = get_extended_data_square(block_height);
let header = get_extended_header(block_height);
let sample = Sample::new(2, 3, AxisType::Row, &eds, block_height).unwrap();
sample.verify(&header.dah).unwrap();sourcepub fn verify(&self, dah: &DataAvailabilityHeader) -> Result<()>
pub fn verify(&self, dah: &DataAvailabilityHeader) -> Result<()>
verify sample with root hash from ExtendedHeader
Trait Implementations§
source§impl<'de> Deserialize<'de> for Sample
impl<'de> Deserialize<'de> for Sample
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>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Protobuf<Sample> for Sample
impl Protobuf<Sample> for Sample
source§fn encode<B>(&self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
fn encode<B>(&self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
Encode into a buffer in Protobuf format. Read more
source§fn encode_length_delimited<B>(&self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
fn encode_length_delimited<B>(&self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
Encode with a length-delimiter to a buffer in Protobuf format. Read more
source§fn decode<B>(buf: B) -> Result<Self, Error>where
B: Buf,
fn decode<B>(buf: B) -> Result<Self, Error>where
B: Buf,
Constructor that attempts to decode an instance from a buffer. Read more
source§fn decode_length_delimited<B>(buf: B) -> Result<Self, Error>where
B: Buf,
fn decode_length_delimited<B>(buf: B) -> Result<Self, Error>where
B: Buf,
Constructor that attempts to decode a length-delimited instance from
the buffer. Read more
source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Returns the encoded length of the message without a length delimiter. Read more
source§fn encode_vec(&self) -> Result<Vec<u8>, Infallible>
fn encode_vec(&self) -> Result<Vec<u8>, Infallible>
Encodes into a Protobuf-encoded
Vec<u8>.source§fn decode_vec(v: &[u8]) -> Result<Self, Error>
fn decode_vec(v: &[u8]) -> Result<Self, Error>
Constructor that attempts to decode a Protobuf-encoded instance from a
Vec<u8> (or equivalent).source§fn encode_length_delimited_vec(&self) -> Result<Vec<u8>, Infallible>
fn encode_length_delimited_vec(&self) -> Result<Vec<u8>, Infallible>
Encode with a length-delimiter to a
Vec<u8> Protobuf-encoded message.Auto Trait Implementations§
impl Freeze for Sample
impl RefUnwindSafe for Sample
impl Send for Sample
impl Sync for Sample
impl Unpin for Sample
impl UnwindSafe for Sample
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)