Skip to main content

ab_archiving/
objects.rs

1//! Data structures related to objects (useful data) contained in archived history.
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::PiecePosition;
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///
26/// This data structure is produced during archiving when the piece index is not yet known, hence it
27/// only contains piece position within a local segment.
28#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Encode, Decode)]
29#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
30#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
31pub struct GlobalObject {
32    /// Object hash.
33    ///
34    /// We order objects by hash, so object hash lookups can be performed efficiently.
35    pub hash: Blake3Hash,
36    /// Position of the piece where the object is contained within a local segment (at least its
37    /// beginning, might not fit fully)
38    pub piece_position: PiecePosition,
39    /// Raw record offset of the object in that piece, for use with `Record::to_raw_record_bytes`
40    pub offset: u32,
41}