-
Notifications
You must be signed in to change notification settings - Fork 225
/
info.rs
113 lines (91 loc) · 2.61 KB
/
info.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! Node information (used in RPC responses)
use crate::{chain, channel::Channels, net, node, serializers, Moniker, Version};
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display};
/// Node information
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Info {
/// Protocol version information
pub protocol_version: ProtocolVersionInfo,
/// Node ID
pub id: node::Id,
/// Listen address
pub listen_addr: ListenAddress,
/// Tendermint network / chain ID,
pub network: chain::Id,
/// Tendermint version
pub version: Version,
/// Channels
pub channels: Channels,
/// Moniker
pub moniker: Moniker,
/// Other status information
pub other: OtherInfo,
}
/// Protocol version information
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ProtocolVersionInfo {
/// P2P protocol version
#[serde(with = "serializers::from_str")]
pub p2p: u64,
/// Block version
#[serde(with = "serializers::from_str")]
pub block: u64,
/// App version
#[serde(with = "serializers::from_str")]
pub app: u64,
}
/// Listen address information
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ListenAddress(String);
impl ListenAddress {
/// Construct `ListenAddress`
pub fn new(s: String) -> ListenAddress {
ListenAddress(s)
}
/// Convert `ListenAddress` to a `net::Address`
pub fn to_net_address(&self) -> Option<net::Address> {
// TODO(tarcieri): validate these and handle them better at parse time
if self.0.starts_with("tcp://") {
self.0.parse().ok()
} else {
format!("tcp://{}", self.0).parse().ok()
}
}
}
impl Display for ListenAddress {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
/// Other information
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct OtherInfo {
/// TX index status
pub tx_index: TxIndexStatus,
/// RPC address
pub rpc_address: net::Address,
}
/// Transaction index status
#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum TxIndexStatus {
/// Index is on
#[serde(rename = "on")]
On,
/// Index is off
#[serde(rename = "off")]
Off,
}
impl Default for TxIndexStatus {
fn default() -> TxIndexStatus {
TxIndexStatus::On
}
}
impl From<TxIndexStatus> for bool {
fn from(status: TxIndexStatus) -> bool {
match status {
TxIndexStatus::On => true,
TxIndexStatus::Off => false,
}
}
}