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 bitcoin::hashes::Hash;
14 use crate::c_types::*;
16 /// Indicates an error on the client's part (usually some variant of attempting to use too-low or
22 /// Indicates the API was wholly misused (see err for more). Cases where these can be returned
23 /// are documented, but generally indicates some precondition of a function was violated.
25 /// A human-readable error message
26 err: crate::c_types::Str,
28 /// Due to a high feerate, we were unable to complete the request.
29 /// For example, this may be returned if the feerate implies we cannot open a channel at the
30 /// requested value, but opening a larger channel would succeed.
32 /// A human-readable error message
33 err: crate::c_types::Str,
34 /// The feerate which was too high.
37 /// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
38 /// too-many-hops, etc).
40 /// A human-readable error message
41 err: crate::c_types::Str,
43 /// We were unable to complete the request as the Channel required to do so is unable to
44 /// complete the request (or was not found). This can take many forms, including disconnected
45 /// peer, channel at capacity, channel shutting down, etc.
47 /// A human-readable error message
48 err: crate::c_types::Str,
50 /// An attempt to call watch/update_channel returned an Err (ie you did this!), causing the
51 /// attempted action to fail.
53 /// [`KeysInterface::get_shutdown_scriptpubkey`] returned a shutdown scriptpubkey incompatible
54 /// with the channel counterparty as negotiated in [`InitFeatures`].
56 /// Using a SegWit v0 script should resolve this issue. If you cannot, you won't be able to open
57 /// a channel or cooperatively close one with this peer (and will have to force-close instead).
59 /// [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey
60 /// [`InitFeatures`]: crate::ln::features::InitFeatures
61 IncompatibleShutdownScript {
62 /// The incompatible shutdown script.
63 script: crate::lightning::ln::script::ShutdownScript,
66 use lightning::util::errors::APIError as nativeAPIError;
69 pub(crate) fn to_native(&self) -> nativeAPIError {
71 APIError::APIMisuseError {ref err, } => {
72 let mut err_nonref = (*err).clone();
73 nativeAPIError::APIMisuseError {
74 err: err_nonref.into_string(),
77 APIError::FeeRateTooHigh {ref err, ref feerate, } => {
78 let mut err_nonref = (*err).clone();
79 let mut feerate_nonref = (*feerate).clone();
80 nativeAPIError::FeeRateTooHigh {
81 err: err_nonref.into_string(),
82 feerate: feerate_nonref,
85 APIError::RouteError {ref err, } => {
86 let mut err_nonref = (*err).clone();
87 nativeAPIError::RouteError {
88 err: err_nonref.into_str(),
91 APIError::ChannelUnavailable {ref err, } => {
92 let mut err_nonref = (*err).clone();
93 nativeAPIError::ChannelUnavailable {
94 err: err_nonref.into_string(),
97 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
98 APIError::IncompatibleShutdownScript {ref script, } => {
99 let mut script_nonref = (*script).clone();
100 nativeAPIError::IncompatibleShutdownScript {
101 script: *unsafe { Box::from_raw(script_nonref.take_inner()) },
107 pub(crate) fn into_native(self) -> nativeAPIError {
109 APIError::APIMisuseError {mut err, } => {
110 nativeAPIError::APIMisuseError {
111 err: err.into_string(),
114 APIError::FeeRateTooHigh {mut err, mut feerate, } => {
115 nativeAPIError::FeeRateTooHigh {
116 err: err.into_string(),
120 APIError::RouteError {mut err, } => {
121 nativeAPIError::RouteError {
125 APIError::ChannelUnavailable {mut err, } => {
126 nativeAPIError::ChannelUnavailable {
127 err: err.into_string(),
130 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
131 APIError::IncompatibleShutdownScript {mut script, } => {
132 nativeAPIError::IncompatibleShutdownScript {
133 script: *unsafe { Box::from_raw(script.take_inner()) },
139 pub(crate) fn from_native(native: &nativeAPIError) -> Self {
141 nativeAPIError::APIMisuseError {ref err, } => {
142 let mut err_nonref = (*err).clone();
143 APIError::APIMisuseError {
144 err: err_nonref.into(),
147 nativeAPIError::FeeRateTooHigh {ref err, ref feerate, } => {
148 let mut err_nonref = (*err).clone();
149 let mut feerate_nonref = (*feerate).clone();
150 APIError::FeeRateTooHigh {
151 err: err_nonref.into(),
152 feerate: feerate_nonref,
155 nativeAPIError::RouteError {ref err, } => {
156 let mut err_nonref = (*err).clone();
157 APIError::RouteError {
158 err: err_nonref.into(),
161 nativeAPIError::ChannelUnavailable {ref err, } => {
162 let mut err_nonref = (*err).clone();
163 APIError::ChannelUnavailable {
164 err: err_nonref.into(),
167 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
168 nativeAPIError::IncompatibleShutdownScript {ref script, } => {
169 let mut script_nonref = (*script).clone();
170 APIError::IncompatibleShutdownScript {
171 script: crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(script_nonref), is_owned: true },
177 pub(crate) fn native_into(native: nativeAPIError) -> Self {
179 nativeAPIError::APIMisuseError {mut err, } => {
180 APIError::APIMisuseError {
184 nativeAPIError::FeeRateTooHigh {mut err, mut feerate, } => {
185 APIError::FeeRateTooHigh {
190 nativeAPIError::RouteError {mut err, } => {
191 APIError::RouteError {
195 nativeAPIError::ChannelUnavailable {mut err, } => {
196 APIError::ChannelUnavailable {
200 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
201 nativeAPIError::IncompatibleShutdownScript {mut script, } => {
202 APIError::IncompatibleShutdownScript {
203 script: crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(script), is_owned: true },
209 /// Frees any resources used by the APIError
211 pub extern "C" fn APIError_free(this_ptr: APIError) { }
212 /// Creates a copy of the APIError
214 pub extern "C" fn APIError_clone(orig: &APIError) -> APIError {
218 /// Utility method to constructs a new APIMisuseError-variant APIError
219 pub extern "C" fn APIError_apimisuse_error(err: crate::c_types::Str) -> APIError {
220 APIError::APIMisuseError {
225 /// Utility method to constructs a new FeeRateTooHigh-variant APIError
226 pub extern "C" fn APIError_fee_rate_too_high(err: crate::c_types::Str, feerate: u32) -> APIError {
227 APIError::FeeRateTooHigh {
233 /// Utility method to constructs a new RouteError-variant APIError
234 pub extern "C" fn APIError_route_error(err: crate::c_types::Str) -> APIError {
235 APIError::RouteError {
240 /// Utility method to constructs a new ChannelUnavailable-variant APIError
241 pub extern "C" fn APIError_channel_unavailable(err: crate::c_types::Str) -> APIError {
242 APIError::ChannelUnavailable {
247 /// Utility method to constructs a new MonitorUpdateFailed-variant APIError
248 pub extern "C" fn APIError_monitor_update_failed() -> APIError {
249 APIError::MonitorUpdateFailed}
251 /// Utility method to constructs a new IncompatibleShutdownScript-variant APIError
252 pub extern "C" fn APIError_incompatible_shutdown_script(script: crate::lightning::ln::script::ShutdownScript) -> APIError {
253 APIError::IncompatibleShutdownScript {