1- use bdk:: blockchain:: esplora;
2- use lightning:: ln:: msgs;
3- use lightning:: util:: errors;
4- use lightning_invoice:: payment;
51use std:: fmt;
6- use std:: io;
7- use std:: time;
82
93#[ derive( Debug ) ]
104/// An error that possibly needs to be handled by the user.
11- pub enum LdkLiteError {
5+ pub enum Error {
126 /// Returned when trying to start LdkLite while it is already running.
137 AlreadyRunning ,
148 /// Returned when trying to stop LdkLite while it is not running.
@@ -19,112 +13,67 @@ pub enum LdkLiteError {
1913 ConnectionFailed ,
2014 /// Payment of the given invoice has already been intiated.
2115 NonUniquePaymentHash ,
16+ /// The given invoice is invalid.
17+ InvoiceInvalid ,
18+ /// Invoice creation failed.
19+ InvoiceCreationFailed ,
20+ /// No route for the given target could be found.
21+ RoutingFailed ,
2222 /// 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 ) ,
23+ PeerInfoParseFailed ,
24+ /// A channel could not be opened.
25+ ChannelCreationFailed ,
26+ /// A channel could not be closed.
27+ ChannelClosingFailed ,
28+ /// Persistence failed.
29+ PersistenceFailed ,
30+ /// A wallet operation failed.
31+ WalletOperationFailed ,
32+ /// A siging operation failed.
33+ WalletSigningFailed ,
34+ /// A transaction sync operation failed.
35+ TxSyncFailed ,
4236}
4337
44- impl fmt:: Display for LdkLiteError {
38+ impl fmt:: Display for Error {
4539 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
4640 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" )
41+ Self :: AlreadyRunning => write ! ( f, "LDKLite is already running." ) ,
42+ Self :: NotRunning => write ! ( f, "LDKLite is not running." ) ,
43+ Self :: FundingTxCreationFailed => {
44+ write ! ( f, "Funding transaction could not be created. " )
5145 }
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) ,
46+ Self :: ConnectionFailed => write ! ( f, "Network connection closed." ) ,
47+ Self :: NonUniquePaymentHash => write ! ( f, "An invoice must not get payed twice." ) ,
48+ Self :: InvoiceInvalid => write ! ( f, "The given invoice is invalid." ) ,
49+ Self :: InvoiceCreationFailed => write ! ( f, "Failed to create invoice." ) ,
50+ Self :: RoutingFailed => write ! ( f, "Failed to find route." ) ,
51+ Self :: PeerInfoParseFailed => write ! ( f, "Failed to parse the given peer information." ) ,
52+ Self :: ChannelCreationFailed => write ! ( f, "Failed to create channel." ) ,
53+ Self :: ChannelClosingFailed => write ! ( f, "Failed to close channel." ) ,
54+ Self :: PersistenceFailed => write ! ( f, "Failed to persist data." ) ,
55+ Self :: WalletOperationFailed => write ! ( f, "Failed to conduct wallet operation." ) ,
56+ Self :: WalletSigningFailed => write ! ( f, "Failed to sign given transaction." ) ,
57+ Self :: TxSyncFailed => write ! ( f, "Failed to sync transactions." ) ,
6858 }
6959 }
7060}
7161
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- }
62+ impl std:: error:: Error for Error { }
8963
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 {
64+ impl From < bdk:: Error > for Error {
9765 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)
66+ match e {
67+ bdk:: Error :: Signer ( _) => Self :: WalletSigningFailed ,
68+ _ => Self :: WalletOperationFailed ,
69+ }
12370 }
12471}
12572
126- impl From < esplora:: EsploraError > for LdkLiteError {
127- fn from ( e : esplora:: EsploraError ) -> Self {
128- Self :: Esplora ( e)
73+ impl From < lightning_transaction_sync:: TxSyncError > for Error {
74+ fn from ( e : lightning_transaction_sync:: TxSyncError ) -> Self {
75+ match e {
76+ _ => Self :: TxSyncFailed ,
77+ }
12978 }
13079}
0 commit comments