Skip to main content

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::constants::{MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, VERSION};
12
13// NOTE: keep `books/user/src/cli.md` updated with this struct.
14#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
15pub struct CupratedVersionInfo {
16    /// `cuprated`'s major version.
17    major_version: u8,
18    /// `cuprated`'s minor version.
19    minor_version: u8,
20    /// `cuprated`'s patch version.
21    patch_version: u8,
22    /// RPC major version (from `monerod`).
23    rpc_major_version: u32,
24    /// RPC minor version (from `monerod`).
25    rpc_minor_version: u32,
26    /// RPC version (from `monerod`).
27    rpc_version: u32,
28    /// The latest hardfork supported.
29    hardfork: u8,
30    /// The blockchain database version specific to `cuprated`.
31    blockchain_db_version: u64,
32    /// `cuprated`'s semantic version.
33    semantic_version: &'static str,
34    /// Build type, either `debug` or `release`.
35    build: &'static str,
36    /// Git commit hash of the build.
37    commit: &'static str,
38}
39
40impl CupratedVersionInfo {
41    /// Generate version info.
42    pub fn new() -> Self {
43        Self {
44            major_version: MAJOR_VERSION.parse().unwrap(),
45            minor_version: MINOR_VERSION.parse().unwrap(),
46            patch_version: PATCH_VERSION.parse().unwrap(),
47            rpc_major_version: CORE_RPC_VERSION_MAJOR,
48            rpc_minor_version: CORE_RPC_VERSION_MINOR,
49            rpc_version: CORE_RPC_VERSION,
50            blockchain_db_version: cuprate_blockchain::DATABASE_VERSION,
51            hardfork: HardFork::LATEST.as_u8(),
52            semantic_version: VERSION,
53            build: BUILD,
54            commit: COMMIT,
55        }
56    }
57}
58
59impl Default for CupratedVersionInfo {
60    fn default() -> Self {
61        Self::new()
62    }
63}
64
65#[cfg(test)]
66mod tests {
67    use super::CupratedVersionInfo;
68
69    /// Tests that [`CupratedVersionInfo`] can be generated.
70    #[test]
71    fn new() {
72        CupratedVersionInfo::new();
73    }
74}