Skip to content

Commit 5251ce3

Browse files
authored
feat: add to_*_env to filler for easy instantiation (#133)
1 parent 86d3d40 commit 5251ce3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
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.31.0"
3+
version = "0.31.1"
44
rust-version = "1.83.0"
55
edition = "2021"
66
authors = ["init4"]

src/fill/traits.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ pub trait Tx: Send + Sync {
2727
{
2828
evm.ctx.modify_tx(|tx_env| self.fill_tx_env(tx_env));
2929
}
30+
31+
/// Create a new [`TxEnv`] filled by this filler.
32+
fn to_tx_env(&self) -> TxEnv {
33+
let mut tx_env = TxEnv::default();
34+
self.fill_tx_env(&mut tx_env);
35+
tx_env
36+
}
3037
}
3138

3239
impl Tx for TxEnv {
@@ -83,6 +90,13 @@ pub trait Block: Send + Sync {
8390
fn tx_count_hint(&self) -> Option<usize> {
8491
None
8592
}
93+
94+
/// Create a new [`BlockEnv`] filled by this filler.
95+
fn to_block_env(&self) -> BlockEnv {
96+
let mut block_env = BlockEnv::default();
97+
self.fill_block_env(&mut block_env);
98+
block_env
99+
}
86100
}
87101

88102
impl<T> Block for T
@@ -142,6 +156,13 @@ pub trait Cfg: Send + Sync {
142156
{
143157
evm.ctx.modify_cfg(|cfg_env| self.fill_cfg_env(cfg_env));
144158
}
159+
160+
/// Create a new [`CfgEnv`] filled by this filler.
161+
fn to_cfg_env(&self) -> CfgEnv {
162+
let mut cfg_env = CfgEnv::default();
163+
self.fill_cfg_env(&mut cfg_env);
164+
cfg_env
165+
}
145166
}
146167

147168
impl Cfg for Arc<dyn Cfg> {

0 commit comments

Comments
 (0)