Struct celestia_types::blob::Blob

source ·
pub struct Blob {
    pub namespace: Namespace,
    pub data: Vec<u8>,
    pub share_version: u8,
    pub commitment: Commitment,
}
Expand description

Arbitrary data that can be stored in the network within certain Namespace.

Fields§

§namespace: Namespace

A Namespace the Blob belongs to.

§data: Vec<u8>

Data stored within the Blob.

§share_version: u8

Version indicating the format in which Shares should be created from this Blob.

§commitment: Commitment

A Commitment computed from the Blobs data.

Implementations§

source§

impl Blob

source

pub fn new(namespace: Namespace, data: Vec<u8>) -> Result<Blob>

Create a new blob with the given data within the Namespace.

§Errors

This function propagates any error from the Commitment creation.

§Example
use celestia_types::{Blob, nmt::Namespace};

let my_namespace = Namespace::new_v0(&[1, 2, 3, 4, 5]).expect("Invalid namespace");
let blob = Blob::new(my_namespace, b"some data to store on blockchain".to_vec())
    .expect("Failed to create a blob");

assert_eq!(
    &serde_json::to_string_pretty(&blob).unwrap(),
    indoc::indoc! {r#"{
      "namespace": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQIDBAU=",
      "data": "c29tZSBkYXRhIHRvIHN0b3JlIG9uIGJsb2NrY2hhaW4=",
      "share_version": 0,
      "commitment": "m0A4feU6Fqd5Zy9td3M7lntG8A3PKqe6YdugmAsWz28="
    }"#},
);
source

pub fn validate(&self) -> Result<()>

Validate Blobs data with the Commitment it has.

§Errors

If validation fails, this function will return an error with a reason of failure.

§Example
use celestia_types::Blob;

let mut blob = Blob::new(namespace, b"foo".to_vec()).unwrap();

assert!(blob.validate().is_ok());

let other_blob = Blob::new(namespace, b"bar".to_vec()).unwrap();
blob.commitment = other_blob.commitment;

assert!(blob.validate().is_err());
source

pub fn to_shares(&self) -> Result<Vec<Share>>

Encode the blob into a sequence of shares.

Check the Share documentation for more information about the share format.

§Errors

This function will return an error if InfoByte creation fails or the data length overflows u32.

§Example
use celestia_types::Blob;

let blob = Blob::new(namespace, b"foo".to_vec()).unwrap();
let shares = blob.to_shares().unwrap();

assert_eq!(shares.len(), 1);

Trait Implementations§

source§

impl Clone for Blob

source§

fn clone(&self) -> Blob

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 Blob

source§

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

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

impl<'de> Deserialize<'de> for Blob

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<Blob> for Blob

source§

fn from(value: Blob) -> RawBlob

Converts to this type from the input type.
source§

impl PartialEq for Blob

source§

fn eq(&self, other: &Blob) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Protobuf<Blob> for Blob

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 Blob

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<Blob> for Blob

§

type Error = Error

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

fn try_from(value: RawBlob) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for Blob

source§

impl StructuralPartialEq for Blob

Auto Trait Implementations§

§

impl Freeze for Blob

§

impl RefUnwindSafe for Blob

§

impl Send for Blob

§

impl Sync for Blob

§

impl Unpin for Blob

§

impl UnwindSafe for Blob

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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>,