PSwap: ClientBuilder observer registration: opt-out + dedup, stop hardcoding the PSWAP observer
- Lingua principale
- Rust
- Stelle
- 78
- Fork
- 129
- Merge medio
- 4g 14h
- PR unite (30g)
- 52
Descrizione
**Context**
Follow-up from PR #2231 review ([thread](https://github.com/0xMiden/miden-client/pull/2231#discussion_r3422130013)). Quoting @igamigo:
> As we discussed, if the decision was to make the implementation generic, we should add `ClientBuilder` methods for extending the list of observers (e.g., `ClientBuilder::with_tx_observer()`). For this, we should not make the observers a list, but rather the observers should be deduplicated so that a user cannot accidentally use the same observer twice. I'm not entirely sure we should enforce PSWAP observers to always be present, or at least we should have a way to opt out of it.
**Problem**
The `PswapTransactionObserver` is hardcoded into every client at `crates/rust-client/src/builder.rs:527`:
```rust
let transaction_observers: Vec> =
vec![Arc::new(PswapTransactionObserver::new(store.clone()))];
```
There is no `ClientBuilder` method to register observers, no deduplication, and no way to opt out of the PSWAP observers — even for a client that only cares about other note types.
**Proposed work**
- Add `ClientBuilder` registration methods (e.g. `with_transaction_observer()` / `with_note_observer()`).
- Deduplicate observers so the same observer can't be attached twice.
- Make the built-in PSWAP observers opt-in/opt-out rather than unconditionally present.
- Applies to both observer kinds: `TransactionObserver` (`PswapTransactionObserver`) and `NoteObserver` (`PswapChainObserver`).
**Acceptance criteria**
- [ ] A client can be built with the PSWAP observers omitted.
- [ ] Registering the same observer twice does not double-fire it.
- [ ] Coordinated with #: if `NoteObserver` collapses into `OnNoteReceived`, the registration story mirrors it.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
L'issue punta al codice del builder in crates/rust-client/src/builder.rs. Inizia esaminando la struttura ClientBuilder e la sua attuale configurazione degli observer. Cerca i pattern di registrazione degli observer esistenti e il PswapTransactionObserver. L'obiettivo è aggiungere metodi come with_transaction_observer, implementare la deduplicazione (probabilmente utilizzando un set o controllando gli observer esistenti) e rendere gli observer PSWAP opzionali. Controlla se ci sono test per il builder per comprendere il comportamento atteso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust
- Ambito
- backend-api-design
- Tipo di issue
- Refactoring
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 55/100