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 the creator's signing
24    /// 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 out of sync with the
31    /// 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 from `output_notes`,
36    /// or was stored without the recipient needed to reconstruct it. The note is written before the
37    /// lineage record, so this signals a broken invariant (e.g. the output note was pruned) rather
38    /// than an expected race.
39    #[error(
40        "PSWAP original note {0} is unavailable in the output-note store or lacks recipient details"
41    )]
42    OriginalNoteUnavailable(NoteId),
43
44    /// A stored lineage's `state` byte has no matching [`PswapLineageState`] variant.
45    #[error("unknown PSWAP lineage state byte: {0}")]
46    UnknownState(u8),
47
48    /// A store call from the PSWAP layer failed.
49    #[error("PSWAP store call failed: {0}")]
50    Store(#[from] StoreError),
51}
52
53impl From<PswapLineageError> for crate::ClientError {
54    fn from(err: PswapLineageError) -> Self {
55        crate::ClientError::Observer(Box::new(err))
56    }
57}