X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Foffers%2Frefund.rs;h=7fcfc66b7c98fbdd921aba55ad539ed7d6c4aaf9;hb=5502fccd64611f16f5ebba3759c68b1a4d69b537;hp=1e44848d0cc3069efa41160c071d697d45c49855;hpb=27a0520e39d348f9949016d4d1219c34d8450da6;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 1e44848..7fcfc66 100644 --- a/lightning-c-bindings/src/lightning/offers/refund.rs +++ b/lightning-c-bindings/src/lightning/offers/refund.rs @@ -9,14 +9,16 @@ //! Data structures and encoding for refunds. //! //! A [`Refund`] is an \"offer for money\" and is typically constructed by a merchant and presented -//! directly to the customer. The recipient responds with an [`Invoice`] to be paid. +//! directly to the customer. The recipient responds with a [`Bolt12Invoice`] to be paid. //! //! This is an [`InvoiceRequest`] produced *not* in response to an [`Offer`]. //! -//! [`Invoice`]: crate::offers::invoice::Invoice +//! [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice //! [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest //! [`Offer`]: crate::offers::offer::Offer //! +//! # Example +//! //! ``` //! extern crate bitcoin; //! extern crate core; @@ -27,7 +29,7 @@ //! //! use bitcoin::network::constants::Network; //! use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey}; -//! use lightning::offers::parse::ParseError; +//! use lightning::offers::parse::Bolt12ParseError; //! use lightning::offers::refund::{Refund, RefundBuilder}; //! use lightning::util::ser::{Readable, Writeable}; //! @@ -39,7 +41,7 @@ //! # fn create_another_blinded_path() -> BlindedPath { unimplemented!() } //! # //! # #[cfg(feature = \"std\")] -//! # fn build() -> Result<(), ParseError> { +//! # fn build() -> Result<(), Bolt12ParseError> { //! let secp_ctx = Secp256k1::new(); //! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap()); //! let pubkey = PublicKey::from(keys); @@ -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; @@ -82,13 +93,13 @@ use alloc::{vec::Vec, boxed::Box}; use lightning::offers::refund::Refund as nativeRefundImport; pub(crate) type nativeRefund = nativeRefundImport; -/// A `Refund` is a request to send an [`Invoice`] without a preceding [`Offer`]. +/// A `Refund` is a request to send an [`Bolt12Invoice`] without a preceding [`Offer`]. /// /// Typically, after an invoice is paid, the recipient may publish a refund allowing the sender to /// recoup their funds. A refund may be used more generally as an \"offer for money\", such as with a /// bitcoin ATM. /// -/// [`Invoice`]: crate::offers::invoice::Invoice +/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice /// [`Offer`]: crate::offers::offer::Offer #[must_use] #[repr(C)] @@ -148,7 +159,7 @@ 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 @@ -169,9 +180,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 } @@ -211,8 +222,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 } @@ -279,7 +290,23 @@ 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) }) } +#[no_mangle] +/// Read a Refund object from a string +pub extern "C" fn Refund_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_RefundBolt12ParseErrorZ { + match lightning::offers::refund::Refund::from_str(s.into_str()) { + Ok(r) => { + crate::c_types::CResultTempl::ok( + crate::lightning::offers::refund::Refund { inner: ObjOps::heap_alloc(r), is_owned: true } + ) + }, + Err(e) => { + crate::c_types::CResultTempl::err( + crate::lightning::offers::parse::Bolt12ParseError { inner: ObjOps::heap_alloc(e), is_owned: true } + ) + }, + }.into() +}