1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum QuantusError {
6 #[error("Wallet error: {0}")]
8 Wallet(#[from] WalletError),
9
10 #[error("IO error: {0}")]
12 Io(#[from] std::io::Error),
13
14 #[error("JSON error: {0}")]
16 Json(#[from] serde_json::Error),
17
18 #[error("TOML error: {0}")]
20 TomlDe(#[from] toml::de::Error),
21
22 #[error("TOML serialization error: {0}")]
24 TomlSer(#[from] toml::ser::Error),
25
26 #[error("SubXT error: {0}")]
28 Subxt(#[from] Box<subxt::Error>),
29
30 #[error("Error: {0}")]
32 Generic(String),
33
34 #[error("Network error: {0}")]
35 NetworkError(String),
36
37 #[error("Insufficient balance: available {available}, required {required}")]
38 InsufficientBalance { available: u128, required: u128 },
39}
40
41#[derive(Error, Debug)]
43pub enum WalletError {
44 #[error("Wallet not found")]
45 NotFound,
46
47 #[error("Wallet already exists")]
48 AlreadyExists,
49
50 #[error("Invalid mnemonic phrase")]
51 InvalidMnemonic,
52 #[error("Mnemonic phrase is not available for this wallet")]
53 MnemonicNotAvailable,
54 #[error("Invalid password")]
55 InvalidPassword,
56
57 #[error("Key generation failed")]
58 KeyGeneration,
59
60 #[error("Encryption failed: {0}")]
61 Encryption(String),
62
63 #[error("Decryption failed. Check your password.")]
64 Decryption,
65}
66
67pub type Result<T> = std::result::Result<T, QuantusError>;
69
70impl From<subxt::Error> for QuantusError {
71 fn from(err: subxt::Error) -> Self {
72 QuantusError::Subxt(Box::new(err))
73 }
74}