Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
byteshijinn committed Jun 30, 2024
1 parent 2868318 commit 17a6f74
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions crates/cast/bin/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,14 @@ use foundry_cli::{
update_progress,
utils::{generate_local_signatures, handle_traces, TraceResult},
};
use foundry_common::{
compile::ProjectCompiler, fs, is_known_system_sender, SYSTEM_TRANSACTION_TYPE,
};
use foundry_common::{compile::ProjectCompiler, is_known_system_sender, SYSTEM_TRANSACTION_TYPE};
use foundry_compilers::EvmVersion;
use foundry_config::{find_project_root_path, Config};
use foundry_evm::{
executors::{EvmError, TracingExecutor},
opts::EvmOpts,
utils::configure_tx_env,
};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

#[derive(Debug, Default, Serialize, Deserialize)]
struct CachedSignatures {
events: BTreeMap<String, String>,
functions: BTreeMap<String, String>,
}

/// CLI arguments for `cast run`.
#[derive(Clone, Debug, Parser)]
Expand Down Expand Up @@ -84,7 +74,11 @@ pub struct RunArgs {
#[arg(long, value_name = "NO_RATE_LIMITS", visible_alias = "no-rpc-rate-limit")]
pub no_rate_limit: bool,

#[arg(long, short, alias = "gs")]
/// If generate a file with the signatures of the functions and events of the project.
/// The file will be saved in the foundry cache directory.
///
/// default value: false
#[arg(long, short = 'G', visible_alias = "gs")]
pub generate_local_signatures: bool,
}

Expand Down Expand Up @@ -233,25 +227,13 @@ impl RunArgs {
if self.generate_local_signatures {
let project = config.project()?;
let compiler = ProjectCompiler::new().quiet(true);
let out = compiler.compile(&project)?;
let mut cached_signatures = CachedSignatures::default();
out.artifacts().for_each(|(_, artifact)| {
if let Some(abi) = &artifact.abi {
for func in abi.functions() {
cached_signatures
.functions
.insert(func.selector().to_string(), func.signature());
}
for event in abi.events() {
cached_signatures
.events
.insert(event.selector().to_string(), event.full_signature());
}
}
});
let path = Config::foundry_cache_dir().unwrap().join("signatures");
if path.is_file() {
let _ = fs::write_json_file(&path, &cached_signatures);
let output = compiler.compile(&project)?;
if let Err(err) =
generate_local_signatures(&output, Config::foundry_cache_dir().unwrap())
{
warn!(target: "cast::run", ?err, "failed to flush signature cache");
} else {
trace!(target: "cast::run", "flushed signature cache")
}
}

Expand Down

0 comments on commit 17a6f74

Please sign in to comment.