ab_archiving/
objects.rs

1//! Data structures related to objects (useful data) stored on Subspace Network.
2//!
3//! There are two kinds of mappings:
4//! * for objects within a block
5//! * for global objects in the global history of the blockchain (inside a piece)
6
7use ab_core_primitives::hashes::Blake3Hash;
8use ab_core_primitives::pieces::PieceIndex;
9use parity_scale_codec::{Decode, Encode};
10#[cfg(feature = "serde")]
11use serde::{Deserialize, Serialize};
12
13/// Object stored inside the block
14#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Encode, Decode)]
15#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
16#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
17pub struct BlockObject {
18    /// Object hash
19    pub hash: Blake3Hash,
20    /// Offset of the object in the encoded block
21    pub offset: u32,
22}
23
24/// Object stored in the history of the blockchain
25#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Encode, Decode)]
26#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
27#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
28pub struct GlobalObject {
29    /// Object hash.
30    ///
31    /// We order objects by hash, so object hash lookups can be performed efficiently.
32    pub hash: Blake3Hash,
33    /// Piece index where the object is contained (at least its beginning, might not fit fully)
34    pub piece_index: PieceIndex,
35    /// Raw record offset of the object in that piece, for use with `Record::to_raw_record_bytes`
36    pub offset: u32,
37}