Update auto-generated bindings
[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 *mut 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
140 use lightning::offers::invoice_error::ErroneousField as nativeErroneousFieldImport;
141 pub(crate) type nativeErroneousField = nativeErroneousFieldImport;
142
143 /// The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error.
144 ///
145 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
146 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
147 #[must_use]
148 #[repr(C)]
149 pub struct ErroneousField {
150         /// A pointer to the opaque Rust object.
151
152         /// Nearly everywhere, inner must be non-null, however in places where
153         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
154         pub inner: *mut nativeErroneousField,
155         /// Indicates that this is the only struct which contains the same pointer.
156
157         /// Rust functions which take ownership of an object provided via an argument require
158         /// this to be true and invalidate the object pointed to by inner.
159         pub is_owned: bool,
160 }
161
162 impl Drop for ErroneousField {
163         fn drop(&mut self) {
164                 if self.is_owned && !<*mut nativeErroneousField>::is_null(self.inner) {
165                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
166                 }
167         }
168 }
169 /// Frees any resources used by the ErroneousField, if is_owned is set and inner is non-NULL.
170 #[no_mangle]
171 pub extern "C" fn ErroneousField_free(this_obj: ErroneousField) { }
172 #[allow(unused)]
173 /// Used only if an object of this type is returned as a trait impl by a method
174 pub(crate) extern "C" fn ErroneousField_free_void(this_ptr: *mut c_void) {
175         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeErroneousField) };
176 }
177 #[allow(unused)]
178 impl ErroneousField {
179         pub(crate) fn get_native_ref(&self) -> &'static nativeErroneousField {
180                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
181         }
182         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeErroneousField {
183                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
184         }
185         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
186         pub(crate) fn take_inner(mut self) -> *mut nativeErroneousField {
187                 assert!(self.is_owned);
188                 let ret = ObjOps::untweak_ptr(self.inner);
189                 self.inner = core::ptr::null_mut();
190                 ret
191         }
192 }
193 /// The type number of the TLV field containing the error.
194 #[no_mangle]
195 pub extern "C" fn ErroneousField_get_tlv_fieldnum(this_ptr: &ErroneousField) -> u64 {
196         let mut inner_val = &mut this_ptr.get_native_mut_ref().tlv_fieldnum;
197         *inner_val
198 }
199 /// The type number of the TLV field containing the error.
200 #[no_mangle]
201 pub extern "C" fn ErroneousField_set_tlv_fieldnum(this_ptr: &mut ErroneousField, mut val: u64) {
202         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tlv_fieldnum = val;
203 }
204 /// A value to use for the TLV field to avoid the error.
205 ///
206 /// Returns a copy of the field.
207 #[no_mangle]
208 pub extern "C" fn ErroneousField_get_suggested_value(this_ptr: &ErroneousField) -> crate::c_types::derived::COption_CVec_u8ZZ {
209         let mut inner_val = this_ptr.get_native_mut_ref().suggested_value.clone();
210         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() }) };
211         local_inner_val
212 }
213 /// A value to use for the TLV field to avoid the error.
214 #[no_mangle]
215 pub extern "C" fn ErroneousField_set_suggested_value(this_ptr: &mut ErroneousField, mut val: crate::c_types::derived::COption_CVec_u8ZZ) {
216         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 }})} };
217         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.suggested_value = local_val;
218 }
219 /// Constructs a new ErroneousField given each field
220 #[must_use]
221 #[no_mangle]
222 pub extern "C" fn ErroneousField_new(mut tlv_fieldnum_arg: u64, mut suggested_value_arg: crate::c_types::derived::COption_CVec_u8ZZ) -> ErroneousField {
223         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 }})} };
224         ErroneousField { inner: ObjOps::heap_alloc(nativeErroneousField {
225                 tlv_fieldnum: tlv_fieldnum_arg,
226                 suggested_value: local_suggested_value_arg,
227         }), is_owned: true }
228 }
229 impl Clone for ErroneousField {
230         fn clone(&self) -> Self {
231                 Self {
232                         inner: if <*mut nativeErroneousField>::is_null(self.inner) { core::ptr::null_mut() } else {
233                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
234                         is_owned: true,
235                 }
236         }
237 }
238 #[allow(unused)]
239 /// Used only if an object of this type is returned as a trait impl by a method
240 pub(crate) extern "C" fn ErroneousField_clone_void(this_ptr: *const c_void) -> *mut c_void {
241         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeErroneousField)).clone() })) as *mut c_void
242 }
243 #[no_mangle]
244 /// Creates a copy of the ErroneousField
245 pub extern "C" fn ErroneousField_clone(orig: &ErroneousField) -> ErroneousField {
246         orig.clone()
247 }
248 #[no_mangle]
249 /// Serialize the InvoiceError object into a byte array which can be read by InvoiceError_read
250 pub extern "C" fn InvoiceError_write(obj: &crate::lightning::offers::invoice_error::InvoiceError) -> crate::c_types::derived::CVec_u8Z {
251         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
252 }
253 #[no_mangle]
254 pub(crate) extern "C" fn InvoiceError_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
255         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceError) })
256 }
257 #[no_mangle]
258 /// Read a InvoiceError from a byte array, created by InvoiceError_write
259 pub extern "C" fn InvoiceError_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InvoiceErrorDecodeErrorZ {
260         let res: Result<lightning::offers::invoice_error::InvoiceError, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
261         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() };
262         local_res
263 }