From b593e4cdae35817f2287161bf48160cc5bd2b88f Mon Sep 17 00:00:00 2001 From: James Date: Thu, 6 Nov 2025 14:50:40 -0500 Subject: [PATCH] feat: add to_*_env to filler for easy instantiation --- Cargo.toml | 2 +- src/fill/traits.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8599a6e..70ea7d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trevm" -version = "0.31.0" +version = "0.31.1" rust-version = "1.83.0" edition = "2021" authors = ["init4"] diff --git a/src/fill/traits.rs b/src/fill/traits.rs index 777616e..d802d01 100644 --- a/src/fill/traits.rs +++ b/src/fill/traits.rs @@ -27,6 +27,13 @@ pub trait Tx: Send + Sync { { evm.ctx.modify_tx(|tx_env| self.fill_tx_env(tx_env)); } + + /// Create a new [`TxEnv`] filled by this filler. + fn to_tx_env(&self) -> TxEnv { + let mut tx_env = TxEnv::default(); + self.fill_tx_env(&mut tx_env); + tx_env + } } impl Tx for TxEnv { @@ -83,6 +90,13 @@ pub trait Block: Send + Sync { fn tx_count_hint(&self) -> Option { None } + + /// Create a new [`BlockEnv`] filled by this filler. + fn to_block_env(&self) -> BlockEnv { + let mut block_env = BlockEnv::default(); + self.fill_block_env(&mut block_env); + block_env + } } impl Block for T @@ -142,6 +156,13 @@ pub trait Cfg: Send + Sync { { evm.ctx.modify_cfg(|cfg_env| self.fill_cfg_env(cfg_env)); } + + /// Create a new [`CfgEnv`] filled by this filler. + fn to_cfg_env(&self) -> CfgEnv { + let mut cfg_env = CfgEnv::default(); + self.fill_cfg_env(&mut cfg_env); + cfg_env + } } impl Cfg for Arc {