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` messages.
11 //! A [`Bolt12Invoice`] can be built from a parsed [`InvoiceRequest`] for the \"offer to be paid\"
12 //! flow or from a [`Refund`] as an \"offer for money\" flow. The expected recipient of the payment
13 //! then sends the invoice to the intended payer, who will then pay it.
15 //! The payment recipient must include a [`PaymentHash`], so as to reveal the preimage upon payment
16 //! receipt, and one or more [`BlindedPath`]s for the payer to use when sending the payment.
19 //! extern crate bitcoin;
20 //! extern crate lightning;
22 //! use bitcoin::hashes::Hash;
23 //! use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
24 //! use core::convert::TryFrom;
25 //! use lightning::offers::invoice::UnsignedBolt12Invoice;
26 //! use lightning::offers::invoice_request::InvoiceRequest;
27 //! use lightning::offers::refund::Refund;
28 //! use lightning::util::ser::Writeable;
30 //! # use lightning::ln::types::PaymentHash;
31 //! # use lightning::offers::invoice::{BlindedPayInfo, ExplicitSigningPubkey, InvoiceBuilder};
32 //! # use lightning::blinded_path::BlindedPath;
34 //! # fn create_payment_paths() -> Vec<(BlindedPayInfo, BlindedPath)> { unimplemented!() }
35 //! # fn create_payment_hash() -> PaymentHash { unimplemented!() }
37 //! # fn parse_invoice_request(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::Bolt12ParseError> {
38 //! let payment_paths = create_payment_paths();
39 //! let payment_hash = create_payment_hash();
40 //! let secp_ctx = Secp256k1::new();
41 //! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32])?);
42 //! let pubkey = PublicKey::from(keys);
43 //! let wpubkey_hash = bitcoin::key::PublicKey::new(pubkey).wpubkey_hash().unwrap();
44 //! let mut buffer = Vec::new();
46 //! // Invoice for the \"offer to be paid\" flow.
47 //! # <InvoiceBuilder<ExplicitSigningPubkey>>::from(
48 //! InvoiceRequest::try_from(bytes)?
50 //! .respond_with(payment_paths, payment_hash)?
53 //! .relative_expiry(3600)
55 //! .fallback_v0_p2wpkh(&wpubkey_hash)
57 //! .sign(|message: &UnsignedBolt12Invoice|
58 //! Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
60 //! .expect(\"failed verifying signature\")
61 //! .write(&mut buffer)
66 //! # fn parse_refund(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::Bolt12ParseError> {
67 //! # let payment_paths = create_payment_paths();
68 //! # let payment_hash = create_payment_hash();
69 //! # let secp_ctx = Secp256k1::new();
70 //! # let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32])?);
71 //! # let pubkey = PublicKey::from(keys);
72 //! # let wpubkey_hash = bitcoin::key::PublicKey::new(pubkey).wpubkey_hash().unwrap();
73 //! # let mut buffer = Vec::new();
75 //! // Invoice for the \"offer for money\" flow.
76 //! # <InvoiceBuilder<ExplicitSigningPubkey>>::from(
77 //! \"lnr1qcp4256ypq\"
78 //! .parse::<Refund>()?
80 //! .respond_with(payment_paths, payment_hash, pubkey)?
83 //! .relative_expiry(3600)
85 //! .fallback_v0_p2wpkh(&wpubkey_hash)
87 //! .sign(|message: &UnsignedBolt12Invoice|
88 //! Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
90 //! .expect(\"failed verifying signature\")
91 //! .write(&mut buffer)
98 use alloc::str::FromStr;
99 use alloc::string::String;
100 use core::ffi::c_void;
101 use core::convert::Infallible;
102 use bitcoin::hashes::Hash;
103 use crate::c_types::*;
104 #[cfg(feature="no-std")]
105 use alloc::{vec::Vec, boxed::Box};
108 use lightning::offers::invoice::InvoiceWithExplicitSigningPubkeyBuilder as nativeInvoiceWithExplicitSigningPubkeyBuilderImport;
109 pub(crate) type nativeInvoiceWithExplicitSigningPubkeyBuilder = nativeInvoiceWithExplicitSigningPubkeyBuilderImport<'static, >;
111 /// Builds a [`Bolt12Invoice`] from either:
112 /// - an [`InvoiceRequest`] for the \"offer to be paid\" flow or
113 /// - a [`Refund`] for the \"offer for money\" flow.
115 /// See [module-level documentation] for usage.
117 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
118 /// [`Refund`]: crate::offers::refund::Refund
119 /// [module-level documentation]: self
122 pub struct InvoiceWithExplicitSigningPubkeyBuilder {
123 /// A pointer to the opaque Rust object.
125 /// Nearly everywhere, inner must be non-null, however in places where
126 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
127 pub inner: *mut nativeInvoiceWithExplicitSigningPubkeyBuilder,
128 /// Indicates that this is the only struct which contains the same pointer.
130 /// Rust functions which take ownership of an object provided via an argument require
131 /// this to be true and invalidate the object pointed to by inner.
135 impl Drop for InvoiceWithExplicitSigningPubkeyBuilder {
137 if self.is_owned && !<*mut nativeInvoiceWithExplicitSigningPubkeyBuilder>::is_null(self.inner) {
138 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
142 /// Frees any resources used by the InvoiceWithExplicitSigningPubkeyBuilder, if is_owned is set and inner is non-NULL.
144 pub extern "C" fn InvoiceWithExplicitSigningPubkeyBuilder_free(this_obj: InvoiceWithExplicitSigningPubkeyBuilder) { }
146 /// Used only if an object of this type is returned as a trait impl by a method
147 pub(crate) extern "C" fn InvoiceWithExplicitSigningPubkeyBuilder_free_void(this_ptr: *mut c_void) {
148 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInvoiceWithExplicitSigningPubkeyBuilder) };
151 impl InvoiceWithExplicitSigningPubkeyBuilder {
152 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceWithExplicitSigningPubkeyBuilder {
153 unsafe { &*ObjOps::untweak_ptr(self.inner) }
155 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceWithExplicitSigningPubkeyBuilder {
156 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
158 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
159 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceWithExplicitSigningPubkeyBuilder {
160 assert!(self.is_owned);
161 let ret = ObjOps::untweak_ptr(self.inner);
162 self.inner = core::ptr::null_mut();
167 use lightning::offers::invoice::InvoiceWithDerivedSigningPubkeyBuilder as nativeInvoiceWithDerivedSigningPubkeyBuilderImport;
168 pub(crate) type nativeInvoiceWithDerivedSigningPubkeyBuilder = nativeInvoiceWithDerivedSigningPubkeyBuilderImport<'static, >;
170 /// Builds a [`Bolt12Invoice`] from either:
171 /// - an [`InvoiceRequest`] for the \"offer to be paid\" flow or
172 /// - a [`Refund`] for the \"offer for money\" flow.
174 /// See [module-level documentation] for usage.
176 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
177 /// [`Refund`]: crate::offers::refund::Refund
178 /// [module-level documentation]: self
181 pub struct InvoiceWithDerivedSigningPubkeyBuilder {
182 /// A pointer to the opaque Rust object.
184 /// Nearly everywhere, inner must be non-null, however in places where
185 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
186 pub inner: *mut nativeInvoiceWithDerivedSigningPubkeyBuilder,
187 /// Indicates that this is the only struct which contains the same pointer.
189 /// Rust functions which take ownership of an object provided via an argument require
190 /// this to be true and invalidate the object pointed to by inner.
194 impl Drop for InvoiceWithDerivedSigningPubkeyBuilder {
196 if self.is_owned && !<*mut nativeInvoiceWithDerivedSigningPubkeyBuilder>::is_null(self.inner) {
197 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
201 /// Frees any resources used by the InvoiceWithDerivedSigningPubkeyBuilder, if is_owned is set and inner is non-NULL.
203 pub extern "C" fn InvoiceWithDerivedSigningPubkeyBuilder_free(this_obj: InvoiceWithDerivedSigningPubkeyBuilder) { }
205 /// Used only if an object of this type is returned as a trait impl by a method
206 pub(crate) extern "C" fn InvoiceWithDerivedSigningPubkeyBuilder_free_void(this_ptr: *mut c_void) {
207 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInvoiceWithDerivedSigningPubkeyBuilder) };
210 impl InvoiceWithDerivedSigningPubkeyBuilder {
211 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceWithDerivedSigningPubkeyBuilder {
212 unsafe { &*ObjOps::untweak_ptr(self.inner) }
214 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceWithDerivedSigningPubkeyBuilder {
215 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
217 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
218 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceWithDerivedSigningPubkeyBuilder {
219 assert!(self.is_owned);
220 let ret = ObjOps::untweak_ptr(self.inner);
221 self.inner = core::ptr::null_mut();
225 /// Builds an unsigned [`Bolt12Invoice`] after checking for valid semantics. It can be signed by
226 /// [`UnsignedBolt12Invoice::sign`].
229 pub extern "C" fn InvoiceWithExplicitSigningPubkeyBuilder_build(mut this_arg: crate::lightning::offers::invoice::InvoiceWithExplicitSigningPubkeyBuilder) -> crate::c_types::derived::CResult_UnsignedBolt12InvoiceBolt12SemanticErrorZ {
230 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).build();
231 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::invoice::UnsignedBolt12Invoice { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() };
235 /// Sets the [`Bolt12Invoice::relative_expiry`] as seconds since [`Bolt12Invoice::created_at`].
236 /// Any expiry that has already passed is valid and can be checked for using
237 /// [`Bolt12Invoice::is_expired`].
239 /// Successive calls to this method will override the previous setting.
242 pub extern "C" fn InvoiceWithExplicitSigningPubkeyBuilder_relative_expiry(mut this_arg: crate::lightning::offers::invoice::InvoiceWithExplicitSigningPubkeyBuilder, mut relative_expiry_secs: u32) {
243 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).relative_expiry(relative_expiry_secs);
247 /// Adds a P2WSH address to [`Bolt12Invoice::fallbacks`].
249 /// Successive calls to this method will add another address. Caller is responsible for not
250 /// adding duplicate addresses and only calling if capable of receiving to P2WSH addresses.
253 pub extern "C" fn InvoiceWithExplicitSigningPubkeyBuilder_fallback_v0_p2wsh(mut this_arg: crate::lightning::offers::invoice::InvoiceWithExplicitSigningPubkeyBuilder, script_hash: *const [u8; 32]) {
254 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).fallback_v0_p2wsh(&bitcoin::hash_types::WScriptHash::from_raw_hash(bitcoin::hashes::Hash::from_byte_array(unsafe { *script_hash }.clone())));
258 /// Adds a P2WPKH address to [`Bolt12Invoice::fallbacks`].
260 /// Successive calls to this method will add another address. Caller is responsible for not
261 /// adding duplicate addresses and only calling if capable of receiving to P2WPKH addresses.
264 pub extern "C" fn InvoiceWithExplicitSigningPubkeyBuilder_fallback_v0_p2wpkh(mut this_arg: crate::lightning::offers::invoice::InvoiceWithExplicitSigningPubkeyBuilder, pubkey_hash: *const [u8; 20]) {
265 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).fallback_v0_p2wpkh(&bitcoin::hash_types::WPubkeyHash::from_raw_hash(bitcoin::hashes::Hash::from_byte_array(unsafe { *pubkey_hash }.clone())));
269 /// Adds a P2TR address to [`Bolt12Invoice::fallbacks`].
271 /// Successive calls to this method will add another address. Caller is responsible for not
272 /// adding duplicate addresses and only calling if capable of receiving to P2TR addresses.
275 pub extern "C" fn InvoiceWithExplicitSigningPubkeyBuilder_fallback_v1_p2tr_tweaked(mut this_arg: crate::lightning::offers::invoice::InvoiceWithExplicitSigningPubkeyBuilder, mut output_key: crate::c_types::TweakedPublicKey) {
276 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).fallback_v1_p2tr_tweaked(&output_key.into_rust());
280 /// Sets [`Bolt12Invoice::invoice_features`] to indicate MPP may be used. Otherwise, MPP is
284 pub extern "C" fn InvoiceWithExplicitSigningPubkeyBuilder_allow_mpp(mut this_arg: crate::lightning::offers::invoice::InvoiceWithExplicitSigningPubkeyBuilder) {
285 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).allow_mpp();
289 /// Builds a signed [`Bolt12Invoice`] after checking for valid semantics.
292 pub extern "C" fn InvoiceWithDerivedSigningPubkeyBuilder_build_and_sign(mut this_arg: crate::lightning::offers::invoice::InvoiceWithDerivedSigningPubkeyBuilder) -> crate::c_types::derived::CResult_Bolt12InvoiceBolt12SemanticErrorZ {
293 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).build_and_sign(secp256k1::global::SECP256K1);
294 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::invoice::Bolt12Invoice { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() };
298 /// Sets the [`Bolt12Invoice::relative_expiry`] as seconds since [`Bolt12Invoice::created_at`].
299 /// Any expiry that has already passed is valid and can be checked for using
300 /// [`Bolt12Invoice::is_expired`].
302 /// Successive calls to this method will override the previous setting.
305 pub extern "C" fn InvoiceWithDerivedSigningPubkeyBuilder_relative_expiry(mut this_arg: crate::lightning::offers::invoice::InvoiceWithDerivedSigningPubkeyBuilder, mut relative_expiry_secs: u32) {
306 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).relative_expiry(relative_expiry_secs);
310 /// Adds a P2WSH address to [`Bolt12Invoice::fallbacks`].
312 /// Successive calls to this method will add another address. Caller is responsible for not
313 /// adding duplicate addresses and only calling if capable of receiving to P2WSH addresses.
316 pub extern "C" fn InvoiceWithDerivedSigningPubkeyBuilder_fallback_v0_p2wsh(mut this_arg: crate::lightning::offers::invoice::InvoiceWithDerivedSigningPubkeyBuilder, script_hash: *const [u8; 32]) {
317 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).fallback_v0_p2wsh(&bitcoin::hash_types::WScriptHash::from_raw_hash(bitcoin::hashes::Hash::from_byte_array(unsafe { *script_hash }.clone())));
321 /// Adds a P2WPKH address to [`Bolt12Invoice::fallbacks`].
323 /// Successive calls to this method will add another address. Caller is responsible for not
324 /// adding duplicate addresses and only calling if capable of receiving to P2WPKH addresses.
327 pub extern "C" fn InvoiceWithDerivedSigningPubkeyBuilder_fallback_v0_p2wpkh(mut this_arg: crate::lightning::offers::invoice::InvoiceWithDerivedSigningPubkeyBuilder, pubkey_hash: *const [u8; 20]) {
328 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).fallback_v0_p2wpkh(&bitcoin::hash_types::WPubkeyHash::from_raw_hash(bitcoin::hashes::Hash::from_byte_array(unsafe { *pubkey_hash }.clone())));
332 /// Adds a P2TR address to [`Bolt12Invoice::fallbacks`].
334 /// Successive calls to this method will add another address. Caller is responsible for not
335 /// adding duplicate addresses and only calling if capable of receiving to P2TR addresses.
338 pub extern "C" fn InvoiceWithDerivedSigningPubkeyBuilder_fallback_v1_p2tr_tweaked(mut this_arg: crate::lightning::offers::invoice::InvoiceWithDerivedSigningPubkeyBuilder, mut output_key: crate::c_types::TweakedPublicKey) {
339 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).fallback_v1_p2tr_tweaked(&output_key.into_rust());
343 /// Sets [`Bolt12Invoice::invoice_features`] to indicate MPP may be used. Otherwise, MPP is
347 pub extern "C" fn InvoiceWithDerivedSigningPubkeyBuilder_allow_mpp(mut this_arg: crate::lightning::offers::invoice::InvoiceWithDerivedSigningPubkeyBuilder) {
348 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).allow_mpp();
353 use lightning::offers::invoice::UnsignedBolt12Invoice as nativeUnsignedBolt12InvoiceImport;
354 pub(crate) type nativeUnsignedBolt12Invoice = nativeUnsignedBolt12InvoiceImport;
356 /// A semantically valid [`Bolt12Invoice`] that hasn't been signed.
360 /// This is serialized as a TLV stream, which includes TLV records from the originating message. As
361 /// such, it may include unknown, odd TLV records.
364 pub struct UnsignedBolt12Invoice {
365 /// A pointer to the opaque Rust object.
367 /// Nearly everywhere, inner must be non-null, however in places where
368 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
369 pub inner: *mut nativeUnsignedBolt12Invoice,
370 /// Indicates that this is the only struct which contains the same pointer.
372 /// Rust functions which take ownership of an object provided via an argument require
373 /// this to be true and invalidate the object pointed to by inner.
377 impl Drop for UnsignedBolt12Invoice {
379 if self.is_owned && !<*mut nativeUnsignedBolt12Invoice>::is_null(self.inner) {
380 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
384 /// Frees any resources used by the UnsignedBolt12Invoice, if is_owned is set and inner is non-NULL.
386 pub extern "C" fn UnsignedBolt12Invoice_free(this_obj: UnsignedBolt12Invoice) { }
388 /// Used only if an object of this type is returned as a trait impl by a method
389 pub(crate) extern "C" fn UnsignedBolt12Invoice_free_void(this_ptr: *mut c_void) {
390 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUnsignedBolt12Invoice) };
393 impl UnsignedBolt12Invoice {
394 pub(crate) fn get_native_ref(&self) -> &'static nativeUnsignedBolt12Invoice {
395 unsafe { &*ObjOps::untweak_ptr(self.inner) }
397 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUnsignedBolt12Invoice {
398 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
400 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
401 pub(crate) fn take_inner(mut self) -> *mut nativeUnsignedBolt12Invoice {
402 assert!(self.is_owned);
403 let ret = ObjOps::untweak_ptr(self.inner);
404 self.inner = core::ptr::null_mut();
408 /// A function for signing an [`UnsignedBolt12Invoice`].
410 pub struct SignBolt12InvoiceFn {
411 /// An opaque pointer which is passed to your function implementations as an argument.
412 /// This has no meaning in the LDK, and can be NULL or any other value.
413 pub this_arg: *mut c_void,
414 /// Signs a [`TaggedHash`] computed over the merkle root of `message`'s TLV stream.
415 pub sign_invoice: extern "C" fn (this_arg: *const c_void, message: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ,
416 /// Frees any resources associated with this object given its this_arg pointer.
417 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
418 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
420 unsafe impl Send for SignBolt12InvoiceFn {}
421 unsafe impl Sync for SignBolt12InvoiceFn {}
423 pub(crate) fn SignBolt12InvoiceFn_clone_fields(orig: &SignBolt12InvoiceFn) -> SignBolt12InvoiceFn {
424 SignBolt12InvoiceFn {
425 this_arg: orig.this_arg,
426 sign_invoice: Clone::clone(&orig.sign_invoice),
427 free: Clone::clone(&orig.free),
431 use lightning::offers::invoice::SignBolt12InvoiceFn as rustSignBolt12InvoiceFn;
432 impl rustSignBolt12InvoiceFn for SignBolt12InvoiceFn {
433 fn sign_invoice(&self, mut message: &lightning::offers::invoice::UnsignedBolt12Invoice) -> Result<bitcoin::secp256k1::schnorr::Signature, ()> {
434 let mut ret = (self.sign_invoice)(self.this_arg, &crate::lightning::offers::invoice::UnsignedBolt12Invoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((message as *const lightning::offers::invoice::UnsignedBolt12Invoice<>) as *mut _) }, is_owned: false });
435 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
440 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
441 // directly as a Deref trait in higher-level structs:
442 impl core::ops::Deref for SignBolt12InvoiceFn {
444 fn deref(&self) -> &Self {
448 impl core::ops::DerefMut for SignBolt12InvoiceFn {
449 fn deref_mut(&mut self) -> &mut Self {
453 /// Calls the free function if one is set
455 pub extern "C" fn SignBolt12InvoiceFn_free(this_ptr: SignBolt12InvoiceFn) { }
456 impl Drop for SignBolt12InvoiceFn {
458 if let Some(f) = self.free {
463 /// Returns the [`TaggedHash`] of the invoice to sign.
466 pub extern "C" fn UnsignedBolt12Invoice_tagged_hash(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::offers::merkle::TaggedHash {
467 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tagged_hash();
468 crate::lightning::offers::merkle::TaggedHash { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::offers::merkle::TaggedHash<>) as *mut _) }, is_owned: false }
472 use lightning::offers::invoice::Bolt12Invoice as nativeBolt12InvoiceImport;
473 pub(crate) type nativeBolt12Invoice = nativeBolt12InvoiceImport;
475 /// A `Bolt12Invoice` is a payment request, typically corresponding to an [`Offer`] or a [`Refund`].
477 /// An invoice may be sent in response to an [`InvoiceRequest`] in the case of an offer or sent
478 /// directly after scanning a refund. It includes all the information needed to pay a recipient.
480 /// [`Offer`]: crate::offers::offer::Offer
481 /// [`Refund`]: crate::offers::refund::Refund
482 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
485 pub struct Bolt12Invoice {
486 /// A pointer to the opaque Rust object.
488 /// Nearly everywhere, inner must be non-null, however in places where
489 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
490 pub inner: *mut nativeBolt12Invoice,
491 /// Indicates that this is the only struct which contains the same pointer.
493 /// Rust functions which take ownership of an object provided via an argument require
494 /// this to be true and invalidate the object pointed to by inner.
498 impl Drop for Bolt12Invoice {
500 if self.is_owned && !<*mut nativeBolt12Invoice>::is_null(self.inner) {
501 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
505 /// Frees any resources used by the Bolt12Invoice, if is_owned is set and inner is non-NULL.
507 pub extern "C" fn Bolt12Invoice_free(this_obj: Bolt12Invoice) { }
509 /// Used only if an object of this type is returned as a trait impl by a method
510 pub(crate) extern "C" fn Bolt12Invoice_free_void(this_ptr: *mut c_void) {
511 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt12Invoice) };
515 pub(crate) fn get_native_ref(&self) -> &'static nativeBolt12Invoice {
516 unsafe { &*ObjOps::untweak_ptr(self.inner) }
518 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt12Invoice {
519 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
521 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
522 pub(crate) fn take_inner(mut self) -> *mut nativeBolt12Invoice {
523 assert!(self.is_owned);
524 let ret = ObjOps::untweak_ptr(self.inner);
525 self.inner = core::ptr::null_mut();
529 impl Clone for Bolt12Invoice {
530 fn clone(&self) -> Self {
532 inner: if <*mut nativeBolt12Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
533 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
539 /// Used only if an object of this type is returned as a trait impl by a method
540 pub(crate) extern "C" fn Bolt12Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
541 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt12Invoice)).clone() })) as *mut c_void
544 /// Creates a copy of the Bolt12Invoice
545 pub extern "C" fn Bolt12Invoice_clone(orig: &Bolt12Invoice) -> Bolt12Invoice {
548 /// Get a string which allows debug introspection of a Bolt12Invoice object
549 pub extern "C" fn Bolt12Invoice_debug_str_void(o: *const c_void) -> Str {
550 alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::invoice::Bolt12Invoice }).into()}
551 /// The chains that may be used when paying a requested invoice.
553 /// From [`Offer::chains`]; `None` if the invoice was created in response to a [`Refund`].
555 /// [`Offer::chains`]: crate::offers::offer::Offer::chains
558 pub extern "C" fn UnsignedBolt12Invoice_offer_chains(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ {
559 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_chains();
560 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.as_ref() } }); }; local_ret_0.into() }) };
564 /// The chain that must be used when paying the invoice; selected from [`offer_chains`] if the
565 /// invoice originated from an offer.
567 /// From [`InvoiceRequest::chain`] or [`Refund::chain`].
569 /// [`offer_chains`]: Self::offer_chains
570 /// [`InvoiceRequest::chain`]: crate::offers::invoice_request::InvoiceRequest::chain
573 pub extern "C" fn UnsignedBolt12Invoice_chain(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
574 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.chain();
575 crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() }
578 /// Opaque bytes set by the originating [`Offer`].
580 /// From [`Offer::metadata`]; `None` if the invoice was created in response to a [`Refund`] or
581 /// if the [`Offer`] did not set it.
583 /// [`Offer`]: crate::offers::offer::Offer
584 /// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
587 pub extern "C" fn UnsignedBolt12Invoice_metadata(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
588 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.metadata();
589 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<Enum> 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() }) };
593 /// The minimum amount required for a successful payment of a single item.
595 /// From [`Offer::amount`]; `None` if the invoice was created in response to a [`Refund`] or if
596 /// the [`Offer`] did not set it.
598 /// [`Offer`]: crate::offers::offer::Offer
599 /// [`Offer::amount`]: crate::offers::offer::Offer::amount
602 pub extern "C" fn UnsignedBolt12Invoice_amount(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_AmountZ {
603 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount();
604 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_AmountZ::None } else { crate::c_types::derived::COption_AmountZ::Some( { crate::lightning::offers::offer::Amount::native_into(ret.unwrap()) }) };
608 /// Features pertaining to the originating [`Offer`].
610 /// From [`Offer::offer_features`]; `None` if the invoice was created in response to a
613 /// [`Offer`]: crate::offers::offer::Offer
614 /// [`Offer::offer_features`]: crate::offers::offer::Offer::offer_features
616 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
619 pub extern "C" fn UnsignedBolt12Invoice_offer_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::OfferFeatures {
620 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_features();
621 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 };
625 /// A complete description of the purpose of the originating offer or refund.
627 /// From [`Offer::description`] or [`Refund::description`].
629 /// [`Offer::description`]: crate::offers::offer::Offer::description
631 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
634 pub extern "C" fn UnsignedBolt12Invoice_description(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString {
635 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
636 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 };
640 /// Duration since the Unix epoch when an invoice should no longer be requested.
642 /// From [`Offer::absolute_expiry`] or [`Refund::absolute_expiry`].
644 /// [`Offer::absolute_expiry`]: crate::offers::offer::Offer::absolute_expiry
647 pub extern "C" fn UnsignedBolt12Invoice_absolute_expiry(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_u64Z {
648 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.absolute_expiry();
649 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() }) };
653 /// The issuer of the offer or refund.
655 /// From [`Offer::issuer`] or [`Refund::issuer`].
657 /// [`Offer::issuer`]: crate::offers::offer::Offer::issuer
659 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
662 pub extern "C" fn UnsignedBolt12Invoice_issuer(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString {
663 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.issuer();
664 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 };
668 /// Paths to the recipient originating from publicly reachable nodes.
670 /// From [`Offer::paths`] or [`Refund::paths`].
672 /// [`Offer::paths`]: crate::offers::offer::Offer::paths
675 pub extern "C" fn UnsignedBolt12Invoice_message_paths(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CVec_BlindedPathZ {
676 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.message_paths();
677 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 } }); };
681 /// The quantity of items supported.
683 /// From [`Offer::supported_quantity`]; `None` if the invoice was created in response to a
686 /// [`Offer::supported_quantity`]: crate::offers::offer::Offer::supported_quantity
689 pub extern "C" fn UnsignedBolt12Invoice_supported_quantity(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_QuantityZ {
690 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supported_quantity();
691 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_QuantityZ::None } else { crate::c_types::derived::COption_QuantityZ::Some( { crate::lightning::offers::offer::Quantity::native_into(ret.unwrap()) }) };
695 /// An unpredictable series of bytes from the payer.
697 /// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
700 pub extern "C" fn UnsignedBolt12Invoice_payer_metadata(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::u8slice {
701 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_metadata();
702 let mut local_ret = crate::c_types::u8slice::from_slice(ret);
706 /// Features pertaining to requesting an invoice.
708 /// From [`InvoiceRequest::invoice_request_features`] or [`Refund::features`].
711 pub extern "C" fn UnsignedBolt12Invoice_invoice_request_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::InvoiceRequestFeatures {
712 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_request_features();
713 crate::lightning::ln::features::InvoiceRequestFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::InvoiceRequestFeatures<>) as *mut _) }, is_owned: false }
716 /// The quantity of items requested or refunded for.
718 /// From [`InvoiceRequest::quantity`] or [`Refund::quantity`].
721 pub extern "C" fn UnsignedBolt12Invoice_quantity(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_u64Z {
722 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.quantity();
723 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() }) };
727 /// A possibly transient pubkey used to sign the invoice request or to send an invoice for a
728 /// refund in case there are no [`message_paths`].
730 /// [`message_paths`]: Self::message_paths
733 pub extern "C" fn UnsignedBolt12Invoice_payer_id(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::PublicKey {
734 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_id();
735 crate::c_types::PublicKey::from_rust(&ret)
738 /// A payer-provided note reflected back in the invoice.
740 /// From [`InvoiceRequest::payer_note`] or [`Refund::payer_note`].
742 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
745 pub extern "C" fn UnsignedBolt12Invoice_payer_note(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString {
746 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_note();
747 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 };
751 /// Duration since the Unix epoch when the invoice was created.
754 pub extern "C" fn UnsignedBolt12Invoice_created_at(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 {
755 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.created_at();
759 /// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
760 /// should no longer be paid.
763 pub extern "C" fn UnsignedBolt12Invoice_relative_expiry(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 {
764 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.relative_expiry();
768 /// Whether the invoice has expired.
771 pub extern "C" fn UnsignedBolt12Invoice_is_expired(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> bool {
772 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
776 /// SHA256 hash of the payment preimage that will be given in return for paying the invoice.
779 pub extern "C" fn UnsignedBolt12Invoice_payment_hash(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
780 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
781 crate::c_types::ThirtyTwoBytes { data: ret.0 }
784 /// The minimum amount required for a successful payment of the invoice.
787 pub extern "C" fn UnsignedBolt12Invoice_amount_msats(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 {
788 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_msats();
792 /// Features pertaining to paying an invoice.
795 pub extern "C" fn UnsignedBolt12Invoice_invoice_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::Bolt12InvoiceFeatures {
796 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_features();
797 crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::Bolt12InvoiceFeatures<>) as *mut _) }, is_owned: false }
800 /// The public key corresponding to the key used to sign the invoice.
803 pub extern "C" fn UnsignedBolt12Invoice_signing_pubkey(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::PublicKey {
804 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signing_pubkey();
805 crate::c_types::PublicKey::from_rust(&ret)
808 /// The chains that may be used when paying a requested invoice.
810 /// From [`Offer::chains`]; `None` if the invoice was created in response to a [`Refund`].
812 /// [`Offer::chains`]: crate::offers::offer::Offer::chains
815 pub extern "C" fn Bolt12Invoice_offer_chains(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ {
816 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_chains();
817 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.as_ref() } }); }; local_ret_0.into() }) };
821 /// The chain that must be used when paying the invoice; selected from [`offer_chains`] if the
822 /// invoice originated from an offer.
824 /// From [`InvoiceRequest::chain`] or [`Refund::chain`].
826 /// [`offer_chains`]: Self::offer_chains
827 /// [`InvoiceRequest::chain`]: crate::offers::invoice_request::InvoiceRequest::chain
830 pub extern "C" fn Bolt12Invoice_chain(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
831 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.chain();
832 crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() }
835 /// Opaque bytes set by the originating [`Offer`].
837 /// From [`Offer::metadata`]; `None` if the invoice was created in response to a [`Refund`] or
838 /// if the [`Offer`] did not set it.
840 /// [`Offer`]: crate::offers::offer::Offer
841 /// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
844 pub extern "C" fn Bolt12Invoice_metadata(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
845 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.metadata();
846 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<Enum> 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() }) };
850 /// The minimum amount required for a successful payment of a single item.
852 /// From [`Offer::amount`]; `None` if the invoice was created in response to a [`Refund`] or if
853 /// the [`Offer`] did not set it.
855 /// [`Offer`]: crate::offers::offer::Offer
856 /// [`Offer::amount`]: crate::offers::offer::Offer::amount
859 pub extern "C" fn Bolt12Invoice_amount(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_AmountZ {
860 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount();
861 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_AmountZ::None } else { crate::c_types::derived::COption_AmountZ::Some( { crate::lightning::offers::offer::Amount::native_into(ret.unwrap()) }) };
865 /// Features pertaining to the originating [`Offer`].
867 /// From [`Offer::offer_features`]; `None` if the invoice was created in response to a
870 /// [`Offer`]: crate::offers::offer::Offer
871 /// [`Offer::offer_features`]: crate::offers::offer::Offer::offer_features
873 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
876 pub extern "C" fn Bolt12Invoice_offer_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::OfferFeatures {
877 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_features();
878 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 };
882 /// A complete description of the purpose of the originating offer or refund.
884 /// From [`Offer::description`] or [`Refund::description`].
886 /// [`Offer::description`]: crate::offers::offer::Offer::description
888 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
891 pub extern "C" fn Bolt12Invoice_description(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString {
892 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
893 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 };
897 /// Duration since the Unix epoch when an invoice should no longer be requested.
899 /// From [`Offer::absolute_expiry`] or [`Refund::absolute_expiry`].
901 /// [`Offer::absolute_expiry`]: crate::offers::offer::Offer::absolute_expiry
904 pub extern "C" fn Bolt12Invoice_absolute_expiry(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_u64Z {
905 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.absolute_expiry();
906 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() }) };
910 /// The issuer of the offer or refund.
912 /// From [`Offer::issuer`] or [`Refund::issuer`].
914 /// [`Offer::issuer`]: crate::offers::offer::Offer::issuer
916 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
919 pub extern "C" fn Bolt12Invoice_issuer(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString {
920 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.issuer();
921 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 };
925 /// Paths to the recipient originating from publicly reachable nodes.
927 /// From [`Offer::paths`] or [`Refund::paths`].
929 /// [`Offer::paths`]: crate::offers::offer::Offer::paths
932 pub extern "C" fn Bolt12Invoice_message_paths(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::CVec_BlindedPathZ {
933 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.message_paths();
934 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 } }); };
938 /// The quantity of items supported.
940 /// From [`Offer::supported_quantity`]; `None` if the invoice was created in response to a
943 /// [`Offer::supported_quantity`]: crate::offers::offer::Offer::supported_quantity
946 pub extern "C" fn Bolt12Invoice_supported_quantity(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_QuantityZ {
947 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supported_quantity();
948 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_QuantityZ::None } else { crate::c_types::derived::COption_QuantityZ::Some( { crate::lightning::offers::offer::Quantity::native_into(ret.unwrap()) }) };
952 /// An unpredictable series of bytes from the payer.
954 /// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
957 pub extern "C" fn Bolt12Invoice_payer_metadata(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::u8slice {
958 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_metadata();
959 let mut local_ret = crate::c_types::u8slice::from_slice(ret);
963 /// Features pertaining to requesting an invoice.
965 /// From [`InvoiceRequest::invoice_request_features`] or [`Refund::features`].
968 pub extern "C" fn Bolt12Invoice_invoice_request_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::InvoiceRequestFeatures {
969 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_request_features();
970 crate::lightning::ln::features::InvoiceRequestFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::InvoiceRequestFeatures<>) as *mut _) }, is_owned: false }
973 /// The quantity of items requested or refunded for.
975 /// From [`InvoiceRequest::quantity`] or [`Refund::quantity`].
978 pub extern "C" fn Bolt12Invoice_quantity(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_u64Z {
979 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.quantity();
980 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() }) };
984 /// A possibly transient pubkey used to sign the invoice request or to send an invoice for a
985 /// refund in case there are no [`message_paths`].
987 /// [`message_paths`]: Self::message_paths
990 pub extern "C" fn Bolt12Invoice_payer_id(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::PublicKey {
991 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_id();
992 crate::c_types::PublicKey::from_rust(&ret)
995 /// A payer-provided note reflected back in the invoice.
997 /// From [`InvoiceRequest::payer_note`] or [`Refund::payer_note`].
999 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1002 pub extern "C" fn Bolt12Invoice_payer_note(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString {
1003 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_note();
1004 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 };
1008 /// Duration since the Unix epoch when the invoice was created.
1011 pub extern "C" fn Bolt12Invoice_created_at(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 {
1012 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.created_at();
1016 /// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
1017 /// should no longer be paid.
1020 pub extern "C" fn Bolt12Invoice_relative_expiry(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 {
1021 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.relative_expiry();
1025 /// Whether the invoice has expired.
1028 pub extern "C" fn Bolt12Invoice_is_expired(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> bool {
1029 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
1033 /// SHA256 hash of the payment preimage that will be given in return for paying the invoice.
1036 pub extern "C" fn Bolt12Invoice_payment_hash(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
1037 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
1038 crate::c_types::ThirtyTwoBytes { data: ret.0 }
1041 /// The minimum amount required for a successful payment of the invoice.
1044 pub extern "C" fn Bolt12Invoice_amount_msats(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 {
1045 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_msats();
1049 /// Features pertaining to paying an invoice.
1052 pub extern "C" fn Bolt12Invoice_invoice_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::Bolt12InvoiceFeatures {
1053 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_features();
1054 crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::Bolt12InvoiceFeatures<>) as *mut _) }, is_owned: false }
1057 /// The public key corresponding to the key used to sign the invoice.
1060 pub extern "C" fn Bolt12Invoice_signing_pubkey(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::PublicKey {
1061 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signing_pubkey();
1062 crate::c_types::PublicKey::from_rust(&ret)
1065 /// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
1068 pub extern "C" fn Bolt12Invoice_signature(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::SchnorrSignature {
1069 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
1070 crate::c_types::SchnorrSignature::from_rust(&ret)
1073 /// Hash that was used for signing the invoice.
1076 pub extern "C" fn Bolt12Invoice_signable_hash(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
1077 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
1078 crate::c_types::ThirtyTwoBytes { data: ret }
1081 /// Verifies that the invoice was for a request or refund created using the given key. Returns
1082 /// the associated [`PaymentId`] to use when sending the payment.
1085 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 {
1086 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.verify(key.get_native_ref(), secp256k1::global::SECP256K1);
1087 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() };
1091 /// Generates a non-cryptographic 64-bit hash of the Bolt12Invoice.
1093 pub extern "C" fn Bolt12Invoice_hash(o: &Bolt12Invoice) -> u64 {
1094 if o.inner.is_null() { return 0; }
1095 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1096 #[allow(deprecated)]
1097 let mut hasher = core::hash::SipHasher::new();
1098 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1099 core::hash::Hasher::finish(&hasher)
1102 /// Serialize the UnsignedBolt12Invoice object into a byte array which can be read by UnsignedBolt12Invoice_read
1103 pub extern "C" fn UnsignedBolt12Invoice_write(obj: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CVec_u8Z {
1104 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1107 pub(crate) extern "C" fn UnsignedBolt12Invoice_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1108 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedBolt12Invoice) })
1111 /// Serialize the Bolt12Invoice object into a byte array which can be read by Bolt12Invoice_read
1112 pub extern "C" fn Bolt12Invoice_write(obj: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::CVec_u8Z {
1113 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1116 pub(crate) extern "C" fn Bolt12Invoice_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1117 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBolt12Invoice) })
1120 use lightning::offers::invoice::BlindedPayInfo as nativeBlindedPayInfoImport;
1121 pub(crate) type nativeBlindedPayInfo = nativeBlindedPayInfoImport;
1123 /// Information needed to route a payment across a [`BlindedPath`].
1126 pub struct BlindedPayInfo {
1127 /// A pointer to the opaque Rust object.
1129 /// Nearly everywhere, inner must be non-null, however in places where
1130 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1131 pub inner: *mut nativeBlindedPayInfo,
1132 /// Indicates that this is the only struct which contains the same pointer.
1134 /// Rust functions which take ownership of an object provided via an argument require
1135 /// this to be true and invalidate the object pointed to by inner.
1139 impl Drop for BlindedPayInfo {
1140 fn drop(&mut self) {
1141 if self.is_owned && !<*mut nativeBlindedPayInfo>::is_null(self.inner) {
1142 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1146 /// Frees any resources used by the BlindedPayInfo, if is_owned is set and inner is non-NULL.
1148 pub extern "C" fn BlindedPayInfo_free(this_obj: BlindedPayInfo) { }
1150 /// Used only if an object of this type is returned as a trait impl by a method
1151 pub(crate) extern "C" fn BlindedPayInfo_free_void(this_ptr: *mut c_void) {
1152 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedPayInfo) };
1155 impl BlindedPayInfo {
1156 pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedPayInfo {
1157 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1159 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedPayInfo {
1160 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1162 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1163 pub(crate) fn take_inner(mut self) -> *mut nativeBlindedPayInfo {
1164 assert!(self.is_owned);
1165 let ret = ObjOps::untweak_ptr(self.inner);
1166 self.inner = core::ptr::null_mut();
1170 /// Base fee charged (in millisatoshi) for the entire blinded path.
1172 pub extern "C" fn BlindedPayInfo_get_fee_base_msat(this_ptr: &BlindedPayInfo) -> u32 {
1173 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
1176 /// Base fee charged (in millisatoshi) for the entire blinded path.
1178 pub extern "C" fn BlindedPayInfo_set_fee_base_msat(this_ptr: &mut BlindedPayInfo, mut val: u32) {
1179 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
1181 /// Liquidity fee charged (in millionths of the amount transferred) for the entire blinded path
1182 /// (i.e., 10,000 is 1%).
1184 pub extern "C" fn BlindedPayInfo_get_fee_proportional_millionths(this_ptr: &BlindedPayInfo) -> u32 {
1185 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
1188 /// Liquidity fee charged (in millionths of the amount transferred) for the entire blinded path
1189 /// (i.e., 10,000 is 1%).
1191 pub extern "C" fn BlindedPayInfo_set_fee_proportional_millionths(this_ptr: &mut BlindedPayInfo, mut val: u32) {
1192 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
1194 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for the entire blinded
1197 pub extern "C" fn BlindedPayInfo_get_cltv_expiry_delta(this_ptr: &BlindedPayInfo) -> u16 {
1198 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
1201 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for the entire blinded
1204 pub extern "C" fn BlindedPayInfo_set_cltv_expiry_delta(this_ptr: &mut BlindedPayInfo, mut val: u16) {
1205 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
1207 /// The minimum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
1208 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
1209 /// seen by the recipient.
1211 pub extern "C" fn BlindedPayInfo_get_htlc_minimum_msat(this_ptr: &BlindedPayInfo) -> u64 {
1212 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
1215 /// The minimum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
1216 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
1217 /// seen by the recipient.
1219 pub extern "C" fn BlindedPayInfo_set_htlc_minimum_msat(this_ptr: &mut BlindedPayInfo, mut val: u64) {
1220 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
1222 /// The maximum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
1223 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
1224 /// seen by the recipient.
1226 pub extern "C" fn BlindedPayInfo_get_htlc_maximum_msat(this_ptr: &BlindedPayInfo) -> u64 {
1227 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
1230 /// The maximum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
1231 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
1232 /// seen by the recipient.
1234 pub extern "C" fn BlindedPayInfo_set_htlc_maximum_msat(this_ptr: &mut BlindedPayInfo, mut val: u64) {
1235 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val;
1237 /// Features set in `encrypted_data_tlv` for the `encrypted_recipient_data` TLV record in an
1240 pub extern "C" fn BlindedPayInfo_get_features(this_ptr: &BlindedPayInfo) -> crate::lightning::ln::features::BlindedHopFeatures {
1241 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1242 crate::lightning::ln::features::BlindedHopFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::BlindedHopFeatures<>) as *mut _) }, is_owned: false }
1244 /// Features set in `encrypted_data_tlv` for the `encrypted_recipient_data` TLV record in an
1247 pub extern "C" fn BlindedPayInfo_set_features(this_ptr: &mut BlindedPayInfo, mut val: crate::lightning::ln::features::BlindedHopFeatures) {
1248 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1250 /// Constructs a new BlindedPayInfo given each field
1253 pub extern "C" fn BlindedPayInfo_new(mut fee_base_msat_arg: u32, mut fee_proportional_millionths_arg: u32, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: u64, mut features_arg: crate::lightning::ln::features::BlindedHopFeatures) -> BlindedPayInfo {
1254 BlindedPayInfo { inner: ObjOps::heap_alloc(nativeBlindedPayInfo {
1255 fee_base_msat: fee_base_msat_arg,
1256 fee_proportional_millionths: fee_proportional_millionths_arg,
1257 cltv_expiry_delta: cltv_expiry_delta_arg,
1258 htlc_minimum_msat: htlc_minimum_msat_arg,
1259 htlc_maximum_msat: htlc_maximum_msat_arg,
1260 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1261 }), is_owned: true }
1263 impl Clone for BlindedPayInfo {
1264 fn clone(&self) -> Self {
1266 inner: if <*mut nativeBlindedPayInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1267 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1273 /// Used only if an object of this type is returned as a trait impl by a method
1274 pub(crate) extern "C" fn BlindedPayInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1275 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedPayInfo)).clone() })) as *mut c_void
1278 /// Creates a copy of the BlindedPayInfo
1279 pub extern "C" fn BlindedPayInfo_clone(orig: &BlindedPayInfo) -> BlindedPayInfo {
1282 /// Get a string which allows debug introspection of a BlindedPayInfo object
1283 pub extern "C" fn BlindedPayInfo_debug_str_void(o: *const c_void) -> Str {
1284 alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::invoice::BlindedPayInfo }).into()}
1285 /// Generates a non-cryptographic 64-bit hash of the BlindedPayInfo.
1287 pub extern "C" fn BlindedPayInfo_hash(o: &BlindedPayInfo) -> u64 {
1288 if o.inner.is_null() { return 0; }
1289 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1290 #[allow(deprecated)]
1291 let mut hasher = core::hash::SipHasher::new();
1292 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1293 core::hash::Hasher::finish(&hasher)
1295 /// Checks if two BlindedPayInfos contain equal inner contents.
1296 /// This ignores pointers and is_owned flags and looks at the values in fields.
1297 /// Two objects with NULL inner values will be considered "equal" here.
1299 pub extern "C" fn BlindedPayInfo_eq(a: &BlindedPayInfo, b: &BlindedPayInfo) -> bool {
1300 if a.inner == b.inner { return true; }
1301 if a.inner.is_null() || b.inner.is_null() { return false; }
1302 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1305 /// Serialize the BlindedPayInfo object into a byte array which can be read by BlindedPayInfo_read
1306 pub extern "C" fn BlindedPayInfo_write(obj: &crate::lightning::offers::invoice::BlindedPayInfo) -> crate::c_types::derived::CVec_u8Z {
1307 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1310 pub(crate) extern "C" fn BlindedPayInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1311 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedPayInfo) })
1314 /// Read a BlindedPayInfo from a byte array, created by BlindedPayInfo_write
1315 pub extern "C" fn BlindedPayInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedPayInfoDecodeErrorZ {
1316 let res: Result<lightning::offers::invoice::BlindedPayInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1317 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::invoice::BlindedPayInfo { 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() };