1
1
use bdk:: blockchain:: esplora;
2
- use lightning:: ln:: msgs;
3
- use lightning:: util:: errors;
4
- use lightning_invoice:: payment;
5
2
use std:: fmt;
6
- use std:: io;
7
- use std:: time;
8
3
9
4
#[ derive( Debug ) ]
10
5
/// An error that possibly needs to be handled by the user.
@@ -19,112 +14,65 @@ pub enum LdkLiteError {
19
14
ConnectionFailed ,
20
15
/// Payment of the given invoice has already been intiated.
21
16
NonUniquePaymentHash ,
17
+ /// The given invoice is invalid.
18
+ InvoiceInvalid ,
19
+ /// Invoice creation failed.
20
+ InvoiceCreationFailed ,
21
+ /// No route for the given target could be found.
22
+ RoutingFailed ,
22
23
/// 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 ) ,
24
+ PeerInfoParseFailed ,
25
+ /// A channel could not be opened.
26
+ ChannelCreationFailed ,
27
+ /// A channel could not be closed.
28
+ ChannelClosingFailed ,
29
+ /// Persistence failed.
30
+ PersistenceFailed ,
31
+ /// A wallet operation failed.
32
+ WalletOperationFailed ,
33
+ /// A siging operation failed.
34
+ WalletSigningFailed ,
35
+ /// A chain access operation failed.
36
+ ChainAccessFailed ,
42
37
}
43
38
44
39
impl fmt:: Display for LdkLiteError {
45
40
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
46
41
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" )
42
+ Self :: AlreadyRunning => write ! ( f, "LDKLite is already running." ) ,
43
+ Self :: NotRunning => write ! ( f, "LDKLite is not running." ) ,
44
+ Self :: FundingTxCreationFailed => {
45
+ write ! ( f, "Funding transaction could not be created. " )
51
46
}
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)
56
- }
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) ,
47
+ Self :: ConnectionFailed => write ! ( f, "Network connection closed." ) ,
48
+ Self :: NonUniquePaymentHash => write ! ( f, "An invoice must not get payed twice." ) ,
49
+ Self :: InvoiceInvalid => write ! ( f, "The given invoice is invalid." ) ,
50
+ Self :: InvoiceCreationFailed => write ! ( f, "Failed to create invoice." ) ,
51
+ Self :: RoutingFailed => write ! ( f, "Failed to find route." ) ,
52
+ Self :: PeerInfoParseFailed => write ! ( f, "Failed to parse the given peer information." ) ,
53
+ Self :: ChannelCreationFailed => write ! ( f, "Failed to create channel." ) ,
54
+ Self :: ChannelClosingFailed => write ! ( f, "Failed to close channel." ) ,
55
+ Self :: PersistenceFailed => write ! ( f, "Failed to persist data." ) ,
56
+ Self :: WalletOperationFailed => write ! ( f, "Failed to conduct wallet operation." ) ,
57
+ Self :: WalletSigningFailed => write ! ( f, "Failed to sign given transaction." ) ,
58
+ Self :: ChainAccessFailed => write ! ( f, "Failed to conduct chain access operation." ) ,
68
59
}
69
60
}
70
61
}
71
62
72
- impl From < errors:: APIError > for LdkLiteError {
73
- fn from ( e : errors:: APIError ) -> Self {
74
- Self :: LdkApi ( e)
75
- }
76
- }
77
-
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
- }
63
+ impl std:: error:: Error for LdkLiteError { }
95
64
96
65
impl From < bdk:: Error > for LdkLiteError {
97
66
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)
67
+ match e {
68
+ bdk:: Error :: Signer ( _) => Self :: WalletSigningFailed ,
69
+ _ => Self :: WalletOperationFailed ,
70
+ }
123
71
}
124
72
}
125
73
126
74
impl From < esplora:: EsploraError > for LdkLiteError {
127
- fn from ( e : esplora:: EsploraError ) -> Self {
128
- Self :: Esplora ( e )
75
+ fn from ( _e : esplora:: EsploraError ) -> Self {
76
+ Self :: ChainAccessFailed
129
77
}
130
78
}
0 commit comments