@@ -2,6 +2,7 @@ use crate::{
2
2
db:: { StateAcc , TryStateAcc } ,
3
3
driver:: DriveBlockResult ,
4
4
helpers:: { Ctx , Evm , Instruction } ,
5
+ inspectors:: Layered ,
5
6
Block , BlockDriver , BundleDriver , Cfg , ChainDriver , DriveBundleResult , DriveChainResult ,
6
7
ErroredState , EvmErrored , EvmExtUnchecked , EvmNeedsBlock , EvmNeedsCfg , EvmNeedsTx , EvmReady ,
7
8
EvmTransacted , HasBlock , HasCfg , HasTx , NeedsCfg , NeedsTx , TransactedState , Tx ,
@@ -101,6 +102,92 @@ where
101
102
self . inner . ctx . journaled_state . database
102
103
}
103
104
105
+ /// Get a reference to the inspector.
106
+ pub fn inspector ( & self ) -> & Insp {
107
+ & self . inner . inspector
108
+ }
109
+
110
+ /// Get a mutable reference to the inspector.
111
+ pub fn inspector_mut ( & mut self ) -> & mut Insp {
112
+ & mut self . inner . inspector
113
+ }
114
+
115
+ /// Replace the current inspector with a new inspector of the same type.
116
+ pub fn replace_inspector ( mut self , inspector : Insp ) -> Self
117
+ where
118
+ TrevmState : Copy ,
119
+ {
120
+ * self . inspector_mut ( ) = inspector;
121
+ self
122
+ }
123
+
124
+ /// Layer a new inspector on top of the current one.
125
+ pub fn layer_inspector < Insp2 > (
126
+ self ,
127
+ inspector : Insp2 ,
128
+ ) -> Trevm < Db , Layered < Insp2 , Insp > , TrevmState >
129
+ where
130
+ Insp2 : Inspector < Ctx < Db > > ,
131
+ TrevmState : Copy ,
132
+ {
133
+ let inner = Box :: new ( Evm {
134
+ ctx : self . inner . ctx ,
135
+ inspector : Layered :: new ( inspector, self . inner . inspector ) ,
136
+ instruction : self . inner . instruction ,
137
+ precompiles : self . inner . precompiles ,
138
+ frame_stack : self . inner . frame_stack ,
139
+ } ) ;
140
+ Trevm { inner, state : self . state }
141
+ }
142
+
143
+ /// Take the inspector out of the Trevm, replacing it with a
144
+ /// [`NoOpInspector`].
145
+ pub fn take_inspector ( self ) -> ( Insp , Trevm < Db , NoOpInspector , TrevmState > ) {
146
+ let inspector = self . inner . inspector ;
147
+ let inner = Box :: new ( Evm {
148
+ ctx : self . inner . ctx ,
149
+ inspector : NoOpInspector ,
150
+ instruction : self . inner . instruction ,
151
+ precompiles : self . inner . precompiles ,
152
+ frame_stack : self . inner . frame_stack ,
153
+ } ) ;
154
+ ( inspector, Trevm { inner, state : self . state } )
155
+ }
156
+
157
+ /// Replace the current inspector with a new one, dropping the old one.
158
+ pub fn set_inspector < Insp2 > ( self , inspector : Insp2 ) -> Trevm < Db , Insp2 , TrevmState >
159
+ where
160
+ Insp2 : Inspector < Ctx < Db > > ,
161
+ TrevmState : Copy ,
162
+ {
163
+ let inner = Box :: new ( Evm {
164
+ ctx : self . inner . ctx ,
165
+ inspector,
166
+ instruction : self . inner . instruction ,
167
+ precompiles : self . inner . precompiles ,
168
+ frame_stack : self . inner . frame_stack ,
169
+ } ) ;
170
+ Trevm { inner, state : self . state }
171
+ }
172
+
173
+ /// Run the closure with a different inspector, then restore the previous
174
+ /// one.
175
+ pub fn with_inspector < Insp2 , F , NewState > (
176
+ self ,
177
+ inspector : Insp2 ,
178
+ f : F ,
179
+ ) -> Trevm < Db , Insp , NewState >
180
+ where
181
+ Insp2 : Inspector < Ctx < Db > > ,
182
+ F : FnOnce ( Trevm < Db , Insp2 , TrevmState > ) -> Trevm < Db , Insp2 , NewState > ,
183
+ TrevmState : Copy ,
184
+ NewState : Copy ,
185
+ {
186
+ let ( old, this) = self . take_inspector ( ) ;
187
+ let this = f ( this. set_inspector ( inspector) ) ;
188
+ this. set_inspector ( old)
189
+ }
190
+
104
191
/// Get the id of the currently running hardfork spec.
105
192
pub fn spec_id ( & self ) -> SpecId {
106
193
self . inner . ctx . cfg ( ) . spec ( )
0 commit comments