Skip to content

Commit a29c7f9

Browse files
authored
feat: maybes and fix ref (#76)
1 parent f5f7fcc commit a29c7f9

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "trevm"
3-
version = "0.19.1"
3+
version = "0.19.2"
44
rust-version = "1.83.0"
55
edition = "2021"
66
authors = ["init4"]

src/evm.rs

+25-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ impl<'a, Ext, Db: Database + DatabaseCommit, TrevmState> Trevm<'a, Ext, Db, Trev
141141
}
142142
}
143143

144-
/// Apply [`StateOverride`]s to the current state.
144+
/// Apply [`StateOverride`]s to the current state. Errors if the overrides
145+
/// contain invalid bytecode.
145146
pub fn apply_state_overrides(
146147
mut self,
147148
overrides: &StateOverride,
@@ -176,6 +177,18 @@ impl<'a, Ext, Db: Database + DatabaseCommit, TrevmState> Trevm<'a, Ext, Db, Trev
176177
}
177178
Ok(self)
178179
}
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+
}
179192
}
180193

181194
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
10241037

10251038
impl<Ext, Db: Database> EvmNeedsTx<'_, Ext, State<Db>> {
10261039
/// 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 {
10281041
overrides.fill_block(&mut self.inner);
10291042

1030-
if let Some(hashes) = overrides.block_hash {
1043+
if let Some(hashes) = &overrides.block_hash {
10311044
self.inner.db_mut().block_hashes.extend(hashes)
10321045
}
10331046

10341047
self
10351048
}
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+
}
10361058
}
10371059

10381060
// --- READY

0 commit comments

Comments
 (0)