Skip to content

Commit

Permalink
fixes from clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
pepoviola committed Sep 11, 2023
1 parent a3a9da5 commit 200361d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 51 deletions.
1 change: 1 addition & 0 deletions crates/examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2021"

[dependencies]
configuration = { path = "../configuration" }
orchestrator = { path = "../orchestrator" }
1 change: 1 addition & 0 deletions crates/examples/examples/small_network_with_default.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use configuration::NetworkConfigBuilder;
use orchestrator::Orchestrator;

fn main() {
let config = NetworkConfigBuilder::new()
Expand Down
6 changes: 3 additions & 3 deletions crates/orchestrator/src/generators/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl ChainSpec {

Self {
build_command: Some(build_command),
chain_name: Some(chain_name.into()),
chain_name: Some(chain_name),
maybe_plain_path: None,
raw_path: None,
}
Expand All @@ -32,13 +32,13 @@ impl ChainSpec {

Self {
build_command: None,
chain_name: Some(chain_name.into()),
chain_name: Some(chain_name),
maybe_plain_path: Some(path.into()),
raw_path: None,
}
}

pub async fn build(&mut self, provider: &impl Provider) -> Result<(), ()> {
pub async fn build(&mut self, _provider: &impl Provider) -> Result<(), ()> {
// create a temp node
todo!()
}
Expand Down
8 changes: 4 additions & 4 deletions crates/orchestrator/src/generators/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::shared::types::{Accounts, NodeAccount};
const KEY_TYPES: [&str; 3] = ["sr", "ed", "ec"];

fn generate<T: Pair>(seed: &str) -> Result<T::Pair, ()> {
let pair = T::Pair::from_string(&seed, None).map_err(|_| ())?;
let pair = T::Pair::from_string(seed, None).map_err(|_| ())?;
Ok(pair)
}

Expand All @@ -15,17 +15,17 @@ pub fn generate_for_node(seed: &str) -> Result<Accounts, GeneratorError> {
// let public = match key {
let (address, public_key) = match key {
"sr" => {
let pair = generate::<sr25519::Pair>(&seed)
let pair = generate::<sr25519::Pair>(seed)
.map_err(|_| GeneratorError::KeyGeneration(key.into(), seed.into()))?;
(pair.public().to_string(), hex::encode(pair.public()))
},
"ed" => {
let pair = generate::<ed25519::Pair>(&seed)
let pair = generate::<ed25519::Pair>(seed)
.map_err(|_| GeneratorError::KeyGeneration(key.into(), seed.into()))?;
(pair.public().to_string(), hex::encode(pair.public()))
},
"ec" => {
let pair = generate::<ecdsa::Pair>(&seed)
let pair = generate::<ecdsa::Pair>(seed)
.map_err(|_| GeneratorError::KeyGeneration(key.into(), seed.into()))?;
(pair.public().to_string(), hex::encode(pair.public()))
},
Expand Down
8 changes: 4 additions & 4 deletions crates/orchestrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ where
pub async fn spawn(&self, network_config: NetworkConfig) -> Result<(), OrchestratorError> {
let global_timeout = network_config.global_settings().network_spawn_timeout();
let network_spec = NetworkSpec::from_config(&network_config).await?;
let r = timeout(

timeout(
Duration::from_secs(global_timeout.into()),
self.spawn_inner(network_spec),
)
.await
.map_err(|_| OrchestratorError::GlobalTimeOut(global_timeout))?;
r
.map_err(|_| OrchestratorError::GlobalTimeOut(global_timeout))?
}

async fn spawn_inner(&self, network_spec: NetworkSpec) -> Result<(), OrchestratorError> {
async fn spawn_inner(&self, _network_spec: NetworkSpec) -> Result<(), OrchestratorError> {
// main dirver for spawn the network

// init provider & create namespace
Expand Down
24 changes: 9 additions & 15 deletions crates/orchestrator/src/network_spec/node.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use configuration::shared::{
node::{EnvVar, NodeConfig},
resources::Resources,
types::{Arg, AssetLocation, Command, Image, Port},
types::{Arg, AssetLocation, Command, Image},
};
use hex;

use multiaddr::Multiaddr;
use sha2::digest::Digest;

Expand Down Expand Up @@ -83,25 +83,19 @@ impl NodeSpec {
let image = if let Some(img) = node_config.image() {
Some(img.clone())
} else {
if let Some(img) = chain_context.default_image {
Some(img.clone())
} else {
None
}
chain_context.default_image.cloned()
};

// Check first if the command is set at node level, then try with the default
let command = if let Some(cmd) = node_config.command() {
cmd.clone()
} else if let Some(cmd) = chain_context.default_command {
cmd.clone()
} else {
if let Some(cmd) = chain_context.default_command {
cmd.clone()
} else {
return Err(OrchestratorError::InvalidNodeConfig(
node_config.name().into(),
"command".to_string(),
));
}
return Err(OrchestratorError::InvalidNodeConfig(
node_config.name().into(),
"command".to_string(),
));
};

// If `args` is set at `node` level use them
Expand Down
24 changes: 11 additions & 13 deletions crates/orchestrator/src/network_spec/parachain.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use configuration::{
shared::types::{Chain, RegistrationStrategy},
shared::types::{RegistrationStrategy},
ParachainConfig,
};

Expand Down Expand Up @@ -29,18 +29,16 @@ impl ParachainSpec {
pub fn from_config(config: &ParachainConfig) -> Result<ParachainSpec, OrchestratorError> {
let main_cmd = if let Some(cmd) = config.default_command() {
cmd
} else {
if let Some(first_node) = config.collators().first() {
let Some(cmd) = first_node.command() else {
return Err(OrchestratorError::InvalidConfig("Parachain, either default_command or command in the first node needs to be set.".to_string()));
};
} else if let Some(first_node) = config.collators().first() {
let Some(cmd) = first_node.command() else {
return Err(OrchestratorError::InvalidConfig("Parachain, either default_command or command in the first node needs to be set.".to_string()));
};

cmd
} else {
return Err(OrchestratorError::InvalidConfig(
"Parachain without nodes and default_command isn't set.".to_string(),
));
}
cmd
} else {
return Err(OrchestratorError::InvalidConfig(
"Parachain without nodes and default_command isn't set.".to_string(),
));
};

let chain_spec = if config.is_cumulus_based() {
Expand Down Expand Up @@ -78,7 +76,7 @@ impl ParachainSpec {
let mut errs: Vec<OrchestratorError> = Default::default();
let mut collators: Vec<NodeSpec> = Default::default();
config.collators().iter().for_each(|node_config| {
match NodeSpec::from_config(&node_config, &chain_context) {
match NodeSpec::from_config(node_config, &chain_context) {
Ok(node) => collators.push(node),
Err(err) => errs.push(err),
}
Expand Down
22 changes: 10 additions & 12 deletions crates/orchestrator/src/network_spec/relaychain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,17 @@ impl RelaychainSpec {
// use the command of the first node.
// If non of those is set, return an error.
let main_cmd = if let Some(cmd) = config.default_command() {
cmd
} else if let Some(first_node) = config.nodes().first() {
let Some(cmd) = first_node.command() else {
return Err(OrchestratorError::InvalidConfig("Relaychain, either default_command or command in the first node needs to be set.".to_string()));
};

cmd
} else {
if let Some(first_node) = config.nodes().first() {
let Some(cmd) = first_node.command() else {
return Err(OrchestratorError::InvalidConfig("Relaychain, either default_command or command in the first node needs to be set.".to_string()));
};

cmd
} else {
return Err(OrchestratorError::InvalidConfig(
"Relaychain without nodes and default_command isn't set.".to_string(),
));
}
return Err(OrchestratorError::InvalidConfig(
"Relaychain without nodes and default_command isn't set.".to_string(),
));
};

let chain_spec = if let Some(chain_spec_path) = config.chain_spec_path() {
Expand All @@ -95,7 +93,7 @@ impl RelaychainSpec {

let mut nodes: Vec<NodeSpec> = Default::default();
config.nodes().iter().for_each(|node_config| {
match NodeSpec::from_config(&node_config, &chain_context) {
match NodeSpec::from_config(node_config, &chain_context) {
Ok(node) => nodes.push(node),
Err(err) => errs.push(err),
}
Expand Down

0 comments on commit 200361d

Please sign in to comment.