diff --git a/crates/optimism/src/handler.rs b/crates/optimism/src/handler.rs index beddf5de54..71251d6b3e 100644 --- a/crates/optimism/src/handler.rs +++ b/crates/optimism/src/handler.rs @@ -2,10 +2,7 @@ use crate::{ api::exec::OpContextTr, constants::{BASE_FEE_RECIPIENT, L1_FEE_RECIPIENT, OPERATOR_FEE_RECIPIENT}, - transaction::{ - deposit::{DepositTransaction, DEPOSIT_TRANSACTION_TYPE}, - OpTransactionError, OpTxTr, - }, + transaction::{deposit::DEPOSIT_TRANSACTION_TYPE, OpTransactionError, OpTxTr}, L1BlockInfo, OpHaltReason, OpSpecId, }; use revm::{ @@ -261,7 +258,7 @@ where self.mainnet.reimburse_caller(evm, exec_result)?; let context = evm.ctx(); - if context.tx().source_hash().is_zero() { + if matches!(context.tx().source_hash(), Some(source_hash) if source_hash.is_zero()) { let caller = context.tx().caller(); let spec = context.cfg().spec(); let operator_fee_refund = context.chain().operator_fee_refund(exec_result.gas(), spec); diff --git a/crates/optimism/src/transaction/abstraction.rs b/crates/optimism/src/transaction/abstraction.rs index 207f34edfc..1fc5852261 100644 --- a/crates/optimism/src/transaction/abstraction.rs +++ b/crates/optimism/src/transaction/abstraction.rs @@ -1,4 +1,4 @@ -use super::deposit::{DepositTransaction, DepositTransactionParts}; +use super::deposit::{DepositTransactionParts, DEPOSIT_TRANSACTION_TYPE}; use auto_impl::auto_impl; use revm::{ context::TxEnv, @@ -8,8 +8,22 @@ use revm::{ use std::vec; #[auto_impl(&, &mut, Box, Arc)] -pub trait OpTxTr: Transaction + DepositTransaction { +pub trait OpTxTr: Transaction { fn enveloped_tx(&self) -> Option<&Bytes>; + + /// Source hash of the deposit transaction + fn source_hash(&self) -> Option; + + /// Mint of the deposit transaction + fn mint(&self) -> Option; + + /// Whether the transaction is a system transaction + fn is_system_transaction(&self) -> bool; + + /// Returns `true` if transaction is of type [`DEPOSIT_TRANSACTION_TYPE`]. + fn is_deposit(&self) -> bool { + self.tx_type() == DEPOSIT_TRANSACTION_TYPE + } } #[derive(Clone, Debug, PartialEq, Eq)] @@ -118,9 +132,16 @@ impl Transaction for OpTransaction { } } -impl DepositTransaction for OpTransaction { - fn source_hash(&self) -> B256 { - self.deposit.source_hash +impl OpTxTr for OpTransaction { + fn enveloped_tx(&self) -> Option<&Bytes> { + self.enveloped_tx.as_ref() + } + + fn source_hash(&self) -> Option { + if self.tx_type() != DEPOSIT_TRANSACTION_TYPE { + return None; + } + Some(self.deposit.source_hash) } fn mint(&self) -> Option { @@ -132,12 +153,6 @@ impl DepositTransaction for OpTransaction { } } -impl OpTxTr for OpTransaction { - fn enveloped_tx(&self) -> Option<&Bytes> { - self.enveloped_tx.as_ref() - } -} - #[cfg(test)] mod tests { use crate::transaction::deposit::DEPOSIT_TRANSACTION_TYPE; diff --git a/crates/optimism/src/transaction/deposit.rs b/crates/optimism/src/transaction/deposit.rs index b1b38de3af..fcd1b2a646 100644 --- a/crates/optimism/src/transaction/deposit.rs +++ b/crates/optimism/src/transaction/deposit.rs @@ -2,18 +2,6 @@ use revm::primitives::B256; pub const DEPOSIT_TRANSACTION_TYPE: u8 = 0x7E; -/// Deposit transaction trait -pub trait DepositTransaction { - /// Source hash of the deposit transaction - fn source_hash(&self) -> B256; - - /// Mint of the deposit transaction - fn mint(&self) -> Option; - - /// Whether the transaction is a system transaction - fn is_system_transaction(&self) -> bool; -} - #[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct DepositTransactionParts {