X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Foffers%2Finvoice.rs;h=2385fd4b86f8db47004b7e1005a9e6864252f9aa;hb=3e46e1794f14640e35f09cc6da4169c152de34ce;hp=778d5b417b8557776cd885af7c074cfe79b91acf;hpb=27a0520e39d348f9949016d4d1219c34d8450da6;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/offers/invoice.rs b/lightning-c-bindings/src/lightning/offers/invoice.rs index 778d5b4..2385fd4 100644 --- a/lightning-c-bindings/src/lightning/offers/invoice.rs +++ b/lightning-c-bindings/src/lightning/offers/invoice.rs @@ -8,9 +8,9 @@ //! Data structures and encoding for `invoice` messages. //! -//! An [`Invoice`] can be built from a parsed [`InvoiceRequest`] for the \"offer to be paid\" flow or -//! from a [`Refund`] as an \"offer for money\" flow. The expected recipient of the payment then sends -//! the invoice to the intended payer, who will then pay it. +//! A [`Bolt12Invoice`] can be built from a parsed [`InvoiceRequest`] for the \"offer to be paid\" +//! flow or from a [`Refund`] as an \"offer for money\" flow. The expected recipient of the payment +//! then sends the invoice to the intended payer, who will then pay it. //! //! The payment recipient must include a [`PaymentHash`], so as to reveal the preimage upon payment //! receipt, and one or more [`BlindedPath`]s for the payer to use when sending the payment. @@ -30,10 +30,10 @@ //! # use lightning::offers::invoice::BlindedPayInfo; //! # use lightning::blinded_path::BlindedPath; //! # -//! # fn create_payment_paths() -> Vec<(BlindedPath, BlindedPayInfo)> { unimplemented!() } +//! # fn create_payment_paths() -> Vec<(BlindedPayInfo, BlindedPath)> { unimplemented!() } //! # fn create_payment_hash() -> PaymentHash { unimplemented!() } //! # -//! # fn parse_invoice_request(bytes: Vec) -> Result<(), lightning::offers::parse::ParseError> { +//! # fn parse_invoice_request(bytes: Vec) -> Result<(), lightning::offers::parse::Bolt12ParseError> { //! let payment_paths = create_payment_paths(); //! let payment_hash = create_payment_hash(); //! let secp_ctx = Secp256k1::new(); @@ -51,14 +51,16 @@ //! .allow_mpp() //! .fallback_v0_p2wpkh(&wpubkey_hash) //! .build()? -//! .sign::<_, Infallible>(|digest| Ok(secp_ctx.sign_schnorr_no_aux_rand(digest, &keys))) +//! .sign::<_, Infallible>( +//! |message| Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys)) +//! ) //! .expect(\"failed verifying signature\") //! .write(&mut buffer) //! .unwrap(); //! # Ok(()) //! # } //! -//! # fn parse_refund(bytes: Vec) -> Result<(), lightning::offers::parse::ParseError> { +//! # fn parse_refund(bytes: Vec) -> Result<(), lightning::offers::parse::Bolt12ParseError> { //! # let payment_paths = create_payment_paths(); //! # let payment_hash = create_payment_hash(); //! # let secp_ctx = Secp256k1::new(); @@ -77,7 +79,9 @@ //! .allow_mpp() //! .fallback_v0_p2wpkh(&wpubkey_hash) //! .build()? -//! .sign::<_, Infallible>(|digest| Ok(secp_ctx.sign_schnorr_no_aux_rand(digest, &keys))) +//! .sign::<_, Infallible>( +//! |message| Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys)) +//! ) //! .expect(\"failed verifying signature\") //! .write(&mut buffer) //! .unwrap(); @@ -87,6 +91,7 @@ //! ``` use alloc::str::FromStr; +use alloc::string::String; use core::ffi::c_void; use core::convert::Infallible; use bitcoin::hashes::Hash; @@ -95,18 +100,23 @@ use crate::c_types::*; use alloc::{vec::Vec, boxed::Box}; -use lightning::offers::invoice::UnsignedInvoice as nativeUnsignedInvoiceImport; -pub(crate) type nativeUnsignedInvoice = nativeUnsignedInvoiceImport<'static>; +use lightning::offers::invoice::UnsignedBolt12Invoice as nativeUnsignedBolt12InvoiceImport; +pub(crate) type nativeUnsignedBolt12Invoice = nativeUnsignedBolt12InvoiceImport; -/// A semantically valid [`Invoice`] that hasn't been signed. +/// A semantically valid [`Bolt12Invoice`] that hasn't been signed. +/// +/// # Serialization +/// +/// This is serialized as a TLV stream, which includes TLV records from the originating message. As +/// such, it may include unknown, odd TLV records. #[must_use] #[repr(C)] -pub struct UnsignedInvoice { +pub struct UnsignedBolt12Invoice { /// A pointer to the opaque Rust object. /// Nearly everywhere, inner must be non-null, however in places where /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeUnsignedInvoice, + pub inner: *mut nativeUnsignedBolt12Invoice, /// Indicates that this is the only struct which contains the same pointer. /// Rust functions which take ownership of an object provided via an argument require @@ -114,45 +124,682 @@ pub struct UnsignedInvoice { pub is_owned: bool, } -impl Drop for UnsignedInvoice { +impl Drop for UnsignedBolt12Invoice { fn drop(&mut self) { - if self.is_owned && !<*mut nativeUnsignedInvoice>::is_null(self.inner) { + if self.is_owned && !<*mut nativeUnsignedBolt12Invoice>::is_null(self.inner) { let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; } } } -/// Frees any resources used by the UnsignedInvoice, if is_owned is set and inner is non-NULL. +/// Frees any resources used by the UnsignedBolt12Invoice, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn UnsignedInvoice_free(this_obj: UnsignedInvoice) { } +pub extern "C" fn UnsignedBolt12Invoice_free(this_obj: UnsignedBolt12Invoice) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn UnsignedInvoice_free_void(this_ptr: *mut c_void) { - let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUnsignedInvoice) }; +pub(crate) extern "C" fn UnsignedBolt12Invoice_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUnsignedBolt12Invoice) }; } #[allow(unused)] -impl UnsignedInvoice { - pub(crate) fn get_native_ref(&self) -> &'static nativeUnsignedInvoice { +impl UnsignedBolt12Invoice { + pub(crate) fn get_native_ref(&self) -> &'static nativeUnsignedBolt12Invoice { unsafe { &*ObjOps::untweak_ptr(self.inner) } } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUnsignedInvoice { + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUnsignedBolt12Invoice { unsafe { &mut *ObjOps::untweak_ptr(self.inner) } } /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy - pub(crate) fn take_inner(mut self) -> *mut nativeUnsignedInvoice { + pub(crate) fn take_inner(mut self) -> *mut nativeUnsignedBolt12Invoice { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); self.inner = core::ptr::null_mut(); ret } } -/// The public key corresponding to the key needed to sign the invoice. +/// Returns the [`TaggedHash`] of the invoice to sign. #[must_use] #[no_mangle] -pub extern "C" fn UnsignedInvoice_signing_pubkey(this_arg: &crate::lightning::offers::invoice::UnsignedInvoice) -> crate::c_types::PublicKey { +pub extern "C" fn UnsignedBolt12Invoice_tagged_hash(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::offers::merkle::TaggedHash { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tagged_hash(); + crate::lightning::offers::merkle::TaggedHash { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::offers::merkle::TaggedHash<>) as *mut _) }, is_owned: false } +} + + +use lightning::offers::invoice::Bolt12Invoice as nativeBolt12InvoiceImport; +pub(crate) type nativeBolt12Invoice = nativeBolt12InvoiceImport; + +/// A `Bolt12Invoice` is a payment request, typically corresponding to an [`Offer`] or a [`Refund`]. +/// +/// An invoice may be sent in response to an [`InvoiceRequest`] in the case of an offer or sent +/// directly after scanning a refund. It includes all the information needed to pay a recipient. +/// +/// [`Offer`]: crate::offers::offer::Offer +/// [`Refund`]: crate::offers::refund::Refund +/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest +#[must_use] +#[repr(C)] +pub struct Bolt12Invoice { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeBolt12Invoice, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for Bolt12Invoice { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeBolt12Invoice>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the Bolt12Invoice, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn Bolt12Invoice_free(this_obj: Bolt12Invoice) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Bolt12Invoice_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt12Invoice) }; +} +#[allow(unused)] +impl Bolt12Invoice { + pub(crate) fn get_native_ref(&self) -> &'static nativeBolt12Invoice { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt12Invoice { + unsafe { &mut *ObjOps::untweak_ptr(self.inner) } + } + /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy + pub(crate) fn take_inner(mut self) -> *mut nativeBolt12Invoice { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } +} +impl Clone for Bolt12Invoice { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeBolt12Invoice>::is_null(self.inner) { core::ptr::null_mut() } else { + ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Bolt12Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBolt12Invoice)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the Bolt12Invoice +pub extern "C" fn Bolt12Invoice_clone(orig: &Bolt12Invoice) -> Bolt12Invoice { + orig.clone() +} +/// The chains that may be used when paying a requested invoice. +/// +/// From [`Offer::chains`]; `None` if the invoice was created in response to a [`Refund`]. +/// +/// [`Offer::chains`]: crate::offers::offer::Offer::chains +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_offer_chains(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_chains(); + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::None } else { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::c_types::ThirtyTwoBytes { data: item.to_bytes() } }); }; local_ret_0.into() }) }; + local_ret +} + +/// The chain that must be used when paying the invoice; selected from [`offer_chains`] if the +/// invoice originated from an offer. +/// +/// From [`InvoiceRequest::chain`] or [`Refund::chain`]. +/// +/// [`offer_chains`]: Self::offer_chains +/// [`InvoiceRequest::chain`]: crate::offers::invoice_request::InvoiceRequest::chain +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_chain(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::ThirtyTwoBytes { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.chain(); + crate::c_types::ThirtyTwoBytes { data: ret.to_bytes() } +} + +/// Opaque bytes set by the originating [`Offer`]. +/// +/// From [`Offer::metadata`]; `None` if the invoice was created in response to a [`Refund`] or +/// if the [`Offer`] did not set it. +/// +/// [`Offer`]: crate::offers::offer::Offer +/// [`Offer::metadata`]: crate::offers::offer::Offer::metadata +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_metadata(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.metadata(); + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { let mut local_ret_0 = Vec::new(); for mut item in (*ret.as_ref().unwrap()).clone().drain(..) { local_ret_0.push( { item }); }; local_ret_0.into() }) }; + local_ret +} + +/// The minimum amount required for a successful payment of a single item. +/// +/// From [`Offer::amount`]; `None` if the invoice was created in response to a [`Refund`] or if +/// the [`Offer`] did not set it. +/// +/// [`Offer`]: crate::offers::offer::Offer +/// [`Offer::amount`]: crate::offers::offer::Offer::amount +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_amount(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::offers::offer::Amount { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount(); + let mut local_ret = crate::lightning::offers::offer::Amount { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::offers::offer::Amount<>) as *mut _ }, is_owned: false }; + local_ret +} + +/// Features pertaining to the originating [`Offer`]. +/// +/// From [`Offer::offer_features`]; `None` if the invoice was created in response to a +/// [`Refund`]. +/// +/// [`Offer`]: crate::offers::offer::Offer +/// [`Offer::offer_features`]: crate::offers::offer::Offer::offer_features +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_offer_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::OfferFeatures { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_features(); + let mut local_ret = crate::lightning::ln::features::OfferFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::OfferFeatures<>) as *mut _ }, is_owned: false }; + local_ret +} + +/// A complete description of the purpose of the originating offer or refund. +/// +/// From [`Offer::description`] or [`Refund::description`]. +/// +/// [`Offer::description`]: crate::offers::offer::Offer::description +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_description(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description(); + crate::lightning::util::string::PrintableString { inner: ObjOps::heap_alloc(ret), is_owned: true } +} + +/// Duration since the Unix epoch when an invoice should no longer be requested. +/// +/// From [`Offer::absolute_expiry`] or [`Refund::absolute_expiry`]. +/// +/// [`Offer::absolute_expiry`]: crate::offers::offer::Offer::absolute_expiry +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_absolute_expiry(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> 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_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap().as_secs() }) }; + local_ret +} + +/// The issuer of the offer or refund. +/// +/// From [`Offer::issuer`] or [`Refund::issuer`]. +/// +/// [`Offer::issuer`]: crate::offers::offer::Offer::issuer +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_issuer(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.issuer(); + let mut local_ret = crate::lightning::util::string::PrintableString { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true }; + local_ret +} + +/// Paths to the recipient originating from publicly reachable nodes. +/// +/// From [`Offer::paths`] or [`Refund::paths`]. +/// +/// [`Offer::paths`]: crate::offers::offer::Offer::paths +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_message_paths(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CVec_BlindedPathZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.message_paths(); + let mut local_ret_clone = Vec::new(); local_ret_clone.extend_from_slice(ret); let mut ret = local_ret_clone; let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; + local_ret.into() +} + +/// The quantity of items supported. +/// +/// From [`Offer::supported_quantity`]; `None` if the invoice was created in response to a +/// [`Refund`]. +/// +/// [`Offer::supported_quantity`]: crate::offers::offer::Offer::supported_quantity +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_supported_quantity(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::offers::offer::Quantity { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supported_quantity(); + let mut local_ret = crate::lightning::offers::offer::Quantity { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true }; + local_ret +} + +/// An unpredictable series of bytes from the payer. +/// +/// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`]. +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_payer_metadata(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> 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 +} + +/// Features pertaining to requesting an invoice. +/// +/// From [`InvoiceRequest::invoice_request_features`] or [`Refund::features`]. +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_invoice_request_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::InvoiceRequestFeatures { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_request_features(); + crate::lightning::ln::features::InvoiceRequestFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::InvoiceRequestFeatures<>) as *mut _) }, is_owned: false } +} + +/// The quantity of items requested or refunded for. +/// +/// From [`InvoiceRequest::quantity`] or [`Refund::quantity`]. +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_quantity(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_u64Z { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.quantity(); + 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() }) }; + local_ret +} + +/// A possibly transient pubkey used to sign the invoice request or to send an invoice for a +/// refund in case there are no [`message_paths`]. +/// +/// [`message_paths`]: Self::message_paths +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_payer_id(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::PublicKey { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_id(); + crate::c_types::PublicKey::from_rust(&ret) +} + +/// A payer-provided note reflected back in the invoice. +/// +/// From [`InvoiceRequest::payer_note`] or [`Refund::payer_note`]. +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_payer_note(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_note(); + let mut local_ret = crate::lightning::util::string::PrintableString { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true }; + local_ret +} + +/// Duration since the Unix epoch when the invoice was created. +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_created_at(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.created_at(); + ret.as_secs() +} + +/// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore +/// should no longer be paid. +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_relative_expiry(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.relative_expiry(); + ret.as_secs() +} + +/// Whether the invoice has expired. +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_is_expired(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> bool { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired(); + ret +} + +/// SHA256 hash of the payment preimage that will be given in return for paying the invoice. +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_payment_hash(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::ThirtyTwoBytes { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash(); + crate::c_types::ThirtyTwoBytes { data: ret.0 } +} + +/// The minimum amount required for a successful payment of the invoice. +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_amount_msats(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_msats(); + ret +} + +/// Features pertaining to paying an invoice. +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_invoice_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::Bolt12InvoiceFeatures { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_features(); + crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::Bolt12InvoiceFeatures<>) as *mut _) }, is_owned: false } +} + +/// The public key corresponding to the key used to sign the invoice. +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedBolt12Invoice_signing_pubkey(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::PublicKey { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signing_pubkey(); crate::c_types::PublicKey::from_rust(&ret) } +/// The chains that may be used when paying a requested invoice. +/// +/// From [`Offer::chains`]; `None` if the invoice was created in response to a [`Refund`]. +/// +/// [`Offer::chains`]: crate::offers::offer::Offer::chains +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_offer_chains(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_chains(); + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::None } else { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::c_types::ThirtyTwoBytes { data: item.to_bytes() } }); }; local_ret_0.into() }) }; + local_ret +} + +/// The chain that must be used when paying the invoice; selected from [`offer_chains`] if the +/// invoice originated from an offer. +/// +/// From [`InvoiceRequest::chain`] or [`Refund::chain`]. +/// +/// [`offer_chains`]: Self::offer_chains +/// [`InvoiceRequest::chain`]: crate::offers::invoice_request::InvoiceRequest::chain +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_chain(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.chain(); + crate::c_types::ThirtyTwoBytes { data: ret.to_bytes() } +} + +/// Opaque bytes set by the originating [`Offer`]. +/// +/// From [`Offer::metadata`]; `None` if the invoice was created in response to a [`Refund`] or +/// if the [`Offer`] did not set it. +/// +/// [`Offer`]: crate::offers::offer::Offer +/// [`Offer::metadata`]: crate::offers::offer::Offer::metadata +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_metadata(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.metadata(); + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { let mut local_ret_0 = Vec::new(); for mut item in (*ret.as_ref().unwrap()).clone().drain(..) { local_ret_0.push( { item }); }; local_ret_0.into() }) }; + local_ret +} + +/// The minimum amount required for a successful payment of a single item. +/// +/// From [`Offer::amount`]; `None` if the invoice was created in response to a [`Refund`] or if +/// the [`Offer`] did not set it. +/// +/// [`Offer`]: crate::offers::offer::Offer +/// [`Offer::amount`]: crate::offers::offer::Offer::amount +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_amount(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::offers::offer::Amount { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount(); + let mut local_ret = crate::lightning::offers::offer::Amount { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::offers::offer::Amount<>) as *mut _ }, is_owned: false }; + local_ret +} + +/// Features pertaining to the originating [`Offer`]. +/// +/// From [`Offer::offer_features`]; `None` if the invoice was created in response to a +/// [`Refund`]. +/// +/// [`Offer`]: crate::offers::offer::Offer +/// [`Offer::offer_features`]: crate::offers::offer::Offer::offer_features +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_offer_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::OfferFeatures { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_features(); + let mut local_ret = crate::lightning::ln::features::OfferFeatures { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::ln::features::OfferFeatures<>) as *mut _ }, is_owned: false }; + local_ret +} + +/// A complete description of the purpose of the originating offer or refund. +/// +/// From [`Offer::description`] or [`Refund::description`]. +/// +/// [`Offer::description`]: crate::offers::offer::Offer::description +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_description(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description(); + crate::lightning::util::string::PrintableString { inner: ObjOps::heap_alloc(ret), is_owned: true } +} + +/// Duration since the Unix epoch when an invoice should no longer be requested. +/// +/// From [`Offer::absolute_expiry`] or [`Refund::absolute_expiry`]. +/// +/// [`Offer::absolute_expiry`]: crate::offers::offer::Offer::absolute_expiry +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_absolute_expiry(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> 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_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap().as_secs() }) }; + local_ret +} + +/// The issuer of the offer or refund. +/// +/// From [`Offer::issuer`] or [`Refund::issuer`]. +/// +/// [`Offer::issuer`]: crate::offers::offer::Offer::issuer +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_issuer(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.issuer(); + let mut local_ret = crate::lightning::util::string::PrintableString { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true }; + local_ret +} + +/// Paths to the recipient originating from publicly reachable nodes. +/// +/// From [`Offer::paths`] or [`Refund::paths`]. +/// +/// [`Offer::paths`]: crate::offers::offer::Offer::paths +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_message_paths(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::CVec_BlindedPathZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.message_paths(); + let mut local_ret_clone = Vec::new(); local_ret_clone.extend_from_slice(ret); let mut ret = local_ret_clone; let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; + local_ret.into() +} + +/// The quantity of items supported. +/// +/// From [`Offer::supported_quantity`]; `None` if the invoice was created in response to a +/// [`Refund`]. +/// +/// [`Offer::supported_quantity`]: crate::offers::offer::Offer::supported_quantity +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_supported_quantity(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::offers::offer::Quantity { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supported_quantity(); + let mut local_ret = crate::lightning::offers::offer::Quantity { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true }; + local_ret +} + +/// An unpredictable series of bytes from the payer. +/// +/// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`]. +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_payer_metadata(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> 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 +} + +/// Features pertaining to requesting an invoice. +/// +/// From [`InvoiceRequest::invoice_request_features`] or [`Refund::features`]. +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_invoice_request_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::InvoiceRequestFeatures { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_request_features(); + crate::lightning::ln::features::InvoiceRequestFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::InvoiceRequestFeatures<>) as *mut _) }, is_owned: false } +} + +/// The quantity of items requested or refunded for. +/// +/// From [`InvoiceRequest::quantity`] or [`Refund::quantity`]. +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_quantity(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_u64Z { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.quantity(); + 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() }) }; + local_ret +} + +/// A possibly transient pubkey used to sign the invoice request or to send an invoice for a +/// refund in case there are no [`message_paths`]. +/// +/// [`message_paths`]: Self::message_paths +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_payer_id(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::PublicKey { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_id(); + crate::c_types::PublicKey::from_rust(&ret) +} + +/// A payer-provided note reflected back in the invoice. +/// +/// From [`InvoiceRequest::payer_note`] or [`Refund::payer_note`]. +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_payer_note(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_note(); + let mut local_ret = crate::lightning::util::string::PrintableString { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true }; + local_ret +} + +/// Duration since the Unix epoch when the invoice was created. +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_created_at(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.created_at(); + ret.as_secs() +} + +/// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore +/// should no longer be paid. +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_relative_expiry(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.relative_expiry(); + ret.as_secs() +} + +/// Whether the invoice has expired. +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_is_expired(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> bool { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired(); + ret +} + +/// SHA256 hash of the payment preimage that will be given in return for paying the invoice. +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_payment_hash(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash(); + crate::c_types::ThirtyTwoBytes { data: ret.0 } +} + +/// The minimum amount required for a successful payment of the invoice. +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_amount_msats(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_msats(); + ret +} + +/// Features pertaining to paying an invoice. +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_invoice_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::Bolt12InvoiceFeatures { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_features(); + crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::Bolt12InvoiceFeatures<>) as *mut _) }, is_owned: false } +} + +/// The public key corresponding to the key used to sign the invoice. +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_signing_pubkey(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::PublicKey { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signing_pubkey(); + crate::c_types::PublicKey::from_rust(&ret) +} + +/// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`]. +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_signature(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::SchnorrSignature { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature(); + crate::c_types::SchnorrSignature::from_rust(&ret) +} + +/// Hash that was used for signing the invoice. +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_signable_hash(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash(); + crate::c_types::ThirtyTwoBytes { data: ret } +} + +/// Verifies that the invoice was for a request or refund created using the given key. Returns +/// the associated [`PaymentId`] to use when sending the payment. +#[must_use] +#[no_mangle] +pub extern "C" fn Bolt12Invoice_verify(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice, key: &crate::lightning::ln::inbound_payment::ExpandedKey) -> crate::c_types::derived::CResult_ThirtyTwoBytesNoneZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.verify(key.get_native_ref(), secp256k1::global::SECP256K1); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.0 } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() }; + local_ret +} + +#[no_mangle] +/// Serialize the UnsignedBolt12Invoice object into a byte array which can be read by UnsignedBolt12Invoice_read +pub extern "C" fn UnsignedBolt12Invoice_write(obj: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[no_mangle] +pub(crate) extern "C" fn UnsignedBolt12Invoice_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedBolt12Invoice) }) +} +#[no_mangle] +/// Serialize the Bolt12Invoice object into a byte array which can be read by Bolt12Invoice_read +pub extern "C" fn Bolt12Invoice_write(obj: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[no_mangle] +pub(crate) extern "C" fn Bolt12Invoice_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBolt12Invoice) }) +} use lightning::offers::invoice::BlindedPayInfo as nativeBlindedPayInfoImport; pub(crate) type nativeBlindedPayInfo = nativeBlindedPayInfoImport;