Skip to content

Commit

Permalink
refactor: examples to use main revm crate (#2152)
Browse files Browse the repository at this point in the history
* chore: examples

* refactor: examples to use main revm crate

* enable serde with serde-json
  • Loading branch information
rakita authored Mar 6, 2025
1 parent 39a3a2b commit fd98dc2
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 34 deletions.
6 changes: 0 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@ serde = [
"primitives/serde",
"handler/serde",
"context-interface/serde",
"inspector/serde",
]
arbitrary = ["primitives/arbitrary"]
asm-keccak = ["primitives/asm-keccak"]
portable = ["precompile/portable"]

# Enables alloydb inside database crate
alloydb = ["database/alloydb"]

# Enables serde-json inside inspector crate
serde-json = ["serde", "inspector/serde-json"]

test-utils = []

dev = [
Expand Down
5 changes: 2 additions & 3 deletions examples/block_traces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ rust_2018_idioms = "deny"
all = "warn"

[dependencies]
revm.workspace = true
database = { workspace = true, features = ["std", "alloydb"] }
inspector = { workspace = true, features = ["std", "serde-json"] }
# revm
revm = { workspace = true, features = ["std", "alloydb", "serde-json"] }

# tokio
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
Expand Down
8 changes: 5 additions & 3 deletions examples/block_traces/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ use alloy_provider::{
network::primitives::{BlockTransactions, BlockTransactionsKind},
Provider, ProviderBuilder,
};
use database::{AlloyDB, CacheDB, StateBuilder};
use indicatif::ProgressBar;
use inspector::{inspectors::TracerEip3155, InspectEvm};
use revm::{
database_interface::WrapDatabaseAsync, primitives::TxKind, Context, MainBuilder, MainContext,
database::{AlloyDB, CacheDB, StateBuilder},
database_interface::WrapDatabaseAsync,
inspector::{inspectors::TracerEip3155, InspectEvm},
primitives::TxKind,
Context, MainBuilder, MainContext,
};
use std::fs::OpenOptions;
use std::io::BufWriter;
Expand Down
5 changes: 2 additions & 3 deletions examples/cheatcode_inspector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ rust_2018_idioms = "deny"
all = "warn"

[dependencies]
revm = {workspace = true, features = ["std"] }
database = { workspace = true, features = ["std"] }
inspector = { workspace = true, features = ["std", "serde-json"] }
# revms
revm = { workspace = true, features = ["std", "serde-json"] }

# misc
anyhow = "1.0.89"
16 changes: 8 additions & 8 deletions examples/cheatcode_inspector/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@

use std::{convert::Infallible, fmt::Debug};

use database::InMemoryDB;
use inspector::{
exec::{inspect_main, InspectEvm},
inspector_context::InspectorContext,
inspectors::TracerEip3155,
journal::JournalExt,
GetInspector, Inspector,
};
use revm::{
bytecode::Bytecode,
context::{BlockEnv, Cfg, CfgEnv, TxEnv},
Expand All @@ -31,6 +23,14 @@ use revm::{
specification::hardfork::SpecId,
state::{Account, EvmState, TransientStorage},
Context, Database, DatabaseCommit, JournalEntry, JournaledState, MainBuilder,
database::InMemoryDB,
inspector::{
exec::{inspect_main, InspectEvm},
inspector_context::InspectorContext,
inspectors::TracerEip3155,
journal::JournalExt,
GetInspector, Inspector,
},
};

/// Backend for cheatcodes.
Expand Down
1 change: 0 additions & 1 deletion examples/contract_deployment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ all = "warn"

[dependencies]
revm = { workspace = true, features = ["std"] }
database.workspace = true

# misc
anyhow = "1.0.89"
2 changes: 1 addition & 1 deletion examples/contract_deployment/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

use anyhow::{anyhow, bail};
use database::CacheDB;
use revm::{
bytecode::opcode,
context::Context,
context_interface::result::{ExecutionResult, Output},
database::CacheDB,
database_interface::EmptyDB,
handler::handler::EvmTr,
primitives::{hex, Bytes, TxKind, U256},
Expand Down
3 changes: 1 addition & 2 deletions examples/erc20_gas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ rust_2018_idioms = "deny"
all = "warn"

[dependencies]
revm.workspace = true
database = { workspace = true, features = ["std", "alloydb"] }
revm = { workspace = true, features = ["std", "alloydb"] }

# tokio
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/erc20_gas/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use alloy_provider::{network::Ethereum, DynProvider, Provider, ProviderBuilder};
use alloy_sol_types::SolValue;
use anyhow::Result;
use database::{AlloyDB, BlockId, CacheDB};
use exec::transact_erc20evm_commit;
use revm::{
context_interface::{
result::{InvalidHeader, InvalidTransaction},
ContextTr, Journal,
},
database::{AlloyDB, BlockId, CacheDB},
database_interface::WrapDatabaseAsync,
precompile::PrecompileError,
primitives::{address, keccak256, Address, Bytes, TxKind, U256},
Expand Down
3 changes: 1 addition & 2 deletions examples/uniswap_get_reserves/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ all = "warn"

[dependencies]
# revm
revm.workspace = true
database = { workspace = true, features = ["std", "alloydb"] }
revm = { workspace = true, features = ["std", "alloydb"] }

# tokio
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/uniswap_get_reserves/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
use alloy_eips::BlockId;
use alloy_provider::ProviderBuilder;
use alloy_sol_types::{sol, SolCall};
use database::{AlloyDB, CacheDB};
use revm::{
context_interface::result::{ExecutionResult, Output},
database::{AlloyDB, CacheDB},
database_interface::{DatabaseRef, EmptyDB, WrapDatabaseAsync},
primitives::{address, TxKind, U256},
Context, ExecuteEvm, MainBuilder, MainContext,
Expand Down
3 changes: 1 addition & 2 deletions examples/uniswap_v2_usdc_swap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ rust_2018_idioms = "deny"
all = "warn"

[dependencies]
revm.workspace = true
database = { workspace = true, features = ["std", "alloydb"] }
revm = { workspace = true, features = ["std", "alloydb"] }

# tokio
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/uniswap_v2_usdc_swap/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use alloy_eips::BlockId;
use alloy_provider::{network::Ethereum, DynProvider, Provider, ProviderBuilder};
use alloy_sol_types::{sol, SolCall, SolValue};
use anyhow::{anyhow, Result};
use database::{AlloyDB, CacheDB};
use revm::{
context_interface::result::{ExecutionResult, Output},
database::{AlloyDB, CacheDB},
database_interface::WrapDatabaseAsync,
primitives::{address, keccak256, Address, Bytes, TxKind, U256},
state::AccountInfo,
Expand Down

0 comments on commit fd98dc2

Please sign in to comment.