pub struct Blob {
pub namespace: Namespace,
pub data: Vec<u8>,
pub share_version: u8,
pub commitment: Commitment,
pub index: Option<u64>,
pub signer: Option<AccAddress>,
}
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.
index: Option<u64>
Index of the blob’s first share in the EDS. Only set for blobs retrieved from chain.
signer: Option<AccAddress>
A signer of the blob, i.e. address of the account which submitted the blob.
Must be present in share_version 1
and absent otherwise.
Implementations§
Source§impl Blob
impl Blob
Sourcepub fn new(
namespace: Namespace,
data: Vec<u8>,
app_version: AppVersion,
) -> Result<Blob>
pub fn new( namespace: Namespace, data: Vec<u8>, app_version: AppVersion, ) -> 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::{AppVersion, 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(), AppVersion::V2)
.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=",
"index": -1,
"signer": null
}"#},
);
Sourcepub fn new_with_signer(
namespace: Namespace,
data: Vec<u8>,
signer: AccAddress,
app_version: AppVersion,
) -> Result<Blob>
pub fn new_with_signer( namespace: Namespace, data: Vec<u8>, signer: AccAddress, app_version: AppVersion, ) -> Result<Blob>
Create a new blob with the given data within the Namespace
and with given signer.
§Errors
This function propagates any error from the Commitment
creation. Also AppVersion
must be at least AppVersion::V3
.
Sourcepub fn from_raw(raw: RawBlob, app_version: AppVersion) -> Result<Blob>
pub fn from_raw(raw: RawBlob, app_version: AppVersion) -> Result<Blob>
Creates a Blob
from RawBlob
and an AppVersion
.
Sourcepub fn validate(&self, app_version: AppVersion) -> Result<()>
pub fn validate(&self, app_version: AppVersion) -> 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(), AppVersion::V2).unwrap();
assert!(blob.validate(AppVersion::V2).is_ok());
let other_blob = Blob::new(namespace, b"bar".to_vec(), AppVersion::V2).unwrap();
blob.commitment = other_blob.commitment;
assert!(blob.validate(AppVersion::V2).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(), AppVersion::V2).unwrap();
let shares = blob.to_shares().unwrap();
assert_eq!(shares.len(), 1);
Sourcepub fn reconstruct<'a, I>(shares: I, app_version: AppVersion) -> Result<Self>where
I: IntoIterator<Item = &'a Share>,
pub fn reconstruct<'a, I>(shares: I, app_version: AppVersion) -> Result<Self>where
I: IntoIterator<Item = &'a Share>,
Reconstructs a blob from shares.
§Errors
This function will return an error if:
- there is not enough shares to reconstruct the blob
- blob doesn’t start with the first share
- shares are from any reserved namespace
- shares for the blob have different namespaces / share version
§Example
use celestia_types::{AppVersion, Blob};
let blob = Blob::new(namespace, b"foo".to_vec(), AppVersion::V2).unwrap();
let shares = blob.to_shares().unwrap();
let reconstructed = Blob::reconstruct(&shares, AppVersion::V2).unwrap();
assert_eq!(blob, reconstructed);
Sourcepub fn reconstruct_all<'a, I>(
shares: I,
app_version: AppVersion,
) -> Result<Vec<Self>>where
I: IntoIterator<Item = &'a Share>,
pub fn reconstruct_all<'a, I>(
shares: I,
app_version: AppVersion,
) -> Result<Vec<Self>>where
I: IntoIterator<Item = &'a Share>,
Reconstructs all the blobs from shares.
This function will seek shares that indicate start of the next blob (with
Share::sequence_length
) and pass them to Blob::reconstruct
.
It will automatically ignore all shares that are within reserved namespaces
e.g. it is completely fine to pass whole ExtendedDataSquare
to this
function and get all blobs in the block.
§Errors
This function propagates any errors from Blob::reconstruct
.
§Example
use celestia_types::{AppVersion, Blob};
let blobs = vec![
Blob::new(namespace1, b"foo".to_vec(), AppVersion::V2).unwrap(),
Blob::new(namespace2, b"bar".to_vec(), AppVersion::V2).unwrap(),
];
let shares: Vec<_> = blobs.iter().flat_map(|blob| blob.to_shares().unwrap()).collect();
let reconstructed = Blob::reconstruct_all(&shares, AppVersion::V2).unwrap();
assert_eq!(blobs, reconstructed);
Get the amount of shares needed to encode this blob.
§Example
use celestia_types::{AppVersion, Blob};
let blob = Blob::new(namespace, b"foo".to_vec(), AppVersion::V3).unwrap();
let shares_len = blob.shares_len();
let blob_shares = blob.to_shares().unwrap();
assert_eq!(shares_len, blob_shares.len());
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>,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.