Skip to content

Commit

Permalink
Merge pull request #73 from flashbots/feature/report-file-default-save
Browse files Browse the repository at this point in the history
save default file on report
  • Loading branch information
zeroXbrock authored Jan 8, 2025
2 parents f47bf5f + fa66bc6 commit c364e1b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
cargotest.toml
*.db
report.csv
10 changes: 10 additions & 0 deletions crates/cli/src/commands/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,20 @@ pub fn report(
let mut writer = WriterBuilder::new().has_headers(true).from_path(out_file)?;
write_run_txs(&mut writer, &txs)?;
} else {
// print to stdout and write to default file
let mut writer = WriterBuilder::new()
.has_headers(true)
.from_writer(std::io::stdout());
write_run_txs(&mut writer, &txs)?; // TODO: write a macro that lets us generalize the writer param to write_run_txs, then refactor this duplication
let home_dir = std::env::var("HOME").expect("Could not get home directory");
let contender_dir = format!("{}/.contender", home_dir);
std::fs::create_dir_all(&contender_dir)?;
let report_path = format!("{}/report.csv", contender_dir);
let mut writer = WriterBuilder::new()
.has_headers(true)
.from_path(&report_path)?;
write_run_txs(&mut writer, &txs)?;
println!("saved report to {}", report_path);
};

Ok(())
Expand Down
10 changes: 9 additions & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ use contender_core::{db::DbOps, generator::RandSeed};
use contender_sqlite::SqliteDb;

static DB: LazyLock<SqliteDb> = std::sync::LazyLock::new(|| {
SqliteDb::from_file("contender.db").expect("failed to open contender.db")
let path = &format!(
"{}{}",
std::env::var("HOME").unwrap(),
"/.contender/contender.db"
);
println!("opening DB at {}", path);
std::fs::create_dir_all(std::env::var("HOME").unwrap() + "/.contender")
.expect("failed to create ~/.contender directory");
SqliteDb::from_file(path).expect("failed to open contender DB file")
});

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/spammer/tx_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ where
}
RunTx {
tx_hash: pending_tx.tx_hash,
start_timestamp: pending_tx.start_timestamp,
start_timestamp: pending_tx.start_timestamp / 1000,
end_timestamp: target_block.header.timestamp as usize,
block_number: target_block.header.number,
gas_used: receipt.gas_used,
Expand Down

0 comments on commit c364e1b

Please sign in to comment.