From fd98dc2e87581f43a094bd543cc66979b6a51a8b Mon Sep 17 00:00:00 2001 From: rakita Date: Thu, 6 Mar 2025 16:42:34 +0100 Subject: [PATCH] refactor: examples to use main revm crate (#2152) * chore: examples * refactor: examples to use main revm crate * enable serde with serde-json --- Cargo.lock | 6 ------ crates/revm/Cargo.toml | 7 +++++++ examples/block_traces/Cargo.toml | 5 ++--- examples/block_traces/src/main.rs | 8 +++++--- examples/cheatcode_inspector/Cargo.toml | 5 ++--- examples/cheatcode_inspector/src/main.rs | 16 ++++++++-------- examples/contract_deployment/Cargo.toml | 1 - examples/contract_deployment/src/main.rs | 2 +- examples/erc20_gas/Cargo.toml | 3 +-- examples/erc20_gas/src/main.rs | 2 +- examples/uniswap_get_reserves/Cargo.toml | 3 +-- examples/uniswap_get_reserves/src/main.rs | 2 +- examples/uniswap_v2_usdc_swap/Cargo.toml | 3 +-- examples/uniswap_v2_usdc_swap/src/main.rs | 2 +- 14 files changed, 31 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f85875c7d5..4365f595f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1458,8 +1458,6 @@ dependencies = [ "anyhow", "indicatif", "revm", - "revm-database", - "revm-inspector", "tokio", ] @@ -1469,7 +1467,6 @@ version = "0.0.0" dependencies = [ "anyhow", "revm", - "revm-database", ] [[package]] @@ -1489,7 +1486,6 @@ dependencies = [ "alloy-sol-types", "anyhow", "revm", - "revm-database", "tokio", ] @@ -1502,7 +1498,6 @@ dependencies = [ "alloy-sol-types", "anyhow", "revm", - "revm-database", "tokio", ] @@ -1515,7 +1510,6 @@ dependencies = [ "alloy-sol-types", "anyhow", "revm", - "revm-database", "tokio", ] diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index cb05f38e3e..ddffc7c395 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -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 = [ diff --git a/examples/block_traces/Cargo.toml b/examples/block_traces/Cargo.toml index 7eecda2d60..8f0691411c 100644 --- a/examples/block_traces/Cargo.toml +++ b/examples/block_traces/Cargo.toml @@ -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"] } diff --git a/examples/block_traces/src/main.rs b/examples/block_traces/src/main.rs index 48f438393f..1121903ff5 100644 --- a/examples/block_traces/src/main.rs +++ b/examples/block_traces/src/main.rs @@ -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; diff --git a/examples/cheatcode_inspector/Cargo.toml b/examples/cheatcode_inspector/Cargo.toml index e53f49088a..38a4ad4b39 100644 --- a/examples/cheatcode_inspector/Cargo.toml +++ b/examples/cheatcode_inspector/Cargo.toml @@ -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" diff --git a/examples/cheatcode_inspector/src/main.rs b/examples/cheatcode_inspector/src/main.rs index 2701f52478..4d7d15bdf9 100644 --- a/examples/cheatcode_inspector/src/main.rs +++ b/examples/cheatcode_inspector/src/main.rs @@ -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}, @@ -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. diff --git a/examples/contract_deployment/Cargo.toml b/examples/contract_deployment/Cargo.toml index 2a27304f89..7b8910b35c 100644 --- a/examples/contract_deployment/Cargo.toml +++ b/examples/contract_deployment/Cargo.toml @@ -23,7 +23,6 @@ all = "warn" [dependencies] revm = { workspace = true, features = ["std"] } -database.workspace = true # misc anyhow = "1.0.89" diff --git a/examples/contract_deployment/src/main.rs b/examples/contract_deployment/src/main.rs index f8beb80070..2100be52c8 100644 --- a/examples/contract_deployment/src/main.rs +++ b/examples/contract_deployment/src/main.rs @@ -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}, diff --git a/examples/erc20_gas/Cargo.toml b/examples/erc20_gas/Cargo.toml index 3674192b7c..14a97c4b4b 100644 --- a/examples/erc20_gas/Cargo.toml +++ b/examples/erc20_gas/Cargo.toml @@ -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"] } diff --git a/examples/erc20_gas/src/main.rs b/examples/erc20_gas/src/main.rs index 55f9386025..6660e3a0fa 100644 --- a/examples/erc20_gas/src/main.rs +++ b/examples/erc20_gas/src/main.rs @@ -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}, diff --git a/examples/uniswap_get_reserves/Cargo.toml b/examples/uniswap_get_reserves/Cargo.toml index b826ae4115..2a6ff9b59b 100644 --- a/examples/uniswap_get_reserves/Cargo.toml +++ b/examples/uniswap_get_reserves/Cargo.toml @@ -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"] } diff --git a/examples/uniswap_get_reserves/src/main.rs b/examples/uniswap_get_reserves/src/main.rs index 3acf3918ed..f573677eb2 100644 --- a/examples/uniswap_get_reserves/src/main.rs +++ b/examples/uniswap_get_reserves/src/main.rs @@ -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, diff --git a/examples/uniswap_v2_usdc_swap/Cargo.toml b/examples/uniswap_v2_usdc_swap/Cargo.toml index d35a979c27..2b2e22e079 100644 --- a/examples/uniswap_v2_usdc_swap/Cargo.toml +++ b/examples/uniswap_v2_usdc_swap/Cargo.toml @@ -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"] } diff --git a/examples/uniswap_v2_usdc_swap/src/main.rs b/examples/uniswap_v2_usdc_swap/src/main.rs index 370b489e40..e22baddb94 100644 --- a/examples/uniswap_v2_usdc_swap/src/main.rs +++ b/examples/uniswap_v2_usdc_swap/src/main.rs @@ -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,