Skip to main content

miden_client/transaction/
observer.rs

1//! Side-effect-only observer trait for committed transactions.
2//!
3//! Analogous to [`crate::sync::NoteObserver`] but scoped to
4//! `Client::apply_transaction`. Lets feature subsystems (e.g. PSWAP
5//! chain tracking) hook into the post-apply pipeline without
6//! `apply_transaction` knowing about them by name.
7
8use alloc::boxed::Box;
9
10use async_trait::async_trait;
11
12use crate::ClientError;
13use crate::transaction::TransactionResult;
14
15/// Side-effect-only observer of committed transactions. `apply()` runs
16/// once per `apply_transaction` AFTER the standard updates land. Errors
17/// are logged (tagged with [`Self::name`]) and never abort sync.
18#[async_trait(?Send)]
19pub trait TransactionObserver: Send + Sync {
20    /// Short identifier for `tracing::warn!` events on `apply()` errors.
21    fn name(&self) -> &'static str;
22
23    /// Return `Ok(())` for "not interested"; reserve `Err(_)` for genuine
24    /// internal failures.
25    async fn apply(&self, tx_result: &TransactionResult) -> Result<(), ClientError>;
26}