1 //! Error types live here.
4 use bitcoin::hashes::Hash;
7 /// Indicates an error on the client's part (usually some variant of attempting to use too-low or
13 /// Indicates the API was wholly misused (see err for more). Cases where these can be returned
14 /// are documented, but generally indicates some precondition of a function was violated.
16 /// A human-readable error message
17 err: crate::c_types::derived::CVec_u8Z,
19 /// Due to a high feerate, we were unable to complete the request.
20 /// For example, this may be returned if the feerate implies we cannot open a channel at the
21 /// requested value, but opening a larger channel would succeed.
23 /// A human-readable error message
24 err: crate::c_types::derived::CVec_u8Z,
25 /// The feerate which was too high.
28 /// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
29 /// too-many-hops, etc).
31 /// A human-readable error message
32 err: crate::c_types::Str,
34 /// We were unable to complete the request as the Channel required to do so is unable to
35 /// complete the request (or was not found). This can take many forms, including disconnected
36 /// peer, channel at capacity, channel shutting down, etc.
38 /// A human-readable error message
39 err: crate::c_types::derived::CVec_u8Z,
41 /// An attempt to call watch/update_channel returned an Err (ie you did this!), causing the
42 /// attempted action to fail.
45 use lightning::util::errors::APIError as nativeAPIError;
48 pub(crate) fn to_native(&self) -> nativeAPIError {
50 APIError::APIMisuseError {ref err, } => {
51 let mut err_nonref = (*err).clone();
52 nativeAPIError::APIMisuseError {
53 err: String::from_utf8(err_nonref.into_rust()).unwrap(),
56 APIError::FeeRateTooHigh {ref err, ref feerate, } => {
57 let mut err_nonref = (*err).clone();
58 let mut feerate_nonref = (*feerate).clone();
59 nativeAPIError::FeeRateTooHigh {
60 err: String::from_utf8(err_nonref.into_rust()).unwrap(),
61 feerate: feerate_nonref,
64 APIError::RouteError {ref err, } => {
65 let mut err_nonref = (*err).clone();
66 nativeAPIError::RouteError {
67 err: err_nonref.into(),
70 APIError::ChannelUnavailable {ref err, } => {
71 let mut err_nonref = (*err).clone();
72 nativeAPIError::ChannelUnavailable {
73 err: String::from_utf8(err_nonref.into_rust()).unwrap(),
76 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
80 pub(crate) fn into_native(self) -> nativeAPIError {
82 APIError::APIMisuseError {mut err, } => {
83 nativeAPIError::APIMisuseError {
84 err: String::from_utf8(err.into_rust()).unwrap(),
87 APIError::FeeRateTooHigh {mut err, mut feerate, } => {
88 nativeAPIError::FeeRateTooHigh {
89 err: String::from_utf8(err.into_rust()).unwrap(),
93 APIError::RouteError {mut err, } => {
94 nativeAPIError::RouteError {
98 APIError::ChannelUnavailable {mut err, } => {
99 nativeAPIError::ChannelUnavailable {
100 err: String::from_utf8(err.into_rust()).unwrap(),
103 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
107 pub(crate) fn from_native(native: &nativeAPIError) -> Self {
109 nativeAPIError::APIMisuseError {ref err, } => {
110 let mut err_nonref = (*err).clone();
111 APIError::APIMisuseError {
112 err: err_nonref.into_bytes().into(),
115 nativeAPIError::FeeRateTooHigh {ref err, ref feerate, } => {
116 let mut err_nonref = (*err).clone();
117 let mut feerate_nonref = (*feerate).clone();
118 APIError::FeeRateTooHigh {
119 err: err_nonref.into_bytes().into(),
120 feerate: feerate_nonref,
123 nativeAPIError::RouteError {ref err, } => {
124 let mut err_nonref = (*err).clone();
125 APIError::RouteError {
126 err: err_nonref.into(),
129 nativeAPIError::ChannelUnavailable {ref err, } => {
130 let mut err_nonref = (*err).clone();
131 APIError::ChannelUnavailable {
132 err: err_nonref.into_bytes().into(),
135 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
139 pub(crate) fn native_into(native: nativeAPIError) -> Self {
141 nativeAPIError::APIMisuseError {mut err, } => {
142 APIError::APIMisuseError {
143 err: err.into_bytes().into(),
146 nativeAPIError::FeeRateTooHigh {mut err, mut feerate, } => {
147 APIError::FeeRateTooHigh {
148 err: err.into_bytes().into(),
152 nativeAPIError::RouteError {mut err, } => {
153 APIError::RouteError {
157 nativeAPIError::ChannelUnavailable {mut err, } => {
158 APIError::ChannelUnavailable {
159 err: err.into_bytes().into(),
162 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
166 /// Frees any resources used by the APIError
168 pub extern "C" fn APIError_free(this_ptr: APIError) { }
169 /// Creates a copy of the APIError
171 pub extern "C" fn APIError_clone(orig: &APIError) -> APIError {