Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add with_handler method to EvmBuilder #1124

Merged
merged 5 commits into from
Feb 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions crates/revm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,33 @@ impl<'a, BuilderStage, EXT, DB: Database> EvmBuilder<'a, BuilderStage, EXT, DB>
Handler::new(handler_cfg)
}

/// This modifies the [EvmBuilder] to make it easy to construct an [`Evm`] with a _specific_
/// handler.
///
/// # Example
/// ```rust
/// use revm::{EvmBuilder, Handler, primitives::{SpecId, HandlerCfg}};
/// use revm_interpreter::primitives::CancunSpec;
/// let builder = EvmBuilder::default();
///
/// // get the desired handler
/// let mainnet = Handler::mainnet::<CancunSpec>();
/// let builder = builder.with_handler(mainnet);
///
/// // build the EVM
/// let evm = builder.build();
/// ```
pub fn with_handler(
self,
handler: Handler<'a, Evm<'a, EXT, DB>, EXT, DB>,
) -> EvmBuilder<'a, BuilderStage, EXT, DB> {
EvmBuilder {
context: self.context,
handler,
phantom: PhantomData,
}
}

/// Builds the [`Evm`].
pub fn build(self) -> Evm<'a, EXT, DB> {
Evm::new(self.context, self.handler)
Expand Down
Loading