Skip to main content

etopay_wallet/
error.rs

1/// A [`core::result::Result`] with [`WalletError`] as its error variant.
2pub type Result<T> = core::result::Result<T, WalletError>;
3
4/// Wrapper for wallet errors
5#[derive(thiserror::Error, Debug)]
6pub enum WalletError {
7    /// Error raises if the feature is not implemented
8    #[error("Wallet feature is not implemented")]
9    WalletFeatureNotImplemented,
10
11    /// Error raises if the wallet address is empty
12    #[error("Wallet address is empty")]
13    EmptyWalletAddress,
14
15    /// Error raises if something failed to parse
16    #[error("ParseError: {0}")]
17    Parse(String),
18
19    /// Error occurs is the transaction amount is invalid
20    #[error("InvalidTransactionAmount: {0}")]
21    InvalidTransactionAmount(String),
22
23    /// Error occurs is the transaction is invalid
24    #[error("InvalidTransaction: {0}")]
25    InvalidTransaction(String),
26
27    /// Insufficient balance on wallet
28    #[error("InsufficientBalanceError: {0}")]
29    InsufficientBalance(String),
30
31    /// Error caused by conversions to/from Decimal and f64
32    #[error("Decimal error: {0}")]
33    Decimal(rust_decimal::Error),
34
35    /// Error occurred while handling bip32 compliant derivation paths
36    #[error("Bip32: {0:?}")]
37    Bip32(#[from] bip32::Error),
38
39    /// Error creating a LocalSigner from the provided mnemonic
40    #[error("LocalSignerError: {0}")]
41    LocalSignerError(#[from] alloy::signers::local::LocalSignerError),
42
43    /// Error waiting for transaction to be included
44    #[error("PendingTransactionError: {0}")]
45    PendingTransactionError(#[from] alloy::providers::PendingTransactionError),
46
47    /// Could not convert hex to address
48    #[error("Invalid hex value: {0}")]
49    FromHexError(#[from] alloy_primitives::hex::FromHexError),
50
51    /// Alloy transport error
52    #[error("Alloy transport RPC error: {0}")]
53    AlloyTransportRpcError(#[from] alloy_json_rpc::RpcError<alloy_transport::TransportErrorKind>),
54
55    /// Error raises if transaction does not exist
56    #[error("TransactionNotFound")]
57    TransactionNotFound,
58
59    /// Error raises if value cannot be converted
60    #[error("Unable to convert: {0}")]
61    ConversionError(String),
62
63    /// Error for calling a Smart Contract
64    #[error("Contract error: {0}")]
65    Contract(#[from] alloy::contract::Error),
66
67    /// Error for decoding a Smart Contract call
68    #[error("SolidityError error: {0}")]
69    SolidityError(#[from] alloy::sol_types::Error),
70
71    /// Iota Rebased Error
72    #[error("IotaRebased: {0}")]
73    IotaRebased(#[from] crate::rebased::RebasedError),
74
75    /// Failed to wait for confirming the transaction status
76    #[error("FailToConfirmTransactionStatus: Failed to confirm tx status for {0} within {1} seconds.")]
77    FailToConfirmTransactionStatus(String, u64),
78}
79
80impl From<rust_decimal::Error> for WalletError {
81    fn from(value: rust_decimal::Error) -> Self {
82        Self::Decimal(value)
83    }
84}