File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ pub use set::InspectorSet;
1010mod spanning;
1111pub use spanning:: SpanningInspector ;
1212
13+ mod with_output;
14+ pub use with_output:: InspectorWithOutput ;
15+
1316#[ cfg( test) ]
1417mod test {
1518 use super :: * ;
Original file line number Diff line number Diff line change 1+ use crate :: { helpers:: Ctx , Trevm } ;
2+ use revm:: { inspector:: CountInspector , Database } ;
3+
4+ /// An inspector that can produce an output value after EVM execution.
5+ pub trait InspectorWithOutput < CTX > : revm:: inspector:: Inspector < CTX > {
6+ /// The type of output produced by the inspector.
7+ type Output ;
8+
9+ /// Returns `true` if the inspector has a valid output value.
10+ fn has_output ( & self ) -> bool ;
11+
12+ /// Reset the output value to the default state, discarding any current
13+ /// value.
14+ fn reset_output ( & mut self ) {
15+ self . take_output ( ) ;
16+ }
17+
18+ /// Take the output value from the inspector, resetting it to the default
19+ /// state.
20+ fn take_output ( & mut self ) -> Self :: Output ;
21+ }
22+
23+ impl < Db : Database , Insp > Trevm < Db , Insp >
24+ where
25+ Insp : InspectorWithOutput < Ctx < Db > > ,
26+ {
27+ /// Take the output value from the inspector.
28+ ///
29+ /// This will also reset the output value in the inspector.
30+ pub fn take_output ( & mut self ) -> Insp :: Output {
31+ self . inspector_mut ( ) . take_output ( )
32+ }
33+ }
34+
35+ impl < Ctx > InspectorWithOutput < Ctx > for CountInspector {
36+ type Output = Self ;
37+
38+ fn has_output ( & self ) -> bool {
39+ self . total_opcodes ( ) > 0
40+ }
41+
42+ fn reset_output ( & mut self ) {
43+ self . clear ( ) ;
44+ }
45+
46+ fn take_output ( & mut self ) -> Self :: Output {
47+ std:: mem:: take ( self )
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments