11//! Geth call tracer types.
22
33use crate :: parity:: LocalizedTransactionTrace ;
4- use alloy_primitives:: { Address , Bytes , B256 , U256 } ;
4+ use alloy_primitives:: { Address , Bytes , Selector , B256 , U256 } ;
55use serde:: { Deserialize , Serialize } ;
66
77/// The response object for `debug_traceTransaction` with `"tracer": "callTracer"`.
@@ -45,6 +45,21 @@ pub struct CallFrame {
4545 pub typ : String ,
4646}
4747
48+ impl CallFrame {
49+ /// Error selector is the first 4 bytes of calldata
50+ pub fn selector ( & self ) -> Option < Selector > {
51+ if self . input . len ( ) < 4 {
52+ return None ;
53+ }
54+ Some ( Selector :: from_slice ( & self . input [ ..4 ] ) )
55+ }
56+
57+ /// Returns true if this call reverted.
58+ pub const fn is_revert ( & self ) -> bool {
59+ self . revert_reason . is_some ( )
60+ }
61+ }
62+
4863/// Represents a recorded log that is emitted during a trace call.
4964#[ derive( Clone , Debug , Default , PartialEq , Eq , Serialize , Deserialize ) ]
5065pub struct CallLogFrame {
@@ -62,6 +77,23 @@ pub struct CallLogFrame {
6277 pub position : Option < u64 > ,
6378}
6479
80+ impl CallLogFrame {
81+ /// Converts this log frame into a primitives log object
82+ pub fn into_log ( self ) -> alloy_primitives:: Log {
83+ alloy_primitives:: Log :: new_unchecked (
84+ self . address . unwrap_or_default ( ) ,
85+ self . topics . unwrap_or_default ( ) ,
86+ self . data . unwrap_or_default ( ) ,
87+ )
88+ }
89+ }
90+
91+ impl From < CallLogFrame > for alloy_primitives:: Log {
92+ fn from ( value : CallLogFrame ) -> Self {
93+ value. into_log ( )
94+ }
95+ }
96+
6597/// The configuration for the call tracer.
6698#[ derive( Clone , Copy , Debug , Default , PartialEq , Eq , Serialize , Deserialize ) ]
6799#[ serde( rename_all = "camelCase" ) ]
0 commit comments