bee_ledger_types/snapshot/
info.rs

1// Copyright 2020-2021 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use bee_block::payload::milestone::MilestoneIndex;
5
6/// Snapshot information to be stored.
7#[derive(Clone, Debug, Eq, PartialEq, packable::Packable)]
8pub struct SnapshotInfo {
9    network_id: u64,
10    snapshot_index: MilestoneIndex,
11    entry_point_index: MilestoneIndex,
12    pruning_index: MilestoneIndex,
13    timestamp: u32,
14}
15
16impl SnapshotInfo {
17    /// Creates a new `SnapshotInfo`.
18    pub fn new(
19        network_id: u64,
20        snapshot_index: MilestoneIndex,
21        entry_point_index: MilestoneIndex,
22        pruning_index: MilestoneIndex,
23        timestamp: u32,
24    ) -> Self {
25        Self {
26            network_id,
27            snapshot_index,
28            entry_point_index,
29            pruning_index,
30            timestamp,
31        }
32    }
33
34    /// Returns the network identifier of a `SnapshotInfo`.
35    pub fn network_id(&self) -> u64 {
36        self.network_id
37    }
38
39    /// Returns the snapshot index of a `SnapshotInfo`.
40    pub fn snapshot_index(&self) -> MilestoneIndex {
41        self.snapshot_index
42    }
43
44    /// Updates the snapshot index of a `SnapshotInfo`.
45    pub fn update_snapshot_index(&mut self, index: MilestoneIndex) {
46        self.snapshot_index = index;
47    }
48
49    /// Returns the entry point index of a `SnapshotInfo`.
50    pub fn entry_point_index(&self) -> MilestoneIndex {
51        self.entry_point_index
52    }
53
54    /// Updates the entry point index of a `SnapshotInfo`.
55    pub fn update_entry_point_index(&mut self, index: MilestoneIndex) {
56        self.entry_point_index = index;
57    }
58
59    /// Returns the pruning index of a `SnapshotInfo`.
60    pub fn pruning_index(&self) -> MilestoneIndex {
61        self.pruning_index
62    }
63
64    /// Updates the pruning index of a `SnapshotInfo`.
65    pub fn update_pruning_index(&mut self, index: MilestoneIndex) {
66        self.pruning_index = index;
67    }
68
69    /// Returns the timestamp of a `SnapshotInfo`.
70    pub fn timestamp(&self) -> u32 {
71        self.timestamp
72    }
73
74    /// Updates the timestamp of a `SnapshotInfo`.
75    pub fn update_timestamp(&mut self, timestamp: u32) {
76        self.timestamp = timestamp;
77    }
78}