Skip to main content

privacy_cash/
error.rs

1//! Error types for Privacy Cash SDK
2
3use thiserror::Error;
4
5/// Result type alias for Privacy Cash operations
6pub type Result<T> = std::result::Result<T, PrivacyCashError>;
7
8/// Errors that can occur when using the Privacy Cash SDK
9#[derive(Error, Debug)]
10pub enum PrivacyCashError {
11    /// Invalid keypair or private key
12    #[error("Invalid keypair: {0}")]
13    InvalidKeypair(String),
14
15    /// Invalid input parameter
16    #[error("Invalid input: {0}")]
17    InvalidInput(String),
18
19    /// Insufficient balance for operation
20    #[error("Insufficient balance: have {have} lamports, need {need} lamports")]
21    InsufficientBalance { have: u64, need: u64 },
22
23    /// Insufficient SPL token balance
24    #[error("Insufficient {token} balance: have {have}, need {need}")]
25    InsufficientTokenBalance {
26        token: String,
27        have: u64,
28        need: u64,
29    },
30
31    /// No UTXOs available for withdrawal
32    #[error("No UTXOs available for withdrawal")]
33    NoUtxosAvailable,
34
35    /// Deposit amount exceeds limit
36    #[error("Deposit amount {amount} exceeds limit {limit}")]
37    DepositLimitExceeded { amount: u64, limit: u64 },
38
39    /// Withdrawal amount too low
40    #[error("Withdrawal amount too low, minimum is {minimum}")]
41    WithdrawalAmountTooLow { minimum: u64 },
42
43    /// Token not supported
44    #[error("Token not supported: {0}")]
45    TokenNotSupported(String),
46
47    /// Encryption error
48    #[error("Encryption error: {0}")]
49    EncryptionError(String),
50
51    /// Decryption error
52    #[error("Decryption error: {0}")]
53    DecryptionError(String),
54
55    /// Proof generation error
56    #[error("Proof generation error: {0}")]
57    ProofGenerationError(String),
58
59    /// Merkle proof error
60    #[error("Merkle proof error: {0}")]
61    MerkleProofError(String),
62
63    /// API request error
64    #[error("API request error: {0}")]
65    ApiError(String),
66
67    /// Transaction error
68    #[error("Transaction error: {0}")]
69    TransactionError(String),
70
71    /// Transaction confirmation timeout
72    #[error("Transaction confirmation timeout after {retries} retries")]
73    ConfirmationTimeout { retries: u32 },
74
75    /// Solana client error
76    #[error("Solana client error: {0}")]
77    SolanaClientError(#[from] solana_client::client_error::ClientError),
78
79    /// Serialization error
80    #[error("Serialization error: {0}")]
81    SerializationError(String),
82
83    /// IO error
84    #[error("IO error: {0}")]
85    IoError(#[from] std::io::Error),
86
87    /// HTTP request error
88    #[error("HTTP error: {0}")]
89    HttpError(#[from] reqwest::Error),
90
91    /// JSON parsing error
92    #[error("JSON error: {0}")]
93    JsonError(#[from] serde_json::Error),
94
95    /// Configuration error
96    #[error("Configuration error: {0}")]
97    ConfigError(String),
98
99    /// Storage error
100    #[error("Storage error: {0}")]
101    StorageError(String),
102
103    /// Circuit file not found
104    #[error("Circuit file not found: {0}")]
105    CircuitNotFound(String),
106
107    /// Operation aborted
108    #[error("Operation aborted")]
109    Aborted,
110}