alloy_zksync/provider/
l1_transaction_receipt.rs

1use super::l1_communication_error::L1CommunicationError;
2use crate::{contracts::l1::bridge_hub::Bridgehub::NewPriorityRequest, network::Zksync};
3use alloy::{
4    providers::{PendingTransactionBuilder, RootProvider},
5    rpc::types::eth::TransactionReceipt,
6};
7
8/// A wrapper struct to hold L1 transaction receipt and L2 provider
9/// which is used by the associated functions.
10pub struct L1TransactionReceipt {
11    /// Ethereum transaction receipt.
12    inner: TransactionReceipt,
13    /// A reference to the L2 provider.
14    l2_provider: RootProvider<Zksync>,
15}
16
17impl L1TransactionReceipt {
18    /// Creates a new `L1TransactionReceipt` object.
19    pub fn new(tx_receipt: TransactionReceipt, l2_provider: RootProvider<Zksync>) -> Self {
20        Self {
21            inner: tx_receipt,
22            l2_provider,
23        }
24    }
25
26    /// Returns a receipt for the L1 operation.
27    pub fn get_receipt(&self) -> &TransactionReceipt {
28        &self.inner
29    }
30
31    /// Returns a [`PendingTransactionBuilder`](https://docs.rs/alloy/latest/alloy/providers/struct.PendingTransactionBuilder.html)
32    /// for the L2 transaction, which can be used to await the transaction on L2.
33    ///
34    /// Will return an error if the transaction request used to create the object does not contain
35    /// priority operation information (e.g. it doesn't correspond to an L1->L2 transaction).
36    pub fn get_l2_tx(&self) -> Result<PendingTransactionBuilder<Zksync>, L1CommunicationError> {
37        let l1_to_l2_tx_log = self
38            .inner
39            .inner
40            .logs()
41            .iter()
42            .filter_map(|log| log.log_decode::<NewPriorityRequest>().ok())
43            .next()
44            .ok_or(L1CommunicationError::NewPriorityRequestLogNotFound)?;
45
46        let l2_tx_hash = l1_to_l2_tx_log.inner.txHash;
47
48        Ok(PendingTransactionBuilder::new(
49            self.l2_provider.clone(),
50            l2_tx_hash,
51        ))
52    }
53}