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
7 changes: 2 additions & 5 deletions crates/optimism/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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);
Expand Down
37 changes: 26 additions & 11 deletions crates/optimism/src/transaction/abstraction.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<B256>;

/// Mint of the deposit transaction
fn mint(&self) -> Option<u128>;

/// 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)]
Expand Down Expand Up @@ -118,9 +132,16 @@ impl<T: Transaction> Transaction for OpTransaction<T> {
}
}

impl<T: Transaction> DepositTransaction for OpTransaction<T> {
fn source_hash(&self) -> B256 {
self.deposit.source_hash
impl<T: Transaction> OpTxTr for OpTransaction<T> {
fn enveloped_tx(&self) -> Option<&Bytes> {
self.enveloped_tx.as_ref()
}

fn source_hash(&self) -> Option<B256> {
if self.tx_type() != DEPOSIT_TRANSACTION_TYPE {
return None;
}
Some(self.deposit.source_hash)
}

fn mint(&self) -> Option<u128> {
Expand All @@ -132,12 +153,6 @@ impl<T: Transaction> DepositTransaction for OpTransaction<T> {
}
}

impl<T: Transaction> OpTxTr for OpTransaction<T> {
fn enveloped_tx(&self) -> Option<&Bytes> {
self.enveloped_tx.as_ref()
}
}

#[cfg(test)]
mod tests {
use crate::transaction::deposit::DEPOSIT_TRANSACTION_TYPE;
Expand Down
12 changes: 0 additions & 12 deletions crates/optimism/src/transaction/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u128>;

/// 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 {
Expand Down
Loading