solana_version/
legacy.rs

1use {
2    crate::compute_commit,
3    serde_derive::{Deserialize, Serialize},
4    solana_sanitize::Sanitize,
5    std::{convert::TryInto, fmt},
6};
7
8// Older version structure used earlier 1.3.x releases
9#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
10#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
11pub struct LegacyVersion1 {
12    major: u16,
13    minor: u16,
14    patch: u16,
15    commit: Option<u32>, // first 4 bytes of the sha1 commit hash
16}
17
18impl Sanitize for LegacyVersion1 {}
19
20#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
21#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
22pub struct LegacyVersion2 {
23    pub major: u16,
24    pub minor: u16,
25    pub patch: u16,
26    pub commit: Option<u32>, // first 4 bytes of the sha1 commit hash
27    pub feature_set: u32,    // first 4 bytes of the FeatureSet identifier
28}
29
30impl Default for LegacyVersion2 {
31    fn default() -> Self {
32        let feature_set =
33            u32::from_le_bytes(solana_feature_set::ID.as_ref()[..4].try_into().unwrap());
34        Self {
35            major: env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap(),
36            minor: env!("CARGO_PKG_VERSION_MINOR").parse().unwrap(),
37            patch: env!("CARGO_PKG_VERSION_PATCH").parse().unwrap(),
38            commit: compute_commit(option_env!("CI_COMMIT")),
39            feature_set,
40        }
41    }
42}
43
44impl fmt::Debug for LegacyVersion2 {
45    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46        write!(
47            f,
48            "{}.{}.{} (src:{}; feat:{})",
49            self.major,
50            self.minor,
51            self.patch,
52            match self.commit {
53                None => "devbuild".to_string(),
54                Some(commit) => format!("{commit:08x}"),
55            },
56            self.feature_set,
57        )
58    }
59}
60
61impl Sanitize for LegacyVersion2 {}