Skip to content

Commit 1ab5e45

Browse files
rootroot
authored andcommitted
fixup! refactor: move parsing into its own module
1 parent f1af8bb commit 1ab5e45

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

sim-cli/src/lib.rs

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub mod parsing;
1+
pub mod parsing;

sim-cli/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
use clap::Parser;
12
use log::LevelFilter;
3+
use sim_cli::parsing::{create_simulation, Cli};
24
use simple_logger::SimpleLogger;
3-
use sim_cli::parsing::{Cli, create_simulation};
4-
use clap::Parser;
5-
65

76
#[tokio::main]
87
async fn main() -> anyhow::Result<()> {
@@ -32,4 +31,4 @@ async fn main() -> anyhow::Result<()> {
3231
sim.run().await?;
3332

3433
Ok(())
35-
}
34+
}

sim-cli/src/parsing.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
use bitcoin::secp256k1::PublicKey;
21
use anyhow::anyhow;
2+
use bitcoin::secp256k1::PublicKey;
33
use clap::{builder::TypedValueParser, Parser};
4-
use std::path::PathBuf;
4+
use log::LevelFilter;
55
use serde::{Deserialize, Serialize};
66
use simln_lib::{
7-
Amount, Interval, cln, lnd, serializers, NodeId, SimulationCfg, Simulation, WriteResults, LightningError, LightningNode,
8-
cln::ClnNode, lnd::LndNode, ActivityDefinition, NodeInfo
7+
cln, cln::ClnNode, lnd, lnd::LndNode, serializers, ActivityDefinition, Amount, Interval,
8+
LightningError, LightningNode, NodeId, NodeInfo, Simulation, SimulationCfg, WriteResults,
99
};
10-
use log::LevelFilter;
11-
use std::sync::Arc;
10+
use std::collections::HashMap;
1211
use std::fs;
12+
use std::path::PathBuf;
13+
use std::sync::Arc;
1314
use tokio::sync::Mutex;
14-
use std::collections::HashMap;
1515

1616
/// The default directory where the simulation files are stored and where the results will be written to.
1717
pub const DEFAULT_DATA_DIR: &str = ".";
@@ -138,10 +138,7 @@ impl TryFrom<&Cli> for SimulationCfg {
138138

139139
/// Parses the cli options provided and creates a simulation to be run, connecting to lightning nodes and validating
140140
/// any activity described in the simulation file.
141-
pub async fn create_simulation(
142-
cli: &Cli,
143-
) -> Result<Simulation, anyhow::Error> {
144-
141+
pub async fn create_simulation(cli: &Cli) -> Result<Simulation, anyhow::Error> {
145142
let cfg: SimulationCfg = SimulationCfg::try_from(cli)?;
146143

147144
let sim_path = read_sim_path(cli.data_dir.clone(), cli.sim_file.clone()).await?;
@@ -168,12 +165,8 @@ pub async fn create_simulation(
168165
))
169166
};
170167

171-
let validated_activities = validate_activities(
172-
activity,
173-
&clients_info,
174-
get_node
175-
).await?;
176-
168+
let validated_activities = validate_activities(activity, &clients_info, get_node).await?;
169+
177170
Ok(Simulation::new(cfg, clients, validated_activities))
178171
}
179172

@@ -212,7 +205,7 @@ async fn get_clients(
212205
/// Adds a lightning node to a client map and tracking maps used to lookup node pubkeys and aliases for activity
213206
/// validation.
214207
async fn add_node_to_maps(
215-
nodes: &HashMap<PublicKey, NodeInfo>
208+
nodes: &HashMap<PublicKey, NodeInfo>,
216209
) -> Result<(HashMap<PublicKey, NodeInfo>, HashMap<String, NodeInfo>), LightningError> {
217210
let mut pk_node_map = HashMap::new();
218211
let mut alias_node_map = HashMap::new();
@@ -255,10 +248,6 @@ async fn validate_activities(
255248
nodes: &HashMap<PublicKey, NodeInfo>,
256249
get_node_info: impl AsyncFn(&PublicKey) -> Result<NodeInfo, LightningError>,
257250
) -> Result<Vec<ActivityDefinition>, LightningError> {
258-
if activity.is_empty() {
259-
return Ok(vec![]);
260-
}
261-
262251
let mut validated_activities = vec![];
263252
let (pk_node_map, alias_node_map) = add_node_to_maps(nodes).await?;
264253

simln-lib/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ impl std::fmt::Display for ShortChannelID {
119119
}
120120
}
121121

122-
123122
/// Either a value or a range parsed from the simulation file.
124123
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
125124
#[serde(untagged)]

0 commit comments

Comments
 (0)