Skip to content

Commit 7db1adc

Browse files
authoredJun 19, 2024··
refactor: replace TransactTo with TxKind (#1542)
* refactor: replace TransactTo with TxKind * misc: apply review suggestions
1 parent e6b52af commit 7db1adc

File tree

23 files changed

+59
-93
lines changed

23 files changed

+59
-93
lines changed
 

‎bins/revm-test/src/bin/analysis.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use revm::{
22
db::BenchmarkDB,
33
interpreter::analysis::to_analysed,
4-
primitives::{address, bytes, Bytecode, Bytes, TransactTo},
4+
primitives::{address, bytes, Bytecode, Bytes, TxKind},
55
Evm,
66
};
77
use std::time::Instant;
@@ -17,7 +17,7 @@ fn main() {
1717
.modify_tx_env(|tx| {
1818
// execution globals block hash/gas_limit/coinbase/timestamp..
1919
tx.caller = address!("1000000000000000000000000000000000000000");
20-
tx.transact_to = TransactTo::Call(address!("0000000000000000000000000000000000000000"));
20+
tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000"));
2121
//evm.env.tx.data = Bytes::from(hex::decode("30627b7c").unwrap());
2222
tx.data = bytes!("8035F0CE");
2323
})

‎bins/revm-test/src/bin/burntpix/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use revm::{
55
db::{CacheDB, EmptyDB},
66
primitives::{
77
address, hex, keccak256, AccountInfo, Address, Bytecode, Bytes, ExecutionResult, Output,
8-
TransactTo, B256, U256,
8+
TxKind, B256, U256,
99
},
1010
Evm,
1111
};
@@ -38,7 +38,7 @@ fn main() {
3838
let mut evm = Evm::builder()
3939
.modify_tx_env(|tx| {
4040
tx.caller = address!("1000000000000000000000000000000000000000");
41-
tx.transact_to = TransactTo::Call(BURNTPIX_MAIN_ADDRESS);
41+
tx.transact_to = TxKind::Call(BURNTPIX_MAIN_ADDRESS);
4242
tx.data = run_call_data.clone().into();
4343
})
4444
.with_db(db)

‎bins/revm-test/src/bin/snailtracer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use revm::{
22
db::BenchmarkDB,
33
interpreter::analysis::to_analysed,
4-
primitives::{address, bytes, Bytecode, Bytes, TransactTo},
4+
primitives::{address, bytes, Bytecode, Bytes, TxKind},
55
Evm,
66
};
77

@@ -14,7 +14,7 @@ pub fn simple_example() {
1414
.modify_tx_env(|tx| {
1515
// execution globals block hash/gas_limit/coinbase/timestamp..
1616
tx.caller = address!("1000000000000000000000000000000000000000");
17-
tx.transact_to = TransactTo::Call(address!("0000000000000000000000000000000000000000"));
17+
tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000"));
1818
tx.data = bytes!("30627b7c");
1919
})
2020
.build();

‎bins/revm-test/src/bin/transfer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use revm::{
22
db::BenchmarkDB,
3-
primitives::{Bytecode, TransactTo, U256},
3+
primitives::{Bytecode, TxKind, U256},
44
Evm,
55
};
66

@@ -16,7 +16,7 @@ fn main() {
1616
.parse()
1717
.unwrap();
1818
tx.value = U256::from(10);
19-
tx.transact_to = TransactTo::Call(
19+
tx.transact_to = TxKind::Call(
2020
"0x0000000000000000000000000000000000000000"
2121
.parse()
2222
.unwrap(),

‎bins/revme/src/cmd/evmrunner.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use revm::{
22
db::BenchmarkDB,
33
inspector_handle_register,
44
inspectors::TracerEip3155,
5-
primitives::{Address, Bytecode, TransactTo},
5+
primitives::{Address, Bytecode, TxKind},
66
Evm,
77
};
88
use std::io::Error as IoError;
@@ -86,7 +86,7 @@ impl Cmd {
8686
tx.caller = "0x0000000000000000000000000000000000000001"
8787
.parse()
8888
.unwrap();
89-
tx.transact_to = TransactTo::Call(Address::ZERO);
89+
tx.transact_to = TxKind::Call(Address::ZERO);
9090
tx.data = input;
9191
})
9292
.build();

‎bins/revme/src/cmd/statetest/runner.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use revm::{
1010
inspectors::TracerEip3155,
1111
primitives::{
1212
calc_excess_blob_gas, keccak256, Bytecode, Bytes, EVMResultGeneric, Env, Eof,
13-
ExecutionResult, SpecId, TransactTo, B256, EOF_MAGIC_BYTES, U256,
13+
ExecutionResult, SpecId, TxKind, B256, EOF_MAGIC_BYTES, U256,
1414
},
1515
Evm, State,
1616
};
@@ -364,8 +364,8 @@ pub fn execute_test_suite(
364364
.collect();
365365

366366
let to = match unit.transaction.to {
367-
Some(add) => TransactTo::Call(add),
368-
None => TransactTo::Create,
367+
Some(add) => TxKind::Call(add),
368+
None => TxKind::Create,
369369
};
370370
env.tx.transact_to = to;
371371

‎crates/interpreter/src/interpreter/contract.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use revm_primitives::TxKind;
2+
13
use super::analysis::to_analysed;
24
use crate::{
3-
primitives::{Address, Bytecode, Bytes, Env, TransactTo, B256, U256},
5+
primitives::{Address, Bytecode, Bytes, Env, B256, U256},
46
CallInputs,
57
};
68

@@ -50,8 +52,8 @@ impl Contract {
5052
#[inline]
5153
pub fn new_env(env: &Env, bytecode: Bytecode, hash: Option<B256>) -> Self {
5254
let contract_address = match env.tx.transact_to {
53-
TransactTo::Call(caller) => caller,
54-
TransactTo::Create => Address::ZERO,
55+
TxKind::Call(caller) => caller,
56+
TxKind::Create => Address::ZERO,
5557
};
5658
Self::new(
5759
env.tx.data.clone(),

‎crates/interpreter/src/interpreter_action/call_inputs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::primitives::{Address, Bytes, TransactTo, TxEnv, U256};
1+
use crate::primitives::{Address, Bytes, TxEnv, TxKind, U256};
22
use core::ops::Range;
33
use std::boxed::Box;
44

@@ -47,7 +47,7 @@ impl CallInputs {
4747
///
4848
/// Returns `None` if the transaction is not a call.
4949
pub fn new(tx_env: &TxEnv, gas_limit: u64) -> Option<Self> {
50-
let TransactTo::Call(target_address) = tx_env.transact_to else {
50+
let TxKind::Call(target_address) = tx_env.transact_to else {
5151
return None;
5252
};
5353
Some(CallInputs {

‎crates/interpreter/src/interpreter_action/create_inputs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub use crate::primitives::CreateScheme;
2-
use crate::primitives::{Address, Bytes, TransactTo, TxEnv, U256};
2+
use crate::primitives::{Address, Bytes, TxEnv, TxKind, U256};
33
use std::boxed::Box;
44

55
/// Inputs for a create call.
@@ -21,7 +21,7 @@ pub struct CreateInputs {
2121
impl CreateInputs {
2222
/// Creates new create inputs.
2323
pub fn new(tx_env: &TxEnv, gas_limit: u64) -> Option<Self> {
24-
let TransactTo::Create = tx_env.transact_to else {
24+
let TxKind::Create = tx_env.transact_to else {
2525
return None;
2626
};
2727

‎crates/primitives/src/env.rs

+5-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod handler_cfg;
22

3+
use alloy_primitives::TxKind;
34
pub use handler_cfg::{CfgEnvWithHandlerCfg, EnvWithHandlerCfg, HandlerCfg};
45

56
use crate::{
@@ -503,7 +504,7 @@ pub struct TxEnv {
503504
/// The gas price of the transaction.
504505
pub gas_price: U256,
505506
/// The destination of the transaction.
506-
pub transact_to: TransactTo,
507+
pub transact_to: TxKind,
507508
/// The value sent to `transact_to`.
508509
pub value: U256,
509510
/// The data of the transaction.
@@ -585,7 +586,7 @@ impl Default for TxEnv {
585586
gas_limit: u64::MAX,
586587
gas_price: U256::ZERO,
587588
gas_priority_fee: None,
588-
transact_to: TransactTo::Call(Address::ZERO), // will do nothing
589+
transact_to: TxKind::Call(Address::ZERO), // will do nothing
589590
value: U256::ZERO,
590591
data: Bytes::new(),
591592
chain_id: None,
@@ -658,40 +659,8 @@ pub struct OptimismFields {
658659
pub enveloped_tx: Option<Bytes>,
659660
}
660661

661-
/// Transaction destination.
662-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
663-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
664-
pub enum TransactTo {
665-
/// Simple call to an address.
666-
Call(Address),
667-
/// Contract creation.
668-
Create,
669-
}
670-
671-
impl TransactTo {
672-
/// Calls the given address.
673-
#[inline]
674-
pub fn call(address: Address) -> Self {
675-
Self::Call(address)
676-
}
677-
678-
/// Creates a contract.
679-
#[inline]
680-
pub fn create() -> Self {
681-
Self::Create
682-
}
683-
/// Returns `true` if the transaction is `Call`.
684-
#[inline]
685-
pub fn is_call(&self) -> bool {
686-
matches!(self, Self::Call(_))
687-
}
688-
689-
/// Returns `true` if the transaction is `Create` or `Create2`.
690-
#[inline]
691-
pub fn is_create(&self) -> bool {
692-
matches!(self, Self::Create)
693-
}
694-
}
662+
/// Transaction destination
663+
pub type TransactTo = TxKind;
695664

696665
/// Create scheme.
697666
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]

‎crates/primitives/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub mod state;
2121
pub mod utilities;
2222
pub use alloy_primitives::{
2323
self, address, b256, bytes, fixed_bytes, hex, hex_literal, ruint, uint, Address, Bytes,
24-
FixedBytes, Log, LogData, B256, I256, U256,
24+
FixedBytes, Log, LogData, TxKind, B256, I256, U256,
2525
};
2626
pub use bitvec;
2727
pub use bytecode::*;

‎crates/revm/benches/bench.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use criterion::{
44
use revm::{
55
db::BenchmarkDB,
66
interpreter::{analysis::to_analysed, Contract, DummyHost, Interpreter},
7-
primitives::{address, bytes, hex, BerlinSpec, Bytecode, Bytes, TransactTo, U256},
7+
primitives::{address, bytes, hex, BerlinSpec, Bytecode, Bytes, TxKind, U256},
88
Evm,
99
};
1010
use revm_interpreter::{opcode::make_instruction_table, SharedMemory, EMPTY_SHARED_MEMORY};
@@ -14,7 +14,7 @@ fn analysis(c: &mut Criterion) {
1414
let evm = Evm::builder()
1515
.modify_tx_env(|tx| {
1616
tx.caller = address!("0000000000000000000000000000000000000002");
17-
tx.transact_to = TransactTo::Call(address!("0000000000000000000000000000000000000000"));
17+
tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000"));
1818
// evm.env.tx.data = bytes!("30627b7c");
1919
tx.data = bytes!("8035F0CE");
2020
})
@@ -50,7 +50,7 @@ fn snailtracer(c: &mut Criterion) {
5050
.with_db(BenchmarkDB::new_bytecode(bytecode(SNAILTRACER)))
5151
.modify_tx_env(|tx| {
5252
tx.caller = address!("1000000000000000000000000000000000000000");
53-
tx.transact_to = TransactTo::Call(address!("0000000000000000000000000000000000000000"));
53+
tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000"));
5454
tx.data = bytes!("30627b7c");
5555
})
5656
.build();
@@ -70,7 +70,7 @@ fn transfer(c: &mut Criterion) {
7070
.with_db(BenchmarkDB::new_bytecode(Bytecode::new()))
7171
.modify_tx_env(|tx| {
7272
tx.caller = address!("0000000000000000000000000000000000000001");
73-
tx.transact_to = TransactTo::Call(address!("0000000000000000000000000000000000000000"));
73+
tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000"));
7474
tx.value = U256::from(10);
7575
})
7676
.build();

‎crates/revm/src/builder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ mod test {
444444
inspector::inspector_handle_register,
445445
inspectors::NoOpInspector,
446446
primitives::{
447-
address, AccountInfo, Address, Bytecode, Bytes, PrecompileResult, TransactTo, U256,
447+
address, AccountInfo, Address, Bytecode, Bytes, PrecompileResult, TxKind, U256,
448448
},
449449
Context, ContextPrecompile, ContextStatefulPrecompile, Evm, InMemoryDB, InnerEvmContext,
450450
};
@@ -474,7 +474,7 @@ mod test {
474474
.modify_db(|db| {
475475
db.insert_account_info(to_addr, AccountInfo::new(U256::ZERO, 0, code_hash, code))
476476
})
477-
.modify_tx_env(|tx| tx.transact_to = TransactTo::Call(to_addr))
477+
.modify_tx_env(|tx| tx.transact_to = TxKind::Call(to_addr))
478478
// we need to use handle register box to capture the custom context in the handle
479479
// register
480480
.append_handler_register_box(Box::new(move |handler| {
@@ -523,7 +523,7 @@ mod test {
523523
.modify_db(|db| {
524524
db.insert_account_info(to_addr, AccountInfo::new(U256::ZERO, 0, code_hash, code))
525525
})
526-
.modify_tx_env(|tx| tx.transact_to = TransactTo::Call(to_addr))
526+
.modify_tx_env(|tx| tx.transact_to = TxKind::Call(to_addr))
527527
.append_handler_register(|handler| {
528528
handler.instruction_table.insert(0xEF, custom_instruction)
529529
})

‎crates/revm/src/evm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
},
99
primitives::{
1010
specification::SpecId, BlockEnv, Bytes, CfgEnv, EVMError, EVMResult, EnvWithHandlerCfg,
11-
ExecutionResult, HandlerCfg, ResultAndState, TransactTo, TxEnv,
11+
ExecutionResult, HandlerCfg, ResultAndState, TxEnv, TxKind,
1212
},
1313
Context, ContextWithHandlerCfg, Frame, FrameOrResult, FrameResult,
1414
};
@@ -344,11 +344,11 @@ impl<EXT, DB: Database> Evm<'_, EXT, DB> {
344344
let exec = self.handler.execution();
345345
// call inner handling of call/create
346346
let first_frame_or_result = match ctx.evm.env.tx.transact_to {
347-
TransactTo::Call(_) => exec.call(
347+
TxKind::Call(_) => exec.call(
348348
ctx,
349349
CallInputs::new_boxed(&ctx.evm.env.tx, gas_limit).unwrap(),
350350
)?,
351-
TransactTo::Create => {
351+
TxKind::Create => {
352352
// if first byte of data is magic 0xEF00, then it is EOFCreate.
353353
if spec_id.is_enabled_in(SpecId::PRAGUE)
354354
&& ctx

‎crates/revm/src/handler/mainnet/pre_execution.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
db::Database,
99
Account, EVMError, Env, Spec,
1010
SpecId::{CANCUN, PRAGUE, SHANGHAI},
11-
TransactTo, BLOCKHASH_STORAGE_ADDRESS, U256,
11+
TxKind, BLOCKHASH_STORAGE_ADDRESS, U256,
1212
},
1313
Context, ContextPrecompiles,
1414
};
@@ -68,7 +68,7 @@ pub fn deduct_caller_inner<SPEC: Spec>(caller_account: &mut Account, env: &Env)
6868
caller_account.info.balance = caller_account.info.balance.saturating_sub(gas_cost);
6969

7070
// bump the nonce for calls. Nonce for CREATE will be bumped in `handle_create`.
71-
if matches!(env.tx.transact_to, TransactTo::Call(_)) {
71+
if matches!(env.tx.transact_to, TxKind::Call(_)) {
7272
// Nonce is already checked
7373
caller_account.info.nonce = caller_account.info.nonce.saturating_add(1);
7474
}

‎crates/revm/src/inspector/customprinter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ mod test {
140140
})
141141
.modify_tx_env(|tx| {
142142
tx.caller = address!("5fdcca53617f4d2b9134b29090c87d01058e27e0");
143-
tx.transact_to = crate::primitives::TransactTo::Call(callee);
143+
tx.transact_to = crate::primitives::TxKind::Call(callee);
144144
tx.data = crate::primitives::Bytes::new();
145145
tx.value = crate::primitives::U256::ZERO;
146146
})

‎crates/revm/src/inspector/gas.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ mod tests {
162162
db::BenchmarkDB,
163163
inspector::inspector_handle_register,
164164
interpreter::opcode,
165-
primitives::{address, Bytecode, Bytes, TransactTo},
165+
primitives::{address, Bytecode, Bytes, TxKind},
166166
Evm,
167167
};
168168

@@ -189,8 +189,7 @@ mod tests {
189189
.modify_tx_env(|tx| {
190190
tx.clear();
191191
tx.caller = address!("1000000000000000000000000000000000000000");
192-
tx.transact_to =
193-
TransactTo::Call(address!("0000000000000000000000000000000000000000"));
192+
tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000"));
194193
tx.gas_limit = 21100;
195194
})
196195
.append_handler_register(inspector_handle_register)

‎crates/revm/src/inspector/handler_register.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ mod tests {
334334
db::BenchmarkDB,
335335
inspector::inspector_handle_register,
336336
interpreter::opcode,
337-
primitives::{address, Bytecode, Bytes, TransactTo},
337+
primitives::{address, Bytecode, Bytes, TxKind},
338338
Evm,
339339
};
340340

@@ -360,8 +360,7 @@ mod tests {
360360
.modify_tx_env(|tx| {
361361
tx.clear();
362362
tx.caller = address!("1000000000000000000000000000000000000000");
363-
tx.transact_to =
364-
TransactTo::Call(address!("0000000000000000000000000000000000000000"));
363+
tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000"));
365364
tx.gas_limit = 21100;
366365
})
367366
.append_handler_register(inspector_handle_register)

‎crates/revm/src/optimism/fast_lz.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ mod tests {
112112
use crate::db::BenchmarkDB;
113113
use crate::{
114114
primitives::address, primitives::bytes, primitives::Bytecode, primitives::Bytes,
115-
primitives::TransactTo, primitives::U256, Evm,
115+
primitives::TxKind, primitives::U256, Evm,
116116
};
117117

118118
use rstest::rstest;
@@ -166,8 +166,7 @@ mod tests {
166166
.with_db(BenchmarkDB::new_bytecode(contract_bytecode.clone()))
167167
.modify_tx_env(|tx| {
168168
tx.caller = address!("1000000000000000000000000000000000000000");
169-
tx.transact_to =
170-
TransactTo::Call(address!("0000000000000000000000000000000000000000"));
169+
tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000"));
171170
tx.data = FastLz::fastLzCall::new((input,)).abi_encode().into();
172171
})
173172
.build();
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Environment
22

3-
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.
3+
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.
44

55
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.

‎examples/fork_ref_transact.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use alloy_sol_types::SolCall;
33
use ethers_providers::{Http, Provider};
44
use revm::{
55
db::{CacheDB, EmptyDB, EthersDB},
6-
primitives::{address, ExecutionResult, Output, TransactTo, U256},
6+
primitives::{address, ExecutionResult, Output, TxKind, U256},
77
Database, Evm,
88
};
99
use std::sync::Arc;
@@ -70,7 +70,7 @@ async fn main() -> anyhow::Result<()> {
7070
// change that to whatever caller you want to be
7171
tx.caller = address!("0000000000000000000000000000000000000000");
7272
// account you want to transact with
73-
tx.transact_to = TransactTo::Call(pool_address);
73+
tx.transact_to = TxKind::Call(pool_address);
7474
// calldata formed via abigen
7575
tx.data = encoded.into();
7676
// transaction value in wei

‎examples/generate_block_traces.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use ethers_providers::{Http, Provider};
66
use indicatif::ProgressBar;
77
use revm::db::{CacheDB, EthersDB, StateBuilder};
88
use revm::inspectors::TracerEip3155;
9-
use revm::primitives::{Address, TransactTo, U256};
9+
use revm::primitives::{Address, TxKind, U256};
1010
use revm::{inspector_handle_register, Evm};
1111
use std::fs::OpenOptions;
1212
use std::io::BufWriter;
@@ -143,10 +143,8 @@ async fn main() -> anyhow::Result<()> {
143143
}
144144

145145
etx.transact_to = match tx.to {
146-
Some(to_address) => {
147-
TransactTo::Call(Address::from(to_address.as_fixed_bytes()))
148-
}
149-
None => TransactTo::create(),
146+
Some(to_address) => TxKind::Call(Address::from(to_address.as_fixed_bytes())),
147+
None => TxKind::Create,
150148
};
151149
})
152150
.build();

‎examples/uniswap_v2_usdc_swap.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use reqwest::Client;
77
use revm::{
88
db::{AlloyDB, CacheDB},
99
primitives::{
10-
address, keccak256, AccountInfo, Address, Bytes, ExecutionResult, Output, TransactTo, U256,
10+
address, keccak256, AccountInfo, Address, Bytes, ExecutionResult, Output, TxKind, U256,
1111
},
1212
Evm,
1313
};
@@ -95,7 +95,7 @@ fn balance_of(token: Address, address: Address, cache_db: &mut AlloyCacheDB) ->
9595
.modify_tx_env(|tx| {
9696
// 0x1 because calling USDC proxy from zero address fails
9797
tx.caller = address!("0000000000000000000000000000000000000001");
98-
tx.transact_to = TransactTo::Call(token);
98+
tx.transact_to = TxKind::Call(token);
9999
tx.data = encoded.into();
100100
tx.value = U256::from(0);
101101
})
@@ -139,7 +139,7 @@ async fn get_amount_out(
139139
.with_db(cache_db)
140140
.modify_tx_env(|tx| {
141141
tx.caller = address!("0000000000000000000000000000000000000000");
142-
tx.transact_to = TransactTo::Call(uniswap_v2_router);
142+
tx.transact_to = TxKind::Call(uniswap_v2_router);
143143
tx.data = encoded.into();
144144
tx.value = U256::from(0);
145145
})
@@ -172,7 +172,7 @@ fn get_reserves(pair_address: Address, cache_db: &mut AlloyCacheDB) -> Result<(U
172172
.with_db(cache_db)
173173
.modify_tx_env(|tx| {
174174
tx.caller = address!("0000000000000000000000000000000000000000");
175-
tx.transact_to = TransactTo::Call(pair_address);
175+
tx.transact_to = TxKind::Call(pair_address);
176176
tx.data = encoded.into();
177177
tx.value = U256::from(0);
178178
})
@@ -221,7 +221,7 @@ fn swap(
221221
.with_db(cache_db)
222222
.modify_tx_env(|tx| {
223223
tx.caller = from;
224-
tx.transact_to = TransactTo::Call(pool_address);
224+
tx.transact_to = TxKind::Call(pool_address);
225225
tx.data = encoded.into();
226226
tx.value = U256::from(0);
227227
})
@@ -254,7 +254,7 @@ fn transfer(
254254
.with_db(cache_db)
255255
.modify_tx_env(|tx| {
256256
tx.caller = from;
257-
tx.transact_to = TransactTo::Call(token);
257+
tx.transact_to = TxKind::Call(token);
258258
tx.data = encoded.into();
259259
tx.value = U256::from(0);
260260
})

0 commit comments

Comments
 (0)
Please sign in to comment.