Skip to main content

foundry_primitives/network/
optimism.rs

1//! OP-stack-specific helpers and type aliases used by [`super::FoundryNetwork`] and
2//! [`super::FoundryTxReceipt`].
3
4use alloy_consensus::{Receipt, ReceiptWithBloom, TxReceipt};
5use alloy_primitives::U64;
6use alloy_rpc_types::Log;
7use alloy_serde::OtherFields;
8use op_alloy_consensus::{OpDepositReceipt, OpDepositReceiptWithBloom};
9
10use crate::FoundryReceiptEnvelope;
11
12/// JSON-RPC transaction response type used by [`super::FoundryNetwork`].
13pub type FoundryTransactionResponse = op_alloy_rpc_types::Transaction<crate::FoundryTxEnvelope>;
14
15/// Build a [`FoundryReceiptEnvelope::Deposit`] from a `ReceiptWithBloom<Log>` plus the OP
16/// deposit-specific fields decoded from the [`OtherFields`] of an `AnyTransactionReceipt`.
17pub(super) fn build_deposit_receipt_envelope(
18    receipt_with_bloom: ReceiptWithBloom<Receipt<Log>>,
19    other: &OtherFields,
20) -> FoundryReceiptEnvelope<Log> {
21    // These fields may not be present in all receipts, so missing/invalid values are None.
22    let deposit_nonce = other
23        .get_deserialized::<U64>("depositNonce")
24        .transpose()
25        .ok()
26        .flatten()
27        .map(|v| v.to::<u64>());
28    let deposit_receipt_version = other
29        .get_deserialized::<U64>("depositReceiptVersion")
30        .transpose()
31        .ok()
32        .flatten()
33        .map(|v| v.to::<u64>());
34
35    FoundryReceiptEnvelope::Deposit(OpDepositReceiptWithBloom {
36        receipt: OpDepositReceipt {
37            inner: Receipt {
38                status: alloy_consensus::Eip658Value::Eip658(receipt_with_bloom.status()),
39                cumulative_gas_used: receipt_with_bloom.cumulative_gas_used(),
40                logs: receipt_with_bloom.receipt.logs,
41            },
42            deposit_nonce,
43            deposit_receipt_version,
44        },
45        logs_bloom: receipt_with_bloom.logs_bloom,
46    })
47}