use crate::node::primitives::TransactionSigned; use alloy_consensus::Transaction as _; use alloy_rpc_types::AccessList; use auto_impl::auto_impl; use reth_evm::{FromRecoveredTx, FromTxWithEncoded, IntoTxEnv, TransactionEnv}; use reth_primitives_traits::SignerRecoverable; use revm::{ context::TxEnv, context_interface::transaction::Transaction, primitives::{Address, B256, Bytes, TxKind, U256}, }; #[auto_impl(&, &mut, Box, Arc)] pub trait HlTxTr: Transaction {} #[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct HlTxEnv { pub base: T, } impl HlTxEnv { pub fn new(base: T) -> Self { Self { base } } } impl Transaction for HlTxEnv { type AccessListItem<'a> = T::AccessListItem<'a> where T: 'a; type Authorization<'a> = T::Authorization<'a> where T: 'a; fn tx_type(&self) -> u8 { self.base.tx_type() } fn caller(&self) -> Address { self.base.caller() } fn gas_limit(&self) -> u64 { self.base.gas_limit() } fn value(&self) -> U256 { self.base.value() } fn input(&self) -> &Bytes { self.base.input() } fn nonce(&self) -> u64 { self.base.nonce() } fn kind(&self) -> TxKind { self.base.kind() } fn chain_id(&self) -> Option { self.base.chain_id() } fn gas_price(&self) -> u128 { self.base.gas_price() } fn access_list(&self) -> Option>> { self.base.access_list() } fn blob_versioned_hashes(&self) -> &[B256] { self.base.blob_versioned_hashes() } fn max_fee_per_blob_gas(&self) -> u128 { self.base.max_fee_per_blob_gas() } fn authorization_list_len(&self) -> usize { self.base.authorization_list_len() } fn authorization_list(&self) -> impl Iterator> { self.base.authorization_list() } fn max_fee_per_gas(&self) -> u128 { self.base.max_fee_per_gas() } fn max_priority_fee_per_gas(&self) -> Option { self.base.max_priority_fee_per_gas() } fn effective_gas_price(&self, base_fee: u128) -> u128 { self.base.effective_gas_price(base_fee) } } impl HlTxTr for HlTxEnv {} impl IntoTxEnv for HlTxEnv { fn into_tx_env(self) -> Self { self } } impl FromRecoveredTx for HlTxEnv { fn from_recovered_tx(tx: &TransactionSigned, sender: Address) -> Self { if tx.gas_price().is_some() && tx.gas_price().unwrap() == 0 { return Self::new(TxEnv::from_recovered_tx(tx, tx.recover_signer().unwrap())); } Self::new(TxEnv::from_recovered_tx(tx, sender)) } } impl FromTxWithEncoded for HlTxEnv { fn from_encoded_tx(tx: &TransactionSigned, sender: Address, _encoded: Bytes) -> Self { use reth_primitives::Transaction; let base = match tx.clone().into_inner().into_typed_transaction() { Transaction::Legacy(tx) => TxEnv::from_recovered_tx(&tx, sender), Transaction::Eip2930(tx) => TxEnv::from_recovered_tx(&tx, sender), Transaction::Eip1559(tx) => TxEnv::from_recovered_tx(&tx, sender), Transaction::Eip4844(tx) => TxEnv::from_recovered_tx(&tx, sender), Transaction::Eip7702(tx) => TxEnv::from_recovered_tx(&tx, sender), }; Self { base } } } impl TransactionEnv for HlTxEnv { fn set_gas_limit(&mut self, gas_limit: u64) { self.base.set_gas_limit(gas_limit); } fn nonce(&self) -> u64 { TransactionEnv::nonce(&self.base) } fn set_nonce(&mut self, nonce: u64) { self.base.set_nonce(nonce); } fn set_access_list(&mut self, access_list: AccessList) { self.base.set_access_list(access_list); } }