rustywallet_recovery/
error.rs

1//! Error types for wallet recovery
2//!
3//! Defines all error types that can occur during wallet recovery operations.
4
5use thiserror::Error;
6
7/// Errors that can occur during wallet recovery
8#[derive(Debug, Error)]
9pub enum RecoveryError {
10    /// Invalid mnemonic phrase
11    #[error("Invalid mnemonic: {0}")]
12    InvalidMnemonic(String),
13
14    /// Invalid extended public key
15    #[error("Invalid xpub: {0}")]
16    InvalidXpub(String),
17
18    /// Invalid extended private key
19    #[error("Invalid xprv: {0}")]
20    InvalidXprv(String),
21
22    /// Invalid derivation path
23    #[error("Invalid derivation path: {0}")]
24    InvalidPath(String),
25
26    /// Backend/network error
27    #[error("Backend error: {0}")]
28    BackendError(String),
29
30    /// Network connection error
31    #[error("Network error: {0}")]
32    NetworkError(String),
33
34    /// API rate limit exceeded
35    #[error("Rate limited - please wait before retrying")]
36    RateLimited,
37
38    /// Scan was interrupted
39    #[error("Scan interrupted")]
40    ScanInterrupted,
41
42    /// Address derivation error
43    #[error("Address derivation error: {0}")]
44    DerivationError(String),
45
46    /// Serialization error
47    #[error("Serialization error: {0}")]
48    SerializationError(String),
49}
50
51impl From<rustywallet_mnemonic::MnemonicError> for RecoveryError {
52    fn from(e: rustywallet_mnemonic::MnemonicError) -> Self {
53        RecoveryError::InvalidMnemonic(e.to_string())
54    }
55}
56
57impl From<rustywallet_hd::HdError> for RecoveryError {
58    fn from(e: rustywallet_hd::HdError) -> Self {
59        RecoveryError::DerivationError(e.to_string())
60    }
61}
62
63impl From<rustywallet_electrum::ElectrumError> for RecoveryError {
64    fn from(e: rustywallet_electrum::ElectrumError) -> Self {
65        RecoveryError::BackendError(e.to_string())
66    }
67}
68
69impl From<serde_json::Error> for RecoveryError {
70    fn from(e: serde_json::Error) -> Self {
71        RecoveryError::SerializationError(e.to_string())
72    }
73}