cuprated/
version.rs

1//! Misc version information about `cuprated`.
2
3use std::fmt::Display;
4
5use serde::{Deserialize, Serialize};
6
7use cuprate_constants::build::{BUILD, COMMIT};
8use cuprate_rpc_types::{CORE_RPC_VERSION, CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR};
9use cuprate_types::HardFork;
10
11use crate::{
12    constants::{MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, VERSION},
13    killswitch::KILLSWITCH_ACTIVATION_TIMESTAMP,
14};
15
16#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
17pub struct CupratedVersionInfo {
18    /// `cuprated`'s major version.
19    major_version: u8,
20    /// `cuprated`'s minor version.
21    minor_version: u8,
22    /// `cuprated`'s patch version.
23    patch_version: u8,
24    /// RPC major version (from `monerod`).
25    rpc_major_version: u32,
26    /// RPC minor version (from `monerod`).
27    rpc_minor_version: u32,
28    /// RPC version (from `monerod`).
29    rpc_version: u32,
30    /// The latest hardfork supported.
31    hardfork: u8,
32    /// The blockchain database version specific to `cuprated`.
33    blockchain_db_version: u64,
34    /// `cuprated`'s semantic version.
35    semantic_version: &'static str,
36    /// Build type, either `debug` or `release`.
37    build: &'static str,
38    /// Git commit hash of the build.
39    commit: &'static str,
40    /// Timestamp at which `cuprated`'s killswitch activates.
41    killswitch_timestamp: u64,
42}
43
44impl CupratedVersionInfo {
45    /// Generate version info.
46    pub fn new() -> Self {
47        Self {
48            major_version: MAJOR_VERSION.parse().unwrap(),
49            minor_version: MINOR_VERSION.parse().unwrap(),
50            patch_version: PATCH_VERSION.parse().unwrap(),
51            rpc_major_version: CORE_RPC_VERSION_MAJOR,
52            rpc_minor_version: CORE_RPC_VERSION_MINOR,
53            rpc_version: CORE_RPC_VERSION,
54            blockchain_db_version: cuprate_blockchain::DATABASE_VERSION,
55            hardfork: HardFork::LATEST.as_u8(),
56            semantic_version: VERSION,
57            build: BUILD,
58            commit: COMMIT,
59            killswitch_timestamp: KILLSWITCH_ACTIVATION_TIMESTAMP,
60        }
61    }
62}
63
64#[cfg(test)]
65mod tests {
66    use super::CupratedVersionInfo;
67
68    /// Tests that [`CupratedVersionInfo`] can be generated.
69    #[test]
70    fn new() {
71        CupratedVersionInfo::new();
72    }
73}