pub struct Namespace(/* private fields */);Expand description
Namespace of the data published to the celestia network.
The Namespace is a single byte defining the version
followed by 28 bytes specifying concrete ID of the namespace.
Currently there are two versions of namespaces:
- version
0- the one allowing for the custom namespace ids. It requires an id to start with 180x00bytes followed by a user specified suffix (except reserved ones, see below). - version
255- for secondary reserved namespaces. It requires an id to start with 270xffbytes followed by a single byte indicating the id.
Some namespaces are reserved for the block creation purposes and cannot be used when submitting the blobs to celestia. Those fall into one of the two categories:
- primary reserved namespaces - those use version
0and have id lower or equal to0xffso they are always placed in blocks before user-submitted data. - secondary reserved namespaces - those use version
0xffso they are always placed after user-submitted data.
Implementations§
Source§impl Namespace
impl Namespace
Sourcepub const TRANSACTION: Namespace
pub const TRANSACTION: Namespace
Primary reserved Namespace for the compact Shares with cosmos SDK transactions.
Sourcepub const PAY_FOR_BLOB: Namespace
pub const PAY_FOR_BLOB: Namespace
Primary reserved Namespace for the compact Shares with MsgPayForBlobs transactions.
Sourcepub const PRIMARY_RESERVED_PADDING: Namespace = Namespace::MAX_PRIMARY_RESERVED
pub const PRIMARY_RESERVED_PADDING: Namespace = Namespace::MAX_PRIMARY_RESERVED
Primary reserved Namespace for the Shares used for padding.
Shares with this namespace are inserted after other shares from primary reserved namespace
so that user-defined namespaces are correctly aligned in ExtendedDataSquare
Sourcepub const MAX_PRIMARY_RESERVED: Namespace
pub const MAX_PRIMARY_RESERVED: Namespace
Maximal primary reserved Namespace.
Used to indicate the end of the primary reserved group.
Sourcepub const MIN_SECONDARY_RESERVED: Namespace
pub const MIN_SECONDARY_RESERVED: Namespace
Minimal secondary reserved Namespace.
Used to indicate the beginning of the secondary reserved group.
Sourcepub const TAIL_PADDING: Namespace
pub const TAIL_PADDING: Namespace
Secondary reserved Namespace used for padding after the blobs.
It is used to fill up the original data square after all user-submitted
blobs before the parity data is generated for the ExtendedDataSquare.
Sourcepub const PARITY_SHARE: Namespace
pub const PARITY_SHARE: Namespace
The Namespace for parity shares.
It is the namespace with which all the parity shares from
ExtendedDataSquare are inserted to the Nmt when computing
merkle roots.
Sourcepub fn from_raw(bytes: &[u8]) -> Result<Self>
pub fn from_raw(bytes: &[u8]) -> Result<Self>
Create a new Namespace from the raw bytes.
§Errors
This function will return an error if the slice length is different than
NS_SIZE or if the namespace is invalid. If you are constructing the
version 0 namespace, check new_v0 for more details.
§Example
use celestia_types::nmt::{Namespace, NS_SIZE};
let raw = [0; NS_SIZE];
let namespace = Namespace::from_raw(&raw).unwrap();Sourcepub fn new(version: u8, id: &[u8]) -> Result<Self>
pub fn new(version: u8, id: &[u8]) -> Result<Self>
Create a new Namespace from the version and id.
§Errors
This function will return an error if provided namespace version isn’t supported
or if the namespace is invalid. If you are constructing the
version 0 namespace, check new_v0 for more details.
§Example
use celestia_types::nmt::Namespace;
let namespace = Namespace::new(0, b"custom-ns").unwrap();Sourcepub fn new_v0(id: &[u8]) -> Result<Self>
pub fn new_v0(id: &[u8]) -> Result<Self>
Create a new Namespace version 0 with given id.
The id must be either:
- a 28 byte slice specifying full id
- a 10 or less byte slice specifying user-defined suffix
Namespaces in version 0 must have id’s prefixed with 18 0x00 bytes.
§Errors
This function will return an error if the provided id has incorrect length
or if the id has 28 bytes and have doesn’t have mandatory 18x0x00 bytes prefix
§Example
use celestia_types::nmt::Namespace;
// construct using 28 byte slice
let id = [0u8; 28];
let namespace = Namespace::new_v0(&id).unwrap();
// construct using <=10 byte suffix
let namespace = Namespace::new_v0(b"any-suffix").unwrap();
// invalid
let mut id = [0u8; 28];
id[4] = 1;
let namespace = Namespace::new_v0(&id).unwrap_err();Sourcepub const fn const_v255(id: u8) -> Self
pub const fn const_v255(id: u8) -> Self
Sourcepub fn new_v255(id: &[u8]) -> Result<Self>
pub fn new_v255(id: &[u8]) -> Result<Self>
Create a new Namespace version 255 with a given id.
Namespaces with version 255 must have ids prefixed with 27 0xff bytes followed by a
single byte with an actual id.
§Errors
This function will return an error, if the provided id has incorrect length
or if the id prefix is incorrect.
§Example
use celestia_types::nmt::Namespace;
// construct using 28 byte slice
let id = [255u8; 28];
let namespace = Namespace::new_v255(&id).unwrap();Sourcepub fn id_v0(&self) -> Option<&[u8]>
pub fn id_v0(&self) -> Option<&[u8]>
Returns the 10 bytes user-defined suffix of the Namespace if it’s a version 0.
Sourcepub fn is_reserved(&self) -> bool
pub fn is_reserved(&self) -> bool
Returns true if the namespace is reserved for special purposes.
§Example
use celestia_types::nmt::Namespace;
let ns = Namespace::new_v0(b"lumina").unwrap();
assert!(!ns.is_reserved());
assert!(Namespace::PAY_FOR_BLOB.is_reserved());
assert!(Namespace::PARITY_SHARE.is_reserved());Methods from Deref<Target = NamespaceId<NS_SIZE>>§
pub const MAX_ID: NamespaceId<NS_ID_SIZE>
pub const MAX_RESERVED_ID_ON_CELESTIA: NamespaceId<NS_ID_SIZE>
Sourcepub fn is_reserved_on_celestia(&self) -> bool
pub fn is_reserved_on_celestia(&self) -> bool
Indicates whether the namespace is reserved for system data on Celestia.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Namespace
impl<'de> Deserialize<'de> for Namespace
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>,
Source§impl From<Namespace> for NamespaceId<NS_SIZE>
impl From<Namespace> for NamespaceId<NS_SIZE>
Source§impl From<NamespaceId<NS_SIZE>> for Namespace
impl From<NamespaceId<NS_SIZE>> for Namespace
Source§fn from(value: NamespaceId<NS_SIZE>) -> Self
fn from(value: NamespaceId<NS_SIZE>) -> Self
Source§impl Ord for Namespace
impl Ord for Namespace
Source§impl PartialOrd for Namespace
impl PartialOrd for Namespace
impl Copy for Namespace
impl Eq for Namespace
impl StructuralPartialEq for Namespace
Auto Trait Implementations§
impl Freeze for Namespace
impl RefUnwindSafe for Namespace
impl Send for Namespace
impl Sync for Namespace
impl Unpin for Namespace
impl UnwindSafe for Namespace
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.