neo3/neo_protocol/responses/
neo_get_version.rs1use crate::deserialize_hardforks;
2use serde::{Deserialize, Serialize};
3
4#[derive(Serialize, Deserialize, Debug, Clone)]
5pub struct NeoVersion {
6 #[serde(rename = "tcpport", default = "default_tcp_port")]
7 pub tcp_port: Option<u16>,
8 #[serde(rename = "wsport", default = "default_ws_port")]
9 pub ws_port: Option<u16>,
10 #[serde(default = "default_nonce")]
11 pub nonce: u32,
12 #[serde(rename = "useragent", default = "default_user_agent")]
13 pub user_agent: String,
14 #[serde(default)]
15 pub rpc: Option<NeoRpcSettings>,
16 #[serde(default = "default_protocol")]
17 pub protocol: Option<NeoProtocol>,
18}
19
20impl Default for NeoVersion {
21 fn default() -> Self {
22 NeoVersion {
23 tcp_port: Some(10333),
24 ws_port: Some(10334),
25 nonce: 1234567890,
26 user_agent: "/Neo:3.5.0/".to_string(),
27 rpc: None,
28 protocol: Some(NeoProtocol::default()),
29 }
30 }
31}
32
33fn default_tcp_port() -> Option<u16> {
34 Some(10333)
35}
36
37fn default_ws_port() -> Option<u16> {
38 Some(10334)
39}
40
41fn default_nonce() -> u32 {
42 1234567890
43}
44
45fn default_user_agent() -> String {
46 "/Neo:3.5.0/".to_string()
47}
48
49fn default_protocol() -> Option<NeoProtocol> {
50 Some(NeoProtocol::default())
51}
52
53impl PartialEq for NeoVersion {
54 fn eq(&self, other: &Self) -> bool {
55 self.tcp_port == other.tcp_port
56 && self.ws_port == other.ws_port
57 && self.nonce == other.nonce
58 && self.user_agent == other.user_agent
59 && self.rpc == other.rpc
60 && self.protocol == other.protocol
61 }
62}
63
64#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Hash)]
65pub struct NeoRpcSettings {
66 #[serde(rename = "maxiteratorresultitems", default = "default_max_iterator_result_items")]
67 pub max_iterator_result_items: u32,
68 #[serde(rename = "sessionenabled", default = "default_session_enabled")]
69 pub session_enabled: bool,
70}
71
72fn default_max_iterator_result_items() -> u32 {
73 100
74}
75
76fn default_session_enabled() -> bool {
77 false
78}
79
80#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Hash)]
81pub struct NeoProtocol {
82 #[serde(default = "default_network")]
83 pub network: u32,
84 #[serde(rename = "validatorscount", default = "default_validators_count")]
85 pub validators_count: Option<u32>,
86 #[serde(rename = "msperblock", default = "default_ms_per_block")]
87 pub ms_per_block: u32,
88 #[serde(
89 rename = "maxvaliduntilblockincrement",
90 default = "default_max_valid_until_block_increment"
91 )]
92 pub max_valid_until_block_increment: u32,
93 #[serde(rename = "maxtraceableblocks", default = "default_max_traceable_blocks")]
94 pub max_traceable_blocks: u32,
95 #[serde(rename = "addressversion", default = "default_address_version")]
96 pub address_version: u32,
97 #[serde(rename = "maxtransactionsperblock", default = "default_max_transactions_per_block")]
98 pub max_transactions_per_block: u32,
99 #[serde(
100 rename = "memorypoolmaxtransactions",
101 default = "default_memory_pool_max_transactions"
102 )]
103 pub memory_pool_max_transactions: u32,
104 #[serde(rename = "initialgasdistribution", default = "default_initial_gas_distribution")]
105 pub initial_gas_distribution: u64,
106 #[serde(rename = "hardforks", default, deserialize_with = "deserialize_hardforks")]
107 pub hard_forks: Vec<HardForks>,
108 #[serde(rename = "standbycommittee", default)]
109 pub standby_committee: Vec<String>,
110 #[serde(rename = "seedlist", default)]
111 pub seed_list: Vec<String>,
112}
113
114impl Default for NeoProtocol {
115 fn default() -> Self {
116 NeoProtocol {
117 network: 860833102,
118 validators_count: Some(7),
119 ms_per_block: 15000,
120 max_valid_until_block_increment: 5760,
121 max_traceable_blocks: 2102400,
122 address_version: 53,
123 max_transactions_per_block: 512,
124 memory_pool_max_transactions: 50000,
125 initial_gas_distribution: 5200000000000000,
126 hard_forks: Vec::new(),
127 standby_committee: Vec::new(),
128 seed_list: Vec::new(),
129 }
130 }
131}
132
133fn default_network() -> u32 {
134 860833102
135}
136fn default_validators_count() -> Option<u32> {
137 Some(7)
138}
139fn default_ms_per_block() -> u32 {
140 15000
141}
142fn default_max_valid_until_block_increment() -> u32 {
143 5760
144}
145fn default_max_traceable_blocks() -> u32 {
146 2102400
147}
148fn default_address_version() -> u32 {
149 53
150}
151fn default_max_transactions_per_block() -> u32 {
152 512
153}
154fn default_memory_pool_max_transactions() -> u32 {
155 50000
156}
157fn default_initial_gas_distribution() -> u64 {
158 5200000000000000
159}
160
161#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
162pub struct HardForks {
163 pub name: String,
164 #[serde(rename = "blockheight")]
165 pub block_height: u32,
166}