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
27 changes: 27 additions & 0 deletions crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,33 @@ pub enum OpTxEnvelope {
Deposit(Sealed<TxDeposit>),
}

/// Represents an Optimism transaction envelope.
///
/// Compared to Ethereum it can tell whether the transaction is a deposit.
pub trait OpTransaction {
/// Returns true if the transaction is a deposit.
fn is_deposit(&self) -> bool;
}

impl OpTransaction for OpTxEnvelope {
fn is_deposit(&self) -> bool {
Self::is_deposit(self)
}
}

impl<B, T> OpTransaction for Extended<B, T>
where
B: OpTransaction,
T: OpTransaction,
{
fn is_deposit(&self) -> bool {
match self {
Self::BuiltIn(b) => b.is_deposit(),
Self::Other(t) => t.is_deposit(),
}
}
}

impl AsRef<Self> for OpTxEnvelope {
fn as_ref(&self) -> &Self {
self
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod tx_type;
pub use tx_type::{DEPOSIT_TX_TYPE_ID, OpTxType};

mod envelope;
pub use envelope::OpTxEnvelope;
pub use envelope::{OpTransaction, OpTxEnvelope};

#[cfg(all(feature = "serde", feature = "serde-bincode-compat"))]
pub use envelope::serde_bincode_compat as envelope_serde_bincode_compat;
Expand Down