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
use crate::{chain, channel::Channels, net, node, serializers, Moniker, Version};
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Info {
pub protocol_version: ProtocolVersionInfo,
pub id: node::Id,
pub listen_addr: ListenAddress,
pub network: chain::Id,
pub version: Version,
pub channels: Channels,
pub moniker: Moniker,
pub other: OtherInfo,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ProtocolVersionInfo {
#[serde(with = "serializers::from_str")]
pub p2p: u64,
#[serde(with = "serializers::from_str")]
pub block: u64,
#[serde(with = "serializers::from_str")]
pub app: u64,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ListenAddress(String);
impl ListenAddress {
pub fn new(s: String) -> ListenAddress {
ListenAddress(s)
}
pub fn to_net_address(&self) -> Option<net::Address> {
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)
}
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct OtherInfo {
pub tx_index: TxIndexStatus,
pub rpc_address: net::Address,
}
#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum TxIndexStatus {
#[serde(rename = "on")]
On,
#[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,
}
}
}