mutant_lib/mutant/
data_structures.rs

1use autonomi::ScratchpadAddress;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6/// Represents how and where a logical piece of data (identified by user key) is stored.
7#[derive(Serialize, Deserialize, Debug, Clone)]
8pub struct KeyStorageInfo {
9    /// List of pads holding the data for this key (Address, Key Bytes)
10    pub(crate) pads: Vec<(ScratchpadAddress, Vec<u8>)>,
11    /// Actual size of the data stored across these pads
12    pub(crate) data_size: usize,
13    /// Timestamp of the last modification (store or update)
14    #[serde(default = "Utc::now")]
15    pub(crate) modified: DateTime<Utc>,
16}
17
18/// The main index mapping user keys to their storage information.
19pub type MasterIndex = HashMap<String, KeyStorageInfo>;
20
21/// Wrapper struct for data stored in the Master Index scratchpad.
22#[derive(Serialize, Deserialize, Debug, Default, Clone)]
23pub struct MasterIndexStorage {
24    /// The actual mapping of user keys to data locations.
25    pub(crate) index: MasterIndex,
26    /// List of (Address, Key Bytes) tuples for scratchpads available for reuse.
27    #[serde(default)]
28    pub(crate) free_pads: Vec<(ScratchpadAddress, Vec<u8>)>,
29    /// The standard size of scratchpads managed by this index (persisted).
30    pub(crate) scratchpad_size: usize,
31}