Skip to content

Commit b55b705

Browse files
committed
feat: review comments, lift up clear fn
1 parent 151af3d commit b55b705

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "trevm"
3-
version = "0.8.0"
3+
version = "0.8.1"
44
rust-version = "1.79.0"
55
edition = "2021"
66
authors = ["init4"]

src/driver/alloy.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,31 @@ pub struct BundleProcessor<B, R> {
7777
/// The bundle to process.
7878
pub bundle: B,
7979
/// The response for the processed bundle.
80-
pub response: R,
80+
response: R,
8181
}
8282

83-
impl<B, R> BundleProcessor<B, R> {
83+
impl<B, R> BundleProcessor<B, R>
84+
where
85+
R: Default,
86+
{
8487
/// Create a new bundle simulator with the given bundle and response.
85-
pub const fn new(bundle: B, response: R) -> Self {
86-
Self { bundle, response }
88+
pub fn new(bundle: B) -> Self {
89+
Self { bundle, response: R::default() }
90+
}
91+
92+
/// Clear the driver, resetting the response. This resets the driver,
93+
/// allowing for resimulation of the same bundle.
94+
pub fn clear(&mut self) -> R {
95+
std::mem::take(&mut self.response)
96+
}
97+
}
98+
99+
impl<B, R> From<B> for BundleProcessor<B, R>
100+
where
101+
R: Default,
102+
{
103+
fn from(bundle: B) -> Self {
104+
Self::new(bundle)
87105
}
88106
}
89107

@@ -129,13 +147,7 @@ impl<B, R> BundleProcessor<B, R> {
129147
impl BundleProcessor<EthCallBundle, EthCallBundleResponse> {
130148
/// Create a new bundle simulator with the given bundle.
131149
pub fn new_call(bundle: EthCallBundle) -> Self {
132-
Self::new(bundle, EthCallBundleResponse::default())
133-
}
134-
135-
/// Clear the driver, resetting the response. This resets the driver,
136-
/// allowing for resimulation of the same bundle.
137-
pub fn clear(&mut self) {
138-
std::mem::take(&mut self.response);
150+
Self::new(bundle)
139151
}
140152

141153
/// Process a bundle transaction and accumulate the results into a [EthCallBundleTransactionResult].

0 commit comments

Comments
 (0)