miden-client 0.17.0-rc.2

Client library that facilitates interaction with the Miden network
Documentation
//! Side-effect-only observer trait for per-note arrivals during sync.

use alloc::boxed::Box;

use async_trait::async_trait;

use crate::ClientError;
use crate::rpc::domain::note::SyncedNote;
use crate::sync::StateSyncUpdate;

/// Per-note + post-sync side-channel into [`crate::sync::StateSync`]. Attach via
/// `StateSync::with_note_observer(...)`. Multiple observers run independently; errors are logged,
/// never abort sync.
#[async_trait(?Send)]
pub trait NoteObserver {
    /// Identifier surfaced on `tracing::warn!` events for this observer.
    fn name(&self) -> &'static str;

    /// Per-note hook. Runs before the screener verdict, so before the note's id is recomputed and
    /// its inclusion proof verified. `note` carries the note's identity, metadata and inclusion
    /// proof from the sync record, its resolved attachments (empty for a note without any) and, for
    /// a fetched public note, its body.
    ///
    /// Returns `true` to mark the enclosing block as relevant even if the screener discards it, so
    /// sync persists its header.
    async fn observe(&self, note: &SyncedNote) -> Result<bool, ClientError>;

    /// Post-sync hook, invoked once after the sync window closes. Default impl is a no-op for
    /// observers that only need `observe()`.
    async fn apply(&self, _sync_update: &StateSyncUpdate) -> Result<(), ClientError> {
        Ok(())
    }
}