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.
12 use bitcoin::hashes::Hash;
13 use crate::c_types::*;
15 /// Indicates an error on the client's part (usually some variant of attempting to use too-low or
21 /// Indicates the API was wholly misused (see err for more). Cases where these can be returned
22 /// are documented, but generally indicates some precondition of a function was violated.
24 /// A human-readable error message
25 err: crate::c_types::derived::CVec_u8Z,
27 /// Due to a high feerate, we were unable to complete the request.
28 /// For example, this may be returned if the feerate implies we cannot open a channel at the
29 /// requested value, but opening a larger channel would succeed.
31 /// A human-readable error message
32 err: crate::c_types::derived::CVec_u8Z,
33 /// The feerate which was too high.
36 /// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
37 /// too-many-hops, etc).
39 /// A human-readable error message
40 err: crate::c_types::Str,
42 /// We were unable to complete the request as the Channel required to do so is unable to
43 /// complete the request (or was not found). This can take many forms, including disconnected
44 /// peer, channel at capacity, channel shutting down, etc.
46 /// A human-readable error message
47 err: crate::c_types::derived::CVec_u8Z,
49 /// An attempt to call watch/update_channel returned an Err (ie you did this!), causing the
50 /// attempted action to fail.
53 use lightning::util::errors::APIError as nativeAPIError;
56 pub(crate) fn to_native(&self) -> nativeAPIError {
58 APIError::APIMisuseError {ref err, } => {
59 let mut err_nonref = (*err).clone();
60 nativeAPIError::APIMisuseError {
61 err: String::from_utf8(err_nonref.into_rust()).unwrap(),
64 APIError::FeeRateTooHigh {ref err, ref feerate, } => {
65 let mut err_nonref = (*err).clone();
66 let mut feerate_nonref = (*feerate).clone();
67 nativeAPIError::FeeRateTooHigh {
68 err: String::from_utf8(err_nonref.into_rust()).unwrap(),
69 feerate: feerate_nonref,
72 APIError::RouteError {ref err, } => {
73 let mut err_nonref = (*err).clone();
74 nativeAPIError::RouteError {
75 err: err_nonref.into(),
78 APIError::ChannelUnavailable {ref err, } => {
79 let mut err_nonref = (*err).clone();
80 nativeAPIError::ChannelUnavailable {
81 err: String::from_utf8(err_nonref.into_rust()).unwrap(),
84 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
88 pub(crate) fn into_native(self) -> nativeAPIError {
90 APIError::APIMisuseError {mut err, } => {
91 nativeAPIError::APIMisuseError {
92 err: String::from_utf8(err.into_rust()).unwrap(),
95 APIError::FeeRateTooHigh {mut err, mut feerate, } => {
96 nativeAPIError::FeeRateTooHigh {
97 err: String::from_utf8(err.into_rust()).unwrap(),
101 APIError::RouteError {mut err, } => {
102 nativeAPIError::RouteError {
106 APIError::ChannelUnavailable {mut err, } => {
107 nativeAPIError::ChannelUnavailable {
108 err: String::from_utf8(err.into_rust()).unwrap(),
111 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
115 pub(crate) fn from_native(native: &nativeAPIError) -> Self {
117 nativeAPIError::APIMisuseError {ref err, } => {
118 let mut err_nonref = (*err).clone();
119 APIError::APIMisuseError {
120 err: err_nonref.into_bytes().into(),
123 nativeAPIError::FeeRateTooHigh {ref err, ref feerate, } => {
124 let mut err_nonref = (*err).clone();
125 let mut feerate_nonref = (*feerate).clone();
126 APIError::FeeRateTooHigh {
127 err: err_nonref.into_bytes().into(),
128 feerate: feerate_nonref,
131 nativeAPIError::RouteError {ref err, } => {
132 let mut err_nonref = (*err).clone();
133 APIError::RouteError {
134 err: err_nonref.into(),
137 nativeAPIError::ChannelUnavailable {ref err, } => {
138 let mut err_nonref = (*err).clone();
139 APIError::ChannelUnavailable {
140 err: err_nonref.into_bytes().into(),
143 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
147 pub(crate) fn native_into(native: nativeAPIError) -> Self {
149 nativeAPIError::APIMisuseError {mut err, } => {
150 APIError::APIMisuseError {
151 err: err.into_bytes().into(),
154 nativeAPIError::FeeRateTooHigh {mut err, mut feerate, } => {
155 APIError::FeeRateTooHigh {
156 err: err.into_bytes().into(),
160 nativeAPIError::RouteError {mut err, } => {
161 APIError::RouteError {
165 nativeAPIError::ChannelUnavailable {mut err, } => {
166 APIError::ChannelUnavailable {
167 err: err.into_bytes().into(),
170 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
174 /// Frees any resources used by the APIError
176 pub extern "C" fn APIError_free(this_ptr: APIError) { }
177 /// Creates a copy of the APIError
179 pub extern "C" fn APIError_clone(orig: &APIError) -> APIError {