cuprated/
version.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Misc version information about `cuprated`.

use std::fmt::Display;

use serde::{Deserialize, Serialize};

use cuprate_constants::build::{BUILD, COMMIT};
use cuprate_rpc_types::{CORE_RPC_VERSION, CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR};
use cuprate_types::HardFork;

use crate::{
    constants::{MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, VERSION},
    killswitch::KILLSWITCH_ACTIVATION_TIMESTAMP,
};

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct CupratedVersionInfo {
    /// `cuprated`'s major version.
    major_version: u8,
    /// `cuprated`'s minor version.
    minor_version: u8,
    /// `cuprated`'s patch version.
    patch_version: u8,
    /// RPC major version (from `monerod`).
    rpc_major_version: u32,
    /// RPC minor version (from `monerod`).
    rpc_minor_version: u32,
    /// RPC version (from `monerod`).
    rpc_version: u32,
    /// The latest hardfork supported.
    hardfork: u8,
    /// The blockchain database version specific to `cuprated`.
    blockchain_db_version: u64,
    /// `cuprated`'s semantic version.
    semantic_version: &'static str,
    /// Build type, either `debug` or `release`.
    build: &'static str,
    /// Git commit hash of the build.
    commit: &'static str,
    /// Timestamp at which `cuprated`'s killswitch activates.
    killswitch_timestamp: u64,
}

impl CupratedVersionInfo {
    /// Generate version info.
    pub fn new() -> Self {
        Self {
            major_version: MAJOR_VERSION.parse().unwrap(),
            minor_version: MINOR_VERSION.parse().unwrap(),
            patch_version: PATCH_VERSION.parse().unwrap(),
            rpc_major_version: CORE_RPC_VERSION_MAJOR,
            rpc_minor_version: CORE_RPC_VERSION_MINOR,
            rpc_version: CORE_RPC_VERSION,
            blockchain_db_version: cuprate_blockchain::DATABASE_VERSION,
            hardfork: HardFork::LATEST.as_u8(),
            semantic_version: VERSION,
            build: BUILD,
            commit: COMMIT,
            killswitch_timestamp: KILLSWITCH_ACTIVATION_TIMESTAMP,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::CupratedVersionInfo;

    /// Tests that [`CupratedVersionInfo`] can be generated.
    #[test]
    fn new() {
        CupratedVersionInfo::new();
    }
}