X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Foffers%2Finvoice_error.rs;h=acf381e192adbda1fc432da668d48129a6e2dd62;hb=5502fccd64611f16f5ebba3759c68b1a4d69b537;hp=374c5e1e163c2d502cddf0da0bdce16ad08ea07b;hpb=48e3445a78b643c837e7d489d90588eb877d0319;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/offers/invoice_error.rs b/lightning-c-bindings/src/lightning/offers/invoice_error.rs index 374c5e1..acf381e 100644 --- a/lightning-c-bindings/src/lightning/offers/invoice_error.rs +++ b/lightning-c-bindings/src/lightning/offers/invoice_error.rs @@ -9,6 +9,7 @@ //! Data structures and encoding for `invoice_error` messages. use alloc::str::FromStr; +use alloc::string::String; use core::ffi::c_void; use core::convert::Infallible; use bitcoin::hashes::Hash; @@ -105,6 +106,8 @@ pub extern "C" fn InvoiceError_set_message(this_ptr: &mut InvoiceError, mut val: unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.message = *unsafe { Box::from_raw(val.take_inner()) }; } /// Constructs a new InvoiceError given each field +/// +/// Note that erroneous_field_arg (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] 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 { @@ -126,7 +129,7 @@ impl Clone for InvoiceError { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn InvoiceError_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceError)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInvoiceError)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the InvoiceError @@ -235,19 +238,27 @@ impl Clone for ErroneousField { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ErroneousField_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeErroneousField)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeErroneousField)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ErroneousField pub extern "C" fn ErroneousField_clone(orig: &ErroneousField) -> ErroneousField { orig.clone() } +/// Creates an [`InvoiceError`] with the given message. +#[must_use] +#[no_mangle] +pub extern "C" fn InvoiceError_from_string(mut s: crate::c_types::Str) -> crate::lightning::offers::invoice_error::InvoiceError { + let mut ret = lightning::offers::invoice_error::InvoiceError::from_string(s.into_string()); + crate::lightning::offers::invoice_error::InvoiceError { inner: ObjOps::heap_alloc(ret), is_owned: true } +} + #[no_mangle] /// Serialize the InvoiceError object into a byte array which can be read by InvoiceError_read pub extern "C" fn InvoiceError_write(obj: &crate::lightning::offers::invoice_error::InvoiceError) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn InvoiceError_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceError) }) }