@@ -34,3 +34,150 @@ fn get_call_trace() -> CallTrace {
34
34
let mut output = cheatcode :: <' get_call_trace' >(array! []. span ());
35
35
Serde :: deserialize (ref output ). unwrap ()
36
36
}
37
+
38
+ use core :: fmt :: {Display , Formatter , Error , Debug };
39
+
40
+ impl DisplayEntryPointType of Display <EntryPointType > {
41
+ fn fmt (self : @ EntryPointType , ref f : Formatter ) -> Result <(), Error > {
42
+ let str : ByteArray = match self {
43
+ EntryPointType :: Constructor => " Constructor" ,
44
+ EntryPointType :: External => " External" ,
45
+ EntryPointType :: L1Handler => " L1 Handler" ,
46
+ };
47
+ f . buffer. append (@ str );
48
+ Result :: Ok (())
49
+ }
50
+ }
51
+
52
+ impl DisplayCallType of Display <CallType > {
53
+ fn fmt (self : @ CallType , ref f : Formatter ) -> Result <(), Error > {
54
+ let str : ByteArray = match self {
55
+ CallType :: Call => " Call" ,
56
+ CallType :: Delegate => " Delegate" ,
57
+ };
58
+ f . buffer. append (@ str );
59
+ Result :: Ok (())
60
+ }
61
+ }
62
+
63
+ impl DisplayCallTrace of Display <CallTrace > {
64
+ fn fmt (self : @ CallTrace , ref f : Formatter ) -> Result <(), Error > {
65
+ Display :: fmt (@ IndentedCallTrace { struct_ref : self , base_indents : 0 }, ref f ). unwrap ();
66
+ Result :: Ok (())
67
+ }
68
+ }
69
+
70
+ #[derive(Drop )]
71
+ struct Indented <T > {
72
+ struct_ref : @ T ,
73
+ base_indents : u8 ,
74
+ }
75
+
76
+ type IndentedEntryPoint = Indented <CallEntryPoint >;
77
+ type IndentedCallTraceArray = Indented <Array <CallTrace >>;
78
+ type IndentedCallTrace = Indented <CallTrace >;
79
+
80
+
81
+ impl DisplayIndentedCallTrace of Display <Indented <CallTrace >> {
82
+ fn fmt (self : @ Indented <CallTrace >, ref f : Formatter ) -> Result <(), Error > {
83
+ Display :: fmt (
84
+ @ IndentedEntryPoint {
85
+ base_indents : * self . base_indents, struct_ref : * self . struct_ref. entry_point
86
+ },
87
+ ref f
88
+ )
89
+ . unwrap ();
90
+ write! (f , " \ n" ). unwrap ();
91
+ write_indents_to_formatter (* self . base_indents, ref f );
92
+ write! (f , " Nested Calls: [" ). unwrap ();
93
+ if (* self . struct_ref. nested_calls). len () > 0 {
94
+ write! (f , " \ n" ). unwrap ();
95
+ Display :: fmt (
96
+ @ IndentedCallTraceArray {
97
+ base_indents : (* self . base_indents) + 1 ,
98
+ struct_ref : * self . struct_ref. nested_calls
99
+ },
100
+ ref f
101
+ )
102
+ . unwrap ();
103
+ write! (f , " \ n" ). unwrap ();
104
+ write_indents_to_formatter (* self . base_indents, ref f );
105
+ }
106
+
107
+ write! (f , " ]" ). unwrap ();
108
+ Result :: Ok (())
109
+ }
110
+ }
111
+
112
+ impl DisplayIndentedCallTraceArray of Display <Indented <Array <CallTrace >>> {
113
+ fn fmt (self : @ Indented <Array <CallTrace >>, ref f : Formatter ) -> Result <(), Error > {
114
+ let mut i : u32 = 0 ;
115
+ let trace_len = (* self . struct_ref). len ();
116
+ while i < trace_len {
117
+ write_indents_to_formatter (* self . base_indents, ref f );
118
+ write! (f , " (\ n" ). unwrap ();
119
+
120
+ Display :: fmt (
121
+ @ IndentedCallTrace {
122
+ base_indents : * self . base_indents + 1 , struct_ref : (* self . struct_ref)[i ]
123
+ },
124
+ ref f
125
+ )
126
+ . unwrap ();
127
+ write! (f , " \ n" ). unwrap ();
128
+ write_indents_to_formatter (* self . base_indents, ref f );
129
+ write! (f , " )" ). unwrap ();
130
+
131
+ i = i + 1 ;
132
+ if i != trace_len {
133
+ write! (f , " ,\ n" ). unwrap ();
134
+ }
135
+ };
136
+
137
+ Result :: Ok (())
138
+ }
139
+ }
140
+
141
+ impl DisplayIndentedEntryPoint of Display <Indented <CallEntryPoint >> {
142
+ fn fmt (self : @ Indented <CallEntryPoint >, ref f : Formatter ) -> Result <(), Error > {
143
+ write_indents_to_formatter (* self . base_indents, ref f );
144
+ write! (f , " Entry point type: " )? ;
145
+ Display :: fmt (* self . struct_ref. entry_point_type, ref f )? ;
146
+
147
+ write! (f , " \ n" )? ;
148
+ write_indents_to_formatter (* self . base_indents, ref f );
149
+ write! (f , " Selector: " )? ;
150
+ Display :: fmt (* self . struct_ref. entry_point_selector, ref f )? ;
151
+
152
+ write! (f , " \ n" )? ;
153
+ write_indents_to_formatter (* self . base_indents, ref f );
154
+ write! (f , " Calldata: " )? ;
155
+ Debug :: fmt (* self . struct_ref. calldata, ref f )? ;
156
+
157
+ write! (f , " \ n" )? ;
158
+ write_indents_to_formatter (* self . base_indents, ref f );
159
+ write! (f , " Storage address: " )? ;
160
+ Debug :: fmt (* self . struct_ref. contract_address, ref f )? ;
161
+
162
+ write! (f , " \ n" )? ;
163
+ write_indents_to_formatter (* self . base_indents, ref f );
164
+ write! (f , " Caller address: " )? ;
165
+ Debug :: fmt (* self . struct_ref. caller_address, ref f )? ;
166
+
167
+ write! (f , " \ n" )? ;
168
+ write_indents_to_formatter (* self . base_indents, ref f );
169
+ write! (f , " Call type: " )? ;
170
+ Display :: fmt (* self . struct_ref. call_type, ref f )? ;
171
+
172
+ Result :: Ok (())
173
+ }
174
+ }
175
+
176
+
177
+ fn write_indents_to_formatter (indents : u8 , ref f : Formatter ) {
178
+ let mut i : u8 = 0 ;
179
+ while i < indents {
180
+ write! (f , " " ). unwrap ();
181
+ i = i + 1 ;
182
+ }
183
+ }
0 commit comments