1use 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)]
18pub enum Error {
20 AlreadyRunning,
22 NotRunning,
24 OnchainTxCreationFailed,
26 ConnectionFailed,
28 InvoiceCreationFailed,
30 InvoiceRequestCreationFailed,
32 OfferCreationFailed,
34 RefundCreationFailed,
36 PaymentSendingFailed,
38 InvalidCustomTlvs,
40 ProbeSendingFailed,
42 ChannelCreationFailed,
44 ChannelClosingFailed,
46 ChannelSplicingFailed,
48 ChannelConfigUpdateFailed,
50 PersistenceFailed,
52 FeerateEstimationUpdateFailed,
54 FeerateEstimationUpdateTimeout,
56 WalletOperationFailed,
58 WalletOperationTimeout,
60 OnchainTxSigningFailed,
62 TxSyncFailed,
64 TxSyncTimeout,
66 GossipUpdateFailed,
68 GossipUpdateTimeout,
70 LiquidityRequestFailed,
72 UriParameterParsingFailed,
74 InvalidAddress,
76 InvalidSocketAddress,
78 InvalidPublicKey,
80 InvalidSecretKey,
82 InvalidOfferId,
84 InvalidNodeId,
86 InvalidPaymentId,
88 InvalidPaymentHash,
90 InvalidPaymentPreimage,
92 InvalidPaymentSecret,
94 InvalidAmount,
96 InvalidInvoice,
98 InvalidOffer,
100 InvalidRefund,
102 InvalidChannelId,
104 InvalidNetwork,
106 InvalidUri,
108 InvalidQuantity,
110 InvalidNodeAlias,
112 InvalidDateTime,
114 InvalidFeeRate,
116 DuplicatePayment,
118 UnsupportedCurrency,
120 InsufficientFunds,
122 LiquiditySourceUnavailable,
124 LiquidityFeeTooHigh,
126 InvalidBlindedPaths,
128 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}