From edb628e40bc750235ac89577785eefaf1f33328a Mon Sep 17 00:00:00 2001 From: rooooooooob Date: Tue, 6 Aug 2024 22:40:26 -0700 Subject: [PATCH 1/3] NetworkConfiguration JSON Related to dcSpark/carp#187 --- blockchain-source/Cargo.toml | 6 +-- .../src/cardano/configuration.rs | 48 ++++++++++++++++++- blockchain-source/src/cardano/time.rs | 2 +- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/blockchain-source/Cargo.toml b/blockchain-source/Cargo.toml index 607e303..5a48f80 100644 --- a/blockchain-source/Cargo.toml +++ b/blockchain-source/Cargo.toml @@ -23,6 +23,6 @@ serde = { version = "1.0.144" } tokio = { version = "1", features = [ "full" ] } thiserror = { version = "1.0" } tracing = { version = "0.1" } -cml-multi-era = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "8999325933c131af8ac474fe8556e585ca39659c" } -cml-chain = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "8999325933c131af8ac474fe8556e585ca39659c" } -cml-core = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "8999325933c131af8ac474fe8556e585ca39659c" } +cml-multi-era = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "01081ee0a6381cfecf6562c78095e8fb9acf74e3" } +cml-chain = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "01081ee0a6381cfecf6562c78095e8fb9acf74e3" } +cml-core = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "01081ee0a6381cfecf6562c78095e8fb9acf74e3" } diff --git a/blockchain-source/src/cardano/configuration.rs b/blockchain-source/src/cardano/configuration.rs index 62e9819..4f34d9d 100644 --- a/blockchain-source/src/cardano/configuration.rs +++ b/blockchain-source/src/cardano/configuration.rs @@ -2,7 +2,9 @@ use super::{time::Era, Point}; use dcspark_core::{BlockId, SlotNumber}; use std::borrow::Cow; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "snake_case")] +#[serde(deny_unknown_fields)] pub struct NetworkConfiguration { pub chain_info: cml_chain::genesis::network_info::NetworkInfo, pub relay: (Cow<'static, str>, u16), @@ -137,3 +139,47 @@ impl NetworkConfiguration { } } } + +#[cfg(test)] +mod tests { + use super::NetworkConfiguration; + + #[test] + fn custom_json_network() { + println!( + "{}", + deps::serde_json::to_string_pretty(&NetworkConfiguration::mainnet()).unwrap() + ); + let json = r#"{ + "chain_info": { + "network_id": 1, + "protocol_magic": 764824073 + }, + "relay": [ + "relays-new.cardano-mainnet.iohk.io.", + 3001 + ], + "from": { + "BlockHeader": { + "slot_nb": 4492800, + "hash": "aa83acbf5904c0edfe4d79b3689d3d00fcfc553cf360fd2229b98d464c28e9de" + } + }, + "genesis_parent": "5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb", + "genesis": { + "BlockHeader": { + "slot_nb": 0, + "hash": "89d9b5a5b8ddc8d7e5a6795e9774d97faf1efea59b2caf7eaf9f8c5b32059df4" + } + }, + "shelley_era_config": { + "first_slot": 4492800, + "start_epoch": 208, + "known_time": 1596059091, + "slot_length": 1, + "epoch_length_seconds": 432000 + } + }"#; + let _config: NetworkConfiguration = deps::serde_json::from_str(json).unwrap(); + } +} diff --git a/blockchain-source/src/cardano/time.rs b/blockchain-source/src/cardano/time.rs index 68dc94f..436f847 100644 --- a/blockchain-source/src/cardano/time.rs +++ b/blockchain-source/src/cardano/time.rs @@ -1,7 +1,7 @@ const EPOCH_LENGTH_IN_SECONDS: u64 = 432000; const BYRON_SLOT_DURATION: u64 = 20; -#[derive(Debug, Clone, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct Era { pub first_slot: u64, pub start_epoch: u64, From 98c21b8d6c4f72a1c1813eaec3b9ccf1ff67106e Mon Sep 17 00:00:00 2001 From: rooooooooob Date: Tue, 6 Aug 2024 22:44:55 -0700 Subject: [PATCH 2/3] remove json test --- .../src/cardano/configuration.rs | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/blockchain-source/src/cardano/configuration.rs b/blockchain-source/src/cardano/configuration.rs index 4f34d9d..3ad327d 100644 --- a/blockchain-source/src/cardano/configuration.rs +++ b/blockchain-source/src/cardano/configuration.rs @@ -139,47 +139,3 @@ impl NetworkConfiguration { } } } - -#[cfg(test)] -mod tests { - use super::NetworkConfiguration; - - #[test] - fn custom_json_network() { - println!( - "{}", - deps::serde_json::to_string_pretty(&NetworkConfiguration::mainnet()).unwrap() - ); - let json = r#"{ - "chain_info": { - "network_id": 1, - "protocol_magic": 764824073 - }, - "relay": [ - "relays-new.cardano-mainnet.iohk.io.", - 3001 - ], - "from": { - "BlockHeader": { - "slot_nb": 4492800, - "hash": "aa83acbf5904c0edfe4d79b3689d3d00fcfc553cf360fd2229b98d464c28e9de" - } - }, - "genesis_parent": "5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb", - "genesis": { - "BlockHeader": { - "slot_nb": 0, - "hash": "89d9b5a5b8ddc8d7e5a6795e9774d97faf1efea59b2caf7eaf9f8c5b32059df4" - } - }, - "shelley_era_config": { - "first_slot": 4492800, - "start_epoch": 208, - "known_time": 1596059091, - "slot_length": 1, - "epoch_length_seconds": 432000 - } - }"#; - let _config: NetworkConfiguration = deps::serde_json::from_str(json).unwrap(); - } -} From 63105adc46478eea57340bcbfc5425ced0ba139f Mon Sep 17 00:00:00 2001 From: rooooooooob Date: Mon, 26 Aug 2024 19:03:36 -0700 Subject: [PATCH 3/3] Bump CML to 6.0.0 --- blockchain-source/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/blockchain-source/Cargo.toml b/blockchain-source/Cargo.toml index 5a48f80..7b8c24f 100644 --- a/blockchain-source/Cargo.toml +++ b/blockchain-source/Cargo.toml @@ -23,6 +23,6 @@ serde = { version = "1.0.144" } tokio = { version = "1", features = [ "full" ] } thiserror = { version = "1.0" } tracing = { version = "0.1" } -cml-multi-era = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "01081ee0a6381cfecf6562c78095e8fb9acf74e3" } -cml-chain = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "01081ee0a6381cfecf6562c78095e8fb9acf74e3" } -cml-core = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "01081ee0a6381cfecf6562c78095e8fb9acf74e3" } +cml-multi-era = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "25ff92b4f6cf0f5dc98f0df3ab812a23af467e98" } +cml-chain = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "25ff92b4f6cf0f5dc98f0df3ab812a23af467e98" } +cml-core = { git = "https://github.com/dcSpark/cardano-multiplatform-lib", rev = "25ff92b4f6cf0f5dc98f0df3ab812a23af467e98" }