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: SampleId

Location of the sample in the EDS and associated block height

§proof_type: AxisType

Indication whether sampling was done row or column-wise

§share: Vec<u8>

Share that is being sampled

§proof: NamespaceProof

Proof of the inclusion of the share

Implementations§

source§

impl Sample

source

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_index falls outside the provided ExtendedDataSquare.
  • ExtendedDataSquare is incorrect (either data shares don’t have their namespace prefixed, or Shares 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();
source

pub fn verify(&self, dah: &DataAvailabilityHeader) -> Result<()>

verify sample with root hash from ExtendedHeader

Trait Implementations§

source§

impl Clone for Sample

source§

fn clone(&self) -> Sample

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Sample

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Sample

source§

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 From<Sample> for Sample

source§

fn from(sample: Sample) -> RawSample

Converts to this type from the input type.
source§

impl Protobuf<Sample> for Sample

source§

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,

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,

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,

Constructor that attempts to decode a length-delimited instance from the buffer. Read more
source§

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>

Encodes into a Protobuf-encoded Vec<u8>.
source§

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>

Encode with a length-delimiter to a Vec<u8> Protobuf-encoded message.
source§

fn decode_length_delimited_vec(v: &[u8]) -> Result<Self, Error>

Constructor that attempts to decode a Protobuf-encoded instance with a length-delimiter from a Vec<u8> or equivalent.
source§

impl Serialize for Sample

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<Sample> for Sample

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(sample: RawSample) -> Result<Sample, Self::Error>

Performs the conversion.

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<S> CondSend for S
where S: Send,

source§

impl<S> CondSync for S
where S: Send + Sync,

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,