1
1
//! Geth call tracer types.
2
2
3
3
use crate :: parity:: LocalizedTransactionTrace ;
4
- use alloy_primitives:: { Address , Bytes , B256 , U256 } ;
4
+ use alloy_primitives:: { Address , Bytes , Selector , B256 , U256 } ;
5
5
use serde:: { Deserialize , Serialize } ;
6
6
7
7
/// The response object for `debug_traceTransaction` with `"tracer": "callTracer"`.
@@ -45,6 +45,21 @@ pub struct CallFrame {
45
45
pub typ : String ,
46
46
}
47
47
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
+
48
63
/// Represents a recorded log that is emitted during a trace call.
49
64
#[ derive( Clone , Debug , Default , PartialEq , Eq , Serialize , Deserialize ) ]
50
65
pub struct CallLogFrame {
@@ -62,6 +77,23 @@ pub struct CallLogFrame {
62
77
pub position : Option < u64 > ,
63
78
}
64
79
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
+
65
97
/// The configuration for the call tracer.
66
98
#[ derive( Clone , Copy , Debug , Default , PartialEq , Eq , Serialize , Deserialize ) ]
67
99
#[ serde( rename_all = "camelCase" ) ]
0 commit comments