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 APIErrorImport;
70 pub(crate) type nativeAPIError = APIErrorImport;
74 pub(crate) fn to_native(&self) -> nativeAPIError {
76 APIError::APIMisuseError {ref err, } => {
77 let mut err_nonref = (*err).clone();
78 nativeAPIError::APIMisuseError {
79 err: err_nonref.into_string(),
82 APIError::FeeRateTooHigh {ref err, ref feerate, } => {
83 let mut err_nonref = (*err).clone();
84 let mut feerate_nonref = (*feerate).clone();
85 nativeAPIError::FeeRateTooHigh {
86 err: err_nonref.into_string(),
87 feerate: feerate_nonref,
90 APIError::RouteError {ref err, } => {
91 let mut err_nonref = (*err).clone();
92 nativeAPIError::RouteError {
93 err: err_nonref.into_str(),
96 APIError::ChannelUnavailable {ref err, } => {
97 let mut err_nonref = (*err).clone();
98 nativeAPIError::ChannelUnavailable {
99 err: err_nonref.into_string(),
102 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
103 APIError::IncompatibleShutdownScript {ref script, } => {
104 let mut script_nonref = (*script).clone();
105 nativeAPIError::IncompatibleShutdownScript {
106 script: *unsafe { Box::from_raw(script_nonref.take_inner()) },
112 pub(crate) fn into_native(self) -> nativeAPIError {
114 APIError::APIMisuseError {mut err, } => {
115 nativeAPIError::APIMisuseError {
116 err: err.into_string(),
119 APIError::FeeRateTooHigh {mut err, mut feerate, } => {
120 nativeAPIError::FeeRateTooHigh {
121 err: err.into_string(),
125 APIError::RouteError {mut err, } => {
126 nativeAPIError::RouteError {
130 APIError::ChannelUnavailable {mut err, } => {
131 nativeAPIError::ChannelUnavailable {
132 err: err.into_string(),
135 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
136 APIError::IncompatibleShutdownScript {mut script, } => {
137 nativeAPIError::IncompatibleShutdownScript {
138 script: *unsafe { Box::from_raw(script.take_inner()) },
144 pub(crate) fn from_native(native: &nativeAPIError) -> Self {
146 nativeAPIError::APIMisuseError {ref err, } => {
147 let mut err_nonref = (*err).clone();
148 APIError::APIMisuseError {
149 err: err_nonref.into(),
152 nativeAPIError::FeeRateTooHigh {ref err, ref feerate, } => {
153 let mut err_nonref = (*err).clone();
154 let mut feerate_nonref = (*feerate).clone();
155 APIError::FeeRateTooHigh {
156 err: err_nonref.into(),
157 feerate: feerate_nonref,
160 nativeAPIError::RouteError {ref err, } => {
161 let mut err_nonref = (*err).clone();
162 APIError::RouteError {
163 err: err_nonref.into(),
166 nativeAPIError::ChannelUnavailable {ref err, } => {
167 let mut err_nonref = (*err).clone();
168 APIError::ChannelUnavailable {
169 err: err_nonref.into(),
172 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
173 nativeAPIError::IncompatibleShutdownScript {ref script, } => {
174 let mut script_nonref = (*script).clone();
175 APIError::IncompatibleShutdownScript {
176 script: crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(script_nonref), is_owned: true },
182 pub(crate) fn native_into(native: nativeAPIError) -> Self {
184 nativeAPIError::APIMisuseError {mut err, } => {
185 APIError::APIMisuseError {
189 nativeAPIError::FeeRateTooHigh {mut err, mut feerate, } => {
190 APIError::FeeRateTooHigh {
195 nativeAPIError::RouteError {mut err, } => {
196 APIError::RouteError {
200 nativeAPIError::ChannelUnavailable {mut err, } => {
201 APIError::ChannelUnavailable {
205 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
206 nativeAPIError::IncompatibleShutdownScript {mut script, } => {
207 APIError::IncompatibleShutdownScript {
208 script: crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(script), is_owned: true },
214 /// Frees any resources used by the APIError
216 pub extern "C" fn APIError_free(this_ptr: APIError) { }
217 /// Creates a copy of the APIError
219 pub extern "C" fn APIError_clone(orig: &APIError) -> APIError {
223 /// Utility method to constructs a new APIMisuseError-variant APIError
224 pub extern "C" fn APIError_apimisuse_error(err: crate::c_types::Str) -> APIError {
225 APIError::APIMisuseError {
230 /// Utility method to constructs a new FeeRateTooHigh-variant APIError
231 pub extern "C" fn APIError_fee_rate_too_high(err: crate::c_types::Str, feerate: u32) -> APIError {
232 APIError::FeeRateTooHigh {
238 /// Utility method to constructs a new RouteError-variant APIError
239 pub extern "C" fn APIError_route_error(err: crate::c_types::Str) -> APIError {
240 APIError::RouteError {
245 /// Utility method to constructs a new ChannelUnavailable-variant APIError
246 pub extern "C" fn APIError_channel_unavailable(err: crate::c_types::Str) -> APIError {
247 APIError::ChannelUnavailable {
252 /// Utility method to constructs a new MonitorUpdateFailed-variant APIError
253 pub extern "C" fn APIError_monitor_update_failed() -> APIError {
254 APIError::MonitorUpdateFailed}
256 /// Utility method to constructs a new IncompatibleShutdownScript-variant APIError
257 pub extern "C" fn APIError_incompatible_shutdown_script(script: crate::lightning::ln::script::ShutdownScript) -> APIError {
258 APIError::IncompatibleShutdownScript {