foundry_primitives/transaction/
deposit.rs1use super::FoundryReceiptEnvelope;
4use alloy_primitives::{B256, U256};
5use alloy_serde::OtherFields;
6use op_alloy_consensus::OpDepositReceipt;
7
8#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
10pub struct DepositTransactionParts {
11 pub source_hash: B256,
13 pub mint: Option<u128>,
15 pub is_system_transaction: bool,
17}
18
19pub fn get_deposit_tx_parts(
21 other: &OtherFields,
22) -> Result<DepositTransactionParts, Vec<&'static str>> {
23 let mut missing = Vec::new();
24 let source_hash =
25 other.get_deserialized::<B256>("sourceHash").transpose().ok().flatten().unwrap_or_else(
26 || {
27 missing.push("sourceHash");
28 Default::default()
29 },
30 );
31 let mint = other
32 .get_deserialized::<U256>("mint")
33 .transpose()
34 .unwrap_or_else(|_| {
35 missing.push("mint");
36 Default::default()
37 })
38 .map(|value| value.saturating_to::<u128>());
39 let is_system_transaction =
40 other.get_deserialized::<bool>("isSystemTx").transpose().ok().flatten().unwrap_or_else(
41 || {
42 missing.push("isSystemTx");
43 Default::default()
44 },
45 );
46 if missing.is_empty() {
47 Ok(DepositTransactionParts { source_hash, mint, is_system_transaction })
48 } else {
49 Err(missing)
50 }
51}
52
53impl<T> FoundryReceiptEnvelope<T> {
55 pub const fn deposit_nonce(&self) -> Option<u64> {
57 match self.as_deposit_receipt() {
58 Some(receipt) => receipt.deposit_nonce,
59 None => None,
60 }
61 }
62
63 pub const fn deposit_receipt_version(&self) -> Option<u64> {
65 match self.as_deposit_receipt() {
66 Some(receipt) => receipt.deposit_receipt_version,
67 None => None,
68 }
69 }
70
71 pub const fn as_deposit_receipt(&self) -> Option<&OpDepositReceipt<T>> {
73 match self {
74 Self::Deposit(t) => Some(&t.receipt),
75 _ => None,
76 }
77 }
78}