|
1 |
| -use bdk::blockchain::esplora; |
2 |
| -use lightning::ln::msgs; |
3 |
| -use lightning::util::errors; |
4 |
| -use lightning_invoice::payment; |
5 | 1 | use std::fmt;
|
6 |
| -use std::io; |
7 |
| -use std::time; |
8 | 2 |
|
9 |
| -#[derive(Debug)] |
| 3 | +#[derive(Debug, PartialEq, Eq)] |
10 | 4 | /// An error that possibly needs to be handled by the user.
|
11 |
| -pub enum LdkLiteError { |
12 |
| - /// Returned when trying to start LdkLite while it is already running. |
| 5 | +pub enum Error { |
| 6 | + /// Returned when trying to start [`crate::Node`] while it is already running. |
13 | 7 | AlreadyRunning,
|
14 |
| - /// Returned when trying to stop LdkLite while it is not running. |
| 8 | + /// Returned when trying to stop [`crate::Node`] while it is not running. |
15 | 9 | NotRunning,
|
16 | 10 | /// The funding transaction could not be created.
|
17 | 11 | FundingTxCreationFailed,
|
18 | 12 | /// A network connection has been closed.
|
19 | 13 | ConnectionFailed,
|
20 | 14 | /// Payment of the given invoice has already been intiated.
|
21 | 15 | NonUniquePaymentHash,
|
| 16 | + /// The given amount is invalid. |
| 17 | + InvalidAmount, |
| 18 | + /// The given invoice is invalid. |
| 19 | + InvalidInvoice, |
| 20 | + /// Invoice creation failed. |
| 21 | + InvoiceCreationFailed, |
| 22 | + /// There are insufficient funds to complete the given operation. |
| 23 | + InsufficientFunds, |
| 24 | + /// An attempted payment has failed. |
| 25 | + PaymentFailed, |
22 | 26 | /// A given peer info could not be parsed.
|
23 |
| - PeerInfoParse(&'static str), |
24 |
| - /// A wrapped LDK `APIError` |
25 |
| - LdkApi(errors::APIError), |
26 |
| - /// A wrapped LDK `DecodeError` |
27 |
| - LdkDecode(msgs::DecodeError), |
28 |
| - /// A wrapped LDK `PaymentError` |
29 |
| - LdkPayment(payment::PaymentError), |
30 |
| - /// A wrapped LDK `SignOrCreationError` |
31 |
| - LdkInvoiceCreation(lightning_invoice::SignOrCreationError), |
32 |
| - /// A wrapped BDK error |
33 |
| - Bdk(bdk::Error), |
34 |
| - /// A wrapped `EsploraError` |
35 |
| - Esplora(esplora::EsploraError), |
36 |
| - /// A wrapped `Bip32` error |
37 |
| - Bip32(bitcoin::util::bip32::Error), |
38 |
| - /// A wrapped `std::io::Error` |
39 |
| - StdIo(io::Error), |
40 |
| - /// A wrapped `SystemTimeError` |
41 |
| - StdTime(time::SystemTimeError), |
| 27 | + PeerInfoParseFailed, |
| 28 | + /// A channel could not be opened. |
| 29 | + ChannelCreationFailed, |
| 30 | + /// A channel could not be closed. |
| 31 | + ChannelClosingFailed, |
| 32 | + /// Persistence failed. |
| 33 | + PersistenceFailed, |
| 34 | + /// A wallet operation failed. |
| 35 | + WalletOperationFailed, |
| 36 | + /// A siging operation failed. |
| 37 | + WalletSigningFailed, |
| 38 | + /// A transaction sync operation failed. |
| 39 | + TxSyncFailed, |
42 | 40 | }
|
43 | 41 |
|
44 |
| -impl fmt::Display for LdkLiteError { |
| 42 | +impl fmt::Display for Error { |
45 | 43 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
46 | 44 | match *self {
|
47 |
| - LdkLiteError::AlreadyRunning => write!(f, "LDKLite is already running."), |
48 |
| - LdkLiteError::NotRunning => write!(f, "LDKLite is not running."), |
49 |
| - LdkLiteError::FundingTxCreationFailed => { |
50 |
| - write!(f, "the funding transaction could not be created") |
| 45 | + Self::AlreadyRunning => write!(f, "Node is already running."), |
| 46 | + Self::NotRunning => write!(f, "Node is not running."), |
| 47 | + Self::FundingTxCreationFailed => { |
| 48 | + write!(f, "Funding transaction could not be created.") |
51 | 49 | }
|
52 |
| - LdkLiteError::ConnectionFailed => write!(f, "network connection closed"), |
53 |
| - LdkLiteError::NonUniquePaymentHash => write!(f, "an invoice must not get payed twice."), |
54 |
| - LdkLiteError::PeerInfoParse(ref e) => { |
55 |
| - write!(f, "given peer info could not be parsed: {}", e) |
| 50 | + Self::ConnectionFailed => write!(f, "Network connection closed."), |
| 51 | + Self::NonUniquePaymentHash => write!(f, "An invoice must not get payed twice."), |
| 52 | + Self::InvalidAmount => write!(f, "The given amount is invalid."), |
| 53 | + Self::InvalidInvoice => write!(f, "The given invoice is invalid."), |
| 54 | + Self::InvoiceCreationFailed => write!(f, "Failed to create invoice."), |
| 55 | + Self::InsufficientFunds => { |
| 56 | + write!(f, "There are insufficient funds to complete the given operation.") |
56 | 57 | }
|
57 |
| - LdkLiteError::LdkDecode(ref e) => write!(f, "LDK decode error: {}", e), |
58 |
| - LdkLiteError::LdkApi(ref e) => write!(f, "LDK API error: {:?}", e), |
59 |
| - LdkLiteError::LdkPayment(ref e) => write!(f, "LDK payment error: {:?}", e), |
60 |
| - LdkLiteError::LdkInvoiceCreation(ref e) => { |
61 |
| - write!(f, "LDK invoice sign or creation error: {:?}", e) |
62 |
| - } |
63 |
| - LdkLiteError::Bdk(ref e) => write!(f, "BDK error: {}", e), |
64 |
| - LdkLiteError::Esplora(ref e) => write!(f, "Esplora error: {}", e), |
65 |
| - LdkLiteError::Bip32(ref e) => write!(f, "Bitcoin error: {}", e), |
66 |
| - LdkLiteError::StdIo(ref e) => write!(f, "IO error: {}", e), |
67 |
| - LdkLiteError::StdTime(ref e) => write!(f, "time error: {}", e), |
| 58 | + Self::PaymentFailed => write!(f, "Failed to send the given payment."), |
| 59 | + Self::PeerInfoParseFailed => write!(f, "Failed to parse the given peer information."), |
| 60 | + Self::ChannelCreationFailed => write!(f, "Failed to create channel."), |
| 61 | + Self::ChannelClosingFailed => write!(f, "Failed to close channel."), |
| 62 | + Self::PersistenceFailed => write!(f, "Failed to persist data."), |
| 63 | + Self::WalletOperationFailed => write!(f, "Failed to conduct wallet operation."), |
| 64 | + Self::WalletSigningFailed => write!(f, "Failed to sign given transaction."), |
| 65 | + Self::TxSyncFailed => write!(f, "Failed to sync transactions."), |
68 | 66 | }
|
69 | 67 | }
|
70 | 68 | }
|
71 | 69 |
|
72 |
| -impl From<errors::APIError> for LdkLiteError { |
73 |
| - fn from(e: errors::APIError) -> Self { |
74 |
| - Self::LdkApi(e) |
75 |
| - } |
76 |
| -} |
| 70 | +impl std::error::Error for Error {} |
77 | 71 |
|
78 |
| -impl From<msgs::DecodeError> for LdkLiteError { |
79 |
| - fn from(e: msgs::DecodeError) -> Self { |
80 |
| - Self::LdkDecode(e) |
81 |
| - } |
82 |
| -} |
83 |
| - |
84 |
| -impl From<payment::PaymentError> for LdkLiteError { |
85 |
| - fn from(e: payment::PaymentError) -> Self { |
86 |
| - Self::LdkPayment(e) |
87 |
| - } |
88 |
| -} |
89 |
| - |
90 |
| -impl From<lightning_invoice::SignOrCreationError> for LdkLiteError { |
91 |
| - fn from(e: lightning_invoice::SignOrCreationError) -> Self { |
92 |
| - Self::LdkInvoiceCreation(e) |
93 |
| - } |
94 |
| -} |
95 |
| - |
96 |
| -impl From<bdk::Error> for LdkLiteError { |
| 72 | +impl From<bdk::Error> for Error { |
97 | 73 | fn from(e: bdk::Error) -> Self {
|
98 |
| - Self::Bdk(e) |
99 |
| - } |
100 |
| -} |
101 |
| - |
102 |
| -impl From<bdk::sled::Error> for LdkLiteError { |
103 |
| - fn from(e: bdk::sled::Error) -> Self { |
104 |
| - Self::Bdk(bdk::Error::Sled(e)) |
105 |
| - } |
106 |
| -} |
107 |
| - |
108 |
| -impl From<bitcoin::util::bip32::Error> for LdkLiteError { |
109 |
| - fn from(e: bitcoin::util::bip32::Error) -> Self { |
110 |
| - Self::Bip32(e) |
111 |
| - } |
112 |
| -} |
113 |
| - |
114 |
| -impl From<io::Error> for LdkLiteError { |
115 |
| - fn from(e: io::Error) -> Self { |
116 |
| - Self::StdIo(e) |
117 |
| - } |
118 |
| -} |
119 |
| - |
120 |
| -impl From<time::SystemTimeError> for LdkLiteError { |
121 |
| - fn from(e: time::SystemTimeError) -> Self { |
122 |
| - Self::StdTime(e) |
| 74 | + match e { |
| 75 | + bdk::Error::Signer(_) => Self::WalletSigningFailed, |
| 76 | + _ => Self::WalletOperationFailed, |
| 77 | + } |
123 | 78 | }
|
124 | 79 | }
|
125 | 80 |
|
126 |
| -impl From<esplora::EsploraError> for LdkLiteError { |
127 |
| - fn from(e: esplora::EsploraError) -> Self { |
128 |
| - Self::Esplora(e) |
| 81 | +impl From<lightning_transaction_sync::TxSyncError> for Error { |
| 82 | + fn from(_e: lightning_transaction_sync::TxSyncError) -> Self { |
| 83 | + Self::TxSyncFailed |
129 | 84 | }
|
130 | 85 | }
|
0 commit comments