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
§data: Vec<u8>
Data stored within the Blob
.
commitment: Commitment
A Commitment
computed from the Blob
s data.
Implementations§
source§impl Blob
impl Blob
sourcepub fn new(namespace: Namespace, data: Vec<u8>) -> Result<Blob>
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="
}"#},
);
sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate Blob
s 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());
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<'de> Deserialize<'de> for Blob
impl<'de> Deserialize<'de> for Blob
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 PartialEq for Blob
impl PartialEq for Blob
source§impl Protobuf<Blob> for Blob
impl Protobuf<Blob> for Blob
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.impl Eq for Blob
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> 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