Skip to content

Commit 36cf1e2

Browse files
committed
refactor: replace TransactTo with TxKind
1 parent 41e2f7f commit 36cf1e2

File tree

23 files changed

+57
-94
lines changed

23 files changed

+57
-94
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

+3-37
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,41 +659,6 @@ 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-
}
695-
696662
/// Create scheme.
697663
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
698664
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]

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)

0 commit comments

Comments
 (0)