Skip to main content

miden_client/pswap/
errors.rs

1//! Errors specific to PSWAP chain tracking.
2
3use alloc::boxed::Box;
4
5use miden_protocol::Felt;
6use miden_protocol::account::AccountId;
7use miden_protocol::note::NoteId;
8
9use super::lineage::PswapLineageState;
10use crate::store::StoreError;
11
12/// Failures raised by the PSWAP chain-tracking subsystem.
13#[derive(Debug, thiserror::Error)]
14pub enum PswapLineageError {
15    /// No tracked PSWAP lineage for the given `order_id`.
16    #[error("no PSWAP lineage tracked for order_id {0}")]
17    NotFound(Felt),
18
19    /// The lineage exists but is already in a terminal state.
20    #[error("PSWAP lineage is not active (state = {0:?}); no further rounds expected")]
21    NotActive(PswapLineageState),
22
23    /// The lineage's creator is not a local account — reclaim requires
24    /// the creator's signing authority.
25    #[error(
26        "PSWAP creator account {0} is not local; reclaim requires the creator's signing authority"
27    )]
28    CreatorNotLocal(AccountId),
29
30    /// The current tip is missing from the store — the tracked lineage is
31    /// out of sync with the stored notes.
32    #[error("current tip note is missing from the local store; the tracked lineage is out of sync")]
33    TipMissing,
34
35    /// The depth-0 note referenced by `original_note_id` could not be fetched
36    /// from `output_notes`, or was stored without the recipient needed to
37    /// reconstruct it. The note is written before the lineage record, so this
38    /// signals a broken invariant (e.g. the output note was pruned) rather than
39    /// an expected race.
40    #[error(
41        "PSWAP original note {0} is unavailable in the output-note store or lacks recipient details"
42    )]
43    OriginalNoteUnavailable(NoteId),
44
45    /// A stored lineage's `state` byte has no matching [`PswapLineageState`] variant.
46    #[error("unknown PSWAP lineage state byte: {0}")]
47    UnknownState(u8),
48
49    /// A store call from the PSWAP layer failed.
50    #[error("PSWAP store call failed: {0}")]
51    Store(#[from] StoreError),
52}
53
54impl From<PswapLineageError> for crate::ClientError {
55    fn from(err: PswapLineageError) -> Self {
56        crate::ClientError::Observer(Box::new(err))
57    }
58}