-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy patherror.rs
More file actions
269 lines (258 loc) · 10.5 KB
/
error.rs
File metadata and controls
269 lines (258 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// This file is Copyright its original authors, visible in version control history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.
use std::fmt;
use bdk_chain::bitcoin::psbt::ExtractTxError as BdkExtractTxError;
use bdk_chain::local_chain::CannotConnectError as BdkChainConnectionError;
use bdk_chain::tx_graph::CalculateFeeError as BdkChainCalculateFeeError;
use bdk_wallet::error::CreateTxError as BdkCreateTxError;
#[allow(deprecated)]
use bdk_wallet::signer::SignerError as BdkSignerError;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
/// An error that possibly needs to be handled by the user.
pub enum Error {
/// Returned when trying to start [`crate::Node`] while it is already running.
AlreadyRunning,
/// Returned when trying to stop [`crate::Node`] while it is not running.
NotRunning,
/// An on-chain transaction could not be created.
OnchainTxCreationFailed,
/// A network connection has been closed.
ConnectionFailed,
/// Invoice creation failed.
InvoiceCreationFailed,
/// Invoice request creation failed.
InvoiceRequestCreationFailed,
/// Offer creation failed.
OfferCreationFailed,
/// Refund creation failed.
RefundCreationFailed,
/// Sending a payment has failed.
PaymentSendingFailed,
/// Sending of spontaneous payment with custom TLVs failed.
InvalidCustomTlvs,
/// Sending a payment probe has failed.
ProbeSendingFailed,
/// A channel could not be opened.
ChannelCreationFailed,
/// A channel could not be closed.
ChannelClosingFailed,
/// A channel could not be spliced.
ChannelSplicingFailed,
/// A channel configuration could not be updated.
ChannelConfigUpdateFailed,
/// Persistence failed.
PersistenceFailed,
/// A fee rate estimation update failed.
FeerateEstimationUpdateFailed,
/// A fee rate estimation update timed out.
FeerateEstimationUpdateTimeout,
/// A wallet operation failed.
WalletOperationFailed,
/// A wallet operation timed out.
WalletOperationTimeout,
/// A signing operation for transaction failed.
OnchainTxSigningFailed,
/// A transaction sync operation failed.
TxSyncFailed,
/// A transaction sync operation timed out.
TxSyncTimeout,
/// A gossip updating operation failed.
GossipUpdateFailed,
/// A gossip updating operation timed out.
GossipUpdateTimeout,
/// A liquidity request operation failed.
LiquidityRequestFailed,
/// Parsing a URI parameter has failed.
UriParameterParsingFailed,
/// The given address is invalid.
InvalidAddress,
/// The given network address is invalid.
InvalidSocketAddress,
/// The given public key is invalid.
InvalidPublicKey,
/// The given secret key is invalid.
InvalidSecretKey,
/// The given offer id is invalid.
InvalidOfferId,
/// The given node id is invalid.
InvalidNodeId,
/// The given payment id is invalid.
InvalidPaymentId,
/// The given payment hash is invalid.
InvalidPaymentHash,
/// The given payment pre-image is invalid.
InvalidPaymentPreimage,
/// The given payment secret is invalid.
InvalidPaymentSecret,
/// The given amount is invalid.
InvalidAmount,
/// The given invoice is invalid.
InvalidInvoice,
/// The given offer is invalid.
InvalidOffer,
/// The given refund is invalid.
InvalidRefund,
/// The given channel ID is invalid.
InvalidChannelId,
/// The given network is invalid.
InvalidNetwork,
/// The given URI is invalid.
InvalidUri,
/// The given quantity is invalid.
InvalidQuantity,
/// The given node alias is invalid.
InvalidNodeAlias,
/// The given date time is invalid.
InvalidDateTime,
/// The given fee rate is invalid.
InvalidFeeRate,
/// The given script public key is invalid.
InvalidScriptPubKey,
/// A payment with the given hash has already been initiated.
DuplicatePayment,
/// The provided offer was denonminated in an unsupported currency.
UnsupportedCurrency,
/// The available funds are insufficient to complete the given operation.
InsufficientFunds,
/// The given operation failed due to the required liquidity source being unavailable.
LiquiditySourceUnavailable,
/// The given operation failed due to the LSP's required opening fee being too high.
LiquidityFeeTooHigh,
/// The given blinded paths are invalid.
InvalidBlindedPaths,
/// Asynchronous payment services are disabled.
AsyncPaymentServicesDisabled,
/// Parsing a Human-Readable Name has failed.
HrnParsingFailed,
/// LNURL-auth authentication failed.
LnurlAuthFailed,
/// LNURL-auth authentication timed out.
LnurlAuthTimeout,
/// The provided lnurl is invalid.
InvalidLnurl,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::AlreadyRunning => write!(f, "Node is already running."),
Self::NotRunning => write!(f, "Node is not running."),
Self::OnchainTxCreationFailed => {
write!(f, "On-chain transaction could not be created.")
},
Self::ConnectionFailed => write!(f, "Network connection closed."),
Self::InvoiceCreationFailed => write!(f, "Failed to create invoice."),
Self::InvoiceRequestCreationFailed => write!(f, "Failed to create invoice request."),
Self::OfferCreationFailed => write!(f, "Failed to create offer."),
Self::RefundCreationFailed => write!(f, "Failed to create refund."),
Self::PaymentSendingFailed => write!(f, "Failed to send the given payment."),
Self::InvalidCustomTlvs => write!(f, "Failed to construct payment with custom TLVs."),
Self::ProbeSendingFailed => write!(f, "Failed to send the given payment probe."),
Self::ChannelCreationFailed => write!(f, "Failed to create channel."),
Self::ChannelClosingFailed => write!(f, "Failed to close channel."),
Self::ChannelSplicingFailed => write!(f, "Failed to splice channel."),
Self::ChannelConfigUpdateFailed => write!(f, "Failed to update channel config."),
Self::PersistenceFailed => write!(f, "Failed to persist data."),
Self::FeerateEstimationUpdateFailed => {
write!(f, "Failed to update fee rate estimates.")
},
Self::FeerateEstimationUpdateTimeout => {
write!(f, "Updating fee rate estimates timed out.")
},
Self::WalletOperationFailed => write!(f, "Failed to conduct wallet operation."),
Self::WalletOperationTimeout => write!(f, "A wallet operation timed out."),
Self::OnchainTxSigningFailed => write!(f, "Failed to sign given transaction."),
Self::TxSyncFailed => write!(f, "Failed to sync transactions."),
Self::TxSyncTimeout => write!(f, "Syncing transactions timed out."),
Self::GossipUpdateFailed => write!(f, "Failed to update gossip data."),
Self::GossipUpdateTimeout => write!(f, "Updating gossip data timed out."),
Self::LiquidityRequestFailed => write!(f, "Failed to request inbound liquidity."),
Self::UriParameterParsingFailed => write!(f, "Failed to parse a URI parameter."),
Self::InvalidAddress => write!(f, "The given address is invalid."),
Self::InvalidSocketAddress => write!(f, "The given network address is invalid."),
Self::InvalidPublicKey => write!(f, "The given public key is invalid."),
Self::InvalidSecretKey => write!(f, "The given secret key is invalid."),
Self::InvalidOfferId => write!(f, "The given offer id is invalid."),
Self::InvalidNodeId => write!(f, "The given node id is invalid."),
Self::InvalidPaymentId => write!(f, "The given payment id is invalid."),
Self::InvalidPaymentHash => write!(f, "The given payment hash is invalid."),
Self::InvalidPaymentPreimage => write!(f, "The given payment preimage is invalid."),
Self::InvalidPaymentSecret => write!(f, "The given payment secret is invalid."),
Self::InvalidAmount => write!(f, "The given amount is invalid."),
Self::InvalidInvoice => write!(f, "The given invoice is invalid."),
Self::InvalidOffer => write!(f, "The given offer is invalid."),
Self::InvalidRefund => write!(f, "The given refund is invalid."),
Self::InvalidChannelId => write!(f, "The given channel ID is invalid."),
Self::InvalidNetwork => write!(f, "The given network is invalid."),
Self::InvalidUri => write!(f, "The given URI is invalid."),
Self::InvalidQuantity => write!(f, "The given quantity is invalid."),
Self::InvalidNodeAlias => write!(f, "The given node alias is invalid."),
Self::InvalidDateTime => write!(f, "The given date time is invalid."),
Self::InvalidFeeRate => write!(f, "The given fee rate is invalid."),
Self::InvalidScriptPubKey => write!(f, "The given script pubkey is invalid."),
Self::DuplicatePayment => {
write!(f, "A payment with the given hash has already been initiated.")
},
Self::InsufficientFunds => {
write!(f, "The available funds are insufficient to complete the given operation.")
},
Self::UnsupportedCurrency => {
write!(f, "The provided offer was denonminated in an unsupported currency.")
},
Self::LiquiditySourceUnavailable => {
write!(f, "The given operation failed due to the required liquidity source being unavailable.")
},
Self::LiquidityFeeTooHigh => {
write!(f, "The given operation failed due to the LSP's required opening fee being too high.")
},
Self::InvalidBlindedPaths => write!(f, "The given blinded paths are invalid."),
Self::AsyncPaymentServicesDisabled => {
write!(f, "Asynchronous payment services are disabled.")
},
Self::HrnParsingFailed => {
write!(f, "Failed to parse a human-readable name.")
},
Self::LnurlAuthFailed => write!(f, "LNURL-auth authentication failed."),
Self::LnurlAuthTimeout => write!(f, "LNURL-auth authentication timed out."),
Self::InvalidLnurl => write!(f, "The provided lnurl is invalid."),
}
}
}
impl std::error::Error for Error {}
#[allow(deprecated)]
impl From<BdkSignerError> for Error {
fn from(_: BdkSignerError) -> Self {
Self::OnchainTxSigningFailed
}
}
impl From<BdkCreateTxError> for Error {
fn from(e: BdkCreateTxError) -> Self {
match e {
BdkCreateTxError::CoinSelection(_) => Self::InsufficientFunds,
_ => Self::OnchainTxCreationFailed,
}
}
}
impl From<BdkExtractTxError> for Error {
fn from(_: BdkExtractTxError) -> Self {
Self::OnchainTxCreationFailed
}
}
impl From<BdkChainConnectionError> for Error {
fn from(_: BdkChainConnectionError) -> Self {
Self::WalletOperationFailed
}
}
impl From<BdkChainCalculateFeeError> for Error {
fn from(_: BdkChainCalculateFeeError) -> Self {
Self::WalletOperationFailed
}
}
impl From<lightning_transaction_sync::TxSyncError> for Error {
fn from(_e: lightning_transaction_sync::TxSyncError) -> Self {
Self::TxSyncFailed
}
}