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
//! Types for getting peer information
use ethereum_types::U256;
use serde::{Deserialize, Serialize};

/// Stores active peer count, connected count, max connected peers
/// and a list of peers for parity node
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct ParityPeerType {
    /// number of active peers
    pub active: usize,
    /// number of connected peers
    pub connected: usize,
    /// maximum number of peers that can connect
    pub max: u32,
    /// list of all peers with details
    pub peers: Vec<ParityPeerInfo>,
}

/// details of a peer
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct ParityPeerInfo {
    /// id of peer
    pub id: Option<String>,
    /// name of peer if set by user
    pub name: String,
    /// sync logic for protocol messaging
    pub caps: Vec<String>,
    /// remote address and local address
    pub network: PeerNetworkInfo,
    /// protocol version of peer
    pub protocols: PeerProtocolsInfo,
}

/// ip address of both local and remote
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PeerNetworkInfo {
    /// remote peer address
    pub remote_address: String,
    /// local peer address
    pub local_address: String,
}

/// chain protocol info
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct PeerProtocolsInfo {
    /// chain info
    pub eth: Option<EthProtocolInfo>,
    /// chain info
    pub pip: Option<PipProtocolInfo>,
}

/// eth chain version, difficulty, and head of chain
/// which soft fork? Olympic, Frontier, Homestead, Metropolis, Serenity, etc.
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct EthProtocolInfo {
    /// version
    pub version: u32,
    /// difficulty
    pub difficulty: Option<U256>,
    /// head of chain
    pub head: String,
}

/// pip version, difficulty, and head
#[derive(Serialize, PartialEq, Clone, Deserialize, Debug)]
pub struct PipProtocolInfo {
    /// version
    pub version: u32,
    /// difficulty
    pub difficulty: U256,
    /// head of chain
    pub head: String,
}