Skip to content

Commit 80b468f

Browse files
authored
feat(BundleDriver): add some ergonomic functions to the BundleDriver (#46)
* feat: add some ergonomic functions to the BundleDriver * feat: review comments, lift up clear fn
1 parent 56a8503 commit 80b468f

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
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.9.0"
44
rust-version = "1.79.0"
55
edition = "2021"
66
authors = ["init4"]

src/driver/alloy.rs

Lines changed: 38 additions & 5 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

@@ -109,12 +127,27 @@ impl<B, R> BundleProcessor<B, R> {
109127
Ok(txs)
110128
}
111129
}
130+
131+
/// Take the response from the bundle driver. This consumes the driver.
132+
pub fn into_response(self) -> R {
133+
self.response
134+
}
135+
136+
/// Get a reference to the bundle.
137+
pub const fn bundle(&self) -> &B {
138+
&self.bundle
139+
}
140+
141+
/// Get a reference to the response.
142+
pub const fn response(&self) -> &R {
143+
&self.response
144+
}
112145
}
113146

114147
impl BundleProcessor<EthCallBundle, EthCallBundleResponse> {
115148
/// Create a new bundle simulator with the given bundle.
116149
pub fn new_call(bundle: EthCallBundle) -> Self {
117-
Self::new(bundle, EthCallBundleResponse::default())
150+
Self::new(bundle)
118151
}
119152

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

0 commit comments

Comments
 (0)