Skip to content

Commit 03c2028

Browse files
authored
fix(anvil): correctly print logs (#8642)
1 parent 77158cc commit 03c2028

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

crates/anvil/src/eth/backend/mem/inspector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Inspector {
4141
self
4242
}
4343

44-
pub fn with_config(mut self, config: TracingInspectorConfig) -> Self {
44+
pub fn with_tracing_config(mut self, config: TracingInspectorConfig) -> Self {
4545
self.tracer = Some(TracingInspector::new(config));
4646
self
4747
}

crates/anvil/src/eth/backend/mem/mod.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ impl Backend {
851851
}
852852

853853
let db = self.db.read().await;
854-
let mut inspector = Inspector::default();
854+
let mut inspector = self.build_inspector();
855855
let mut evm = self.new_evm_with_inspector_ref(&**db, env, &mut inspector);
856856
let ResultAndState { result, state } = evm.transact()?;
857857
let (exit_reason, gas_used, out, logs) = match result {
@@ -1200,6 +1200,17 @@ impl Backend {
12001200
env
12011201
}
12021202

1203+
/// Builds [`Inspector`] with the configured options
1204+
fn build_inspector(&self) -> Inspector {
1205+
let mut inspector = Inspector::default();
1206+
1207+
if self.print_logs {
1208+
inspector = inspector.with_log_collector();
1209+
}
1210+
1211+
inspector
1212+
}
1213+
12031214
pub fn call_with_state<D>(
12041215
&self,
12051216
state: D,
@@ -1210,7 +1221,7 @@ impl Backend {
12101221
where
12111222
D: DatabaseRef<Error = DatabaseError>,
12121223
{
1213-
let mut inspector = Inspector::default();
1224+
let mut inspector = self.build_inspector();
12141225

12151226
let env = self.build_call_env(request, fee_details, block_env);
12161227
let mut evm = self.new_evm_with_inspector_ref(state, env, &mut inspector);
@@ -1251,7 +1262,7 @@ impl Backend {
12511262
.into_call_config()
12521263
.map_err(|e| (RpcError::invalid_params(e.to_string())))?;
12531264

1254-
let mut inspector = Inspector::default().with_config(
1265+
let mut inspector = self.build_inspector().with_tracing_config(
12551266
TracingInspectorConfig::from_geth_call_config(&call_config),
12561267
);
12571268

@@ -1283,8 +1294,9 @@ impl Backend {
12831294
}
12841295

12851296
// defaults to StructLog tracer used since no tracer is specified
1286-
let mut inspector =
1287-
Inspector::default().with_config(TracingInspectorConfig::from_geth_config(&config));
1297+
let mut inspector = self
1298+
.build_inspector()
1299+
.with_tracing_config(TracingInspectorConfig::from_geth_config(&config));
12881300

12891301
let env = self.build_call_env(request, fee_details, block);
12901302
let mut evm = self.new_evm_with_inspector_ref(state, env, &mut inspector);

0 commit comments

Comments
 (0)