Skip to content

Commit

Permalink
feat(BundleDriver): add some ergonomic functions to the BundleDriver (
Browse files Browse the repository at this point in the history
#46)

* feat: add some ergonomic functions to the BundleDriver

* feat: review comments, lift up clear fn
  • Loading branch information
Evalir authored Sep 7, 2024
1 parent 56a8503 commit 80b468f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trevm"
version = "0.8.0"
version = "0.9.0"
rust-version = "1.79.0"
edition = "2021"
authors = ["init4"]
Expand Down
43 changes: 38 additions & 5 deletions src/driver/alloy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,31 @@ pub struct BundleProcessor<B, R> {
/// The bundle to process.
pub bundle: B,
/// The response for the processed bundle.
pub response: R,
response: R,
}

impl<B, R> BundleProcessor<B, R> {
impl<B, R> BundleProcessor<B, R>
where
R: Default,
{
/// Create a new bundle simulator with the given bundle and response.
pub const fn new(bundle: B, response: R) -> Self {
Self { bundle, response }
pub fn new(bundle: B) -> Self {
Self { bundle, response: R::default() }
}

/// Clear the driver, resetting the response. This resets the driver,
/// allowing for resimulation of the same bundle.
pub fn clear(&mut self) -> R {
std::mem::take(&mut self.response)
}
}

impl<B, R> From<B> for BundleProcessor<B, R>
where
R: Default,
{
fn from(bundle: B) -> Self {
Self::new(bundle)
}
}

Expand All @@ -109,12 +127,27 @@ impl<B, R> BundleProcessor<B, R> {
Ok(txs)
}
}

/// Take the response from the bundle driver. This consumes the driver.
pub fn into_response(self) -> R {
self.response
}

/// Get a reference to the bundle.
pub const fn bundle(&self) -> &B {
&self.bundle
}

/// Get a reference to the response.
pub const fn response(&self) -> &R {
&self.response
}
}

impl BundleProcessor<EthCallBundle, EthCallBundleResponse> {
/// Create a new bundle simulator with the given bundle.
pub fn new_call(bundle: EthCallBundle) -> Self {
Self::new(bundle, EthCallBundleResponse::default())
Self::new(bundle)
}

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

0 comments on commit 80b468f

Please sign in to comment.