Skip to main content

cuprated/
version.rs

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