1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, Serialize)]
4pub struct Version {
5 pub package: &'static str,
6 pub version: &'static str,
7 pub proto: &'static str,
8 pub proto_richat: &'static str,
9 pub solana: &'static str,
10 pub git: &'static str,
11 pub rustc: &'static str,
12 pub buildts: &'static str,
13}
14
15impl Version {
16 pub fn create_grpc_version_info(self) -> GrpcVersionInfo {
17 GrpcVersionInfo::new(self)
18 }
19}
20
21#[derive(Debug, Clone, Deserialize, Serialize)]
22pub struct GrpcVersionInfoExtra {
23 hostname: Option<String>,
24}
25
26#[derive(Debug, Clone, Serialize)]
27pub struct GrpcVersionInfo {
28 version: Version,
29 extra: GrpcVersionInfoExtra,
30}
31
32impl GrpcVersionInfo {
33 pub fn new(version: Version) -> Self {
34 Self {
35 version,
36 extra: GrpcVersionInfoExtra {
37 hostname: hostname::get()
38 .ok()
39 .and_then(|name| name.into_string().ok()),
40 },
41 }
42 }
43
44 pub fn json(&self) -> String {
45 serde_json::to_string(self).expect("json serialization never fail")
46 }
47
48 pub fn value(&self) -> serde_json::Value {
49 serde_json::to_value(self).expect("json serialization never fail")
50 }
51}