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
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
// This file is part of OpenEthereum.

// OpenEthereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// OpenEthereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with OpenEthereum.  If not, see <http://www.gnu.org/licenses/>.

//! Description of the node.

/// Describes the kind of node. This information can provide a hint to
/// applications about how to utilize the RPC.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct NodeKind {
    /// The capability of the node.
    pub capability: Capability,
    /// Who the node is available to.
    pub availability: Availability,
}

/// Who the node is available to.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum Availability {
    /// A personal node, not intended to be available to everyone.
    Personal,
    /// A public, open node.
    Public,
}

/// The capability of the node.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum Capability {
    /// A full node stores the full state and fully enacts incoming blocks.
    Full,
}

#[cfg(test)]
mod tests {
    use super::{Availability, Capability, NodeKind};
    use serde_json;

    #[test]
    fn availability() {
        let personal = r#""personal""#;
        let public = r#""public""#;

        assert_eq!(
            serde_json::to_string(&Availability::Personal).unwrap(),
            personal
        );
        assert_eq!(
            serde_json::to_string(&Availability::Public).unwrap(),
            public
        );

        assert_eq!(
            serde_json::from_str::<Availability>(personal).unwrap(),
            Availability::Personal
        );
        assert_eq!(
            serde_json::from_str::<Availability>(public).unwrap(),
            Availability::Public
        );
    }

    #[test]
    fn capability() {
        let full = r#""full""#;

        assert_eq!(serde_json::to_string(&Capability::Full).unwrap(), full);

        assert_eq!(
            serde_json::from_str::<Capability>(full).unwrap(),
            Capability::Full
        );
    }

    #[test]
    fn node_kind() {
        let kind = NodeKind {
            capability: Capability::Full,
            availability: Availability::Public,
        };
        let s = r#"{"capability":"full","availability":"public"}"#;

        assert_eq!(serde_json::to_string(&kind).unwrap(), s);
        assert_eq!(serde_json::from_str::<NodeKind>(s).unwrap(), kind);
    }
}