@@ -350,8 +350,7 @@ impl CallTraceDecoder {
350
350
return DecodedCallTrace {
351
351
label,
352
352
call_data : Some ( DecodedCallData { signature : "create2" . to_string ( ) , args : vec ! [ ] } ) ,
353
- return_data : ( !trace. status . is_ok ( ) )
354
- . then ( || self . revert_decoder . decode ( & trace. output , Some ( trace. status ) ) ) ,
353
+ return_data : self . default_return_data ( trace) ,
355
354
} ;
356
355
}
357
356
@@ -372,7 +371,11 @@ impl CallTraceDecoder {
372
371
}
373
372
} ;
374
373
let [ func, ..] = & functions[ ..] else {
375
- return DecodedCallTrace { label, call_data : None , return_data : None } ;
374
+ return DecodedCallTrace {
375
+ label,
376
+ call_data : None ,
377
+ return_data : self . default_return_data ( trace) ,
378
+ } ;
376
379
} ;
377
380
378
381
DecodedCallTrace {
@@ -388,11 +391,7 @@ impl CallTraceDecoder {
388
391
DecodedCallTrace {
389
392
label,
390
393
call_data : Some ( DecodedCallData { signature, args } ) ,
391
- return_data : if !trace. success {
392
- Some ( self . revert_decoder . decode ( & trace. output , Some ( trace. status ) ) )
393
- } else {
394
- None
395
- } ,
394
+ return_data : self . default_return_data ( trace) ,
396
395
}
397
396
}
398
397
}
@@ -410,7 +409,7 @@ impl CallTraceDecoder {
410
409
411
410
if args. is_none ( ) {
412
411
if let Ok ( v) = func. abi_decode_input ( & trace. data [ SELECTOR_LEN ..] , false ) {
413
- args = Some ( v. iter ( ) . map ( |value| self . apply_label ( value) ) . collect ( ) ) ;
412
+ args = Some ( v. iter ( ) . map ( |value| self . format_value ( value) ) . collect ( ) ) ;
414
413
}
415
414
}
416
415
}
@@ -523,34 +522,32 @@ impl CallTraceDecoder {
523
522
524
523
/// Decodes a function's output into the given trace.
525
524
fn decode_function_output ( & self , trace : & CallTrace , funcs : & [ Function ] ) -> Option < String > {
526
- let data = & trace. output ;
527
- if trace. success {
528
- if trace. address == CHEATCODE_ADDRESS {
529
- if let Some ( decoded) =
530
- funcs. iter ( ) . find_map ( |func| self . decode_cheatcode_outputs ( func) )
531
- {
532
- return Some ( decoded) ;
533
- }
534
- }
525
+ if !trace. success {
526
+ return self . default_return_data ( trace) ;
527
+ }
535
528
536
- if let Some ( values ) =
537
- funcs. iter ( ) . find_map ( |func| func . abi_decode_output ( data , false ) . ok ( ) )
529
+ if trace . address == CHEATCODE_ADDRESS {
530
+ if let Some ( decoded ) = funcs. iter ( ) . find_map ( |func| self . decode_cheatcode_outputs ( func ) )
538
531
{
539
- // Functions coming from an external database do not have any outputs specified,
540
- // and will lead to returning an empty list of values.
541
- if values. is_empty ( ) {
542
- return None ;
543
- }
532
+ return Some ( decoded) ;
533
+ }
534
+ }
544
535
545
- return Some (
546
- values. iter ( ) . map ( |value| self . apply_label ( value) ) . format ( ", " ) . to_string ( ) ,
547
- ) ;
536
+ if let Some ( values) =
537
+ funcs. iter ( ) . find_map ( |func| func. abi_decode_output ( & trace. output , false ) . ok ( ) )
538
+ {
539
+ // Functions coming from an external database do not have any outputs specified,
540
+ // and will lead to returning an empty list of values.
541
+ if values. is_empty ( ) {
542
+ return None ;
548
543
}
549
544
550
- None
551
- } else {
552
- Some ( self . revert_decoder . decode ( data , Some ( trace . status ) ) )
545
+ return Some (
546
+ values . iter ( ) . map ( |value| self . format_value ( value ) ) . format ( ", " ) . to_string ( ) ,
547
+ ) ;
553
548
}
549
+
550
+ None
554
551
}
555
552
556
553
/// Custom decoding for cheatcode outputs.
@@ -566,6 +563,11 @@ impl CallTraceDecoder {
566
563
. map ( Into :: into)
567
564
}
568
565
566
+ /// The default decoded return data for a trace.
567
+ fn default_return_data ( & self , trace : & CallTrace ) -> Option < String > {
568
+ ( !trace. success ) . then ( || self . revert_decoder . decode ( & trace. output , Some ( trace. status ) ) )
569
+ }
570
+
569
571
/// Decodes an event.
570
572
pub async fn decode_event ( & self , log : & LogData ) -> DecodedCallLog {
571
573
let & [ t0, ..] = log. topics ( ) else { return DecodedCallLog { name : None , params : None } } ;
@@ -594,7 +596,7 @@ impl CallTraceDecoder {
594
596
. map ( |( param, input) | {
595
597
// undo patched names
596
598
let name = input. name . clone ( ) ;
597
- ( name, self . apply_label ( & param) )
599
+ ( name, self . format_value ( & param) )
598
600
} )
599
601
. collect ( ) ,
600
602
) ,
@@ -628,7 +630,8 @@ impl CallTraceDecoder {
628
630
identifier. write ( ) . await . identify_functions ( funcs_it) . await ;
629
631
}
630
632
631
- fn apply_label ( & self , value : & DynSolValue ) -> String {
633
+ /// Pretty-prints a value.
634
+ fn format_value ( & self , value : & DynSolValue ) -> String {
632
635
if let DynSolValue :: Address ( addr) = value {
633
636
if let Some ( label) = self . labels . get ( addr) {
634
637
return format ! ( "{label}: [{addr}]" ) ;
0 commit comments