Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 4 additions & 103 deletions crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use alloy_network::{AnyReceiptEnvelope, AnyRpcTransaction, AnyTransactionReceipt
use alloy_primitives::{Address, B256, Bloom, Bytes, TxHash, TxKind, U64, U256};
use alloy_rlp::{Decodable, Encodable, Header};
use alloy_rpc_types::{
AccessList, ConversionError, Transaction as RpcTransaction, TransactionReceipt,
ConversionError, Transaction as RpcTransaction, TransactionReceipt,
request::TransactionRequest, trace::otterscan::OtsReceipt,
};
use alloy_serde::{OtherFields, WithOtherFields};
Expand Down Expand Up @@ -466,93 +466,10 @@ impl TypedTransaction {
}
}

/// Returns a helper type that contains commonly used values as fields
pub fn essentials(&self) -> TransactionEssentials {
pub fn as_legacy(&self) -> Option<&Signed<TxLegacy>> {
match self {
Self::Legacy(t) => TransactionEssentials {
kind: t.tx().to,
input: t.tx().input.clone(),
nonce: t.tx().nonce,
gas_limit: t.tx().gas_limit,
gas_price: Some(t.tx().gas_price),
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
max_fee_per_blob_gas: None,
blob_versioned_hashes: None,
value: t.tx().value,
chain_id: t.tx().chain_id,
access_list: Default::default(),
},
Self::EIP2930(t) => TransactionEssentials {
kind: t.tx().to,
input: t.tx().input.clone(),
nonce: t.tx().nonce,
gas_limit: t.tx().gas_limit,
gas_price: Some(t.tx().gas_price),
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
max_fee_per_blob_gas: None,
blob_versioned_hashes: None,
value: t.tx().value,
chain_id: Some(t.tx().chain_id),
access_list: t.tx().access_list.clone(),
},
Self::EIP1559(t) => TransactionEssentials {
kind: t.tx().to,
input: t.tx().input.clone(),
nonce: t.tx().nonce,
gas_limit: t.tx().gas_limit,
gas_price: None,
max_fee_per_gas: Some(t.tx().max_fee_per_gas),
max_priority_fee_per_gas: Some(t.tx().max_priority_fee_per_gas),
max_fee_per_blob_gas: None,
blob_versioned_hashes: None,
value: t.tx().value,
chain_id: Some(t.tx().chain_id),
access_list: t.tx().access_list.clone(),
},
Self::EIP4844(t) => TransactionEssentials {
kind: TxKind::Call(t.tx().tx().to),
input: t.tx().tx().input.clone(),
nonce: t.tx().tx().nonce,
gas_limit: t.tx().tx().gas_limit,
gas_price: None,
max_fee_per_gas: Some(t.tx().tx().max_fee_per_gas),
max_priority_fee_per_gas: Some(t.tx().tx().max_priority_fee_per_gas),
max_fee_per_blob_gas: Some(t.tx().tx().max_fee_per_blob_gas),
blob_versioned_hashes: Some(t.tx().tx().blob_versioned_hashes.clone()),
value: t.tx().tx().value,
chain_id: Some(t.tx().tx().chain_id),
access_list: t.tx().tx().access_list.clone(),
},
Self::EIP7702(t) => TransactionEssentials {
kind: TxKind::Call(t.tx().to),
input: t.tx().input.clone(),
nonce: t.tx().nonce,
gas_limit: t.tx().gas_limit,
gas_price: None,
max_fee_per_gas: Some(t.tx().max_fee_per_gas),
max_priority_fee_per_gas: Some(t.tx().max_priority_fee_per_gas),
max_fee_per_blob_gas: None,
blob_versioned_hashes: None,
value: t.tx().value,
chain_id: Some(t.tx().chain_id),
access_list: t.tx().access_list.clone(),
},
Self::Deposit(t) => TransactionEssentials {
kind: t.to,
input: t.input.clone(),
nonce: 0,
gas_limit: t.gas_limit,
gas_price: Some(0),
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
max_fee_per_blob_gas: None,
blob_versioned_hashes: None,
value: t.value,
chain_id: t.chain_id(),
access_list: Default::default(),
},
Self::Legacy(tx) => Some(tx),
_ => None,
}
}

Expand Down Expand Up @@ -594,22 +511,6 @@ impl TypedTransaction {
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TransactionEssentials {
pub kind: TxKind,
pub input: Bytes,
pub nonce: u64,
pub gas_limit: u64,
pub gas_price: Option<u128>,
pub max_fee_per_gas: Option<u128>,
pub max_priority_fee_per_gas: Option<u128>,
pub max_fee_per_blob_gas: Option<u128>,
pub blob_versioned_hashes: Option<Vec<B256>>,
pub value: U256,
pub chain_id: Option<u64>,
pub access_list: AccessList,
}

/// Represents all relevant information of an executed transaction
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct TransactionInfo {
Expand Down
6 changes: 3 additions & 3 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3752,8 +3752,8 @@ impl TransactionValidator for Backend {
return Err(InvalidTransactionError::FeeCapTooLow);
}

if let (Some(max_priority_fee_per_gas), Some(max_fee_per_gas)) =
(tx.essentials().max_priority_fee_per_gas, tx.essentials().max_fee_per_gas)
if let (Some(max_priority_fee_per_gas), max_fee_per_gas) =
(tx.as_ref().max_priority_fee_per_gas(), tx.as_ref().max_fee_per_gas())
&& max_priority_fee_per_gas > max_fee_per_gas
{
warn!(target: "backend", "max priority fee per gas={}, too high, max fee per gas={}", max_priority_fee_per_gas, max_fee_per_gas);
Expand All @@ -3764,7 +3764,7 @@ impl TransactionValidator for Backend {
// EIP-4844 blob fee validation
if env.evm_env.cfg_env.spec >= SpecId::CANCUN
&& tx.transaction.is_eip4844()
&& let Some(max_fee_per_blob_gas) = tx.essentials().max_fee_per_blob_gas
&& let Some(max_fee_per_blob_gas) = tx.as_ref().max_fee_per_blob_gas()
&& let Some(blob_gas_and_price) = &env.evm_env.block_env.blob_excess_gas_and_price
&& max_fee_per_blob_gas < blob_gas_and_price.blob_gasprice
{
Expand Down
Loading