snops_common/state/
snarkos_status.rs

1use std::sync::Arc;
2
3use chrono::Utc;
4use serde::{Deserialize, Serialize};
5
6use super::LatestBlockInfo;
7
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "snake_case")]
10pub enum SnarkOSStatus {
11    /// Initial node status
12    Starting,
13    /// Node is loading the ledger
14    LedgerLoading,
15    /// Failure to load the ledger
16    LedgerFailure(String),
17    /// Node is running
18    Started,
19    /// Node crashed
20    Halted(Option<String>),
21}
22
23/// Messages from snarkos to the agent, containing information about the status
24/// of the node
25#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
26#[serde(rename_all = "snake_case")]
27pub struct SnarkOSBlockInfo {
28    pub height: u32,
29    pub state_root: String,
30    pub block_hash: String,
31    pub previous_hash: String,
32    pub block_timestamp: i64,
33}
34
35/// Messages from snarkos to the agent, containing information about the status
36/// of the node
37#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
38#[serde(rename_all = "snake_case")]
39pub struct SnarkOSLiteBlock {
40    pub info: SnarkOSBlockInfo,
41    pub transactions: Vec<String>,
42}
43
44impl SnarkOSLiteBlock {
45    pub fn split(self) -> (LatestBlockInfo, Vec<Arc<str>>) {
46        (
47            LatestBlockInfo {
48                height: self.info.height,
49                state_root: self.info.state_root,
50                block_hash: self.info.block_hash,
51                previous_hash: self.info.previous_hash,
52                block_timestamp: self.info.block_timestamp,
53                update_time: Utc::now(),
54            },
55            self.transactions.into_iter().map(Arc::from).collect(),
56        )
57    }
58}