@@ -141,7 +141,8 @@ impl<'a, Ext, Db: Database + DatabaseCommit, TrevmState> Trevm<'a, Ext, Db, Trev
141
141
}
142
142
}
143
143
144
- /// Apply [`StateOverride`]s to the current state.
144
+ /// Apply [`StateOverride`]s to the current state. Errors if the overrides
145
+ /// contain invalid bytecode.
145
146
pub fn apply_state_overrides (
146
147
mut self ,
147
148
overrides : & StateOverride ,
@@ -176,6 +177,18 @@ impl<'a, Ext, Db: Database + DatabaseCommit, TrevmState> Trevm<'a, Ext, Db, Trev
176
177
}
177
178
Ok ( self )
178
179
}
180
+
181
+ /// Apply [`StateOverride`]s to the current state, if they are provided.
182
+ pub fn maybe_apply_state_overrides (
183
+ self ,
184
+ overrides : Option < & StateOverride > ,
185
+ ) -> Result < Self , EVMError < Db :: Error > > {
186
+ if let Some ( overrides) = overrides {
187
+ self . apply_state_overrides ( overrides)
188
+ } else {
189
+ Ok ( self )
190
+ }
191
+ }
179
192
}
180
193
181
194
impl < Ext , Db : Database + DatabaseCommit + DatabaseRef , TrevmState > Trevm < ' _ , Ext , Db , TrevmState > {
@@ -1024,15 +1037,24 @@ impl<'a, Ext, Db: Database + DatabaseCommit, TrevmState: HasTx> Trevm<'a, Ext, D
1024
1037
1025
1038
impl < Ext , Db : Database > EvmNeedsTx < ' _ , Ext , State < Db > > {
1026
1039
/// Apply block overrides to the current block.
1027
- pub fn apply_block_overrides ( mut self , overrides : BlockOverrides ) -> Self {
1040
+ pub fn apply_block_overrides ( mut self , overrides : & BlockOverrides ) -> Self {
1028
1041
overrides. fill_block ( & mut self . inner ) ;
1029
1042
1030
- if let Some ( hashes) = overrides. block_hash {
1043
+ if let Some ( hashes) = & overrides. block_hash {
1031
1044
self . inner . db_mut ( ) . block_hashes . extend ( hashes)
1032
1045
}
1033
1046
1034
1047
self
1035
1048
}
1049
+
1050
+ /// Apply block overrides to the current block, if they are provided.
1051
+ pub fn maybe_apply_block_overrides ( self , overrides : Option < & BlockOverrides > ) -> Self {
1052
+ if let Some ( overrides) = overrides {
1053
+ self . apply_block_overrides ( overrides)
1054
+ } else {
1055
+ self
1056
+ }
1057
+ }
1036
1058
}
1037
1059
1038
1060
// --- READY
0 commit comments