From e279c2100c7ed96685380c05d795be62581fc1c8 Mon Sep 17 00:00:00 2001 From: Roman Petriv Date: Wed, 18 Dec 2024 00:14:11 +0200 Subject: [PATCH] fix: don't print console logs title when no console logs printed (#500) * fix: don't print console logs title when no console logs printed * fix: lint --- crates/core/src/console_log.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/crates/core/src/console_log.rs b/crates/core/src/console_log.rs index d0aac4e5..89cb3807 100644 --- a/crates/core/src/console_log.rs +++ b/crates/core/src/console_log.rs @@ -36,25 +36,33 @@ impl Default for ConsoleLogHandler { impl ConsoleLogHandler { pub fn handle_calls_recursive(&self, calls: &Vec) { - tracing::info!(""); - tracing::info!("==== Console logs: "); - + let mut messages: Vec = vec![]; for call in calls { - self.handle_call_recursive(call); + self.handle_call_recursive(call, &mut messages); + } + + if !messages.is_empty() { + tracing::info!(""); + tracing::info!("==== Console logs: "); + } + for message in messages { + tracing::info!("{}", message.cyan()); } } - pub fn handle_call_recursive(&self, current_call: &Call) { - self.handle_call(current_call); + pub fn handle_call_recursive(&self, current_call: &Call, messages: &mut Vec) { + if let Some(message) = self.handle_call(current_call) { + messages.push(message); + }; for call in ¤t_call.calls { - self.handle_call_recursive(call); + self.handle_call_recursive(call, messages); } } - pub fn handle_call(&self, current_call: &Call) { + pub fn handle_call(&self, current_call: &Call) -> Option { if current_call.to != self.target_contract { - return; + return None; } if current_call.input.len() < 4 { - return; + return None; } let signature = ¤t_call.input[..4]; let message = @@ -67,7 +75,7 @@ impl ConsoleLogHandler { tokens.iter().map(|t| format!("{}", t)).join(" ") }) }); - tracing::info!("{}", message.cyan()); + Some(message) } }