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