Skip to content

Commit 8436d7c

Browse files
mablrmattsse
andauthored
refactor(anvil): remove TypedTransaction::essentials() method (#12631)
* refactor(anvil): remove `TypedTransaction::essentials()` method * refactor(anvil): remove `TransactionEssentials` struct * fix: remove used import --------- Co-authored-by: Matthias Seitz <[email protected]>
1 parent 9b22631 commit 8436d7c

File tree

2 files changed

+7
-106
lines changed
  • crates/anvil

2 files changed

+7
-106
lines changed

crates/anvil/core/src/eth/transaction/mod.rs

Lines changed: 4 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use alloy_network::{AnyReceiptEnvelope, AnyRpcTransaction, AnyTransactionReceipt
1414
use alloy_primitives::{Address, B256, Bloom, Bytes, TxHash, TxKind, U64, U256};
1515
use alloy_rlp::{Decodable, Encodable, Header};
1616
use alloy_rpc_types::{
17-
AccessList, ConversionError, Transaction as RpcTransaction, TransactionReceipt,
17+
ConversionError, Transaction as RpcTransaction, TransactionReceipt,
1818
request::TransactionRequest, trace::otterscan::OtsReceipt,
1919
};
2020
use alloy_serde::{OtherFields, WithOtherFields};
@@ -466,93 +466,10 @@ impl TypedTransaction {
466466
}
467467
}
468468

469-
/// Returns a helper type that contains commonly used values as fields
470-
pub fn essentials(&self) -> TransactionEssentials {
469+
pub fn as_legacy(&self) -> Option<&Signed<TxLegacy>> {
471470
match self {
472-
Self::Legacy(t) => TransactionEssentials {
473-
kind: t.tx().to,
474-
input: t.tx().input.clone(),
475-
nonce: t.tx().nonce,
476-
gas_limit: t.tx().gas_limit,
477-
gas_price: Some(t.tx().gas_price),
478-
max_fee_per_gas: None,
479-
max_priority_fee_per_gas: None,
480-
max_fee_per_blob_gas: None,
481-
blob_versioned_hashes: None,
482-
value: t.tx().value,
483-
chain_id: t.tx().chain_id,
484-
access_list: Default::default(),
485-
},
486-
Self::EIP2930(t) => TransactionEssentials {
487-
kind: t.tx().to,
488-
input: t.tx().input.clone(),
489-
nonce: t.tx().nonce,
490-
gas_limit: t.tx().gas_limit,
491-
gas_price: Some(t.tx().gas_price),
492-
max_fee_per_gas: None,
493-
max_priority_fee_per_gas: None,
494-
max_fee_per_blob_gas: None,
495-
blob_versioned_hashes: None,
496-
value: t.tx().value,
497-
chain_id: Some(t.tx().chain_id),
498-
access_list: t.tx().access_list.clone(),
499-
},
500-
Self::EIP1559(t) => TransactionEssentials {
501-
kind: t.tx().to,
502-
input: t.tx().input.clone(),
503-
nonce: t.tx().nonce,
504-
gas_limit: t.tx().gas_limit,
505-
gas_price: None,
506-
max_fee_per_gas: Some(t.tx().max_fee_per_gas),
507-
max_priority_fee_per_gas: Some(t.tx().max_priority_fee_per_gas),
508-
max_fee_per_blob_gas: None,
509-
blob_versioned_hashes: None,
510-
value: t.tx().value,
511-
chain_id: Some(t.tx().chain_id),
512-
access_list: t.tx().access_list.clone(),
513-
},
514-
Self::EIP4844(t) => TransactionEssentials {
515-
kind: TxKind::Call(t.tx().tx().to),
516-
input: t.tx().tx().input.clone(),
517-
nonce: t.tx().tx().nonce,
518-
gas_limit: t.tx().tx().gas_limit,
519-
gas_price: None,
520-
max_fee_per_gas: Some(t.tx().tx().max_fee_per_gas),
521-
max_priority_fee_per_gas: Some(t.tx().tx().max_priority_fee_per_gas),
522-
max_fee_per_blob_gas: Some(t.tx().tx().max_fee_per_blob_gas),
523-
blob_versioned_hashes: Some(t.tx().tx().blob_versioned_hashes.clone()),
524-
value: t.tx().tx().value,
525-
chain_id: Some(t.tx().tx().chain_id),
526-
access_list: t.tx().tx().access_list.clone(),
527-
},
528-
Self::EIP7702(t) => TransactionEssentials {
529-
kind: TxKind::Call(t.tx().to),
530-
input: t.tx().input.clone(),
531-
nonce: t.tx().nonce,
532-
gas_limit: t.tx().gas_limit,
533-
gas_price: None,
534-
max_fee_per_gas: Some(t.tx().max_fee_per_gas),
535-
max_priority_fee_per_gas: Some(t.tx().max_priority_fee_per_gas),
536-
max_fee_per_blob_gas: None,
537-
blob_versioned_hashes: None,
538-
value: t.tx().value,
539-
chain_id: Some(t.tx().chain_id),
540-
access_list: t.tx().access_list.clone(),
541-
},
542-
Self::Deposit(t) => TransactionEssentials {
543-
kind: t.to,
544-
input: t.input.clone(),
545-
nonce: 0,
546-
gas_limit: t.gas_limit,
547-
gas_price: Some(0),
548-
max_fee_per_gas: None,
549-
max_priority_fee_per_gas: None,
550-
max_fee_per_blob_gas: None,
551-
blob_versioned_hashes: None,
552-
value: t.value,
553-
chain_id: t.chain_id(),
554-
access_list: Default::default(),
555-
},
471+
Self::Legacy(tx) => Some(tx),
472+
_ => None,
556473
}
557474
}
558475

@@ -594,22 +511,6 @@ impl TypedTransaction {
594511
}
595512
}
596513

597-
#[derive(Clone, Debug, PartialEq, Eq)]
598-
pub struct TransactionEssentials {
599-
pub kind: TxKind,
600-
pub input: Bytes,
601-
pub nonce: u64,
602-
pub gas_limit: u64,
603-
pub gas_price: Option<u128>,
604-
pub max_fee_per_gas: Option<u128>,
605-
pub max_priority_fee_per_gas: Option<u128>,
606-
pub max_fee_per_blob_gas: Option<u128>,
607-
pub blob_versioned_hashes: Option<Vec<B256>>,
608-
pub value: U256,
609-
pub chain_id: Option<u64>,
610-
pub access_list: AccessList,
611-
}
612-
613514
/// Represents all relevant information of an executed transaction
614515
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
615516
pub struct TransactionInfo {

crates/anvil/src/eth/backend/mem/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,8 +3752,8 @@ impl TransactionValidator for Backend {
37523752
return Err(InvalidTransactionError::FeeCapTooLow);
37533753
}
37543754

3755-
if let (Some(max_priority_fee_per_gas), Some(max_fee_per_gas)) =
3756-
(tx.essentials().max_priority_fee_per_gas, tx.essentials().max_fee_per_gas)
3755+
if let (Some(max_priority_fee_per_gas), max_fee_per_gas) =
3756+
(tx.as_ref().max_priority_fee_per_gas(), tx.as_ref().max_fee_per_gas())
37573757
&& max_priority_fee_per_gas > max_fee_per_gas
37583758
{
37593759
warn!(target: "backend", "max priority fee per gas={}, too high, max fee per gas={}", max_priority_fee_per_gas, max_fee_per_gas);
@@ -3764,7 +3764,7 @@ impl TransactionValidator for Backend {
37643764
// EIP-4844 blob fee validation
37653765
if env.evm_env.cfg_env.spec >= SpecId::CANCUN
37663766
&& tx.transaction.is_eip4844()
3767-
&& let Some(max_fee_per_blob_gas) = tx.essentials().max_fee_per_blob_gas
3767+
&& let Some(max_fee_per_blob_gas) = tx.as_ref().max_fee_per_blob_gas()
37683768
&& let Some(blob_gas_and_price) = &env.evm_env.block_env.blob_excess_gas_and_price
37693769
&& max_fee_per_blob_gas < blob_gas_and_price.blob_gasprice
37703770
{

0 commit comments

Comments
 (0)