1use crate::{
20 bytes::Bytes,
21 hash::{H256, Address},
22 uint::{self, Uint}
23};
24use serde::Deserialize;
25
26#[derive(Debug, PartialEq, Deserialize)]
28#[serde(deny_unknown_fields)]
29#[serde(rename_all = "camelCase")]
30pub struct Params {
31 pub account_start_nonce: Option<Uint>,
33 pub maximum_extra_data_size: Uint,
35 pub min_gas_limit: Uint,
37
38 #[serde(rename = "networkID")]
40 pub network_id: Uint,
41 #[serde(rename = "chainID")]
43 pub chain_id: Option<Uint>,
44
45 pub subprotocol_name: Option<String>,
47
48 pub fork_block: Option<Uint>,
50 #[serde(rename = "forkCanonHash")]
52 pub fork_hash: Option<H256>,
53
54 pub eip150_transition: Option<Uint>,
56
57 pub eip160_transition: Option<Uint>,
59
60 pub eip161abc_transition: Option<Uint>,
62 pub eip161d_transition: Option<Uint>,
64
65 pub eip98_transition: Option<Uint>,
67 pub eip155_transition: Option<Uint>,
69 pub validate_chain_id_transition: Option<Uint>,
71 pub validate_receipts_transition: Option<Uint>,
73 pub eip140_transition: Option<Uint>,
75 pub eip210_transition: Option<Uint>,
77 pub eip210_contract_address: Option<Address>,
79 pub eip210_contract_code: Option<Bytes>,
81 pub eip210_contract_gas: Option<Uint>,
83 pub eip211_transition: Option<Uint>,
85 pub eip145_transition: Option<Uint>,
87 pub eip214_transition: Option<Uint>,
89 pub eip658_transition: Option<Uint>,
91 pub eip1052_transition: Option<Uint>,
93 pub eip1283_transition: Option<Uint>,
95 pub eip1283_disable_transition: Option<Uint>,
97 pub eip1283_reenable_transition: Option<Uint>,
99 pub eip1014_transition: Option<Uint>,
101 pub eip1706_transition: Option<Uint>,
103 pub eip1344_transition: Option<Uint>,
105 pub eip1884_transition: Option<Uint>,
107 pub eip2028_transition: Option<Uint>,
109 pub eip2200_advance_transition: Option<Uint>,
111 pub dust_protection_transition: Option<Uint>,
113 pub nonce_cap_increment: Option<Uint>,
115 pub remove_dust_contracts : Option<bool>,
117 #[serde(deserialize_with="uint::validate_non_zero")]
119 pub gas_limit_bound_divisor: Uint,
120 pub tetsy_registrar: Option<Address>,
122 pub apply_reward: Option<bool>,
124 pub node_permission_contract: Option<Address>,
126 pub max_code_size: Option<Uint>,
128 pub max_transaction_size: Option<Uint>,
130 pub max_code_size_transition: Option<Uint>,
132 pub transaction_permission_contract: Option<Address>,
134 pub transaction_permission_contract_transition: Option<Uint>,
136 pub wasm_activation_transition: Option<Uint>,
138 pub wasm_version: Option<Uint>,
140 pub kip4_transition: Option<Uint>,
142 pub kip6_transition: Option<Uint>,
144}
145
146#[cfg(test)]
147mod tests {
148 use super::{Params, Uint};
149 use vapory_types::U256;
150
151 #[test]
152 fn params_deserialization() {
153 let s = r#"{
154 "maximumExtraDataSize": "0x20",
155 "networkID": "0x1",
156 "chainID": "0x15",
157 "subprotocolName": "exp",
158 "minGasLimit": "0x1388",
159 "accountStartNonce": "0x01",
160 "gasLimitBoundDivisor": "0x20",
161 "maxCodeSize": "0x1000",
162 "wasmActivationTransition": "0x1010"
163 }"#;
164
165 let deserialized: Params = serde_json::from_str(s).unwrap();
166 assert_eq!(deserialized.maximum_extra_data_size, Uint(U256::from(0x20)));
167 assert_eq!(deserialized.network_id, Uint(U256::from(0x1)));
168 assert_eq!(deserialized.chain_id, Some(Uint(U256::from(0x15))));
169 assert_eq!(deserialized.subprotocol_name, Some("exp".to_owned()));
170 assert_eq!(deserialized.min_gas_limit, Uint(U256::from(0x1388)));
171 assert_eq!(deserialized.account_start_nonce, Some(Uint(U256::from(0x01))));
172 assert_eq!(deserialized.gas_limit_bound_divisor, Uint(U256::from(0x20)));
173 assert_eq!(deserialized.max_code_size, Some(Uint(U256::from(0x1000))));
174 assert_eq!(deserialized.wasm_activation_transition, Some(Uint(U256::from(0x1010))));
175 }
176
177 #[test]
178 #[should_panic(expected = "a non-zero value")]
179 fn test_zero_value_divisor() {
180 let s = r#"{
181 "maximumExtraDataSize": "0x20",
182 "networkID" : "0x1",
183 "chainID" : "0x15",
184 "subprotocolName" : "exp",
185 "minGasLimit": "0x1388",
186 "accountStartNonce": "0x01",
187 "gasLimitBoundDivisor": "0x0",
188 "maxCodeSize": "0x1000"
189 }"#;
190
191 let _deserialized: Params = serde_json::from_str(s).unwrap();
192 }
193}