From b42de2b3d919cea95fd68961f67c614b19bd042c Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 23 Feb 2024 17:28:57 -0500 Subject: [PATCH 1/5] feat: add with_handler method to EvmBuilder --- crates/revm/src/builder.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/crates/revm/src/builder.rs b/crates/revm/src/builder.rs index 20a8fd37a0..dc7ff8c996 100644 --- a/crates/revm/src/builder.rs +++ b/crates/revm/src/builder.rs @@ -195,6 +195,36 @@ impl<'a, EXT, DB: Database> EvmBuilder<'a, HandlerStage, EXT, DB> { } } + /// Modifies the [`Evm`] being built by specifying a handler to use. + /// + /// This can be used to easily construct an EVM with a _specific_ handler. + /// + /// # Example + /// ```rust + /// + /// let builder = EvmBuilder::default(); + /// // set up empty handler cfg + /// let handler = HandlerCfg::new(SpecId::LATEST); + /// let builder = builder.with_handler_cfg(handler); + /// + /// // get the desired handler + /// let mainnet = Handler::mainnet(); + /// 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, HandlerStage, EXT, DB> { + EvmBuilder { + context: self.context, + handler, + phantom: PhantomData, + } + } + /// Sets the [`EmptyDB`] and resets the [`Handler`] to default mainnet. pub fn reset_handler_with_empty_db(self) -> EvmBuilder<'a, HandlerStage, EXT, EmptyDB> { EvmBuilder { From a1246bbc4f64f04c60d64017b68f0ed813335d79 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 23 Feb 2024 17:36:45 -0500 Subject: [PATCH 2/5] improve docs --- crates/revm/src/builder.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/revm/src/builder.rs b/crates/revm/src/builder.rs index dc7ff8c996..9974c42eef 100644 --- a/crates/revm/src/builder.rs +++ b/crates/revm/src/builder.rs @@ -195,9 +195,8 @@ impl<'a, EXT, DB: Database> EvmBuilder<'a, HandlerStage, EXT, DB> { } } - /// Modifies the [`Evm`] being built by specifying a handler to use. - /// - /// This can be used to easily construct an EVM with a _specific_ handler. + /// This modifies the [EvmBuilder] to make it easy to construct an [`Evm`] with a _specific_ + /// handler. /// /// # Example /// ```rust From 98dbc7e3dda8c5631c64523737faf2983a485e1e Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 23 Feb 2024 17:40:32 -0500 Subject: [PATCH 3/5] add imports to docs --- crates/revm/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/revm/src/builder.rs b/crates/revm/src/builder.rs index 9974c42eef..77ee00ea66 100644 --- a/crates/revm/src/builder.rs +++ b/crates/revm/src/builder.rs @@ -200,7 +200,7 @@ impl<'a, EXT, DB: Database> EvmBuilder<'a, HandlerStage, EXT, DB> { /// /// # Example /// ```rust - /// + /// use revm::{EvmBuilder, Handler, primitives::{SpecId, HandlerCfg}}; /// let builder = EvmBuilder::default(); /// // set up empty handler cfg /// let handler = HandlerCfg::new(SpecId::LATEST); From 5071155aa2b5bb60149c64be829142f2b541d94b Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:05:42 -0500 Subject: [PATCH 4/5] fix docs --- crates/revm/src/builder.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/revm/src/builder.rs b/crates/revm/src/builder.rs index 77ee00ea66..f12e12a9ef 100644 --- a/crates/revm/src/builder.rs +++ b/crates/revm/src/builder.rs @@ -201,13 +201,14 @@ impl<'a, EXT, DB: Database> EvmBuilder<'a, HandlerStage, EXT, DB> { /// # Example /// ```rust /// use revm::{EvmBuilder, Handler, primitives::{SpecId, HandlerCfg}}; + /// use revm_interpreter::primitives::CancunSpec; /// let builder = EvmBuilder::default(); /// // set up empty handler cfg /// let handler = HandlerCfg::new(SpecId::LATEST); /// let builder = builder.with_handler_cfg(handler); /// /// // get the desired handler - /// let mainnet = Handler::mainnet(); + /// let mainnet = Handler::mainnet::(); /// let builder = builder.with_handler(mainnet); /// /// // build the EVM From 8c1b0fc2a0e2f1173ac27a18be1dbeed8d43d4de Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Sat, 24 Feb 2024 01:21:34 -0500 Subject: [PATCH 5/5] move with_handler to BuilderStage --- crates/revm/src/builder.rs | 57 ++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/crates/revm/src/builder.rs b/crates/revm/src/builder.rs index f12e12a9ef..7cb47f57a2 100644 --- a/crates/revm/src/builder.rs +++ b/crates/revm/src/builder.rs @@ -195,36 +195,6 @@ impl<'a, EXT, DB: Database> EvmBuilder<'a, HandlerStage, EXT, DB> { } } - /// 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(); - /// // set up empty handler cfg - /// let handler = HandlerCfg::new(SpecId::LATEST); - /// let builder = builder.with_handler_cfg(handler); - /// - /// // get the desired handler - /// let mainnet = Handler::mainnet::(); - /// 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, HandlerStage, EXT, DB> { - EvmBuilder { - context: self.context, - handler, - phantom: PhantomData, - } - } - /// Sets the [`EmptyDB`] and resets the [`Handler`] to default mainnet. pub fn reset_handler_with_empty_db(self) -> EvmBuilder<'a, HandlerStage, EXT, EmptyDB> { EvmBuilder { @@ -303,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::(); + /// 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)