miden_client/sync/note_observer.rs
1//! Side-effect-only observer trait for per-note arrivals during sync.
2
3use alloc::boxed::Box;
4
5use async_trait::async_trait;
6
7use crate::ClientError;
8use crate::rpc::domain::note::SyncedNote;
9use crate::sync::StateSyncUpdate;
10
11/// Per-note + post-sync side-channel into [`crate::sync::StateSync`]. Attach via
12/// `StateSync::with_note_observer(...)`. Multiple observers run independently; errors are logged,
13/// never abort sync.
14#[async_trait(?Send)]
15pub trait NoteObserver {
16 /// Identifier surfaced on `tracing::warn!` events for this observer.
17 fn name(&self) -> &'static str;
18
19 /// Per-note hook. Runs before the screener verdict, so before the note's id is recomputed and
20 /// its inclusion proof verified. `note` carries the note's identity, metadata and inclusion
21 /// proof from the sync record, its resolved attachments (empty for a note without any) and, for
22 /// a fetched public note, its body.
23 ///
24 /// Returns `true` to mark the enclosing block as relevant even if the screener discards it, so
25 /// sync persists its header.
26 async fn observe(&self, note: &SyncedNote) -> Result<bool, ClientError>;
27
28 /// Post-sync hook, invoked once after the sync window closes. Default impl is a no-op for
29 /// observers that only need `observe()`.
30 async fn apply(&self, _sync_update: &StateSyncUpdate) -> Result<(), ClientError> {
31 Ok(())
32 }
33}