0a529d063ec81187336df0ba6b58055093ecca7d
[rust-lightning] / lightning-transaction-sync / src / error.rs
1 use std::fmt;
2
3 #[derive(Debug)]
4 /// An error that possibly needs to be handled by the user.
5 pub enum TxSyncError {
6         /// A transaction sync failed and needs to be retried eventually.
7         Failed,
8 }
9
10 impl std::error::Error for TxSyncError {}
11
12 impl fmt::Display for TxSyncError {
13         fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14                 match *self {
15                         Self::Failed => write!(f, "Failed to conduct transaction sync."),
16                 }
17         }
18 }
19
20 #[derive(Debug)]
21 #[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
22 pub(crate) enum InternalError {
23         /// A transaction sync failed and needs to be retried eventually.
24         Failed,
25         /// An inconsisteny was encounterd during transaction sync.
26         Inconsistency,
27 }
28
29 #[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
30 impl fmt::Display for InternalError {
31         fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32                 match *self {
33                         Self::Failed => write!(f, "Failed to conduct transaction sync."),
34                         Self::Inconsistency => {
35                                 write!(f, "Encountered an inconsisteny during transaction sync.")
36                         }
37                 }
38         }
39 }
40
41 #[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
42 impl std::error::Error for InternalError {}
43
44 #[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
45 impl From<esplora_client::Error> for TxSyncError {
46         fn from(_e: esplora_client::Error) -> Self {
47                 Self::Failed
48         }
49 }
50
51 #[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
52 impl From<esplora_client::Error> for InternalError {
53         fn from(_e: esplora_client::Error) -> Self {
54                 Self::Failed
55         }
56 }
57
58 #[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
59 impl From<InternalError> for TxSyncError {
60         fn from(_e: InternalError) -> Self {
61                 Self::Failed
62         }
63 }