Update auto-generated bindings to LDK 0.0.121
[ldk-c-bindings] / lightning-c-bindings / src / lightning / offers / invoice_error.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
9 //! Data structures and encoding for `invoice_error` messages.
10
11 use alloc::str::FromStr;
12 use alloc::string::String;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
19
20
21 use lightning::offers::invoice_error::InvoiceError as nativeInvoiceErrorImport;
22 pub(crate) type nativeInvoiceError = nativeInvoiceErrorImport;
23
24 /// An error in response to an [`InvoiceRequest`] or an [`Bolt12Invoice`].
25 ///
26 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
27 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
28 #[must_use]
29 #[repr(C)]
30 pub struct InvoiceError {
31         /// A pointer to the opaque Rust object.
32
33         /// Nearly everywhere, inner must be non-null, however in places where
34         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
35         pub inner: *mut nativeInvoiceError,
36         /// Indicates that this is the only struct which contains the same pointer.
37
38         /// Rust functions which take ownership of an object provided via an argument require
39         /// this to be true and invalidate the object pointed to by inner.
40         pub is_owned: bool,
41 }
42
43 impl Drop for InvoiceError {
44         fn drop(&mut self) {
45                 if self.is_owned && !<*mut nativeInvoiceError>::is_null(self.inner) {
46                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
47                 }
48         }
49 }
50 /// Frees any resources used by the InvoiceError, if is_owned is set and inner is non-NULL.
51 #[no_mangle]
52 pub extern "C" fn InvoiceError_free(this_obj: InvoiceError) { }
53 #[allow(unused)]
54 /// Used only if an object of this type is returned as a trait impl by a method
55 pub(crate) extern "C" fn InvoiceError_free_void(this_ptr: *mut c_void) {
56         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInvoiceError) };
57 }
58 #[allow(unused)]
59 impl InvoiceError {
60         pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceError {
61                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
62         }
63         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceError {
64                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
65         }
66         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
67         pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceError {
68                 assert!(self.is_owned);
69                 let ret = ObjOps::untweak_ptr(self.inner);
70                 self.inner = core::ptr::null_mut();
71                 ret
72         }
73 }
74 /// The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error.
75 ///
76 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
77 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
78 ///
79 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
80 #[no_mangle]
81 pub extern "C" fn InvoiceError_get_erroneous_field(this_ptr: &InvoiceError) -> crate::lightning::offers::invoice_error::ErroneousField {
82         let mut inner_val = &mut this_ptr.get_native_mut_ref().erroneous_field;
83         let mut local_inner_val = crate::lightning::offers::invoice_error::ErroneousField { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::offers::invoice_error::ErroneousField<>) as *mut _ }, is_owned: false };
84         local_inner_val
85 }
86 /// The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error.
87 ///
88 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
89 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
90 ///
91 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
92 #[no_mangle]
93 pub extern "C" fn InvoiceError_set_erroneous_field(this_ptr: &mut InvoiceError, mut val: crate::lightning::offers::invoice_error::ErroneousField) {
94         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
95         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.erroneous_field = local_val;
96 }
97 /// An explanation of the error.
98 #[no_mangle]
99 pub extern "C" fn InvoiceError_get_message(this_ptr: &InvoiceError) -> crate::lightning::util::string::UntrustedString {
100         let mut inner_val = &mut this_ptr.get_native_mut_ref().message;
101         crate::lightning::util::string::UntrustedString { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::util::string::UntrustedString<>) as *mut _) }, is_owned: false }
102 }
103 /// An explanation of the error.
104 #[no_mangle]
105 pub extern "C" fn InvoiceError_set_message(this_ptr: &mut InvoiceError, mut val: crate::lightning::util::string::UntrustedString) {
106         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.message = *unsafe { Box::from_raw(val.take_inner()) };
107 }
108 /// Constructs a new InvoiceError given each field
109 ///
110 /// Note that erroneous_field_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
111 #[must_use]
112 #[no_mangle]
113 pub extern "C" fn InvoiceError_new(mut erroneous_field_arg: crate::lightning::offers::invoice_error::ErroneousField, mut message_arg: crate::lightning::util::string::UntrustedString) -> InvoiceError {
114         let mut local_erroneous_field_arg = if erroneous_field_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(erroneous_field_arg.take_inner()) } }) };
115         InvoiceError { inner: ObjOps::heap_alloc(nativeInvoiceError {
116                 erroneous_field: local_erroneous_field_arg,
117                 message: *unsafe { Box::from_raw(message_arg.take_inner()) },
118         }), is_owned: true }
119 }
120 impl Clone for InvoiceError {
121         fn clone(&self) -> Self {
122                 Self {
123                         inner: if <*mut nativeInvoiceError>::is_null(self.inner) { core::ptr::null_mut() } else {
124                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
125                         is_owned: true,
126                 }
127         }
128 }
129 #[allow(unused)]
130 /// Used only if an object of this type is returned as a trait impl by a method
131 pub(crate) extern "C" fn InvoiceError_clone_void(this_ptr: *const c_void) -> *mut c_void {
132         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInvoiceError)).clone() })) as *mut c_void
133 }
134 #[no_mangle]
135 /// Creates a copy of the InvoiceError
136 pub extern "C" fn InvoiceError_clone(orig: &InvoiceError) -> InvoiceError {
137         orig.clone()
138 }
139 /// Get a string which allows debug introspection of a InvoiceError object
140 pub extern "C" fn InvoiceError_debug_str_void(o: *const c_void) -> Str {
141         alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::invoice_error::InvoiceError }).into()}
142
143 use lightning::offers::invoice_error::ErroneousField as nativeErroneousFieldImport;
144 pub(crate) type nativeErroneousField = nativeErroneousFieldImport;
145
146 /// The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error.
147 ///
148 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
149 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
150 #[must_use]
151 #[repr(C)]
152 pub struct ErroneousField {
153         /// A pointer to the opaque Rust object.
154
155         /// Nearly everywhere, inner must be non-null, however in places where
156         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
157         pub inner: *mut nativeErroneousField,
158         /// Indicates that this is the only struct which contains the same pointer.
159
160         /// Rust functions which take ownership of an object provided via an argument require
161         /// this to be true and invalidate the object pointed to by inner.
162         pub is_owned: bool,
163 }
164
165 impl Drop for ErroneousField {
166         fn drop(&mut self) {
167                 if self.is_owned && !<*mut nativeErroneousField>::is_null(self.inner) {
168                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
169                 }
170         }
171 }
172 /// Frees any resources used by the ErroneousField, if is_owned is set and inner is non-NULL.
173 #[no_mangle]
174 pub extern "C" fn ErroneousField_free(this_obj: ErroneousField) { }
175 #[allow(unused)]
176 /// Used only if an object of this type is returned as a trait impl by a method
177 pub(crate) extern "C" fn ErroneousField_free_void(this_ptr: *mut c_void) {
178         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeErroneousField) };
179 }
180 #[allow(unused)]
181 impl ErroneousField {
182         pub(crate) fn get_native_ref(&self) -> &'static nativeErroneousField {
183                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
184         }
185         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeErroneousField {
186                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
187         }
188         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
189         pub(crate) fn take_inner(mut self) -> *mut nativeErroneousField {
190                 assert!(self.is_owned);
191                 let ret = ObjOps::untweak_ptr(self.inner);
192                 self.inner = core::ptr::null_mut();
193                 ret
194         }
195 }
196 /// The type number of the TLV field containing the error.
197 #[no_mangle]
198 pub extern "C" fn ErroneousField_get_tlv_fieldnum(this_ptr: &ErroneousField) -> u64 {
199         let mut inner_val = &mut this_ptr.get_native_mut_ref().tlv_fieldnum;
200         *inner_val
201 }
202 /// The type number of the TLV field containing the error.
203 #[no_mangle]
204 pub extern "C" fn ErroneousField_set_tlv_fieldnum(this_ptr: &mut ErroneousField, mut val: u64) {
205         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tlv_fieldnum = val;
206 }
207 /// A value to use for the TLV field to avoid the error.
208 ///
209 /// Returns a copy of the field.
210 #[no_mangle]
211 pub extern "C" fn ErroneousField_get_suggested_value(this_ptr: &ErroneousField) -> crate::c_types::derived::COption_CVec_u8ZZ {
212         let mut inner_val = this_ptr.get_native_mut_ref().suggested_value.clone();
213         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some( { let mut local_inner_val_0 = Vec::new(); for mut item in inner_val.unwrap().drain(..) { local_inner_val_0.push( { item }); }; local_inner_val_0.into() }) };
214         local_inner_val
215 }
216 /// A value to use for the TLV field to avoid the error.
217 #[no_mangle]
218 pub extern "C" fn ErroneousField_set_suggested_value(this_ptr: &mut ErroneousField, mut val: crate::c_types::derived::COption_CVec_u8ZZ) {
219         let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { let mut local_val_0 = Vec::new(); for mut item in { val_opt.take() }.into_rust().drain(..) { local_val_0.push( { item }); }; local_val_0 }})} };
220         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.suggested_value = local_val;
221 }
222 /// Constructs a new ErroneousField given each field
223 #[must_use]
224 #[no_mangle]
225 pub extern "C" fn ErroneousField_new(mut tlv_fieldnum_arg: u64, mut suggested_value_arg: crate::c_types::derived::COption_CVec_u8ZZ) -> ErroneousField {
226         let mut local_suggested_value_arg = { /*suggested_value_arg*/ let suggested_value_arg_opt = suggested_value_arg; if suggested_value_arg_opt.is_none() { None } else { Some({ { let mut local_suggested_value_arg_0 = Vec::new(); for mut item in { suggested_value_arg_opt.take() }.into_rust().drain(..) { local_suggested_value_arg_0.push( { item }); }; local_suggested_value_arg_0 }})} };
227         ErroneousField { inner: ObjOps::heap_alloc(nativeErroneousField {
228                 tlv_fieldnum: tlv_fieldnum_arg,
229                 suggested_value: local_suggested_value_arg,
230         }), is_owned: true }
231 }
232 impl Clone for ErroneousField {
233         fn clone(&self) -> Self {
234                 Self {
235                         inner: if <*mut nativeErroneousField>::is_null(self.inner) { core::ptr::null_mut() } else {
236                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
237                         is_owned: true,
238                 }
239         }
240 }
241 #[allow(unused)]
242 /// Used only if an object of this type is returned as a trait impl by a method
243 pub(crate) extern "C" fn ErroneousField_clone_void(this_ptr: *const c_void) -> *mut c_void {
244         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeErroneousField)).clone() })) as *mut c_void
245 }
246 #[no_mangle]
247 /// Creates a copy of the ErroneousField
248 pub extern "C" fn ErroneousField_clone(orig: &ErroneousField) -> ErroneousField {
249         orig.clone()
250 }
251 /// Get a string which allows debug introspection of a ErroneousField object
252 pub extern "C" fn ErroneousField_debug_str_void(o: *const c_void) -> Str {
253         alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::invoice_error::ErroneousField }).into()}
254 /// Creates an [`InvoiceError`] with the given message.
255 #[must_use]
256 #[no_mangle]
257 pub extern "C" fn InvoiceError_from_string(mut s: crate::c_types::Str) -> crate::lightning::offers::invoice_error::InvoiceError {
258         let mut ret = lightning::offers::invoice_error::InvoiceError::from_string(s.into_string());
259         crate::lightning::offers::invoice_error::InvoiceError { inner: ObjOps::heap_alloc(ret), is_owned: true }
260 }
261
262 #[no_mangle]
263 /// Serialize the InvoiceError object into a byte array which can be read by InvoiceError_read
264 pub extern "C" fn InvoiceError_write(obj: &crate::lightning::offers::invoice_error::InvoiceError) -> crate::c_types::derived::CVec_u8Z {
265         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
266 }
267 #[allow(unused)]
268 pub(crate) extern "C" fn InvoiceError_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
269         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceError) })
270 }
271 #[no_mangle]
272 /// Read a InvoiceError from a byte array, created by InvoiceError_write
273 pub extern "C" fn InvoiceError_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InvoiceErrorDecodeErrorZ {
274         let res: Result<lightning::offers::invoice_error::InvoiceError, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
275         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::invoice_error::InvoiceError { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
276         local_res
277 }