Skip to main content

fedimint_bitcoind/
error.rs

1use bitcoin::Txid;
2use fedimint_core::encoding::DecodeError;
3use thiserror::Error;
4
5/// A failure talking to the Bitcoin data source.
6///
7/// `Display` prints only the outermost layer; the backend's own error is
8/// reachable through [`std::error::Error::source`] and printed flat by
9/// [`FmtCompact::fmt_compact`](fedimint_core::util::FmtCompact).
10#[derive(Debug, Error)]
11#[non_exhaustive]
12pub enum BitcoinRpcError {
13    /// The backend url could not be parsed, or a client for it could not be
14    /// built.
15    #[error("Invalid Bitcoin rpc url {url}")]
16    InvalidUrl {
17        /// The url that was rejected, with any credentials redacted, or the
18        /// name of the environment variable it came from when it could
19        /// not be parsed at all.
20        url: String,
21        /// Why it was rejected.
22        #[source]
23        source: Box<dyn std::error::Error + Send + Sync>,
24    },
25
26    /// The backend refused the call or could not be reached.
27    #[error("The Bitcoin rpc backend failed")]
28    Backend(#[source] Box<dyn std::error::Error + Send + Sync>),
29
30    /// The script is not one the backend can watch as an address.
31    #[error("Script is not a standard address")]
32    NonStandardScript(#[source] Box<dyn std::error::Error + Send + Sync>),
33
34    /// The backend answered, but the answer cannot be used.
35    #[error("Invalid Bitcoin rpc response: {message}")]
36    InvalidResponse {
37        /// What is wrong with the response.
38        message: String,
39    },
40
41    /// No merkle proof is available for the transaction.
42    #[error("No merkle proof found for transaction {txid}")]
43    ProofNotFound {
44        /// The transaction the proof was requested for.
45        txid: Txid,
46    },
47
48    /// The script has more history than can be processed in one go.
49    #[error("Script history exceeds the maximum of {max} transactions")]
50    ScriptHistoryTooLong {
51        /// The maximum number of transactions that can be processed.
52        max: usize,
53    },
54
55    /// A response could not be decoded.
56    #[error("Failed to decode a Bitcoin rpc response")]
57    Decode(#[source] DecodeError),
58}