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 = "default_protocol")]
15 pub protocol: Option<NeoProtocol>,
16}
17
18impl Default for NeoVersion {
19 fn default() -> Self {
20 NeoVersion {
21 tcp_port: Some(10333),
22 ws_port: Some(10334),
23 nonce: 1234567890,
24 user_agent: "/Neo:3.5.0/".to_string(),
25 protocol: Some(NeoProtocol::default()),
26 }
27 }
28}
29
30fn default_tcp_port() -> Option<u16> {
31 Some(10333)
32}
33
34fn default_ws_port() -> Option<u16> {
35 Some(10334)
36}
37
38fn default_nonce() -> u32 {
39 1234567890
40}
41
42fn default_user_agent() -> String {
43 "/Neo:3.5.0/".to_string()
44}
45
46fn default_protocol() -> Option<NeoProtocol> {
47 Some(NeoProtocol::default())
48}
49
50impl PartialEq for NeoVersion {
51 fn eq(&self, other: &Self) -> bool {
52 self.tcp_port == other.tcp_port
53 && self.ws_port == other.ws_port
54 && self.nonce == other.nonce
55 && self.user_agent == other.user_agent
56 && self.protocol == other.protocol
57 }
58}
59
60#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Hash)]
61pub struct NeoProtocol {
62 #[serde(default = "default_network")]
63 pub network: u32,
64 #[serde(rename = "validatorscount", default = "default_validators_count")]
65 pub validators_count: Option<u32>,
66 #[serde(rename = "msperblock", default = "default_ms_per_block")]
67 pub ms_per_block: u32,
68 #[serde(
69 rename = "maxvaliduntilblockincrement",
70 default = "default_max_valid_until_block_increment"
71 )]
72 pub max_valid_until_block_increment: u32,
73 #[serde(rename = "maxtraceableblocks", default = "default_max_traceable_blocks")]
74 pub max_traceable_blocks: u32,
75 #[serde(rename = "addressversion", default = "default_address_version")]
76 pub address_version: u32,
77 #[serde(rename = "maxtransactionsperblock", default = "default_max_transactions_per_block")]
78 pub max_transactions_per_block: u32,
79 #[serde(
80 rename = "memorypoolmaxtransactions",
81 default = "default_memory_pool_max_transactions"
82 )]
83 pub memory_pool_max_transactions: u32,
84 #[serde(rename = "initialgasdistribution", default = "default_initial_gas_distribution")]
85 pub initial_gas_distribution: u64,
86 #[serde(rename = "hardforks", default, deserialize_with = "deserialize_hardforks")]
87 pub hard_forks: Vec<HardForks>,
88}
89
90impl Default for NeoProtocol {
91 fn default() -> Self {
92 NeoProtocol {
93 network: 860833102,
94 validators_count: Some(7),
95 ms_per_block: 15000,
96 max_valid_until_block_increment: 5760,
97 max_traceable_blocks: 2102400,
98 address_version: 53,
99 max_transactions_per_block: 512,
100 memory_pool_max_transactions: 50000,
101 initial_gas_distribution: 5200000000000000,
102 hard_forks: Vec::new(),
103 }
104 }
105}
106
107fn default_network() -> u32 {
108 860833102
109}
110fn default_validators_count() -> Option<u32> {
111 Some(7)
112}
113fn default_ms_per_block() -> u32 {
114 15000
115}
116fn default_max_valid_until_block_increment() -> u32 {
117 5760
118}
119fn default_max_traceable_blocks() -> u32 {
120 2102400
121}
122fn default_address_version() -> u32 {
123 53
124}
125fn default_max_transactions_per_block() -> u32 {
126 512
127}
128fn default_memory_pool_max_transactions() -> u32 {
129 50000
130}
131fn default_initial_gas_distribution() -> u64 {
132 5200000000000000
133}
134
135#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
136pub struct HardForks {
137 pub name: String,
138 #[serde(rename = "blockheight")]
139 pub block_height: u32,
140}