Skip to content

Commit

Permalink
Merge pull request #22 from primitivefinance/patch
Browse files Browse the repository at this point in the history
fix issue
  • Loading branch information
0xJepsen authored Nov 21, 2023
2 parents e19bfc3 + f747af3 commit ec6f0c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
42 changes: 23 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
fs::{self, DirEntry},
time::Instant,
};
use std::time::Instant;

use anyhow::Result;
use clap::{ArgAction, CommandFactory, Parser, Subcommand};
Expand All @@ -13,7 +10,7 @@ pub mod simulations;

/// Represents command-line arguments passed to this binary.
#[derive(Parser)]
#[clap(name = "Excalibur")]
#[clap(name = "Template")]
#[clap(version = env!("CARGO_PKG_VERSION"))]
#[clap(about = "Simulation driven development.", long_about = None)]
#[clap(author)]
Expand Down Expand Up @@ -53,17 +50,20 @@ enum Commands {
/// By default, if no configuration path is provided, it will read from "src/config/".
///
/// These simulations are performed in Arbiter's in memory revm instance and with the exposed RevmMiddleware.
fn main() -> Result<()> {
#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();

match &args.command {
Some(Commands::Simulate { config_path }) => {
println!("Reading from config path: {}", config_path);
let start = Instant::now();
// This is the entry point for the simulation
let files = read_toml_files(config_path)?;
let files = read_toml_file(config_path)?;
println!("files: {:?}", files);
simulations::batch(files)?;
let simulation = settings::SimulationConfig::new(files.clone())?;
println!("simulation: {:?}", simulation);
simulations::SimulationType::run(simulation).await.unwrap();
let duration = start.elapsed();
println!("Total duration of simulations: {:?}", duration);
}
Expand All @@ -72,17 +72,21 @@ fn main() -> Result<()> {
Ok(())
}

// Function to read .toml files from a directory and return their paths
fn read_toml_files(dir: &str) -> Result<Vec<String>, std::io::Error> {
let paths = fs::read_dir(dir)?
.filter_map(Result::ok)
.filter(is_toml_file)
.map(|entry| entry.path().to_string_lossy().into_owned())
.collect();
Ok(paths)
// Function to read a .toml file and return its path
fn read_toml_file(file: &str) -> Result<String, std::io::Error> {
if is_toml_file(file) {
Ok(file.to_string())
} else {
Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Not a TOML file",
))
}
}

// Helper function to check if a DirEntry is a .toml file
fn is_toml_file(entry: &DirEntry) -> bool {
entry.path().extension().map_or(false, |ext| ext == "toml")
// Helper function to check if a file is a .toml file
fn is_toml_file(file: &str) -> bool {
std::path::Path::new(file)
.extension()
.map_or(false, |ext| ext == "toml")
}
2 changes: 1 addition & 1 deletion src/simulations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl SimulationType {
///
/// This function matches on the `SimulationType` to determine which simulation setup to use,
/// then executes the chosen simulation.
async fn run(config: SimulationConfig) -> Result<()> {
pub async fn run(config: SimulationConfig) -> Result<()> {
let simulation = match config.simulation {
SimulationType::SimulatedPricePath => {
price_path_simulation::setup(config.clone()).await?
Expand Down

0 comments on commit ec6f0c9

Please sign in to comment.