@@ -2,7 +2,9 @@ use super::{time::Era, Point};
2
2
use dcspark_core:: { BlockId , SlotNumber } ;
3
3
use std:: borrow:: Cow ;
4
4
5
- #[ derive( Clone , Debug ) ]
5
+ #[ derive( Clone , Debug , serde:: Serialize , serde:: Deserialize ) ]
6
+ #[ serde( rename_all = "snake_case" ) ]
7
+ #[ serde( deny_unknown_fields) ]
6
8
pub struct NetworkConfiguration {
7
9
pub chain_info : cml_chain:: genesis:: network_info:: NetworkInfo ,
8
10
pub relay : ( Cow < ' static , str > , u16 ) ,
@@ -137,3 +139,47 @@ impl NetworkConfiguration {
137
139
}
138
140
}
139
141
}
142
+
143
+ #[ cfg( test) ]
144
+ mod tests {
145
+ use super :: NetworkConfiguration ;
146
+
147
+ #[ test]
148
+ fn custom_json_network ( ) {
149
+ println ! (
150
+ "{}" ,
151
+ deps:: serde_json:: to_string_pretty( & NetworkConfiguration :: mainnet( ) ) . unwrap( )
152
+ ) ;
153
+ let json = r#"{
154
+ "chain_info": {
155
+ "network_id": 1,
156
+ "protocol_magic": 764824073
157
+ },
158
+ "relay": [
159
+ "relays-new.cardano-mainnet.iohk.io.",
160
+ 3001
161
+ ],
162
+ "from": {
163
+ "BlockHeader": {
164
+ "slot_nb": 4492800,
165
+ "hash": "aa83acbf5904c0edfe4d79b3689d3d00fcfc553cf360fd2229b98d464c28e9de"
166
+ }
167
+ },
168
+ "genesis_parent": "5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb",
169
+ "genesis": {
170
+ "BlockHeader": {
171
+ "slot_nb": 0,
172
+ "hash": "89d9b5a5b8ddc8d7e5a6795e9774d97faf1efea59b2caf7eaf9f8c5b32059df4"
173
+ }
174
+ },
175
+ "shelley_era_config": {
176
+ "first_slot": 4492800,
177
+ "start_epoch": 208,
178
+ "known_time": 1596059091,
179
+ "slot_length": 1,
180
+ "epoch_length_seconds": 432000
181
+ }
182
+ }"# ;
183
+ let _config: NetworkConfiguration = deps:: serde_json:: from_str ( json) . unwrap ( ) ;
184
+ }
185
+ }
0 commit comments