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 std::str::FromStr;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
17 /// Indicates an error on the client's part (usually some variant of attempting to use too-low or
23 /// Indicates the API was wholly misused (see err for more). Cases where these can be returned
24 /// are documented, but generally indicates some precondition of a function was violated.
26 /// A human-readable error message
27 err: crate::c_types::Str,
29 /// Due to a high feerate, we were unable to complete the request.
30 /// For example, this may be returned if the feerate implies we cannot open a channel at the
31 /// requested value, but opening a larger channel would succeed.
33 /// A human-readable error message
34 err: crate::c_types::Str,
35 /// The feerate which was too high.
38 /// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
39 /// too-many-hops, etc).
41 /// A human-readable error message
42 err: crate::c_types::Str,
44 /// We were unable to complete the request as the Channel required to do so is unable to
45 /// complete the request (or was not found). This can take many forms, including disconnected
46 /// peer, channel at capacity, channel shutting down, etc.
48 /// A human-readable error message
49 err: crate::c_types::Str,
51 /// An attempt to call watch/update_channel returned an Err (ie you did this!), causing the
52 /// attempted action to fail.
54 /// [`KeysInterface::get_shutdown_scriptpubkey`] returned a shutdown scriptpubkey incompatible
55 /// with the channel counterparty as negotiated in [`InitFeatures`].
57 /// Using a SegWit v0 script should resolve this issue. If you cannot, you won't be able to open
58 /// a channel or cooperatively close one with this peer (and will have to force-close instead).
60 /// [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey
61 /// [`InitFeatures`]: crate::ln::features::InitFeatures
62 IncompatibleShutdownScript {
63 /// The incompatible shutdown script.
64 script: crate::lightning::ln::script::ShutdownScript,
67 use lightning::util::errors::APIError as nativeAPIError;
70 pub(crate) fn to_native(&self) -> nativeAPIError {
72 APIError::APIMisuseError {ref err, } => {
73 let mut err_nonref = (*err).clone();
74 nativeAPIError::APIMisuseError {
75 err: err_nonref.into_string(),
78 APIError::FeeRateTooHigh {ref err, ref feerate, } => {
79 let mut err_nonref = (*err).clone();
80 let mut feerate_nonref = (*feerate).clone();
81 nativeAPIError::FeeRateTooHigh {
82 err: err_nonref.into_string(),
83 feerate: feerate_nonref,
86 APIError::RouteError {ref err, } => {
87 let mut err_nonref = (*err).clone();
88 nativeAPIError::RouteError {
89 err: err_nonref.into_str(),
92 APIError::ChannelUnavailable {ref err, } => {
93 let mut err_nonref = (*err).clone();
94 nativeAPIError::ChannelUnavailable {
95 err: err_nonref.into_string(),
98 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
99 APIError::IncompatibleShutdownScript {ref script, } => {
100 let mut script_nonref = (*script).clone();
101 nativeAPIError::IncompatibleShutdownScript {
102 script: *unsafe { Box::from_raw(script_nonref.take_inner()) },
108 pub(crate) fn into_native(self) -> nativeAPIError {
110 APIError::APIMisuseError {mut err, } => {
111 nativeAPIError::APIMisuseError {
112 err: err.into_string(),
115 APIError::FeeRateTooHigh {mut err, mut feerate, } => {
116 nativeAPIError::FeeRateTooHigh {
117 err: err.into_string(),
121 APIError::RouteError {mut err, } => {
122 nativeAPIError::RouteError {
126 APIError::ChannelUnavailable {mut err, } => {
127 nativeAPIError::ChannelUnavailable {
128 err: err.into_string(),
131 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
132 APIError::IncompatibleShutdownScript {mut script, } => {
133 nativeAPIError::IncompatibleShutdownScript {
134 script: *unsafe { Box::from_raw(script.take_inner()) },
140 pub(crate) fn from_native(native: &nativeAPIError) -> Self {
142 nativeAPIError::APIMisuseError {ref err, } => {
143 let mut err_nonref = (*err).clone();
144 APIError::APIMisuseError {
145 err: err_nonref.into(),
148 nativeAPIError::FeeRateTooHigh {ref err, ref feerate, } => {
149 let mut err_nonref = (*err).clone();
150 let mut feerate_nonref = (*feerate).clone();
151 APIError::FeeRateTooHigh {
152 err: err_nonref.into(),
153 feerate: feerate_nonref,
156 nativeAPIError::RouteError {ref err, } => {
157 let mut err_nonref = (*err).clone();
158 APIError::RouteError {
159 err: err_nonref.into(),
162 nativeAPIError::ChannelUnavailable {ref err, } => {
163 let mut err_nonref = (*err).clone();
164 APIError::ChannelUnavailable {
165 err: err_nonref.into(),
168 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
169 nativeAPIError::IncompatibleShutdownScript {ref script, } => {
170 let mut script_nonref = (*script).clone();
171 APIError::IncompatibleShutdownScript {
172 script: crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(script_nonref), is_owned: true },
178 pub(crate) fn native_into(native: nativeAPIError) -> Self {
180 nativeAPIError::APIMisuseError {mut err, } => {
181 APIError::APIMisuseError {
185 nativeAPIError::FeeRateTooHigh {mut err, mut feerate, } => {
186 APIError::FeeRateTooHigh {
191 nativeAPIError::RouteError {mut err, } => {
192 APIError::RouteError {
196 nativeAPIError::ChannelUnavailable {mut err, } => {
197 APIError::ChannelUnavailable {
201 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
202 nativeAPIError::IncompatibleShutdownScript {mut script, } => {
203 APIError::IncompatibleShutdownScript {
204 script: crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(script), is_owned: true },
210 /// Frees any resources used by the APIError
212 pub extern "C" fn APIError_free(this_ptr: APIError) { }
213 /// Creates a copy of the APIError
215 pub extern "C" fn APIError_clone(orig: &APIError) -> APIError {
219 /// Utility method to constructs a new APIMisuseError-variant APIError
220 pub extern "C" fn APIError_apimisuse_error(err: crate::c_types::Str) -> APIError {
221 APIError::APIMisuseError {
226 /// Utility method to constructs a new FeeRateTooHigh-variant APIError
227 pub extern "C" fn APIError_fee_rate_too_high(err: crate::c_types::Str, feerate: u32) -> APIError {
228 APIError::FeeRateTooHigh {
234 /// Utility method to constructs a new RouteError-variant APIError
235 pub extern "C" fn APIError_route_error(err: crate::c_types::Str) -> APIError {
236 APIError::RouteError {
241 /// Utility method to constructs a new ChannelUnavailable-variant APIError
242 pub extern "C" fn APIError_channel_unavailable(err: crate::c_types::Str) -> APIError {
243 APIError::ChannelUnavailable {
248 /// Utility method to constructs a new MonitorUpdateFailed-variant APIError
249 pub extern "C" fn APIError_monitor_update_failed() -> APIError {
250 APIError::MonitorUpdateFailed}
252 /// Utility method to constructs a new IncompatibleShutdownScript-variant APIError
253 pub extern "C" fn APIError_incompatible_shutdown_script(script: crate::lightning::ln::script::ShutdownScript) -> APIError {
254 APIError::IncompatibleShutdownScript {