diff --git a/crates/configuration/src/network.rs b/crates/configuration/src/network.rs index 505169eb29183183ec1ec414974dfc7f18778cd6..6f13de6adf5179c67aac116b786228f1762e7cdd 100644 --- a/crates/configuration/src/network.rs +++ b/crates/configuration/src/network.rs @@ -67,7 +67,7 @@ impl NetworkConfig { let file_str = fs::read_to_string(path).expect(&format!("{} {}", RW_FAILED, THIS_IS_A_BUG)); let re: Regex = Regex::new(r"(?<field_name>(initial_)?balance)\s+=\s+(?<u128_value>\d+)") .expect(&format!("{} {}", VALID_REGEX, THIS_IS_A_BUG)); - let mut network_config: NetworkConfig = toml::from_str( + let network_config: NetworkConfig = toml::from_str( re.replace_all(&file_str, "$field_name = \"$u128_value\"") .as_ref(), )?; @@ -142,7 +142,7 @@ impl NetworkConfig { if node.args().is_empty() { node.set_args(default_args.clone()); - node.chain_context.set_default_args(default_args.clone()) + node.chain_context.default_args = default_args.clone() } } diff --git a/crates/configuration/src/parachain.rs b/crates/configuration/src/parachain.rs index 7324d0fda409aa62f5ce23f7ebf3d8b54136405f..d8e1f486789573e66c6c37cd0f34bc6a14b76785 100644 --- a/crates/configuration/src/parachain.rs +++ b/crates/configuration/src/parachain.rs @@ -218,33 +218,13 @@ impl<A> ParachainConfigBuilder<A> { } fn default_chain_context(&self) -> ChainDefaultContext { - let mut chain_default = ChainDefaultContext::default(); - chain_default.set_default_command( - self.config - .default_command() - .cloned() - .expect("default command should be set"), - ); - chain_default.set_default_image( - self.config - .default_image() - .cloned() - .expect("default image should be set"), - ); - chain_default.set_default_resouces( - self.config - .default_resources - .clone() - .expect("default resources should be set"), - ); - chain_default.set_default_db_snapshot( - self.config - .default_db_snapshot - .clone() - .expect("default db snapshot should be set"), - ); - chain_default.set_default_args(self.config.default_args().into_iter().cloned().collect()); - chain_default + ChainDefaultContext { + default_command: self.config.default_command.clone(), + default_image: self.config.default_image.clone(), + default_resources: self.config.default_resources.clone(), + default_db_snapshot: self.config.default_db_snapshot.clone(), + default_args: self.config.default_args().into_iter().cloned().collect(), + } } } diff --git a/crates/configuration/src/relaychain.rs b/crates/configuration/src/relaychain.rs index b6b9cdb25b2d9e9acf2447a117239a9819009a54..ce35c8233bf63c1f97a06b0b72d107aeca215324 100644 --- a/crates/configuration/src/relaychain.rs +++ b/crates/configuration/src/relaychain.rs @@ -59,10 +59,10 @@ impl RelaychainConfig { self.default_args.iter().collect::<Vec<&Arg>>() } - // /// Set the default arguments that will be used to launch the node command. - // pub(crate) fn set_default_args(&mut self, args: Vec<Arg>) { - // self.default_args = args; - // } + /// Set the default arguments that will be used to launch the node command. + pub(crate) fn set_default_args(&mut self, args: Vec<Arg>) { + self.default_args = args; + } /// The location of an pre-existing chain specification for the relay chain. pub fn chain_spec_path(&self) -> Option<&AssetLocation> { @@ -84,10 +84,10 @@ impl RelaychainConfig { self.nodes.iter().collect::<Vec<&NodeConfig>>() } - // /// The nodes of the relay chain. - // pub(crate) fn set_nodes(&mut self, nodes: Vec<NodeConfig>) { - // self.nodes = nodes; - // } + /// The nodes of the relay chain. + pub(crate) fn set_nodes(&mut self, nodes: Vec<NodeConfig>) { + self.nodes = nodes; + } } states! { @@ -145,31 +145,11 @@ impl<A> RelaychainConfigBuilder<A> { fn default_chain_context(&self) -> ChainDefaultContext { let mut chain_default = ChainDefaultContext::default(); - chain_default.set_default_command( - self.config - .default_command() - .cloned() - .expect("default command should be set"), - ); - chain_default.set_default_image( - self.config - .default_image() - .cloned() - .expect("default image should be set"), - ); - chain_default.set_default_resouces( - self.config - .default_resources - .clone() - .expect("default resources should be set"), - ); - chain_default.set_default_db_snapshot( - self.config - .default_db_snapshot - .clone() - .expect("default db snapshot should be set"), - ); - chain_default.set_default_args(self.config.default_args().into_iter().cloned().collect()); + chain_default.default_command = self.config.default_command().cloned(); + chain_default.default_image = self.config.default_image().cloned(); + chain_default.default_resources = self.config.default_resources.clone(); + chain_default.default_db_snapshot = self.config.default_db_snapshot.clone(); + chain_default.default_args = self.config.default_args().into_iter().cloned().collect(); chain_default } } diff --git a/crates/configuration/src/shared/node.rs b/crates/configuration/src/shared/node.rs index 4a626e4e291ea6fdc21ff99f5c200f0b05a1dea2..46225d81d04f959ab32b574f55d88f9def5ae5f4 100644 --- a/crates/configuration/src/shared/node.rs +++ b/crates/configuration/src/shared/node.rs @@ -92,19 +92,19 @@ impl Serialize for NodeConfig { let mut state = serializer.serialize_struct("NodeConfig", 18)?; state.serialize_field("name", &self.name)?; - if self.image == self.chain_context.default_image().cloned() { + if self.image == self.chain_context.default_image { state.skip_field("image")?; } else { state.serialize_field("image", &self.image)?; } - if self.command == self.chain_context.default_command().cloned() { + if self.command == self.chain_context.default_command { state.skip_field("command")?; } else { state.serialize_field("command", &self.command)?; } - if self.args.is_empty() || self.args() == self.chain_context.default_args() { + if self.args.is_empty() || self.args() == self.chain_context.default_args.iter().collect::<Vec<&Arg>>() { state.skip_field("args")?; } else { state.serialize_field("args", &self.args)?; @@ -127,7 +127,7 @@ impl Serialize for NodeConfig { state.serialize_field("bootnodes_addresses", &self.bootnodes_addresses)?; } - if self.resources == self.chain_context.default_resources().cloned() { + if self.resources == self.chain_context.default_resources { state.skip_field("resources")?; } else { state.serialize_field("resources", &self.resources)?; @@ -139,7 +139,7 @@ impl Serialize for NodeConfig { state.serialize_field("p2p_port", &self.p2p_port)?; state.serialize_field("p2p_cert_hash", &self.p2p_cert_hash)?; - if self.db_snapshot == self.chain_context.default_db_snapshot().cloned() { + if self.db_snapshot == self.chain_context.default_db_snapshot { state.skip_field("db_snapshot")?; } else { state.serialize_field("db_snapshot", &self.db_snapshot)?; @@ -342,11 +342,11 @@ impl NodeConfigBuilder<Initial> { ) -> Self { Self::transition( NodeConfig { - command: chain_context.default_command().cloned(), - image: chain_context.default_image().cloned(), - resources: chain_context.default_resources().cloned(), - db_snapshot: chain_context.default_db_snapshot().cloned(), - args: chain_context.default_args().into_iter().cloned().collect(), + command: chain_context.default_command.clone(), + image: chain_context.default_image.clone(), + resources: chain_context.default_resources.clone(), + db_snapshot: chain_context.default_db_snapshot.clone(), + args: chain_context.default_args.clone(), chain_context, ..Self::default().config }, diff --git a/crates/configuration/src/shared/types.rs b/crates/configuration/src/shared/types.rs index 39241ae6243f4e7e01c77c65c9b9de28078deb9b..a9faf73bc8a8d9a9018a67bfbbce39e8eaf63bab 100644 --- a/crates/configuration/src/shared/types.rs +++ b/crates/configuration/src/shared/types.rs @@ -364,60 +364,12 @@ pub struct ValidationContext { #[derive(Default, Debug, Clone, PartialEq, Deserialize)] pub struct ChainDefaultContext { - default_command: Option<Command>, - default_image: Option<Image>, - default_resources: Option<Resources>, - default_db_snapshot: Option<AssetLocation>, + pub(crate) default_command: Option<Command>, + pub(crate) default_image: Option<Image>, + pub(crate) default_resources: Option<Resources>, + pub(crate) default_db_snapshot: Option<AssetLocation>, #[serde(default)] - default_args: Vec<Arg>, -} - -impl ChainDefaultContext { - /// The default command used for nodes. - pub(crate) fn default_command(&self) -> Option<&Command> { - self.default_command.as_ref() - } - - pub(crate) fn set_default_command(&mut self, command: Command) { - self.default_command = Some(command); - } - - /// The default container image used for nodes. - pub(crate) fn default_image(&self) -> Option<&Image> { - self.default_image.as_ref() - } - - pub(crate) fn set_default_image(&mut self, image: Image) { - self.default_image = Some(image); - } - - /// The default resources limits used for nodes. - pub(crate) fn default_resources(&self) -> Option<&Resources> { - self.default_resources.as_ref() - } - - pub(crate) fn set_default_resouces(&mut self, resources: Resources) { - self.default_resources = Some(resources); - } - - /// The default database snapshot location that will be used for state. - pub(crate) fn default_db_snapshot(&self) -> Option<&AssetLocation> { - self.default_db_snapshot.as_ref() - } - - pub(crate) fn set_default_db_snapshot(&mut self, db_snapshot: AssetLocation) { - self.default_db_snapshot = Some(db_snapshot); - } - - /// The default arguments that will be used from the ChainDefaultContext - pub(crate) fn default_args(&self) -> Vec<&Arg> { - self.default_args.iter().collect::<Vec<&Arg>>() - } - - /// Set the default arguments - pub(crate) fn set_default_args(&mut self, args: Vec<Arg>) { - self.default_args = args; - } + pub(crate) default_args: Vec<Arg>, } #[cfg(test)] diff --git a/crates/examples/examples/small_network.rs b/crates/examples/examples/small_network.rs index bb44ece6e7b024e663387d196237b1dd9d3bc597..5909267837ea7aa0757d18bd9d4ea5b776459a32 100644 --- a/crates/examples/examples/small_network.rs +++ b/crates/examples/examples/small_network.rs @@ -1,4 +1,4 @@ -use configuration::NetworkConfigBuilder; +use configuration::{NetworkConfigBuilder, ParachainConfigBuilder}; fn main() { let config = NetworkConfigBuilder::new() @@ -8,5 +8,10 @@ fn main() { }) .build(); - println!("{:?}", config.unwrap()); + println!("{:?}", config.unwrap().parachains() ); + + for parachain in config.unwrap().parachains() { + let builder = ParachainConfigBuilder::new(Default::default()); + println!("{:?}", parachain.chain_context().name() ); + } }