Skip to main content

moonproof_wallet/
error.rs

1use thiserror::Error;
2
3/// Top-level error type for the wallet crate. Downstream crates should match
4/// on the variant of interest and bubble the rest with `?`.
5#[derive(Debug, Error)]
6pub enum WalletError {
7    #[error("invalid mnemonic: {0}")]
8    Mnemonic(String),
9
10    #[error("invalid seed length {0}: BIP32 master seeds must be 16..=64 bytes")]
11    SeedLength(usize),
12
13    #[error("invalid seed encoding: {0}")]
14    InvalidSeed(String),
15
16    #[error("BIP32 derivation error: {0}")]
17    Derivation(String),
18
19    #[error("BIP32 derivation produced an out-of-bounds key")]
20    KeyOutOfBounds,
21
22    #[error("invalid Bech32 address: {0}")]
23    Bech32(String),
24
25    #[error("insufficient funds: could not balance token `{token}`")]
26    InsufficientFunds { token: String },
27
28    #[error("amount arithmetic overflow")]
29    AmountOverflow,
30
31    /// A first-time registration pays its fee from the dust its NIGHT
32    /// has generated so far, and that does not yet cover the fee;
33    /// submitted, the node would reject it as `BalanceCheckOverspend`.
34    #[error(
35        "insufficient dust for the registration fee: {fee_payment} generated, fee {fee} ({estimate:?})"
36    )]
37    InsufficientDustForFee {
38        fee: u128,
39        fee_payment: u128,
40        estimate: crate::dust::transacting::FeeCoverageEstimate,
41    },
42
43    #[error(
44        "unshielded UTXO not found: intent_hash=0x{} output_no={}",
45        hex::encode(id.intent_hash),
46        id.output_no
47    )]
48    UtxoNotFound { id: crate::unshielded::UtxoId },
49
50    #[error("invalid update status: expected {expected}, got {got}")]
51    InvalidUpdateStatus {
52        expected: &'static str,
53        got: &'static str,
54    },
55
56    #[error("invalid token type: {0}")]
57    InvalidTokenType(String),
58
59    #[error("signing failed: {0}")]
60    SigningFailed(String),
61
62    #[error("serialization failed: {0}")]
63    Serialization(String),
64
65    #[error("transaction submission failed: {0}")]
66    Submission(String),
67
68    #[error("invalid amount `{0}`: not a valid signed 128-bit integer")]
69    InvalidAmount(String),
70
71    #[error("dust replay error: {0}")]
72    DustReplay(String),
73
74    #[error("dust spend error: {0}")]
75    DustSpend(String),
76
77    #[error("dust wallet error: {0}")]
78    Dust(String),
79
80    #[error("unshielded sync error: {0}")]
81    UnshieldedSync(String),
82
83    #[error("shielded offer build error: {0}")]
84    ShieldedOffer(String),
85
86    #[error("shielded sync error: {0}")]
87    ShieldedSync(String),
88
89    #[error(
90        "stale snapshot: chain reports highest {scope} index {chain_highest} below the \
91         snapshot's applied index {snapshot_applied} — the chain was reset or the snapshot \
92         belongs to a different chain instance"
93    )]
94    StaleSnapshot {
95        scope: &'static str,
96        snapshot_applied: i64,
97        chain_highest: i64,
98    },
99
100    #[error("I/O error: {0}")]
101    Io(#[from] std::io::Error),
102}
103
104/// Convenience `Result` alias used throughout the crate.
105pub type Result<T> = std::result::Result<T, WalletError>;