rustywallet_tx/
error.rs

1//! Error types for transaction operations.
2
3use thiserror::Error;
4
5/// Errors that can occur during transaction operations.
6#[derive(Debug, Error)]
7pub enum TxError {
8    /// Insufficient funds to cover outputs + fees
9    #[error("Insufficient funds: need {needed} sat, have {available} sat")]
10    InsufficientFunds {
11        /// Amount needed (outputs + fees)
12        needed: u64,
13        /// Amount available from UTXOs
14        available: u64,
15    },
16
17    /// Invalid address format
18    #[error("Invalid address: {0}")]
19    InvalidAddress(String),
20
21    /// Invalid UTXO
22    #[error("Invalid UTXO: {0}")]
23    InvalidUtxo(String),
24
25    /// Signing failed
26    #[error("Signing failed: {0}")]
27    SigningFailed(String),
28
29    /// Serialization failed
30    #[error("Serialization failed: {0}")]
31    SerializationFailed(String),
32
33    /// Output amount below dust threshold
34    #[error("Dust output: {0} sat is below dust threshold")]
35    DustOutput(u64),
36
37    /// No inputs provided
38    #[error("No inputs provided")]
39    NoInputs,
40
41    /// No outputs provided
42    #[error("No outputs provided")]
43    NoOutputs,
44
45    /// Invalid transaction structure
46    #[error("Invalid transaction: {0}")]
47    InvalidTransaction(String),
48
49    /// Input index out of bounds
50    #[error("Input index {index} out of bounds (have {count} inputs)")]
51    InputIndexOutOfBounds {
52        /// Requested index
53        index: usize,
54        /// Number of inputs
55        count: usize,
56    },
57}
58
59/// Result type alias for transaction operations.
60pub type Result<T> = std::result::Result<T, TxError>;