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.
54 use lightning::util::errors::APIError as nativeAPIError;
57 pub(crate) fn to_native(&self) -> nativeAPIError {
59 APIError::APIMisuseError {ref err, } => {
60 let mut err_nonref = (*err).clone();
61 nativeAPIError::APIMisuseError {
62 err: err_nonref.into_string(),
65 APIError::FeeRateTooHigh {ref err, ref feerate, } => {
66 let mut err_nonref = (*err).clone();
67 let mut feerate_nonref = (*feerate).clone();
68 nativeAPIError::FeeRateTooHigh {
69 err: err_nonref.into_string(),
70 feerate: feerate_nonref,
73 APIError::RouteError {ref err, } => {
74 let mut err_nonref = (*err).clone();
75 nativeAPIError::RouteError {
76 err: err_nonref.into_str(),
79 APIError::ChannelUnavailable {ref err, } => {
80 let mut err_nonref = (*err).clone();
81 nativeAPIError::ChannelUnavailable {
82 err: err_nonref.into_string(),
85 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
89 pub(crate) fn into_native(self) -> nativeAPIError {
91 APIError::APIMisuseError {mut err, } => {
92 nativeAPIError::APIMisuseError {
93 err: err.into_string(),
96 APIError::FeeRateTooHigh {mut err, mut feerate, } => {
97 nativeAPIError::FeeRateTooHigh {
98 err: err.into_string(),
102 APIError::RouteError {mut err, } => {
103 nativeAPIError::RouteError {
107 APIError::ChannelUnavailable {mut err, } => {
108 nativeAPIError::ChannelUnavailable {
109 err: err.into_string(),
112 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
116 pub(crate) fn from_native(native: &nativeAPIError) -> Self {
118 nativeAPIError::APIMisuseError {ref err, } => {
119 let mut err_nonref = (*err).clone();
120 APIError::APIMisuseError {
121 err: err_nonref.into(),
124 nativeAPIError::FeeRateTooHigh {ref err, ref feerate, } => {
125 let mut err_nonref = (*err).clone();
126 let mut feerate_nonref = (*feerate).clone();
127 APIError::FeeRateTooHigh {
128 err: err_nonref.into(),
129 feerate: feerate_nonref,
132 nativeAPIError::RouteError {ref err, } => {
133 let mut err_nonref = (*err).clone();
134 APIError::RouteError {
135 err: err_nonref.into(),
138 nativeAPIError::ChannelUnavailable {ref err, } => {
139 let mut err_nonref = (*err).clone();
140 APIError::ChannelUnavailable {
141 err: err_nonref.into(),
144 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
148 pub(crate) fn native_into(native: nativeAPIError) -> Self {
150 nativeAPIError::APIMisuseError {mut err, } => {
151 APIError::APIMisuseError {
155 nativeAPIError::FeeRateTooHigh {mut err, mut feerate, } => {
156 APIError::FeeRateTooHigh {
161 nativeAPIError::RouteError {mut err, } => {
162 APIError::RouteError {
166 nativeAPIError::ChannelUnavailable {mut err, } => {
167 APIError::ChannelUnavailable {
171 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
175 /// Frees any resources used by the APIError
177 pub extern "C" fn APIError_free(this_ptr: APIError) { }
178 /// Creates a copy of the APIError
180 pub extern "C" fn APIError_clone(orig: &APIError) -> APIError {