op_revm/transaction/
deposit.rs

1//! Contains Deposit transaction parts.
2use revm::primitives::B256;
3
4/// Deposit transaction type.
5pub const DEPOSIT_TRANSACTION_TYPE: u8 = 0x7E;
6
7/// Deposit transaction parts.
8#[derive(Clone, Debug, Default, PartialEq, Eq)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10pub struct DepositTransactionParts {
11    /// Source hash of the deposit transaction.
12    pub source_hash: B256,
13    /// Minted value of the deposit transaction.
14    pub mint: Option<u128>,
15    /// Whether the transaction is a system transaction.
16    pub is_system_transaction: bool,
17}
18
19impl DepositTransactionParts {
20    /// Create a new deposit transaction parts.
21    pub fn new(source_hash: B256, mint: Option<u128>, is_system_transaction: bool) -> Self {
22        Self {
23            source_hash,
24            mint,
25            is_system_transaction,
26        }
27    }
28}
29
30#[cfg(all(test, feature = "serde"))]
31mod tests {
32    use super::*;
33    use revm::primitives::b256;
34
35    #[test]
36    fn serialize_json_deposit_tx_parts() {
37        let response = r#"{"source_hash":"0xe927a1448525fb5d32cb50ee1408461a945ba6c39bd5cf5621407d500ecc8de9","mint":52,"is_system_transaction":false}"#;
38
39        let deposit_tx_parts: DepositTransactionParts = serde_json::from_str(response).unwrap();
40        assert_eq!(
41            deposit_tx_parts,
42            DepositTransactionParts::new(
43                b256!("0xe927a1448525fb5d32cb50ee1408461a945ba6c39bd5cf5621407d500ecc8de9"),
44                Some(0x34),
45                false,
46            )
47        );
48    }
49}