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 //! Data structures and encoding for `invoice_error` messages.
11 use alloc::str::FromStr;
12 use core::ffi::c_void;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
16 #[cfg(feature="no-std")]
17 use alloc::{vec::Vec, boxed::Box};
20 use lightning::offers::invoice_error::InvoiceError as nativeInvoiceErrorImport;
21 pub(crate) type nativeInvoiceError = nativeInvoiceErrorImport;
23 /// An error in response to an [`InvoiceRequest`] or an [`Bolt12Invoice`].
25 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
26 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
29 pub struct InvoiceError {
30 /// A pointer to the opaque Rust object.
32 /// Nearly everywhere, inner must be non-null, however in places where
33 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
34 pub inner: *mut nativeInvoiceError,
35 /// Indicates that this is the only struct which contains the same pointer.
37 /// Rust functions which take ownership of an object provided via an argument require
38 /// this to be true and invalidate the object pointed to by inner.
42 impl Drop for InvoiceError {
44 if self.is_owned && !<*mut nativeInvoiceError>::is_null(self.inner) {
45 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
49 /// Frees any resources used by the InvoiceError, if is_owned is set and inner is non-NULL.
51 pub extern "C" fn InvoiceError_free(this_obj: InvoiceError) { }
53 /// Used only if an object of this type is returned as a trait impl by a method
54 pub(crate) extern "C" fn InvoiceError_free_void(this_ptr: *mut c_void) {
55 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInvoiceError) };
59 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceError {
60 unsafe { &*ObjOps::untweak_ptr(self.inner) }
62 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceError {
63 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
65 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
66 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceError {
67 assert!(self.is_owned);
68 let ret = ObjOps::untweak_ptr(self.inner);
69 self.inner = core::ptr::null_mut();
73 /// The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error.
75 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
76 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
78 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
80 pub extern "C" fn InvoiceError_get_erroneous_field(this_ptr: &InvoiceError) -> crate::lightning::offers::invoice_error::ErroneousField {
81 let mut inner_val = &mut this_ptr.get_native_mut_ref().erroneous_field;
82 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 };
85 /// The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error.
87 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
88 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
90 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
92 pub extern "C" fn InvoiceError_set_erroneous_field(this_ptr: &mut InvoiceError, mut val: crate::lightning::offers::invoice_error::ErroneousField) {
93 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
94 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.erroneous_field = local_val;
96 /// An explanation of the error.
98 pub extern "C" fn InvoiceError_get_message(this_ptr: &InvoiceError) -> crate::lightning::util::string::UntrustedString {
99 let mut inner_val = &mut this_ptr.get_native_mut_ref().message;
100 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 /// An explanation of the error.
104 pub extern "C" fn InvoiceError_set_message(this_ptr: &mut InvoiceError, mut val: crate::lightning::util::string::UntrustedString) {
105 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.message = *unsafe { Box::from_raw(val.take_inner()) };
107 /// Constructs a new InvoiceError given each field
110 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 {
111 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()) } }) };
112 InvoiceError { inner: ObjOps::heap_alloc(nativeInvoiceError {
113 erroneous_field: local_erroneous_field_arg,
114 message: *unsafe { Box::from_raw(message_arg.take_inner()) },
117 impl Clone for InvoiceError {
118 fn clone(&self) -> Self {
120 inner: if <*mut nativeInvoiceError>::is_null(self.inner) { core::ptr::null_mut() } else {
121 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
127 /// Used only if an object of this type is returned as a trait impl by a method
128 pub(crate) extern "C" fn InvoiceError_clone_void(this_ptr: *const c_void) -> *mut c_void {
129 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceError)).clone() })) as *mut c_void
132 /// Creates a copy of the InvoiceError
133 pub extern "C" fn InvoiceError_clone(orig: &InvoiceError) -> InvoiceError {
137 use lightning::offers::invoice_error::ErroneousField as nativeErroneousFieldImport;
138 pub(crate) type nativeErroneousField = nativeErroneousFieldImport;
140 /// The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error.
142 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
143 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
146 pub struct ErroneousField {
147 /// A pointer to the opaque Rust object.
149 /// Nearly everywhere, inner must be non-null, however in places where
150 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
151 pub inner: *mut nativeErroneousField,
152 /// Indicates that this is the only struct which contains the same pointer.
154 /// Rust functions which take ownership of an object provided via an argument require
155 /// this to be true and invalidate the object pointed to by inner.
159 impl Drop for ErroneousField {
161 if self.is_owned && !<*mut nativeErroneousField>::is_null(self.inner) {
162 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
166 /// Frees any resources used by the ErroneousField, if is_owned is set and inner is non-NULL.
168 pub extern "C" fn ErroneousField_free(this_obj: ErroneousField) { }
170 /// Used only if an object of this type is returned as a trait impl by a method
171 pub(crate) extern "C" fn ErroneousField_free_void(this_ptr: *mut c_void) {
172 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeErroneousField) };
175 impl ErroneousField {
176 pub(crate) fn get_native_ref(&self) -> &'static nativeErroneousField {
177 unsafe { &*ObjOps::untweak_ptr(self.inner) }
179 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeErroneousField {
180 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
182 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
183 pub(crate) fn take_inner(mut self) -> *mut nativeErroneousField {
184 assert!(self.is_owned);
185 let ret = ObjOps::untweak_ptr(self.inner);
186 self.inner = core::ptr::null_mut();
190 /// The type number of the TLV field containing the error.
192 pub extern "C" fn ErroneousField_get_tlv_fieldnum(this_ptr: &ErroneousField) -> u64 {
193 let mut inner_val = &mut this_ptr.get_native_mut_ref().tlv_fieldnum;
196 /// The type number of the TLV field containing the error.
198 pub extern "C" fn ErroneousField_set_tlv_fieldnum(this_ptr: &mut ErroneousField, mut val: u64) {
199 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tlv_fieldnum = val;
201 /// A value to use for the TLV field to avoid the error.
203 /// Returns a copy of the field.
205 pub extern "C" fn ErroneousField_get_suggested_value(this_ptr: &ErroneousField) -> crate::c_types::derived::COption_CVec_u8ZZ {
206 let mut inner_val = this_ptr.get_native_mut_ref().suggested_value.clone();
207 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() }) };
210 /// A value to use for the TLV field to avoid the error.
212 pub extern "C" fn ErroneousField_set_suggested_value(this_ptr: &mut ErroneousField, mut val: crate::c_types::derived::COption_CVec_u8ZZ) {
213 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 }})} };
214 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.suggested_value = local_val;
216 /// Constructs a new ErroneousField given each field
219 pub extern "C" fn ErroneousField_new(mut tlv_fieldnum_arg: u64, mut suggested_value_arg: crate::c_types::derived::COption_CVec_u8ZZ) -> ErroneousField {
220 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 }})} };
221 ErroneousField { inner: ObjOps::heap_alloc(nativeErroneousField {
222 tlv_fieldnum: tlv_fieldnum_arg,
223 suggested_value: local_suggested_value_arg,
226 impl Clone for ErroneousField {
227 fn clone(&self) -> Self {
229 inner: if <*mut nativeErroneousField>::is_null(self.inner) { core::ptr::null_mut() } else {
230 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
236 /// Used only if an object of this type is returned as a trait impl by a method
237 pub(crate) extern "C" fn ErroneousField_clone_void(this_ptr: *const c_void) -> *mut c_void {
238 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeErroneousField)).clone() })) as *mut c_void
241 /// Creates a copy of the ErroneousField
242 pub extern "C" fn ErroneousField_clone(orig: &ErroneousField) -> ErroneousField {
246 /// Serialize the InvoiceError object into a byte array which can be read by InvoiceError_read
247 pub extern "C" fn InvoiceError_write(obj: &crate::lightning::offers::invoice_error::InvoiceError) -> crate::c_types::derived::CVec_u8Z {
248 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
251 pub(crate) extern "C" fn InvoiceError_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
252 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceError) })
255 /// Read a InvoiceError from a byte array, created by InvoiceError_write
256 pub extern "C" fn InvoiceError_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InvoiceErrorDecodeErrorZ {
257 let res: Result<lightning::offers::invoice_error::InvoiceError, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
258 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() };