reth_db_models/
client_version.rs

1//! Client version model.
2
3use alloc::string::String;
4use serde::{Deserialize, Serialize};
5
6/// Client version that accessed the database.
7#[derive(Clone, Eq, PartialEq, Debug, Default, Serialize, Deserialize)]
8#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
9#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
10pub struct ClientVersion {
11    /// Client version
12    pub version: String,
13    /// The git commit sha
14    pub git_sha: String,
15    /// Build timestamp
16    pub build_timestamp: String,
17}
18
19impl ClientVersion {
20    /// Returns `true` if no version fields are set.
21    pub fn is_empty(&self) -> bool {
22        self.version.is_empty() && self.git_sha.is_empty() && self.build_timestamp.is_empty()
23    }
24}
25
26#[cfg(feature = "reth-codec")]
27impl reth_codecs::Compact for ClientVersion {
28    fn to_compact<B>(&self, buf: &mut B) -> usize
29    where
30        B: bytes::BufMut + AsMut<[u8]>,
31    {
32        self.version.to_compact(buf);
33        self.git_sha.to_compact(buf);
34        self.build_timestamp.to_compact(buf)
35    }
36
37    fn from_compact(buf: &[u8], len: usize) -> (Self, &[u8]) {
38        let (version, buf) = String::from_compact(buf, len);
39        let (git_sha, buf) = String::from_compact(buf, len);
40        let (build_timestamp, buf) = String::from_compact(buf, len);
41        let client_version = Self { version, git_sha, build_timestamp };
42        (client_version, buf)
43    }
44}