tendermint/node/
info.rs

1//! Node information (used in RPC responses)
2
3use core::fmt::{self, Display};
4
5use serde::{Deserialize, Serialize};
6
7use crate::{chain, channel::Channels, node, prelude::*, serializers, Moniker, Version};
8
9/// Node information
10#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
11pub struct Info {
12    /// Protocol version information
13    pub protocol_version: ProtocolVersionInfo,
14
15    /// Node ID
16    pub id: node::Id,
17
18    /// Listen address
19    pub listen_addr: ListenAddress,
20
21    /// Tendermint network / chain ID,
22    pub network: chain::Id,
23
24    /// Tendermint version
25    pub version: Version,
26
27    /// Channels
28    pub channels: Channels,
29
30    /// Moniker
31    pub moniker: Moniker,
32
33    /// Other status information
34    pub other: OtherInfo,
35}
36
37/// Protocol version information
38#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
39pub struct ProtocolVersionInfo {
40    /// P2P protocol version
41    #[serde(with = "serializers::from_str")]
42    pub p2p: u64,
43
44    /// Block version
45    #[serde(with = "serializers::from_str")]
46    pub block: u64,
47
48    /// App version
49    #[serde(with = "serializers::from_str")]
50    pub app: u64,
51}
52
53/// Listen address information
54#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
55pub struct ListenAddress(String);
56
57impl ListenAddress {
58    /// Construct `ListenAddress`
59    pub fn new(s: String) -> ListenAddress {
60        ListenAddress(s)
61    }
62
63    pub fn as_str(&self) -> &str {
64        &self.0
65    }
66}
67
68impl Display for ListenAddress {
69    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
70        write!(f, "{}", self.0)
71    }
72}
73
74/// Other information
75#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
76pub struct OtherInfo {
77    /// TX index status
78    pub tx_index: TxIndexStatus,
79
80    /// RPC address
81    pub rpc_address: String,
82}
83
84/// Transaction index status
85#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize, Default)]
86pub enum TxIndexStatus {
87    /// Index is on
88    #[serde(rename = "on")]
89    #[default]
90    On,
91
92    /// Index is off
93    #[serde(rename = "off")]
94    Off,
95}
96
97impl From<TxIndexStatus> for bool {
98    fn from(status: TxIndexStatus) -> bool {
99        match status {
100            TxIndexStatus::On => true,
101            TxIndexStatus::Off => false,
102        }
103    }
104}