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 err: crate::c_types::derived::CVec_u8Z,
18 /// Due to a high feerate, we were unable to complete the request.
19 /// For example, this may be returned if the feerate implies we cannot open a channel at the
20 /// requested value, but opening a larger channel would succeed.
22 err: crate::c_types::derived::CVec_u8Z,
25 /// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route,
26 /// too-many-hops, etc).
28 err: crate::c_types::Str,
30 /// We were unable to complete the request as the Channel required to do so is unable to
31 /// complete the request (or was not found). This can take many forms, including disconnected
32 /// peer, channel at capacity, channel shutting down, etc.
34 err: crate::c_types::derived::CVec_u8Z,
36 /// An attempt to call watch/update_channel returned an Err (ie you did this!), causing the
37 /// attempted action to fail.
40 use lightning::util::errors::APIError as nativeAPIError;
43 pub(crate) fn to_native(&self) -> nativeAPIError {
45 APIError::APIMisuseError {ref err, } => {
46 let mut err_nonref = (*err).clone();
47 nativeAPIError::APIMisuseError {
48 err: String::from_utf8(err_nonref.into_rust()).unwrap(),
51 APIError::FeeRateTooHigh {ref err, ref feerate, } => {
52 let mut err_nonref = (*err).clone();
53 let mut feerate_nonref = (*feerate).clone();
54 nativeAPIError::FeeRateTooHigh {
55 err: String::from_utf8(err_nonref.into_rust()).unwrap(),
56 feerate: feerate_nonref,
59 APIError::RouteError {ref err, } => {
60 let mut err_nonref = (*err).clone();
61 nativeAPIError::RouteError {
62 err: err_nonref.into(),
65 APIError::ChannelUnavailable {ref err, } => {
66 let mut err_nonref = (*err).clone();
67 nativeAPIError::ChannelUnavailable {
68 err: String::from_utf8(err_nonref.into_rust()).unwrap(),
71 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
75 pub(crate) fn into_native(self) -> nativeAPIError {
77 APIError::APIMisuseError {mut err, } => {
78 nativeAPIError::APIMisuseError {
79 err: String::from_utf8(err.into_rust()).unwrap(),
82 APIError::FeeRateTooHigh {mut err, mut feerate, } => {
83 nativeAPIError::FeeRateTooHigh {
84 err: String::from_utf8(err.into_rust()).unwrap(),
88 APIError::RouteError {mut err, } => {
89 nativeAPIError::RouteError {
93 APIError::ChannelUnavailable {mut err, } => {
94 nativeAPIError::ChannelUnavailable {
95 err: String::from_utf8(err.into_rust()).unwrap(),
98 APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed,
102 pub(crate) fn from_native(native: &nativeAPIError) -> Self {
104 nativeAPIError::APIMisuseError {ref err, } => {
105 let mut err_nonref = (*err).clone();
106 APIError::APIMisuseError {
107 err: err_nonref.into_bytes().into(),
110 nativeAPIError::FeeRateTooHigh {ref err, ref feerate, } => {
111 let mut err_nonref = (*err).clone();
112 let mut feerate_nonref = (*feerate).clone();
113 APIError::FeeRateTooHigh {
114 err: err_nonref.into_bytes().into(),
115 feerate: feerate_nonref,
118 nativeAPIError::RouteError {ref err, } => {
119 let mut err_nonref = (*err).clone();
120 APIError::RouteError {
121 err: err_nonref.into(),
124 nativeAPIError::ChannelUnavailable {ref err, } => {
125 let mut err_nonref = (*err).clone();
126 APIError::ChannelUnavailable {
127 err: err_nonref.into_bytes().into(),
130 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
134 pub(crate) fn native_into(native: nativeAPIError) -> Self {
136 nativeAPIError::APIMisuseError {mut err, } => {
137 APIError::APIMisuseError {
138 err: err.into_bytes().into(),
141 nativeAPIError::FeeRateTooHigh {mut err, mut feerate, } => {
142 APIError::FeeRateTooHigh {
143 err: err.into_bytes().into(),
147 nativeAPIError::RouteError {mut err, } => {
148 APIError::RouteError {
152 nativeAPIError::ChannelUnavailable {mut err, } => {
153 APIError::ChannelUnavailable {
154 err: err.into_bytes().into(),
157 nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed,
162 pub extern "C" fn APIError_free(this_ptr: APIError) { }
164 pub extern "C" fn APIError_clone(orig: &APIError) -> APIError {