lightning_transaction_sync/
error.rs

1// This file is Copyright its original authors, visible in version control history.
2//
3// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
6// accordance with one or both of these licenses.
7
8use std::fmt;
9
10#[derive(Debug)]
11/// An error that possibly needs to be handled by the user.
12pub enum TxSyncError {
13	/// A transaction sync failed and needs to be retried eventually.
14	Failed,
15}
16
17impl std::error::Error for TxSyncError {}
18
19impl fmt::Display for TxSyncError {
20	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21		match *self {
22			Self::Failed => write!(f, "Failed to conduct transaction sync."),
23		}
24	}
25}
26
27#[derive(Debug)]
28pub(crate) enum InternalError {
29	/// A transaction sync failed and needs to be retried eventually.
30	Failed,
31	/// An inconsistency was encountered during transaction sync.
32	Inconsistency,
33}
34
35impl fmt::Display for InternalError {
36	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
37		match *self {
38			Self::Failed => write!(f, "Failed to conduct transaction sync."),
39			Self::Inconsistency => {
40				write!(f, "Encountered an inconsistency during transaction sync.")
41			},
42		}
43	}
44}
45
46impl std::error::Error for InternalError {}
47
48impl From<InternalError> for TxSyncError {
49	fn from(_e: InternalError) -> Self {
50		Self::Failed
51	}
52}
53
54#[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
55impl From<esplora_client::Error> for TxSyncError {
56	fn from(_e: esplora_client::Error) -> Self {
57		Self::Failed
58	}
59}
60
61#[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
62impl From<esplora_client::Error> for InternalError {
63	fn from(_e: esplora_client::Error) -> Self {
64		Self::Failed
65	}
66}
67
68#[cfg(feature = "electrum")]
69impl From<electrum_client::Error> for InternalError {
70	fn from(_e: electrum_client::Error) -> Self {
71		Self::Failed
72	}
73}
74
75#[cfg(feature = "electrum")]
76impl From<electrum_client::Error> for TxSyncError {
77	fn from(_e: electrum_client::Error) -> Self {
78		Self::Failed
79	}
80}