1use bdk_chain::bitcoin::psbt::ExtractTxError as BdkExtractTxError;
9use bdk_chain::local_chain::CannotConnectError as BdkChainConnectionError;
10use bdk_chain::tx_graph::CalculateFeeError as BdkChainCalculateFeeError;
11use bdk_wallet::error::CreateTxError as BdkCreateTxError;
12use bdk_wallet::signer::SignerError as BdkSignerError;
13
14use std::fmt;
15
16#[derive(Copy, Clone, Debug, PartialEq, Eq)]
17pub enum Error {
19 AlreadyRunning,
21 NotRunning,
23 OnchainTxCreationFailed,
25 ConnectionFailed,
27 InvoiceCreationFailed,
29 InvoiceRequestCreationFailed,
31 OfferCreationFailed,
33 RefundCreationFailed,
35 PaymentSendingFailed,
37 InvalidCustomTlvs,
39 ProbeSendingFailed,
41 ChannelCreationFailed,
43 ChannelClosingFailed,
45 ChannelConfigUpdateFailed,
47 PersistenceFailed,
49 FeerateEstimationUpdateFailed,
51 FeerateEstimationUpdateTimeout,
53 WalletOperationFailed,
55 WalletOperationTimeout,
57 OnchainTxSigningFailed,
59 TxSyncFailed,
61 TxSyncTimeout,
63 GossipUpdateFailed,
65 GossipUpdateTimeout,
67 LiquidityRequestFailed,
69 UriParameterParsingFailed,
71 InvalidAddress,
73 InvalidSocketAddress,
75 InvalidPublicKey,
77 InvalidSecretKey,
79 InvalidOfferId,
81 InvalidNodeId,
83 InvalidPaymentId,
85 InvalidPaymentHash,
87 InvalidPaymentPreimage,
89 InvalidPaymentSecret,
91 InvalidAmount,
93 InvalidInvoice,
95 InvalidOffer,
97 InvalidRefund,
99 InvalidChannelId,
101 InvalidNetwork,
103 InvalidUri,
105 InvalidQuantity,
107 InvalidNodeAlias,
109 InvalidDateTime,
111 InvalidFeeRate,
113 DuplicatePayment,
115 UnsupportedCurrency,
117 InsufficientFunds,
119 LiquiditySourceUnavailable,
121 LiquidityFeeTooHigh,
123}
124
125impl fmt::Display for Error {
126 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
127 match *self {
128 Self::AlreadyRunning => write!(f, "Node is already running."),
129 Self::NotRunning => write!(f, "Node is not running."),
130 Self::OnchainTxCreationFailed => {
131 write!(f, "On-chain transaction could not be created.")
132 },
133 Self::ConnectionFailed => write!(f, "Network connection closed."),
134 Self::InvoiceCreationFailed => write!(f, "Failed to create invoice."),
135 Self::InvoiceRequestCreationFailed => write!(f, "Failed to create invoice request."),
136 Self::OfferCreationFailed => write!(f, "Failed to create offer."),
137 Self::RefundCreationFailed => write!(f, "Failed to create refund."),
138 Self::PaymentSendingFailed => write!(f, "Failed to send the given payment."),
139 Self::InvalidCustomTlvs => write!(f, "Failed to construct payment with custom TLVs."),
140 Self::ProbeSendingFailed => write!(f, "Failed to send the given payment probe."),
141 Self::ChannelCreationFailed => write!(f, "Failed to create channel."),
142 Self::ChannelClosingFailed => write!(f, "Failed to close channel."),
143 Self::ChannelConfigUpdateFailed => write!(f, "Failed to update channel config."),
144 Self::PersistenceFailed => write!(f, "Failed to persist data."),
145 Self::FeerateEstimationUpdateFailed => {
146 write!(f, "Failed to update fee rate estimates.")
147 },
148 Self::FeerateEstimationUpdateTimeout => {
149 write!(f, "Updating fee rate estimates timed out.")
150 },
151 Self::WalletOperationFailed => write!(f, "Failed to conduct wallet operation."),
152 Self::WalletOperationTimeout => write!(f, "A wallet operation timed out."),
153 Self::OnchainTxSigningFailed => write!(f, "Failed to sign given transaction."),
154 Self::TxSyncFailed => write!(f, "Failed to sync transactions."),
155 Self::TxSyncTimeout => write!(f, "Syncing transactions timed out."),
156 Self::GossipUpdateFailed => write!(f, "Failed to update gossip data."),
157 Self::GossipUpdateTimeout => write!(f, "Updating gossip data timed out."),
158 Self::LiquidityRequestFailed => write!(f, "Failed to request inbound liquidity."),
159 Self::UriParameterParsingFailed => write!(f, "Failed to parse a URI parameter."),
160 Self::InvalidAddress => write!(f, "The given address is invalid."),
161 Self::InvalidSocketAddress => write!(f, "The given network address is invalid."),
162 Self::InvalidPublicKey => write!(f, "The given public key is invalid."),
163 Self::InvalidSecretKey => write!(f, "The given secret key is invalid."),
164 Self::InvalidOfferId => write!(f, "The given offer id is invalid."),
165 Self::InvalidNodeId => write!(f, "The given node id is invalid."),
166 Self::InvalidPaymentId => write!(f, "The given payment id is invalid."),
167 Self::InvalidPaymentHash => write!(f, "The given payment hash is invalid."),
168 Self::InvalidPaymentPreimage => write!(f, "The given payment preimage is invalid."),
169 Self::InvalidPaymentSecret => write!(f, "The given payment secret is invalid."),
170 Self::InvalidAmount => write!(f, "The given amount is invalid."),
171 Self::InvalidInvoice => write!(f, "The given invoice is invalid."),
172 Self::InvalidOffer => write!(f, "The given offer is invalid."),
173 Self::InvalidRefund => write!(f, "The given refund is invalid."),
174 Self::InvalidChannelId => write!(f, "The given channel ID is invalid."),
175 Self::InvalidNetwork => write!(f, "The given network is invalid."),
176 Self::InvalidUri => write!(f, "The given URI is invalid."),
177 Self::InvalidQuantity => write!(f, "The given quantity is invalid."),
178 Self::InvalidNodeAlias => write!(f, "The given node alias is invalid."),
179 Self::InvalidDateTime => write!(f, "The given date time is invalid."),
180 Self::InvalidFeeRate => write!(f, "The given fee rate is invalid."),
181 Self::DuplicatePayment => {
182 write!(f, "A payment with the given hash has already been initiated.")
183 },
184 Self::InsufficientFunds => {
185 write!(f, "The available funds are insufficient to complete the given operation.")
186 },
187 Self::UnsupportedCurrency => {
188 write!(f, "The provided offer was denonminated in an unsupported currency.")
189 },
190 Self::LiquiditySourceUnavailable => {
191 write!(f, "The given operation failed due to the required liquidity source being unavailable.")
192 },
193 Self::LiquidityFeeTooHigh => {
194 write!(f, "The given operation failed due to the LSP's required opening fee being too high.")
195 },
196 }
197 }
198}
199
200impl std::error::Error for Error {}
201
202impl From<BdkSignerError> for Error {
203 fn from(_: BdkSignerError) -> Self {
204 Self::OnchainTxSigningFailed
205 }
206}
207
208impl From<BdkCreateTxError> for Error {
209 fn from(e: BdkCreateTxError) -> Self {
210 match e {
211 BdkCreateTxError::CoinSelection(_) => Self::InsufficientFunds,
212 _ => Self::OnchainTxCreationFailed,
213 }
214 }
215}
216
217impl From<BdkExtractTxError> for Error {
218 fn from(_: BdkExtractTxError) -> Self {
219 Self::OnchainTxCreationFailed
220 }
221}
222
223impl From<BdkChainConnectionError> for Error {
224 fn from(_: BdkChainConnectionError) -> Self {
225 Self::WalletOperationFailed
226 }
227}
228
229impl From<BdkChainCalculateFeeError> for Error {
230 fn from(_: BdkChainCalculateFeeError) -> Self {
231 Self::WalletOperationFailed
232 }
233}
234
235impl From<lightning_transaction_sync::TxSyncError> for Error {
236 fn from(_e: lightning_transaction_sync::TxSyncError) -> Self {
237 Self::TxSyncFailed
238 }
239}