Skip to main content

bsv/wallet/
error.rs

1//! Error types for the wallet module.
2
3use thiserror::Error;
4
5/// Unified error type for all wallet operations.
6#[derive(Debug, Error)]
7pub enum WalletError {
8    /// Protocol-level error with a numeric code and message.
9    #[error("protocol error (code {code}): {message}")]
10    Protocol { code: u8, message: String },
11
12    /// Invalid parameter supplied to a wallet operation.
13    #[error("invalid parameter: {0}")]
14    InvalidParameter(String),
15
16    /// Requested functionality is not yet implemented.
17    #[error("not implemented: {0}")]
18    NotImplemented(String),
19
20    /// Internal error wrapping lower-level failures.
21    #[error("internal error: {0}")]
22    Internal(String),
23}
24
25impl From<crate::primitives::PrimitivesError> for WalletError {
26    fn from(e: crate::primitives::PrimitivesError) -> Self {
27        WalletError::Internal(e.to_string())
28    }
29}
30
31impl From<crate::script::ScriptError> for WalletError {
32    fn from(e: crate::script::ScriptError) -> Self {
33        WalletError::Internal(e.to_string())
34    }
35}
36
37impl From<crate::transaction::TransactionError> for WalletError {
38    fn from(e: crate::transaction::TransactionError) -> Self {
39        WalletError::Internal(e.to_string())
40    }
41}
42
43impl From<std::io::Error> for WalletError {
44    fn from(e: std::io::Error) -> Self {
45        WalletError::Internal(e.to_string())
46    }
47}