1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! Error types live here.
11 use alloc::str::FromStr;
12 use core::ffi::c_void;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
16 #[cfg(feature="no-std")]
17 use alloc::{vec::Vec, boxed::Box};
19 /// Indicates an error on the client's part (usually some variant of attempting to use too-low or
25 /// Indicates the API was wholly misused (see err for more). Cases where these can be returned
26 /// are documented, but generally indicates some precondition of a function was violated.
28 /// A human-readable error message
29 err: crate::c_types::Str,
31 /// Due to a high feerate, we were unable to complete the request.
32 /// For example, this may be returned if the feerate implies we cannot open a channel at the
33 /// requested value, but opening a larger channel would succeed.
35 /// A human-readable error message
36 err: crate::c_types::Str,
37 /// The feerate which was too high.
40 /// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
41 /// too-many-hops, etc).
43 /// A human-readable error message
44 err: crate::c_types::Str,
46 /// We were unable to complete the request as the Channel required to do so is unable to
47 /// complete the request (or was not found). This can take many forms, including disconnected
48 /// peer, channel at capacity, channel shutting down, etc.
50 /// A human-readable error message
51 err: crate::c_types::Str,
53 /// An attempt to call watch/update_channel returned an Err (ie you did this!), causing the
54 /// attempted action to fail.
56 /// [`KeysInterface::get_shutdown_scriptpubkey`] returned a shutdown scriptpubkey incompatible
57 /// with the channel counterparty as negotiated in [`InitFeatures`].
59 /// Using a SegWit v0 script should resolve this issue. If you cannot, you won't be able to open
60 /// a channel or cooperatively close one with this peer (and will have to force-close instead).
62 /// [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey
63 /// [`InitFeatures`]: crate::ln::features::InitFeatures
64 IncompatibleShutdownScript {
65 /// The incompatible shutdown script.
66 script: crate::lightning::ln::script::ShutdownScript,
69 use lightning::util::errors::APIError as nativeAPIError;
72 pub(crate) fn to_native(&self) -> nativeAPIError {
74 APIError::APIMisuseError {ref err, } => {
75 let mut err_nonref = (*err).clone();
76 nativeAPIError::APIMisuseError {
77 err: err_nonref.into_string(),
80 APIError::FeeRateTooHigh {ref err, ref feerate, } => {
81 let mut err_nonref = (*err).clone();
82 let mut feerate_nonref = (*feerate).clone();
83 nativeAPIError::FeeRateTooHigh {
84 err: err_nonref.into_string(),
85 feerate: feerate_nonref,
88 APIError::RouteError {ref err, } => {
89 let mut err_nonref = (*err).clone();
90 nativeAPIError::RouteError {
91 err: err_nonref.into_str(),
94 APIError::ChannelUnavailable {ref err, } => {
95 let mut err_nonref = (*err).clone();
96 nativeAPIError::ChannelUnavailable {
97 err: err_nonref.into_string(),
100 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
101 APIError::IncompatibleShutdownScript {ref script, } => {
102 let mut script_nonref = (*script).clone();
103 nativeAPIError::IncompatibleShutdownScript {
104 script: *unsafe { Box::from_raw(script_nonref.take_inner()) },
110 pub(crate) fn into_native(self) -> nativeAPIError {
112 APIError::APIMisuseError {mut err, } => {
113 nativeAPIError::APIMisuseError {
114 err: err.into_string(),
117 APIError::FeeRateTooHigh {mut err, mut feerate, } => {
118 nativeAPIError::FeeRateTooHigh {
119 err: err.into_string(),
123 APIError::RouteError {mut err, } => {
124 nativeAPIError::RouteError {
128 APIError::ChannelUnavailable {mut err, } => {
129 nativeAPIError::ChannelUnavailable {
130 err: err.into_string(),
133 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
134 APIError::IncompatibleShutdownScript {mut script, } => {
135 nativeAPIError::IncompatibleShutdownScript {
136 script: *unsafe { Box::from_raw(script.take_inner()) },
142 pub(crate) fn from_native(native: &nativeAPIError) -> Self {
144 nativeAPIError::APIMisuseError {ref err, } => {
145 let mut err_nonref = (*err).clone();
146 APIError::APIMisuseError {
147 err: err_nonref.into(),
150 nativeAPIError::FeeRateTooHigh {ref err, ref feerate, } => {
151 let mut err_nonref = (*err).clone();
152 let mut feerate_nonref = (*feerate).clone();
153 APIError::FeeRateTooHigh {
154 err: err_nonref.into(),
155 feerate: feerate_nonref,
158 nativeAPIError::RouteError {ref err, } => {
159 let mut err_nonref = (*err).clone();
160 APIError::RouteError {
161 err: err_nonref.into(),
164 nativeAPIError::ChannelUnavailable {ref err, } => {
165 let mut err_nonref = (*err).clone();
166 APIError::ChannelUnavailable {
167 err: err_nonref.into(),
170 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
171 nativeAPIError::IncompatibleShutdownScript {ref script, } => {
172 let mut script_nonref = (*script).clone();
173 APIError::IncompatibleShutdownScript {
174 script: crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(script_nonref), is_owned: true },
180 pub(crate) fn native_into(native: nativeAPIError) -> Self {
182 nativeAPIError::APIMisuseError {mut err, } => {
183 APIError::APIMisuseError {
187 nativeAPIError::FeeRateTooHigh {mut err, mut feerate, } => {
188 APIError::FeeRateTooHigh {
193 nativeAPIError::RouteError {mut err, } => {
194 APIError::RouteError {
198 nativeAPIError::ChannelUnavailable {mut err, } => {
199 APIError::ChannelUnavailable {
203 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
204 nativeAPIError::IncompatibleShutdownScript {mut script, } => {
205 APIError::IncompatibleShutdownScript {
206 script: crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(script), is_owned: true },
212 /// Frees any resources used by the APIError
214 pub extern "C" fn APIError_free(this_ptr: APIError) { }
215 /// Creates a copy of the APIError
217 pub extern "C" fn APIError_clone(orig: &APIError) -> APIError {
221 /// Utility method to constructs a new APIMisuseError-variant APIError
222 pub extern "C" fn APIError_apimisuse_error(err: crate::c_types::Str) -> APIError {
223 APIError::APIMisuseError {
228 /// Utility method to constructs a new FeeRateTooHigh-variant APIError
229 pub extern "C" fn APIError_fee_rate_too_high(err: crate::c_types::Str, feerate: u32) -> APIError {
230 APIError::FeeRateTooHigh {
236 /// Utility method to constructs a new RouteError-variant APIError
237 pub extern "C" fn APIError_route_error(err: crate::c_types::Str) -> APIError {
238 APIError::RouteError {
243 /// Utility method to constructs a new ChannelUnavailable-variant APIError
244 pub extern "C" fn APIError_channel_unavailable(err: crate::c_types::Str) -> APIError {
245 APIError::ChannelUnavailable {
250 /// Utility method to constructs a new MonitorUpdateFailed-variant APIError
251 pub extern "C" fn APIError_monitor_update_failed() -> APIError {
252 APIError::MonitorUpdateFailed}
254 /// Utility method to constructs a new IncompatibleShutdownScript-variant APIError
255 pub extern "C" fn APIError_incompatible_shutdown_script(script: crate::lightning::ln::script::ShutdownScript) -> APIError {
256 APIError::IncompatibleShutdownScript {