X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Foffers%2Frefund.rs;h=c55fc20a5bec1b2126be8906449e963d8f69f307;hb=0ac4dbdb8352c898100b34f0ef8ed9cebfea7786;hp=fe35bc20ce048d68ed22f2851f5fced127d811db;hpb=48e3445a78b643c837e7d489d90588eb877d0319;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/offers/refund.rs b/lightning-c-bindings/src/lightning/offers/refund.rs index fe35bc2..c55fc20 100644 --- a/lightning-c-bindings/src/lightning/offers/refund.rs +++ b/lightning-c-bindings/src/lightning/offers/refund.rs @@ -17,6 +17,8 @@ //! [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest //! [`Offer`]: crate::offers::offer::Offer //! +//! # Example +//! //! ``` //! extern crate bitcoin; //! extern crate core; @@ -69,8 +71,17 @@ //! # Ok(()) //! # } //! ``` +//! +//! # Note +//! +//! If constructing a [`Refund`] for use with a [`ChannelManager`], use +//! [`ChannelManager::create_refund_builder`] instead of [`RefundBuilder::new`]. +//! +//! [`ChannelManager`]: crate::ln::channelmanager::ChannelManager +//! [`ChannelManager::create_refund_builder`]: crate::ln::channelmanager::ChannelManager::create_refund_builder use alloc::str::FromStr; +use alloc::string::String; use core::ffi::c_void; use core::convert::Infallible; use bitcoin::hashes::Hash; @@ -148,13 +159,16 @@ impl Clone for Refund { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Refund_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRefund)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRefund)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Refund pub extern "C" fn Refund_clone(orig: &Refund) -> Refund { orig.clone() } +/// Get a string which allows debug introspection of a Refund object +pub extern "C" fn Refund_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::refund::Refund }).into()} /// A complete description of the purpose of the refund. Intended to be displayed to the user /// but with the caveat that it has not been verified in any way. #[must_use] @@ -169,9 +183,9 @@ pub extern "C" fn Refund_description(this_arg: &crate::lightning::offers::refund /// If `None`, the refund does not expire. #[must_use] #[no_mangle] -pub extern "C" fn Refund_absolute_expiry(this_arg: &crate::lightning::offers::refund::Refund) -> crate::c_types::derived::COption_DurationZ { +pub extern "C" fn Refund_absolute_expiry(this_arg: &crate::lightning::offers::refund::Refund) -> crate::c_types::derived::COption_u64Z { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.absolute_expiry(); - let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_DurationZ::None } else { crate::c_types::derived::COption_DurationZ::Some( { ret.unwrap().as_secs() }) }; + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap().as_secs() }) }; local_ret } @@ -183,6 +197,14 @@ pub extern "C" fn Refund_is_expired(this_arg: &crate::lightning::offers::refund: ret } +/// Whether the refund has expired given the duration since the Unix epoch. +#[must_use] +#[no_mangle] +pub extern "C" fn Refund_is_expired_no_std(this_arg: &crate::lightning::offers::refund::Refund, mut duration_since_epoch: u64) -> bool { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired_no_std(core::time::Duration::from_secs(duration_since_epoch)); + ret +} + /// The issuer of the refund, possibly beginning with `user@domain` or `domain`. Intended to be /// displayed to the user but with the caveat that it has not been verified in any way. /// @@ -211,8 +233,8 @@ pub extern "C" fn Refund_paths(this_arg: &crate::lightning::offers::refund::Refu /// [`payer_id`]: Self::payer_id #[must_use] #[no_mangle] -pub extern "C" fn Refund_metadata(this_arg: &crate::lightning::offers::refund::Refund) -> crate::c_types::u8slice { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.metadata(); +pub extern "C" fn Refund_payer_metadata(this_arg: &crate::lightning::offers::refund::Refund) -> crate::c_types::u8slice { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_metadata(); let mut local_ret = crate::c_types::u8slice::from_slice(ret); local_ret } @@ -222,7 +244,7 @@ pub extern "C" fn Refund_metadata(this_arg: &crate::lightning::offers::refund::R #[no_mangle] pub extern "C" fn Refund_chain(this_arg: &crate::lightning::offers::refund::Refund) -> crate::c_types::ThirtyTwoBytes { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.chain(); - crate::c_types::ThirtyTwoBytes { data: ret.to_bytes() } + crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() } } /// The amount to refund in msats (i.e., the minimum lightning-payable unit for [`chain`]). @@ -279,7 +301,7 @@ pub extern "C" fn Refund_payer_note(this_arg: &crate::lightning::offers::refund: pub extern "C" fn Refund_write(obj: &crate::lightning::offers::refund::Refund) -> 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 Refund_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRefund) }) }