diff --git a/bins/revm-test/src/bin/analysis.rs b/bins/revm-test/src/bin/analysis.rs index 40bbcf39c4..a6fa92f46d 100644 --- a/bins/revm-test/src/bin/analysis.rs +++ b/bins/revm-test/src/bin/analysis.rs @@ -1,7 +1,7 @@ use revm::{ db::BenchmarkDB, interpreter::analysis::to_analysed, - primitives::{address, bytes, Bytecode, Bytes, TransactTo}, + primitives::{address, bytes, Bytecode, Bytes, TxKind}, Evm, }; use std::time::Instant; @@ -17,7 +17,7 @@ fn main() { .modify_tx_env(|tx| { // execution globals block hash/gas_limit/coinbase/timestamp.. tx.caller = address!("1000000000000000000000000000000000000000"); - tx.transact_to = TransactTo::Call(address!("0000000000000000000000000000000000000000")); + tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000")); //evm.env.tx.data = Bytes::from(hex::decode("30627b7c").unwrap()); tx.data = bytes!("8035F0CE"); }) diff --git a/bins/revm-test/src/bin/burntpix/main.rs b/bins/revm-test/src/bin/burntpix/main.rs index 8cd9eea66c..ea1ac56f70 100644 --- a/bins/revm-test/src/bin/burntpix/main.rs +++ b/bins/revm-test/src/bin/burntpix/main.rs @@ -5,7 +5,7 @@ use revm::{ db::{CacheDB, EmptyDB}, primitives::{ address, hex, keccak256, AccountInfo, Address, Bytecode, Bytes, ExecutionResult, Output, - TransactTo, B256, U256, + TxKind, B256, U256, }, Evm, }; @@ -38,7 +38,7 @@ fn main() { let mut evm = Evm::builder() .modify_tx_env(|tx| { tx.caller = address!("1000000000000000000000000000000000000000"); - tx.transact_to = TransactTo::Call(BURNTPIX_MAIN_ADDRESS); + tx.transact_to = TxKind::Call(BURNTPIX_MAIN_ADDRESS); tx.data = run_call_data.clone().into(); }) .with_db(db) diff --git a/bins/revm-test/src/bin/snailtracer.rs b/bins/revm-test/src/bin/snailtracer.rs index a931dc3a31..cebe950a7f 100644 --- a/bins/revm-test/src/bin/snailtracer.rs +++ b/bins/revm-test/src/bin/snailtracer.rs @@ -1,7 +1,7 @@ use revm::{ db::BenchmarkDB, interpreter::analysis::to_analysed, - primitives::{address, bytes, Bytecode, Bytes, TransactTo}, + primitives::{address, bytes, Bytecode, Bytes, TxKind}, Evm, }; @@ -14,7 +14,7 @@ pub fn simple_example() { .modify_tx_env(|tx| { // execution globals block hash/gas_limit/coinbase/timestamp.. tx.caller = address!("1000000000000000000000000000000000000000"); - tx.transact_to = TransactTo::Call(address!("0000000000000000000000000000000000000000")); + tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000")); tx.data = bytes!("30627b7c"); }) .build(); diff --git a/bins/revm-test/src/bin/transfer.rs b/bins/revm-test/src/bin/transfer.rs index 8abd0910ef..4fa1f29b09 100644 --- a/bins/revm-test/src/bin/transfer.rs +++ b/bins/revm-test/src/bin/transfer.rs @@ -1,6 +1,6 @@ use revm::{ db::BenchmarkDB, - primitives::{Bytecode, TransactTo, U256}, + primitives::{Bytecode, TxKind, U256}, Evm, }; @@ -16,7 +16,7 @@ fn main() { .parse() .unwrap(); tx.value = U256::from(10); - tx.transact_to = TransactTo::Call( + tx.transact_to = TxKind::Call( "0x0000000000000000000000000000000000000000" .parse() .unwrap(), diff --git a/bins/revme/src/cmd/evmrunner.rs b/bins/revme/src/cmd/evmrunner.rs index 8c93d3182b..50a75a8deb 100644 --- a/bins/revme/src/cmd/evmrunner.rs +++ b/bins/revme/src/cmd/evmrunner.rs @@ -2,7 +2,7 @@ use revm::{ db::BenchmarkDB, inspector_handle_register, inspectors::TracerEip3155, - primitives::{Address, Bytecode, TransactTo}, + primitives::{Address, Bytecode, TxKind}, Evm, }; use std::io::Error as IoError; @@ -86,7 +86,7 @@ impl Cmd { tx.caller = "0x0000000000000000000000000000000000000001" .parse() .unwrap(); - tx.transact_to = TransactTo::Call(Address::ZERO); + tx.transact_to = TxKind::Call(Address::ZERO); tx.data = input; }) .build(); diff --git a/bins/revme/src/cmd/statetest/runner.rs b/bins/revme/src/cmd/statetest/runner.rs index df14560a1f..06ab1d64bd 100644 --- a/bins/revme/src/cmd/statetest/runner.rs +++ b/bins/revme/src/cmd/statetest/runner.rs @@ -10,7 +10,7 @@ use revm::{ inspectors::TracerEip3155, primitives::{ calc_excess_blob_gas, keccak256, Bytecode, Bytes, EVMResultGeneric, Env, Eof, - ExecutionResult, SpecId, TransactTo, B256, EOF_MAGIC_BYTES, U256, + ExecutionResult, SpecId, TxKind, B256, EOF_MAGIC_BYTES, U256, }, Evm, State, }; @@ -364,8 +364,8 @@ pub fn execute_test_suite( .collect(); let to = match unit.transaction.to { - Some(add) => TransactTo::Call(add), - None => TransactTo::Create, + Some(add) => TxKind::Call(add), + None => TxKind::Create, }; env.tx.transact_to = to; diff --git a/crates/interpreter/src/interpreter/contract.rs b/crates/interpreter/src/interpreter/contract.rs index f8625e8533..49e511f66e 100644 --- a/crates/interpreter/src/interpreter/contract.rs +++ b/crates/interpreter/src/interpreter/contract.rs @@ -1,6 +1,8 @@ +use revm_primitives::TxKind; + use super::analysis::to_analysed; use crate::{ - primitives::{Address, Bytecode, Bytes, Env, TransactTo, B256, U256}, + primitives::{Address, Bytecode, Bytes, Env, B256, U256}, CallInputs, }; @@ -50,8 +52,8 @@ impl Contract { #[inline] pub fn new_env(env: &Env, bytecode: Bytecode, hash: Option) -> Self { let contract_address = match env.tx.transact_to { - TransactTo::Call(caller) => caller, - TransactTo::Create => Address::ZERO, + TxKind::Call(caller) => caller, + TxKind::Create => Address::ZERO, }; Self::new( env.tx.data.clone(), diff --git a/crates/interpreter/src/interpreter_action/call_inputs.rs b/crates/interpreter/src/interpreter_action/call_inputs.rs index 0e51bd5ec6..85d0c8fb71 100644 --- a/crates/interpreter/src/interpreter_action/call_inputs.rs +++ b/crates/interpreter/src/interpreter_action/call_inputs.rs @@ -1,4 +1,4 @@ -use crate::primitives::{Address, Bytes, TransactTo, TxEnv, U256}; +use crate::primitives::{Address, Bytes, TxEnv, TxKind, U256}; use core::ops::Range; use std::boxed::Box; @@ -47,7 +47,7 @@ impl CallInputs { /// /// Returns `None` if the transaction is not a call. pub fn new(tx_env: &TxEnv, gas_limit: u64) -> Option { - let TransactTo::Call(target_address) = tx_env.transact_to else { + let TxKind::Call(target_address) = tx_env.transact_to else { return None; }; Some(CallInputs { diff --git a/crates/interpreter/src/interpreter_action/create_inputs.rs b/crates/interpreter/src/interpreter_action/create_inputs.rs index 6db951831a..adae96ac2d 100644 --- a/crates/interpreter/src/interpreter_action/create_inputs.rs +++ b/crates/interpreter/src/interpreter_action/create_inputs.rs @@ -1,5 +1,5 @@ pub use crate::primitives::CreateScheme; -use crate::primitives::{Address, Bytes, TransactTo, TxEnv, U256}; +use crate::primitives::{Address, Bytes, TxEnv, TxKind, U256}; use std::boxed::Box; /// Inputs for a create call. @@ -21,7 +21,7 @@ pub struct CreateInputs { impl CreateInputs { /// Creates new create inputs. pub fn new(tx_env: &TxEnv, gas_limit: u64) -> Option { - let TransactTo::Create = tx_env.transact_to else { + let TxKind::Create = tx_env.transact_to else { return None; }; diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index 44b0736977..fde04c5734 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -1,5 +1,6 @@ pub mod handler_cfg; +use alloy_primitives::TxKind; pub use handler_cfg::{CfgEnvWithHandlerCfg, EnvWithHandlerCfg, HandlerCfg}; use crate::{ @@ -503,7 +504,7 @@ pub struct TxEnv { /// The gas price of the transaction. pub gas_price: U256, /// The destination of the transaction. - pub transact_to: TransactTo, + pub transact_to: TxKind, /// The value sent to `transact_to`. pub value: U256, /// The data of the transaction. @@ -585,7 +586,7 @@ impl Default for TxEnv { gas_limit: u64::MAX, gas_price: U256::ZERO, gas_priority_fee: None, - transact_to: TransactTo::Call(Address::ZERO), // will do nothing + transact_to: TxKind::Call(Address::ZERO), // will do nothing value: U256::ZERO, data: Bytes::new(), chain_id: None, @@ -658,40 +659,8 @@ pub struct OptimismFields { pub enveloped_tx: Option, } -/// Transaction destination. -#[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub enum TransactTo { - /// Simple call to an address. - Call(Address), - /// Contract creation. - Create, -} - -impl TransactTo { - /// Calls the given address. - #[inline] - pub fn call(address: Address) -> Self { - Self::Call(address) - } - - /// Creates a contract. - #[inline] - pub fn create() -> Self { - Self::Create - } - /// Returns `true` if the transaction is `Call`. - #[inline] - pub fn is_call(&self) -> bool { - matches!(self, Self::Call(_)) - } - - /// Returns `true` if the transaction is `Create` or `Create2`. - #[inline] - pub fn is_create(&self) -> bool { - matches!(self, Self::Create) - } -} +/// Transaction destination +pub type TransactTo = TxKind; /// Create scheme. #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index c57f900b90..35019aa041 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -21,7 +21,7 @@ pub mod state; pub mod utilities; pub use alloy_primitives::{ self, address, b256, bytes, fixed_bytes, hex, hex_literal, ruint, uint, Address, Bytes, - FixedBytes, Log, LogData, B256, I256, U256, + FixedBytes, Log, LogData, TxKind, B256, I256, U256, }; pub use bitvec; pub use bytecode::*; diff --git a/crates/revm/benches/bench.rs b/crates/revm/benches/bench.rs index b45beefd6f..a135a367d2 100644 --- a/crates/revm/benches/bench.rs +++ b/crates/revm/benches/bench.rs @@ -4,7 +4,7 @@ use criterion::{ use revm::{ db::BenchmarkDB, interpreter::{analysis::to_analysed, Contract, DummyHost, Interpreter}, - primitives::{address, bytes, hex, BerlinSpec, Bytecode, Bytes, TransactTo, U256}, + primitives::{address, bytes, hex, BerlinSpec, Bytecode, Bytes, TxKind, U256}, Evm, }; use revm_interpreter::{opcode::make_instruction_table, SharedMemory, EMPTY_SHARED_MEMORY}; @@ -14,7 +14,7 @@ fn analysis(c: &mut Criterion) { let evm = Evm::builder() .modify_tx_env(|tx| { tx.caller = address!("0000000000000000000000000000000000000002"); - tx.transact_to = TransactTo::Call(address!("0000000000000000000000000000000000000000")); + tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000")); // evm.env.tx.data = bytes!("30627b7c"); tx.data = bytes!("8035F0CE"); }) @@ -50,7 +50,7 @@ fn snailtracer(c: &mut Criterion) { .with_db(BenchmarkDB::new_bytecode(bytecode(SNAILTRACER))) .modify_tx_env(|tx| { tx.caller = address!("1000000000000000000000000000000000000000"); - tx.transact_to = TransactTo::Call(address!("0000000000000000000000000000000000000000")); + tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000")); tx.data = bytes!("30627b7c"); }) .build(); @@ -70,7 +70,7 @@ fn transfer(c: &mut Criterion) { .with_db(BenchmarkDB::new_bytecode(Bytecode::new())) .modify_tx_env(|tx| { tx.caller = address!("0000000000000000000000000000000000000001"); - tx.transact_to = TransactTo::Call(address!("0000000000000000000000000000000000000000")); + tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000")); tx.value = U256::from(10); }) .build(); diff --git a/crates/revm/src/builder.rs b/crates/revm/src/builder.rs index a09f7c0bf5..c66b61f556 100644 --- a/crates/revm/src/builder.rs +++ b/crates/revm/src/builder.rs @@ -444,7 +444,7 @@ mod test { inspector::inspector_handle_register, inspectors::NoOpInspector, primitives::{ - address, AccountInfo, Address, Bytecode, Bytes, PrecompileResult, TransactTo, U256, + address, AccountInfo, Address, Bytecode, Bytes, PrecompileResult, TxKind, U256, }, Context, ContextPrecompile, ContextStatefulPrecompile, Evm, InMemoryDB, InnerEvmContext, }; @@ -474,7 +474,7 @@ mod test { .modify_db(|db| { db.insert_account_info(to_addr, AccountInfo::new(U256::ZERO, 0, code_hash, code)) }) - .modify_tx_env(|tx| tx.transact_to = TransactTo::Call(to_addr)) + .modify_tx_env(|tx| tx.transact_to = TxKind::Call(to_addr)) // we need to use handle register box to capture the custom context in the handle // register .append_handler_register_box(Box::new(move |handler| { @@ -523,7 +523,7 @@ mod test { .modify_db(|db| { db.insert_account_info(to_addr, AccountInfo::new(U256::ZERO, 0, code_hash, code)) }) - .modify_tx_env(|tx| tx.transact_to = TransactTo::Call(to_addr)) + .modify_tx_env(|tx| tx.transact_to = TxKind::Call(to_addr)) .append_handler_register(|handler| { handler.instruction_table.insert(0xEF, custom_instruction) }) diff --git a/crates/revm/src/evm.rs b/crates/revm/src/evm.rs index d5b853d220..5cb64af8c5 100644 --- a/crates/revm/src/evm.rs +++ b/crates/revm/src/evm.rs @@ -8,7 +8,7 @@ use crate::{ }, primitives::{ specification::SpecId, BlockEnv, Bytes, CfgEnv, EVMError, EVMResult, EnvWithHandlerCfg, - ExecutionResult, HandlerCfg, ResultAndState, TransactTo, TxEnv, + ExecutionResult, HandlerCfg, ResultAndState, TxEnv, TxKind, }, Context, ContextWithHandlerCfg, Frame, FrameOrResult, FrameResult, }; @@ -344,11 +344,11 @@ impl Evm<'_, EXT, DB> { let exec = self.handler.execution(); // call inner handling of call/create let first_frame_or_result = match ctx.evm.env.tx.transact_to { - TransactTo::Call(_) => exec.call( + TxKind::Call(_) => exec.call( ctx, CallInputs::new_boxed(&ctx.evm.env.tx, gas_limit).unwrap(), )?, - TransactTo::Create => { + TxKind::Create => { // if first byte of data is magic 0xEF00, then it is EOFCreate. if spec_id.is_enabled_in(SpecId::PRAGUE) && ctx diff --git a/crates/revm/src/handler/mainnet/pre_execution.rs b/crates/revm/src/handler/mainnet/pre_execution.rs index d3b9759dcf..3cc1d89a61 100644 --- a/crates/revm/src/handler/mainnet/pre_execution.rs +++ b/crates/revm/src/handler/mainnet/pre_execution.rs @@ -8,7 +8,7 @@ use crate::{ db::Database, Account, EVMError, Env, Spec, SpecId::{CANCUN, PRAGUE, SHANGHAI}, - TransactTo, BLOCKHASH_STORAGE_ADDRESS, U256, + TxKind, BLOCKHASH_STORAGE_ADDRESS, U256, }, Context, ContextPrecompiles, }; @@ -68,7 +68,7 @@ pub fn deduct_caller_inner(caller_account: &mut Account, env: &Env) caller_account.info.balance = caller_account.info.balance.saturating_sub(gas_cost); // bump the nonce for calls. Nonce for CREATE will be bumped in `handle_create`. - if matches!(env.tx.transact_to, TransactTo::Call(_)) { + if matches!(env.tx.transact_to, TxKind::Call(_)) { // Nonce is already checked caller_account.info.nonce = caller_account.info.nonce.saturating_add(1); } diff --git a/crates/revm/src/inspector/customprinter.rs b/crates/revm/src/inspector/customprinter.rs index ac7dd26537..ed42c4f7b4 100644 --- a/crates/revm/src/inspector/customprinter.rs +++ b/crates/revm/src/inspector/customprinter.rs @@ -140,7 +140,7 @@ mod test { }) .modify_tx_env(|tx| { tx.caller = address!("5fdcca53617f4d2b9134b29090c87d01058e27e0"); - tx.transact_to = crate::primitives::TransactTo::Call(callee); + tx.transact_to = crate::primitives::TxKind::Call(callee); tx.data = crate::primitives::Bytes::new(); tx.value = crate::primitives::U256::ZERO; }) diff --git a/crates/revm/src/inspector/gas.rs b/crates/revm/src/inspector/gas.rs index 7542c3d3bf..1100bd98e4 100644 --- a/crates/revm/src/inspector/gas.rs +++ b/crates/revm/src/inspector/gas.rs @@ -162,7 +162,7 @@ mod tests { db::BenchmarkDB, inspector::inspector_handle_register, interpreter::opcode, - primitives::{address, Bytecode, Bytes, TransactTo}, + primitives::{address, Bytecode, Bytes, TxKind}, Evm, }; @@ -189,8 +189,7 @@ mod tests { .modify_tx_env(|tx| { tx.clear(); tx.caller = address!("1000000000000000000000000000000000000000"); - tx.transact_to = - TransactTo::Call(address!("0000000000000000000000000000000000000000")); + tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000")); tx.gas_limit = 21100; }) .append_handler_register(inspector_handle_register) diff --git a/crates/revm/src/inspector/handler_register.rs b/crates/revm/src/inspector/handler_register.rs index 0c50058885..7c48284a03 100644 --- a/crates/revm/src/inspector/handler_register.rs +++ b/crates/revm/src/inspector/handler_register.rs @@ -334,7 +334,7 @@ mod tests { db::BenchmarkDB, inspector::inspector_handle_register, interpreter::opcode, - primitives::{address, Bytecode, Bytes, TransactTo}, + primitives::{address, Bytecode, Bytes, TxKind}, Evm, }; @@ -360,8 +360,7 @@ mod tests { .modify_tx_env(|tx| { tx.clear(); tx.caller = address!("1000000000000000000000000000000000000000"); - tx.transact_to = - TransactTo::Call(address!("0000000000000000000000000000000000000000")); + tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000")); tx.gas_limit = 21100; }) .append_handler_register(inspector_handle_register) diff --git a/crates/revm/src/optimism/fast_lz.rs b/crates/revm/src/optimism/fast_lz.rs index 51ea82d493..3906bcb362 100644 --- a/crates/revm/src/optimism/fast_lz.rs +++ b/crates/revm/src/optimism/fast_lz.rs @@ -112,7 +112,7 @@ mod tests { use crate::db::BenchmarkDB; use crate::{ primitives::address, primitives::bytes, primitives::Bytecode, primitives::Bytes, - primitives::TransactTo, primitives::U256, Evm, + primitives::TxKind, primitives::U256, Evm, }; use rstest::rstest; @@ -166,8 +166,7 @@ mod tests { .with_db(BenchmarkDB::new_bytecode(contract_bytecode.clone())) .modify_tx_env(|tx| { tx.caller = address!("1000000000000000000000000000000000000000"); - tx.transact_to = - TransactTo::Call(address!("0000000000000000000000000000000000000000")); + tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000")); tx.data = FastLz::fastLzCall::new((input,)).abi_encode().into(); }) .build(); diff --git a/documentation/src/crates/primitives/environment.md b/documentation/src/crates/primitives/environment.md index 8e33181527..8d56024b55 100644 --- a/documentation/src/crates/primitives/environment.md +++ b/documentation/src/crates/primitives/environment.md @@ -1,5 +1,5 @@ # Environment -A significant module that manages the execution environment of the EVM. The module contains objects and methods associated with processing transactions and blocks within such a blockchain environment. It defines several structures: `Env`, `BlockEnv`, `TxEnv`, `CfgEnv`, `TransactTo`, and `CreateScheme`. These structures contain various fields representing the block data, transaction data, environmental configurations, transaction recipient details, and the method of contract creation respectively. +A significant module that manages the execution environment of the EVM. The module contains objects and methods associated with processing transactions and blocks within such a blockchain environment. It defines several structures: `Env`, `BlockEnv`, `TxEnv`, `CfgEnv`, and `CreateScheme`. These structures contain various fields representing the block data, transaction data, environmental configurations, transaction recipient details, and the method of contract creation respectively. The `Env` structure, which encapsulates the environment of the EVM, contains methods for calculating effective gas prices and for validating block and transaction data. It also checks transactions against the current state of the associated account, which is necessary to validate the transaction's nonce and the account balance. Various Ethereum Improvement Proposals (EIPs) are also considered in these validations, such as [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) for the base fee, [EIP-3607](https://eips.ethereum.org/EIPS/eip-3607) for rejecting transactions from senders with deployed code, and [EIP-3298](https://eips.ethereum.org/EIPS/eip-3298) for disabling gas refunds. The code is structured to include optional features and to allow for changes in the EVM specifications. diff --git a/examples/fork_ref_transact.rs b/examples/fork_ref_transact.rs index 6953fda2a0..33258b46f0 100644 --- a/examples/fork_ref_transact.rs +++ b/examples/fork_ref_transact.rs @@ -3,7 +3,7 @@ use alloy_sol_types::SolCall; use ethers_providers::{Http, Provider}; use revm::{ db::{CacheDB, EmptyDB, EthersDB}, - primitives::{address, ExecutionResult, Output, TransactTo, U256}, + primitives::{address, ExecutionResult, Output, TxKind, U256}, Database, Evm, }; use std::sync::Arc; @@ -70,7 +70,7 @@ async fn main() -> anyhow::Result<()> { // change that to whatever caller you want to be tx.caller = address!("0000000000000000000000000000000000000000"); // account you want to transact with - tx.transact_to = TransactTo::Call(pool_address); + tx.transact_to = TxKind::Call(pool_address); // calldata formed via abigen tx.data = encoded.into(); // transaction value in wei diff --git a/examples/generate_block_traces.rs b/examples/generate_block_traces.rs index cfd8f030c1..59d9d03680 100644 --- a/examples/generate_block_traces.rs +++ b/examples/generate_block_traces.rs @@ -6,7 +6,7 @@ use ethers_providers::{Http, Provider}; use indicatif::ProgressBar; use revm::db::{CacheDB, EthersDB, StateBuilder}; use revm::inspectors::TracerEip3155; -use revm::primitives::{Address, TransactTo, U256}; +use revm::primitives::{Address, TxKind, U256}; use revm::{inspector_handle_register, Evm}; use std::fs::OpenOptions; use std::io::BufWriter; @@ -143,10 +143,8 @@ async fn main() -> anyhow::Result<()> { } etx.transact_to = match tx.to { - Some(to_address) => { - TransactTo::Call(Address::from(to_address.as_fixed_bytes())) - } - None => TransactTo::create(), + Some(to_address) => TxKind::Call(Address::from(to_address.as_fixed_bytes())), + None => TxKind::Create, }; }) .build(); diff --git a/examples/uniswap_v2_usdc_swap.rs b/examples/uniswap_v2_usdc_swap.rs index a57a982642..3f9905bf42 100644 --- a/examples/uniswap_v2_usdc_swap.rs +++ b/examples/uniswap_v2_usdc_swap.rs @@ -7,7 +7,7 @@ use reqwest::Client; use revm::{ db::{AlloyDB, CacheDB}, primitives::{ - address, keccak256, AccountInfo, Address, Bytes, ExecutionResult, Output, TransactTo, U256, + address, keccak256, AccountInfo, Address, Bytes, ExecutionResult, Output, TxKind, U256, }, Evm, }; @@ -95,7 +95,7 @@ fn balance_of(token: Address, address: Address, cache_db: &mut AlloyCacheDB) -> .modify_tx_env(|tx| { // 0x1 because calling USDC proxy from zero address fails tx.caller = address!("0000000000000000000000000000000000000001"); - tx.transact_to = TransactTo::Call(token); + tx.transact_to = TxKind::Call(token); tx.data = encoded.into(); tx.value = U256::from(0); }) @@ -139,7 +139,7 @@ async fn get_amount_out( .with_db(cache_db) .modify_tx_env(|tx| { tx.caller = address!("0000000000000000000000000000000000000000"); - tx.transact_to = TransactTo::Call(uniswap_v2_router); + tx.transact_to = TxKind::Call(uniswap_v2_router); tx.data = encoded.into(); tx.value = U256::from(0); }) @@ -172,7 +172,7 @@ fn get_reserves(pair_address: Address, cache_db: &mut AlloyCacheDB) -> Result<(U .with_db(cache_db) .modify_tx_env(|tx| { tx.caller = address!("0000000000000000000000000000000000000000"); - tx.transact_to = TransactTo::Call(pair_address); + tx.transact_to = TxKind::Call(pair_address); tx.data = encoded.into(); tx.value = U256::from(0); }) @@ -221,7 +221,7 @@ fn swap( .with_db(cache_db) .modify_tx_env(|tx| { tx.caller = from; - tx.transact_to = TransactTo::Call(pool_address); + tx.transact_to = TxKind::Call(pool_address); tx.data = encoded.into(); tx.value = U256::from(0); }) @@ -254,7 +254,7 @@ fn transfer( .with_db(cache_db) .modify_tx_env(|tx| { tx.caller = from; - tx.transact_to = TransactTo::Call(token); + tx.transact_to = TxKind::Call(token); tx.data = encoded.into(); tx.value = U256::from(0); })