Skip to content

Commit

Permalink
Add default contracts events and functions to decoder by default
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Dec 6, 2023
1 parent dcf25ff commit 8075269
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions crates/evm/traces/src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ impl CallTraceDecoderBuilder {
self
}

/// Add known functions to the decoder.
#[inline]
pub fn with_functions(mut self, functions: impl IntoIterator<Item = Function>) -> Self {
for function in functions {
self.decoder.functions.entry(function.selector()).or_default().push(function);
}
self
}

/// Add known events to the decoder.
#[inline]
pub fn with_events(mut self, events: impl IntoIterator<Item = Event>) -> Self {
Expand Down
7 changes: 6 additions & 1 deletion crates/evm/traces/src/identifier/local.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{AddressIdentity, TraceIdentifier};
use alloy_json_abi::Event;
use alloy_json_abi::{Event, Function};
use alloy_primitives::Address;
use foundry_common::contracts::{diff_score, ContractsByArtifact};
use ordered_float::OrderedFloat;
Expand All @@ -15,6 +15,11 @@ impl<'a> LocalTraceIdentifier<'a> {
Self { known_contracts }
}

/// Get all the functions of the local contracts.
pub fn functions(&self) -> impl Iterator<Item = &Function> {
self.known_contracts.iter().flat_map(|(_, (abi, _))| abi.functions())
}

/// Get all the events of the local contracts.
pub fn events(&self) -> impl Iterator<Item = &Event> {
self.known_contracts.iter().flat_map(|(_, (abi, _))| abi.events())
Expand Down
2 changes: 2 additions & 0 deletions crates/forge/bin/cmd/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ impl ScriptArgs {
let mut decoder = CallTraceDecoderBuilder::new()
.with_labels(result.labeled_addresses.clone())
.with_verbosity(verbosity)
.with_events(local_identifier.events().cloned())
.with_functions(local_identifier.functions().cloned())
.with_signature_identifier(SignaturesIdentifier::new(
Config::foundry_cache_dir(),
script_config.config.offline,
Expand Down
2 changes: 2 additions & 0 deletions crates/forge/bin/cmd/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl TestArgs {
let mut builder = CallTraceDecoderBuilder::new()
.with_labels(result.labeled_addresses.clone())
.with_events(local_identifier.events().cloned())
.with_functions(local_identifier.functions().cloned())
.with_verbosity(verbosity);

// Signatures are of no value for gas reports
Expand Down Expand Up @@ -692,6 +693,7 @@ async fn test(
let mut builder = CallTraceDecoderBuilder::new()
.with_labels(result.labeled_addresses.iter().map(|(a, s)| (*a, s.clone())))
.with_events(local_identifier.events().cloned())
.with_functions(local_identifier.functions().cloned())
.with_verbosity(verbosity);

// Signatures are of no value for gas reports
Expand Down

0 comments on commit 8075269

Please sign in to comment.