Skip to content

Commit 399b368

Browse files
authored
chore(consensus): Migrate deposit tx behaviour to maili (#383)
Implements `maili-common` traits `DepsoitTransaction` and `DepositTxEnvelope` for `DepositTx` and `OpTxEnvelope` respectively
1 parent 19635a8 commit 399b368

File tree

5 files changed

+27
-51
lines changed

5 files changed

+27
-51
lines changed

crates/consensus/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010
extern crate alloc;
1111

12+
pub use maili_common::{DepositTransaction, DepositTxEnvelope};
13+
1214
mod receipt;
1315
pub use receipt::{OpDepositReceipt, OpDepositReceiptWithBloom, OpReceiptEnvelope, OpTxReceipt};
1416

1517
mod transaction;
1618
pub use transaction::{
17-
DepositTransaction, OpPooledTransaction, OpTxEnvelope, OpTxType, OpTypedTransaction, TxDeposit,
18-
DEPOSIT_TX_TYPE_ID,
19+
OpPooledTransaction, OpTxEnvelope, OpTxType, OpTypedTransaction, TxDeposit, DEPOSIT_TX_TYPE_ID,
1920
};
2021

2122
pub mod eip1559;

crates/consensus/src/transaction/deposit.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Deposit Transaction type.
22
33
use super::OpTxType;
4-
use crate::DepositTransaction;
54
use alloc::vec::Vec;
65
use alloy_consensus::{Sealable, Transaction, Typed2718};
76
use alloy_eips::{
@@ -15,6 +14,7 @@ use alloy_rlp::{
1514
Buf, BufMut, Decodable, Encodable, Error as DecodeError, Header, EMPTY_STRING_CODE,
1615
};
1716
use core::mem;
17+
use maili_common::DepositTransaction;
1818

1919
/// Deposit transactions, also known as deposits are initiated on L1, and executed on L2.
2020
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
@@ -55,21 +55,20 @@ pub struct TxDeposit {
5555
}
5656

5757
impl DepositTransaction for TxDeposit {
58+
#[inline]
5859
fn source_hash(&self) -> Option<B256> {
5960
Some(self.source_hash)
6061
}
6162

63+
#[inline]
6264
fn mint(&self) -> Option<u128> {
6365
self.mint
6466
}
6567

68+
#[inline]
6669
fn is_system_transaction(&self) -> bool {
6770
self.is_system_transaction
6871
}
69-
70-
fn is_deposit(&self) -> bool {
71-
true
72-
}
7372
}
7473

7574
impl TxDeposit {

crates/consensus/src/transaction/envelope.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use alloy_eips::{
99
};
1010
use alloy_primitives::{Address, Bytes, TxKind, B256, U256};
1111
use alloy_rlp::{Decodable, Encodable};
12+
use maili_common::DepositTxEnvelope;
1213

1314
use crate::{OpTxType, TxDeposit};
1415

@@ -293,12 +294,6 @@ impl OpTxEnvelope {
293294
matches!(self, Self::Eip1559(_))
294295
}
295296

296-
/// Returns true if the transaction is a deposit transaction.
297-
#[inline]
298-
pub const fn is_deposit(&self) -> bool {
299-
matches!(self, Self::Deposit(_))
300-
}
301-
302297
/// Returns true if the transaction is a system transaction.
303298
#[inline]
304299
pub const fn is_system_transaction(&self) -> bool {
@@ -332,14 +327,6 @@ impl OpTxEnvelope {
332327
}
333328
}
334329

335-
/// Returns the [`TxDeposit`] variant if the transaction is a deposit transaction.
336-
pub const fn as_deposit(&self) -> Option<&Sealed<TxDeposit>> {
337-
match self {
338-
Self::Deposit(tx) => Some(tx),
339-
_ => None,
340-
}
341-
}
342-
343330
/// Return the [`OpTxType`] of the inner txn.
344331
pub const fn tx_type(&self) -> OpTxType {
345332
match self {
@@ -454,6 +441,24 @@ impl Encodable2718 for OpTxEnvelope {
454441
}
455442
}
456443

444+
impl DepositTxEnvelope for OpTxEnvelope {
445+
type DepositTx = TxDeposit;
446+
447+
/// Returns true if the transaction is a deposit transaction.
448+
#[inline]
449+
fn is_deposit(&self) -> bool {
450+
matches!(self, Self::Deposit(_))
451+
}
452+
453+
/// Returns the [`TxDeposit`] variant if the transaction is a deposit transaction.
454+
fn as_deposit(&self) -> Option<&Sealed<TxDeposit>> {
455+
match self {
456+
Self::Deposit(tx) => Some(tx),
457+
_ => None,
458+
}
459+
}
460+
}
461+
457462
#[cfg(feature = "serde")]
458463
mod serde_from {
459464
//! NB: Why do we need this?

crates/consensus/src/transaction/mod.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,3 @@ pub use deposit::serde_deposit_tx_rpc;
2323
pub(super) mod serde_bincode_compat {
2424
pub use super::deposit::serde_bincode_compat::TxDeposit;
2525
}
26-
27-
use alloy_primitives::B256;
28-
29-
/// A trait representing a deposit transaction with specific attributes.
30-
pub trait DepositTransaction {
31-
/// Returns the hash that uniquely identifies the source of the deposit.
32-
///
33-
/// # Returns
34-
/// An `Option<B256>` containing the source hash if available.
35-
fn source_hash(&self) -> Option<B256>;
36-
37-
/// Returns the optional mint value of the deposit transaction.
38-
///
39-
/// # Returns
40-
/// An `Option<u128>` representing the ETH value to mint on L2, if any.
41-
fn mint(&self) -> Option<u128>;
42-
43-
/// Indicates whether the transaction is exempt from the L2 gas limit.
44-
///
45-
/// # Returns
46-
/// A `bool` indicating if the transaction is a system transaction.
47-
fn is_system_transaction(&self) -> bool;
48-
49-
/// Checks if the transaction is a deposit transaction.
50-
///
51-
/// # Returns
52-
/// A `bool` that is always `true` for deposit transactions.
53-
fn is_deposit(&self) -> bool;
54-
}

crates/rpc-types/src/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use alloy_consensus::{Transaction as _, Typed2718};
44
use alloy_eips::{eip2930::AccessList, eip7702::SignedAuthorization};
55
use alloy_primitives::{Address, BlockHash, Bytes, ChainId, TxKind, B256, U256};
66
use alloy_serde::OtherFields;
7-
use op_alloy_consensus::OpTxEnvelope;
7+
use op_alloy_consensus::{DepositTxEnvelope, OpTxEnvelope};
88
use serde::{Deserialize, Serialize};
99

1010
mod request;

0 commit comments

Comments
 (0)