Merge pull request #2822 from TheBlueMatt/2024-01-pm-dyn-ref
[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 pub(crate) enum InternalError {
22         /// A transaction sync failed and needs to be retried eventually.
23         Failed,
24         /// An inconsistency was encountered during transaction sync.
25         Inconsistency,
26 }
27
28 impl fmt::Display for InternalError {
29         fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30                 match *self {
31                         Self::Failed => write!(f, "Failed to conduct transaction sync."),
32                         Self::Inconsistency => {
33                                 write!(f, "Encountered an inconsistency during transaction sync.")
34                         }
35                 }
36         }
37 }
38
39 impl std::error::Error for InternalError {}
40
41 impl From<InternalError> for TxSyncError {
42         fn from(_e: InternalError) -> Self {
43                 Self::Failed
44         }
45 }
46
47 #[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
48 impl From<esplora_client::Error> for TxSyncError {
49         fn from(_e: esplora_client::Error) -> Self {
50                 Self::Failed
51         }
52 }
53
54 #[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
55 impl From<esplora_client::Error> for InternalError {
56         fn from(_e: esplora_client::Error) -> Self {
57                 Self::Failed
58         }
59 }
60
61 #[cfg(feature = "electrum")]
62 impl From<electrum_client::Error> for InternalError {
63         fn from(_e: electrum_client::Error) -> Self {
64                 Self::Failed
65         }
66 }
67
68 #[cfg(feature = "electrum")]
69 impl From<electrum_client::Error> for TxSyncError {
70         fn from(_e: electrum_client::Error) -> Self {
71                 Self::Failed
72         }
73 }