Skip to content

Commit edb628e

Browse files
committed
NetworkConfiguration JSON
Related to dcSpark/carp#187
1 parent 4f0865f commit edb628e

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

blockchain-source/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ serde = { version = "1.0.144" }
2323
tokio = { version = "1", features = [ "full" ] }
2424
thiserror = { version = "1.0" }
2525
tracing = { version = "0.1" }
26-
cml-multi-era = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "8999325933c131af8ac474fe8556e585ca39659c" }
27-
cml-chain = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "8999325933c131af8ac474fe8556e585ca39659c" }
28-
cml-core = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "8999325933c131af8ac474fe8556e585ca39659c" }
26+
cml-multi-era = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "01081ee0a6381cfecf6562c78095e8fb9acf74e3" }
27+
cml-chain = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "01081ee0a6381cfecf6562c78095e8fb9acf74e3" }
28+
cml-core = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "01081ee0a6381cfecf6562c78095e8fb9acf74e3" }

blockchain-source/src/cardano/configuration.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use super::{time::Era, Point};
22
use dcspark_core::{BlockId, SlotNumber};
33
use std::borrow::Cow;
44

5-
#[derive(Clone, Debug)]
5+
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
6+
#[serde(rename_all = "snake_case")]
7+
#[serde(deny_unknown_fields)]
68
pub struct NetworkConfiguration {
79
pub chain_info: cml_chain::genesis::network_info::NetworkInfo,
810
pub relay: (Cow<'static, str>, u16),
@@ -137,3 +139,47 @@ impl NetworkConfiguration {
137139
}
138140
}
139141
}
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+
}

blockchain-source/src/cardano/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const EPOCH_LENGTH_IN_SECONDS: u64 = 432000;
22
const BYRON_SLOT_DURATION: u64 = 20;
33

4-
#[derive(Debug, Clone, serde::Deserialize)]
4+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
55
pub struct Era {
66
pub first_slot: u64,
77
pub start_epoch: u64,

0 commit comments

Comments
 (0)