Pin compiler_builtins to 0.1.109 when building std
[ldk-c-bindings] / lightning-c-bindings / src / lightning / offers / invoice.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
9 //! Data structures and encoding for `invoice` messages.
10 //!
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.
14 //!
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.
17 //!
18 //! ```
19 //! extern crate bitcoin;
20 //! extern crate lightning;
21 //!
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;
29 //!
30 //! # use lightning::ln::types::PaymentHash;
31 //! # use lightning::offers::invoice::{BlindedPayInfo, ExplicitSigningPubkey, InvoiceBuilder};
32 //! # use lightning::blinded_path::BlindedPath;
33 //! #
34 //! # fn create_payment_paths() -> Vec<(BlindedPayInfo, BlindedPath)> { unimplemented!() }
35 //! # fn create_payment_hash() -> PaymentHash { unimplemented!() }
36 //! #
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();
45 //!
46 //! // Invoice for the \"offer to be paid\" flow.
47 //! # <InvoiceBuilder<ExplicitSigningPubkey>>::from(
48 //! InvoiceRequest::try_from(bytes)?
49 //!
50 //!    .respond_with(payment_paths, payment_hash)?
51 //!
52 //! # )
53 //!     .relative_expiry(3600)
54 //!     .allow_mpp()
55 //!     .fallback_v0_p2wpkh(&wpubkey_hash)
56 //!     .build()?
57 //!     .sign(|message: &UnsignedBolt12Invoice|
58 //!         Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
59 //!     )
60 //!     .expect(\"failed verifying signature\")
61 //!     .write(&mut buffer)
62 //!     .unwrap();
63 //! # Ok(())
64 //! # }
65 //!
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();
74 //!
75 //! // Invoice for the \"offer for money\" flow.
76 //! # <InvoiceBuilder<ExplicitSigningPubkey>>::from(
77 //! \"lnr1qcp4256ypq\"
78 //!     .parse::<Refund>()?
79 //!
80 //!    .respond_with(payment_paths, payment_hash, pubkey)?
81 //!
82 //! # )
83 //!     .relative_expiry(3600)
84 //!     .allow_mpp()
85 //!     .fallback_v0_p2wpkh(&wpubkey_hash)
86 //!     .build()?
87 //!     .sign(|message: &UnsignedBolt12Invoice|
88 //!         Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
89 //!     )
90 //!     .expect(\"failed verifying signature\")
91 //!     .write(&mut buffer)
92 //!     .unwrap();
93 //! # Ok(())
94 //! # }
95 //!
96 //! ```
97
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};
106
107
108 use lightning::offers::invoice::InvoiceWithExplicitSigningPubkeyBuilder as nativeInvoiceWithExplicitSigningPubkeyBuilderImport;
109 pub(crate) type nativeInvoiceWithExplicitSigningPubkeyBuilder = nativeInvoiceWithExplicitSigningPubkeyBuilderImport<'static, >;
110
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.
114 ///
115 /// See [module-level documentation] for usage.
116 ///
117 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
118 /// [`Refund`]: crate::offers::refund::Refund
119 /// [module-level documentation]: self
120 #[must_use]
121 #[repr(C)]
122 pub struct InvoiceWithExplicitSigningPubkeyBuilder {
123         /// A pointer to the opaque Rust object.
124
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.
129
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.
132         pub is_owned: bool,
133 }
134
135 impl Drop for InvoiceWithExplicitSigningPubkeyBuilder {
136         fn drop(&mut self) {
137                 if self.is_owned && !<*mut nativeInvoiceWithExplicitSigningPubkeyBuilder>::is_null(self.inner) {
138                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
139                 }
140         }
141 }
142 /// Frees any resources used by the InvoiceWithExplicitSigningPubkeyBuilder, if is_owned is set and inner is non-NULL.
143 #[no_mangle]
144 pub extern "C" fn InvoiceWithExplicitSigningPubkeyBuilder_free(this_obj: InvoiceWithExplicitSigningPubkeyBuilder) { }
145 #[allow(unused)]
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) };
149 }
150 #[allow(unused)]
151 impl InvoiceWithExplicitSigningPubkeyBuilder {
152         pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceWithExplicitSigningPubkeyBuilder {
153                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
154         }
155         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceWithExplicitSigningPubkeyBuilder {
156                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
157         }
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();
163                 ret
164         }
165 }
166
167 use lightning::offers::invoice::InvoiceWithDerivedSigningPubkeyBuilder as nativeInvoiceWithDerivedSigningPubkeyBuilderImport;
168 pub(crate) type nativeInvoiceWithDerivedSigningPubkeyBuilder = nativeInvoiceWithDerivedSigningPubkeyBuilderImport<'static, >;
169
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.
173 ///
174 /// See [module-level documentation] for usage.
175 ///
176 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
177 /// [`Refund`]: crate::offers::refund::Refund
178 /// [module-level documentation]: self
179 #[must_use]
180 #[repr(C)]
181 pub struct InvoiceWithDerivedSigningPubkeyBuilder {
182         /// A pointer to the opaque Rust object.
183
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.
188
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.
191         pub is_owned: bool,
192 }
193
194 impl Drop for InvoiceWithDerivedSigningPubkeyBuilder {
195         fn drop(&mut self) {
196                 if self.is_owned && !<*mut nativeInvoiceWithDerivedSigningPubkeyBuilder>::is_null(self.inner) {
197                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
198                 }
199         }
200 }
201 /// Frees any resources used by the InvoiceWithDerivedSigningPubkeyBuilder, if is_owned is set and inner is non-NULL.
202 #[no_mangle]
203 pub extern "C" fn InvoiceWithDerivedSigningPubkeyBuilder_free(this_obj: InvoiceWithDerivedSigningPubkeyBuilder) { }
204 #[allow(unused)]
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) };
208 }
209 #[allow(unused)]
210 impl InvoiceWithDerivedSigningPubkeyBuilder {
211         pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceWithDerivedSigningPubkeyBuilder {
212                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
213         }
214         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceWithDerivedSigningPubkeyBuilder {
215                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
216         }
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();
222                 ret
223         }
224 }
225 /// Builds an unsigned [`Bolt12Invoice`] after checking for valid semantics. It can be signed by
226 /// [`UnsignedBolt12Invoice::sign`].
227 #[must_use]
228 #[no_mangle]
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() };
232         local_ret
233 }
234
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`].
238 ///
239 /// Successive calls to this method will override the previous setting.
240 #[must_use]
241 #[no_mangle]
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);
244         () /*ret*/
245 }
246
247 /// Adds a P2WSH address to [`Bolt12Invoice::fallbacks`].
248 ///
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.
251 #[must_use]
252 #[no_mangle]
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())));
255         () /*ret*/
256 }
257
258 /// Adds a P2WPKH address to [`Bolt12Invoice::fallbacks`].
259 ///
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.
262 #[must_use]
263 #[no_mangle]
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())));
266         () /*ret*/
267 }
268
269 /// Adds a P2TR address to [`Bolt12Invoice::fallbacks`].
270 ///
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.
273 #[must_use]
274 #[no_mangle]
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());
277         () /*ret*/
278 }
279
280 /// Sets [`Bolt12Invoice::invoice_features`] to indicate MPP may be used. Otherwise, MPP is
281 /// disallowed.
282 #[must_use]
283 #[no_mangle]
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();
286         () /*ret*/
287 }
288
289 /// Builds a signed [`Bolt12Invoice`] after checking for valid semantics.
290 #[must_use]
291 #[no_mangle]
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() };
295         local_ret
296 }
297
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`].
301 ///
302 /// Successive calls to this method will override the previous setting.
303 #[must_use]
304 #[no_mangle]
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);
307         () /*ret*/
308 }
309
310 /// Adds a P2WSH address to [`Bolt12Invoice::fallbacks`].
311 ///
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.
314 #[must_use]
315 #[no_mangle]
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())));
318         () /*ret*/
319 }
320
321 /// Adds a P2WPKH address to [`Bolt12Invoice::fallbacks`].
322 ///
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.
325 #[must_use]
326 #[no_mangle]
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())));
329         () /*ret*/
330 }
331
332 /// Adds a P2TR address to [`Bolt12Invoice::fallbacks`].
333 ///
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.
336 #[must_use]
337 #[no_mangle]
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());
340         () /*ret*/
341 }
342
343 /// Sets [`Bolt12Invoice::invoice_features`] to indicate MPP may be used. Otherwise, MPP is
344 /// disallowed.
345 #[must_use]
346 #[no_mangle]
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();
349         () /*ret*/
350 }
351
352
353 use lightning::offers::invoice::UnsignedBolt12Invoice as nativeUnsignedBolt12InvoiceImport;
354 pub(crate) type nativeUnsignedBolt12Invoice = nativeUnsignedBolt12InvoiceImport;
355
356 /// A semantically valid [`Bolt12Invoice`] that hasn't been signed.
357 ///
358 /// # Serialization
359 ///
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.
362 #[must_use]
363 #[repr(C)]
364 pub struct UnsignedBolt12Invoice {
365         /// A pointer to the opaque Rust object.
366
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.
371
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.
374         pub is_owned: bool,
375 }
376
377 impl Drop for UnsignedBolt12Invoice {
378         fn drop(&mut self) {
379                 if self.is_owned && !<*mut nativeUnsignedBolt12Invoice>::is_null(self.inner) {
380                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
381                 }
382         }
383 }
384 /// Frees any resources used by the UnsignedBolt12Invoice, if is_owned is set and inner is non-NULL.
385 #[no_mangle]
386 pub extern "C" fn UnsignedBolt12Invoice_free(this_obj: UnsignedBolt12Invoice) { }
387 #[allow(unused)]
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) };
391 }
392 #[allow(unused)]
393 impl UnsignedBolt12Invoice {
394         pub(crate) fn get_native_ref(&self) -> &'static nativeUnsignedBolt12Invoice {
395                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
396         }
397         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUnsignedBolt12Invoice {
398                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
399         }
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();
405                 ret
406         }
407 }
408 impl Clone for UnsignedBolt12Invoice {
409         fn clone(&self) -> Self {
410                 Self {
411                         inner: if <*mut nativeUnsignedBolt12Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
412                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
413                         is_owned: true,
414                 }
415         }
416 }
417 #[allow(unused)]
418 /// Used only if an object of this type is returned as a trait impl by a method
419 pub(crate) extern "C" fn UnsignedBolt12Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
420         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUnsignedBolt12Invoice)).clone() })) as *mut c_void
421 }
422 #[no_mangle]
423 /// Creates a copy of the UnsignedBolt12Invoice
424 pub extern "C" fn UnsignedBolt12Invoice_clone(orig: &UnsignedBolt12Invoice) -> UnsignedBolt12Invoice {
425         orig.clone()
426 }
427 /// A function for signing an [`UnsignedBolt12Invoice`].
428 #[repr(C)]
429 pub struct SignBolt12InvoiceFn {
430         /// An opaque pointer which is passed to your function implementations as an argument.
431         /// This has no meaning in the LDK, and can be NULL or any other value.
432         pub this_arg: *mut c_void,
433         /// Signs a [`TaggedHash`] computed over the merkle root of `message`'s TLV stream.
434         pub sign_invoice: extern "C" fn (this_arg: *const c_void, message: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CResult_SchnorrSignatureNoneZ,
435         /// Frees any resources associated with this object given its this_arg pointer.
436         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
437         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
438 }
439 unsafe impl Send for SignBolt12InvoiceFn {}
440 unsafe impl Sync for SignBolt12InvoiceFn {}
441 #[allow(unused)]
442 pub(crate) fn SignBolt12InvoiceFn_clone_fields(orig: &SignBolt12InvoiceFn) -> SignBolt12InvoiceFn {
443         SignBolt12InvoiceFn {
444                 this_arg: orig.this_arg,
445                 sign_invoice: Clone::clone(&orig.sign_invoice),
446                 free: Clone::clone(&orig.free),
447         }
448 }
449
450 use lightning::offers::invoice::SignBolt12InvoiceFn as rustSignBolt12InvoiceFn;
451 impl rustSignBolt12InvoiceFn for SignBolt12InvoiceFn {
452         fn sign_invoice(&self, mut message: &lightning::offers::invoice::UnsignedBolt12Invoice) -> Result<bitcoin::secp256k1::schnorr::Signature, ()> {
453                 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 });
454                 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)) })*/ })};
455                 local_ret
456         }
457 }
458
459 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
460 // directly as a Deref trait in higher-level structs:
461 impl core::ops::Deref for SignBolt12InvoiceFn {
462         type Target = Self;
463         fn deref(&self) -> &Self {
464                 self
465         }
466 }
467 impl core::ops::DerefMut for SignBolt12InvoiceFn {
468         fn deref_mut(&mut self) -> &mut Self {
469                 self
470         }
471 }
472 /// Calls the free function if one is set
473 #[no_mangle]
474 pub extern "C" fn SignBolt12InvoiceFn_free(this_ptr: SignBolt12InvoiceFn) { }
475 impl Drop for SignBolt12InvoiceFn {
476         fn drop(&mut self) {
477                 if let Some(f) = self.free {
478                         f(self.this_arg);
479                 }
480         }
481 }
482 /// Returns the [`TaggedHash`] of the invoice to sign.
483 #[must_use]
484 #[no_mangle]
485 pub extern "C" fn UnsignedBolt12Invoice_tagged_hash(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::offers::merkle::TaggedHash {
486         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tagged_hash();
487         crate::lightning::offers::merkle::TaggedHash { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::offers::merkle::TaggedHash<>) as *mut _) }, is_owned: false }
488 }
489
490
491 use lightning::offers::invoice::Bolt12Invoice as nativeBolt12InvoiceImport;
492 pub(crate) type nativeBolt12Invoice = nativeBolt12InvoiceImport;
493
494 /// A `Bolt12Invoice` is a payment request, typically corresponding to an [`Offer`] or a [`Refund`].
495 ///
496 /// An invoice may be sent in response to an [`InvoiceRequest`] in the case of an offer or sent
497 /// directly after scanning a refund. It includes all the information needed to pay a recipient.
498 ///
499 /// [`Offer`]: crate::offers::offer::Offer
500 /// [`Refund`]: crate::offers::refund::Refund
501 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
502 #[must_use]
503 #[repr(C)]
504 pub struct Bolt12Invoice {
505         /// A pointer to the opaque Rust object.
506
507         /// Nearly everywhere, inner must be non-null, however in places where
508         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
509         pub inner: *mut nativeBolt12Invoice,
510         /// Indicates that this is the only struct which contains the same pointer.
511
512         /// Rust functions which take ownership of an object provided via an argument require
513         /// this to be true and invalidate the object pointed to by inner.
514         pub is_owned: bool,
515 }
516
517 impl Drop for Bolt12Invoice {
518         fn drop(&mut self) {
519                 if self.is_owned && !<*mut nativeBolt12Invoice>::is_null(self.inner) {
520                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
521                 }
522         }
523 }
524 /// Frees any resources used by the Bolt12Invoice, if is_owned is set and inner is non-NULL.
525 #[no_mangle]
526 pub extern "C" fn Bolt12Invoice_free(this_obj: Bolt12Invoice) { }
527 #[allow(unused)]
528 /// Used only if an object of this type is returned as a trait impl by a method
529 pub(crate) extern "C" fn Bolt12Invoice_free_void(this_ptr: *mut c_void) {
530         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt12Invoice) };
531 }
532 #[allow(unused)]
533 impl Bolt12Invoice {
534         pub(crate) fn get_native_ref(&self) -> &'static nativeBolt12Invoice {
535                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
536         }
537         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt12Invoice {
538                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
539         }
540         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
541         pub(crate) fn take_inner(mut self) -> *mut nativeBolt12Invoice {
542                 assert!(self.is_owned);
543                 let ret = ObjOps::untweak_ptr(self.inner);
544                 self.inner = core::ptr::null_mut();
545                 ret
546         }
547 }
548 impl Clone for Bolt12Invoice {
549         fn clone(&self) -> Self {
550                 Self {
551                         inner: if <*mut nativeBolt12Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
552                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
553                         is_owned: true,
554                 }
555         }
556 }
557 #[allow(unused)]
558 /// Used only if an object of this type is returned as a trait impl by a method
559 pub(crate) extern "C" fn Bolt12Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
560         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt12Invoice)).clone() })) as *mut c_void
561 }
562 #[no_mangle]
563 /// Creates a copy of the Bolt12Invoice
564 pub extern "C" fn Bolt12Invoice_clone(orig: &Bolt12Invoice) -> Bolt12Invoice {
565         orig.clone()
566 }
567 /// Get a string which allows debug introspection of a Bolt12Invoice object
568 pub extern "C" fn Bolt12Invoice_debug_str_void(o: *const c_void) -> Str {
569         alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::invoice::Bolt12Invoice }).into()}
570 /// The chains that may be used when paying a requested invoice.
571 ///
572 /// From [`Offer::chains`]; `None` if the invoice was created in response to a [`Refund`].
573 ///
574 /// [`Offer::chains`]: crate::offers::offer::Offer::chains
575 #[must_use]
576 #[no_mangle]
577 pub extern "C" fn UnsignedBolt12Invoice_offer_chains(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ {
578         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_chains();
579         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() }) };
580         local_ret
581 }
582
583 /// The chain that must be used when paying the invoice; selected from [`offer_chains`] if the
584 /// invoice originated from an offer.
585 ///
586 /// From [`InvoiceRequest::chain`] or [`Refund::chain`].
587 ///
588 /// [`offer_chains`]: Self::offer_chains
589 /// [`InvoiceRequest::chain`]: crate::offers::invoice_request::InvoiceRequest::chain
590 #[must_use]
591 #[no_mangle]
592 pub extern "C" fn UnsignedBolt12Invoice_chain(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
593         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.chain();
594         crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() }
595 }
596
597 /// Opaque bytes set by the originating [`Offer`].
598 ///
599 /// From [`Offer::metadata`]; `None` if the invoice was created in response to a [`Refund`] or
600 /// if the [`Offer`] did not set it.
601 ///
602 /// [`Offer`]: crate::offers::offer::Offer
603 /// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
604 #[must_use]
605 #[no_mangle]
606 pub extern "C" fn UnsignedBolt12Invoice_metadata(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
607         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.metadata();
608         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() }) };
609         local_ret
610 }
611
612 /// The minimum amount required for a successful payment of a single item.
613 ///
614 /// From [`Offer::amount`]; `None` if the invoice was created in response to a [`Refund`] or if
615 /// the [`Offer`] did not set it.
616 ///
617 /// [`Offer`]: crate::offers::offer::Offer
618 /// [`Offer::amount`]: crate::offers::offer::Offer::amount
619 #[must_use]
620 #[no_mangle]
621 pub extern "C" fn UnsignedBolt12Invoice_amount(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_AmountZ {
622         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount();
623         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()) }) };
624         local_ret
625 }
626
627 /// Features pertaining to the originating [`Offer`].
628 ///
629 /// From [`Offer::offer_features`]; `None` if the invoice was created in response to a
630 /// [`Refund`].
631 ///
632 /// [`Offer`]: crate::offers::offer::Offer
633 /// [`Offer::offer_features`]: crate::offers::offer::Offer::offer_features
634 ///
635 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
636 #[must_use]
637 #[no_mangle]
638 pub extern "C" fn UnsignedBolt12Invoice_offer_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::OfferFeatures {
639         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_features();
640         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 };
641         local_ret
642 }
643
644 /// A complete description of the purpose of the originating offer or refund.
645 ///
646 /// From [`Offer::description`] or [`Refund::description`].
647 ///
648 /// [`Offer::description`]: crate::offers::offer::Offer::description
649 ///
650 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
651 #[must_use]
652 #[no_mangle]
653 pub extern "C" fn UnsignedBolt12Invoice_description(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString {
654         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
655         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 };
656         local_ret
657 }
658
659 /// Duration since the Unix epoch when an invoice should no longer be requested.
660 ///
661 /// From [`Offer::absolute_expiry`] or [`Refund::absolute_expiry`].
662 ///
663 /// [`Offer::absolute_expiry`]: crate::offers::offer::Offer::absolute_expiry
664 #[must_use]
665 #[no_mangle]
666 pub extern "C" fn UnsignedBolt12Invoice_absolute_expiry(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_u64Z {
667         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.absolute_expiry();
668         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() }) };
669         local_ret
670 }
671
672 /// The issuer of the offer or refund.
673 ///
674 /// From [`Offer::issuer`] or [`Refund::issuer`].
675 ///
676 /// [`Offer::issuer`]: crate::offers::offer::Offer::issuer
677 ///
678 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
679 #[must_use]
680 #[no_mangle]
681 pub extern "C" fn UnsignedBolt12Invoice_issuer(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString {
682         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.issuer();
683         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 };
684         local_ret
685 }
686
687 /// Paths to the recipient originating from publicly reachable nodes.
688 ///
689 /// From [`Offer::paths`] or [`Refund::paths`].
690 ///
691 /// [`Offer::paths`]: crate::offers::offer::Offer::paths
692 #[must_use]
693 #[no_mangle]
694 pub extern "C" fn UnsignedBolt12Invoice_message_paths(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CVec_BlindedPathZ {
695         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.message_paths();
696         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 } }); };
697         local_ret.into()
698 }
699
700 /// The quantity of items supported.
701 ///
702 /// From [`Offer::supported_quantity`]; `None` if the invoice was created in response to a
703 /// [`Refund`].
704 ///
705 /// [`Offer::supported_quantity`]: crate::offers::offer::Offer::supported_quantity
706 #[must_use]
707 #[no_mangle]
708 pub extern "C" fn UnsignedBolt12Invoice_supported_quantity(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_QuantityZ {
709         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supported_quantity();
710         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()) }) };
711         local_ret
712 }
713
714 /// An unpredictable series of bytes from the payer.
715 ///
716 /// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
717 #[must_use]
718 #[no_mangle]
719 pub extern "C" fn UnsignedBolt12Invoice_payer_metadata(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::u8slice {
720         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_metadata();
721         let mut local_ret = crate::c_types::u8slice::from_slice(ret);
722         local_ret
723 }
724
725 /// Features pertaining to requesting an invoice.
726 ///
727 /// From [`InvoiceRequest::invoice_request_features`] or [`Refund::features`].
728 #[must_use]
729 #[no_mangle]
730 pub extern "C" fn UnsignedBolt12Invoice_invoice_request_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::InvoiceRequestFeatures {
731         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_request_features();
732         crate::lightning::ln::features::InvoiceRequestFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::InvoiceRequestFeatures<>) as *mut _) }, is_owned: false }
733 }
734
735 /// The quantity of items requested or refunded for.
736 ///
737 /// From [`InvoiceRequest::quantity`] or [`Refund::quantity`].
738 #[must_use]
739 #[no_mangle]
740 pub extern "C" fn UnsignedBolt12Invoice_quantity(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_u64Z {
741         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.quantity();
742         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() }) };
743         local_ret
744 }
745
746 /// A possibly transient pubkey used to sign the invoice request or to send an invoice for a
747 /// refund in case there are no [`message_paths`].
748 ///
749 /// [`message_paths`]: Self::message_paths
750 #[must_use]
751 #[no_mangle]
752 pub extern "C" fn UnsignedBolt12Invoice_payer_id(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::PublicKey {
753         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_id();
754         crate::c_types::PublicKey::from_rust(&ret)
755 }
756
757 /// A payer-provided note reflected back in the invoice.
758 ///
759 /// From [`InvoiceRequest::payer_note`] or [`Refund::payer_note`].
760 ///
761 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
762 #[must_use]
763 #[no_mangle]
764 pub extern "C" fn UnsignedBolt12Invoice_payer_note(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString {
765         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_note();
766         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 };
767         local_ret
768 }
769
770 /// Duration since the Unix epoch when the invoice was created.
771 #[must_use]
772 #[no_mangle]
773 pub extern "C" fn UnsignedBolt12Invoice_created_at(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 {
774         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.created_at();
775         ret.as_secs()
776 }
777
778 /// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
779 /// should no longer be paid.
780 #[must_use]
781 #[no_mangle]
782 pub extern "C" fn UnsignedBolt12Invoice_relative_expiry(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 {
783         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.relative_expiry();
784         ret.as_secs()
785 }
786
787 /// Whether the invoice has expired.
788 #[must_use]
789 #[no_mangle]
790 pub extern "C" fn UnsignedBolt12Invoice_is_expired(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> bool {
791         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
792         ret
793 }
794
795 /// SHA256 hash of the payment preimage that will be given in return for paying the invoice.
796 #[must_use]
797 #[no_mangle]
798 pub extern "C" fn UnsignedBolt12Invoice_payment_hash(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
799         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
800         crate::c_types::ThirtyTwoBytes { data: ret.0 }
801 }
802
803 /// The minimum amount required for a successful payment of the invoice.
804 #[must_use]
805 #[no_mangle]
806 pub extern "C" fn UnsignedBolt12Invoice_amount_msats(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 {
807         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_msats();
808         ret
809 }
810
811 /// Features pertaining to paying an invoice.
812 #[must_use]
813 #[no_mangle]
814 pub extern "C" fn UnsignedBolt12Invoice_invoice_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::Bolt12InvoiceFeatures {
815         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_features();
816         crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::Bolt12InvoiceFeatures<>) as *mut _) }, is_owned: false }
817 }
818
819 /// The public key corresponding to the key used to sign the invoice.
820 #[must_use]
821 #[no_mangle]
822 pub extern "C" fn UnsignedBolt12Invoice_signing_pubkey(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::PublicKey {
823         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signing_pubkey();
824         crate::c_types::PublicKey::from_rust(&ret)
825 }
826
827 /// The chains that may be used when paying a requested invoice.
828 ///
829 /// From [`Offer::chains`]; `None` if the invoice was created in response to a [`Refund`].
830 ///
831 /// [`Offer::chains`]: crate::offers::offer::Offer::chains
832 #[must_use]
833 #[no_mangle]
834 pub extern "C" fn Bolt12Invoice_offer_chains(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ {
835         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_chains();
836         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() }) };
837         local_ret
838 }
839
840 /// The chain that must be used when paying the invoice; selected from [`offer_chains`] if the
841 /// invoice originated from an offer.
842 ///
843 /// From [`InvoiceRequest::chain`] or [`Refund::chain`].
844 ///
845 /// [`offer_chains`]: Self::offer_chains
846 /// [`InvoiceRequest::chain`]: crate::offers::invoice_request::InvoiceRequest::chain
847 #[must_use]
848 #[no_mangle]
849 pub extern "C" fn Bolt12Invoice_chain(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
850         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.chain();
851         crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() }
852 }
853
854 /// Opaque bytes set by the originating [`Offer`].
855 ///
856 /// From [`Offer::metadata`]; `None` if the invoice was created in response to a [`Refund`] or
857 /// if the [`Offer`] did not set it.
858 ///
859 /// [`Offer`]: crate::offers::offer::Offer
860 /// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
861 #[must_use]
862 #[no_mangle]
863 pub extern "C" fn Bolt12Invoice_metadata(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
864         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.metadata();
865         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() }) };
866         local_ret
867 }
868
869 /// The minimum amount required for a successful payment of a single item.
870 ///
871 /// From [`Offer::amount`]; `None` if the invoice was created in response to a [`Refund`] or if
872 /// the [`Offer`] did not set it.
873 ///
874 /// [`Offer`]: crate::offers::offer::Offer
875 /// [`Offer::amount`]: crate::offers::offer::Offer::amount
876 #[must_use]
877 #[no_mangle]
878 pub extern "C" fn Bolt12Invoice_amount(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_AmountZ {
879         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount();
880         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()) }) };
881         local_ret
882 }
883
884 /// Features pertaining to the originating [`Offer`].
885 ///
886 /// From [`Offer::offer_features`]; `None` if the invoice was created in response to a
887 /// [`Refund`].
888 ///
889 /// [`Offer`]: crate::offers::offer::Offer
890 /// [`Offer::offer_features`]: crate::offers::offer::Offer::offer_features
891 ///
892 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
893 #[must_use]
894 #[no_mangle]
895 pub extern "C" fn Bolt12Invoice_offer_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::OfferFeatures {
896         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_features();
897         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 };
898         local_ret
899 }
900
901 /// A complete description of the purpose of the originating offer or refund.
902 ///
903 /// From [`Offer::description`] or [`Refund::description`].
904 ///
905 /// [`Offer::description`]: crate::offers::offer::Offer::description
906 ///
907 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
908 #[must_use]
909 #[no_mangle]
910 pub extern "C" fn Bolt12Invoice_description(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString {
911         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
912         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 };
913         local_ret
914 }
915
916 /// Duration since the Unix epoch when an invoice should no longer be requested.
917 ///
918 /// From [`Offer::absolute_expiry`] or [`Refund::absolute_expiry`].
919 ///
920 /// [`Offer::absolute_expiry`]: crate::offers::offer::Offer::absolute_expiry
921 #[must_use]
922 #[no_mangle]
923 pub extern "C" fn Bolt12Invoice_absolute_expiry(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_u64Z {
924         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.absolute_expiry();
925         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() }) };
926         local_ret
927 }
928
929 /// The issuer of the offer or refund.
930 ///
931 /// From [`Offer::issuer`] or [`Refund::issuer`].
932 ///
933 /// [`Offer::issuer`]: crate::offers::offer::Offer::issuer
934 ///
935 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
936 #[must_use]
937 #[no_mangle]
938 pub extern "C" fn Bolt12Invoice_issuer(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString {
939         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.issuer();
940         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 };
941         local_ret
942 }
943
944 /// Paths to the recipient originating from publicly reachable nodes.
945 ///
946 /// From [`Offer::paths`] or [`Refund::paths`].
947 ///
948 /// [`Offer::paths`]: crate::offers::offer::Offer::paths
949 #[must_use]
950 #[no_mangle]
951 pub extern "C" fn Bolt12Invoice_message_paths(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::CVec_BlindedPathZ {
952         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.message_paths();
953         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 } }); };
954         local_ret.into()
955 }
956
957 /// The quantity of items supported.
958 ///
959 /// From [`Offer::supported_quantity`]; `None` if the invoice was created in response to a
960 /// [`Refund`].
961 ///
962 /// [`Offer::supported_quantity`]: crate::offers::offer::Offer::supported_quantity
963 #[must_use]
964 #[no_mangle]
965 pub extern "C" fn Bolt12Invoice_supported_quantity(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_QuantityZ {
966         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supported_quantity();
967         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()) }) };
968         local_ret
969 }
970
971 /// An unpredictable series of bytes from the payer.
972 ///
973 /// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
974 #[must_use]
975 #[no_mangle]
976 pub extern "C" fn Bolt12Invoice_payer_metadata(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::u8slice {
977         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_metadata();
978         let mut local_ret = crate::c_types::u8slice::from_slice(ret);
979         local_ret
980 }
981
982 /// Features pertaining to requesting an invoice.
983 ///
984 /// From [`InvoiceRequest::invoice_request_features`] or [`Refund::features`].
985 #[must_use]
986 #[no_mangle]
987 pub extern "C" fn Bolt12Invoice_invoice_request_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::InvoiceRequestFeatures {
988         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_request_features();
989         crate::lightning::ln::features::InvoiceRequestFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::InvoiceRequestFeatures<>) as *mut _) }, is_owned: false }
990 }
991
992 /// The quantity of items requested or refunded for.
993 ///
994 /// From [`InvoiceRequest::quantity`] or [`Refund::quantity`].
995 #[must_use]
996 #[no_mangle]
997 pub extern "C" fn Bolt12Invoice_quantity(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_u64Z {
998         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.quantity();
999         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() }) };
1000         local_ret
1001 }
1002
1003 /// A possibly transient pubkey used to sign the invoice request or to send an invoice for a
1004 /// refund in case there are no [`message_paths`].
1005 ///
1006 /// [`message_paths`]: Self::message_paths
1007 #[must_use]
1008 #[no_mangle]
1009 pub extern "C" fn Bolt12Invoice_payer_id(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::PublicKey {
1010         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_id();
1011         crate::c_types::PublicKey::from_rust(&ret)
1012 }
1013
1014 /// A payer-provided note reflected back in the invoice.
1015 ///
1016 /// From [`InvoiceRequest::payer_note`] or [`Refund::payer_note`].
1017 ///
1018 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1019 #[must_use]
1020 #[no_mangle]
1021 pub extern "C" fn Bolt12Invoice_payer_note(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString {
1022         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_note();
1023         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 };
1024         local_ret
1025 }
1026
1027 /// Duration since the Unix epoch when the invoice was created.
1028 #[must_use]
1029 #[no_mangle]
1030 pub extern "C" fn Bolt12Invoice_created_at(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 {
1031         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.created_at();
1032         ret.as_secs()
1033 }
1034
1035 /// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
1036 /// should no longer be paid.
1037 #[must_use]
1038 #[no_mangle]
1039 pub extern "C" fn Bolt12Invoice_relative_expiry(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 {
1040         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.relative_expiry();
1041         ret.as_secs()
1042 }
1043
1044 /// Whether the invoice has expired.
1045 #[must_use]
1046 #[no_mangle]
1047 pub extern "C" fn Bolt12Invoice_is_expired(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> bool {
1048         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
1049         ret
1050 }
1051
1052 /// SHA256 hash of the payment preimage that will be given in return for paying the invoice.
1053 #[must_use]
1054 #[no_mangle]
1055 pub extern "C" fn Bolt12Invoice_payment_hash(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
1056         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
1057         crate::c_types::ThirtyTwoBytes { data: ret.0 }
1058 }
1059
1060 /// The minimum amount required for a successful payment of the invoice.
1061 #[must_use]
1062 #[no_mangle]
1063 pub extern "C" fn Bolt12Invoice_amount_msats(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 {
1064         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_msats();
1065         ret
1066 }
1067
1068 /// Features pertaining to paying an invoice.
1069 #[must_use]
1070 #[no_mangle]
1071 pub extern "C" fn Bolt12Invoice_invoice_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::Bolt12InvoiceFeatures {
1072         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_features();
1073         crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::Bolt12InvoiceFeatures<>) as *mut _) }, is_owned: false }
1074 }
1075
1076 /// The public key corresponding to the key used to sign the invoice.
1077 #[must_use]
1078 #[no_mangle]
1079 pub extern "C" fn Bolt12Invoice_signing_pubkey(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::PublicKey {
1080         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signing_pubkey();
1081         crate::c_types::PublicKey::from_rust(&ret)
1082 }
1083
1084 /// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
1085 #[must_use]
1086 #[no_mangle]
1087 pub extern "C" fn Bolt12Invoice_signature(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::SchnorrSignature {
1088         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
1089         crate::c_types::SchnorrSignature::from_rust(&ret)
1090 }
1091
1092 /// Hash that was used for signing the invoice.
1093 #[must_use]
1094 #[no_mangle]
1095 pub extern "C" fn Bolt12Invoice_signable_hash(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
1096         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
1097         crate::c_types::ThirtyTwoBytes { data: ret }
1098 }
1099
1100 /// Verifies that the invoice was for a request or refund created using the given key. Returns
1101 /// the associated [`PaymentId`] to use when sending the payment.
1102 #[must_use]
1103 #[no_mangle]
1104 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 {
1105         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.verify(key.get_native_ref(), secp256k1::global::SECP256K1);
1106         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() };
1107         local_ret
1108 }
1109
1110 /// Generates a non-cryptographic 64-bit hash of the Bolt12Invoice.
1111 #[no_mangle]
1112 pub extern "C" fn Bolt12Invoice_hash(o: &Bolt12Invoice) -> u64 {
1113         if o.inner.is_null() { return 0; }
1114         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1115         #[allow(deprecated)]
1116         let mut hasher = core::hash::SipHasher::new();
1117         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1118         core::hash::Hasher::finish(&hasher)
1119 }
1120 #[no_mangle]
1121 /// Serialize the UnsignedBolt12Invoice object into a byte array which can be read by UnsignedBolt12Invoice_read
1122 pub extern "C" fn UnsignedBolt12Invoice_write(obj: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CVec_u8Z {
1123         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1124 }
1125 #[allow(unused)]
1126 pub(crate) extern "C" fn UnsignedBolt12Invoice_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1127         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedBolt12Invoice) })
1128 }
1129 #[no_mangle]
1130 /// Serialize the Bolt12Invoice object into a byte array which can be read by Bolt12Invoice_read
1131 pub extern "C" fn Bolt12Invoice_write(obj: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::CVec_u8Z {
1132         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1133 }
1134 #[allow(unused)]
1135 pub(crate) extern "C" fn Bolt12Invoice_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1136         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBolt12Invoice) })
1137 }
1138
1139 use lightning::offers::invoice::BlindedPayInfo as nativeBlindedPayInfoImport;
1140 pub(crate) type nativeBlindedPayInfo = nativeBlindedPayInfoImport;
1141
1142 /// Information needed to route a payment across a [`BlindedPath`].
1143 #[must_use]
1144 #[repr(C)]
1145 pub struct BlindedPayInfo {
1146         /// A pointer to the opaque Rust object.
1147
1148         /// Nearly everywhere, inner must be non-null, however in places where
1149         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1150         pub inner: *mut nativeBlindedPayInfo,
1151         /// Indicates that this is the only struct which contains the same pointer.
1152
1153         /// Rust functions which take ownership of an object provided via an argument require
1154         /// this to be true and invalidate the object pointed to by inner.
1155         pub is_owned: bool,
1156 }
1157
1158 impl Drop for BlindedPayInfo {
1159         fn drop(&mut self) {
1160                 if self.is_owned && !<*mut nativeBlindedPayInfo>::is_null(self.inner) {
1161                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1162                 }
1163         }
1164 }
1165 /// Frees any resources used by the BlindedPayInfo, if is_owned is set and inner is non-NULL.
1166 #[no_mangle]
1167 pub extern "C" fn BlindedPayInfo_free(this_obj: BlindedPayInfo) { }
1168 #[allow(unused)]
1169 /// Used only if an object of this type is returned as a trait impl by a method
1170 pub(crate) extern "C" fn BlindedPayInfo_free_void(this_ptr: *mut c_void) {
1171         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedPayInfo) };
1172 }
1173 #[allow(unused)]
1174 impl BlindedPayInfo {
1175         pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedPayInfo {
1176                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1177         }
1178         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedPayInfo {
1179                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1180         }
1181         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1182         pub(crate) fn take_inner(mut self) -> *mut nativeBlindedPayInfo {
1183                 assert!(self.is_owned);
1184                 let ret = ObjOps::untweak_ptr(self.inner);
1185                 self.inner = core::ptr::null_mut();
1186                 ret
1187         }
1188 }
1189 /// Base fee charged (in millisatoshi) for the entire blinded path.
1190 #[no_mangle]
1191 pub extern "C" fn BlindedPayInfo_get_fee_base_msat(this_ptr: &BlindedPayInfo) -> u32 {
1192         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
1193         *inner_val
1194 }
1195 /// Base fee charged (in millisatoshi) for the entire blinded path.
1196 #[no_mangle]
1197 pub extern "C" fn BlindedPayInfo_set_fee_base_msat(this_ptr: &mut BlindedPayInfo, mut val: u32) {
1198         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
1199 }
1200 /// Liquidity fee charged (in millionths of the amount transferred) for the entire blinded path
1201 /// (i.e., 10,000 is 1%).
1202 #[no_mangle]
1203 pub extern "C" fn BlindedPayInfo_get_fee_proportional_millionths(this_ptr: &BlindedPayInfo) -> u32 {
1204         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
1205         *inner_val
1206 }
1207 /// Liquidity fee charged (in millionths of the amount transferred) for the entire blinded path
1208 /// (i.e., 10,000 is 1%).
1209 #[no_mangle]
1210 pub extern "C" fn BlindedPayInfo_set_fee_proportional_millionths(this_ptr: &mut BlindedPayInfo, mut val: u32) {
1211         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
1212 }
1213 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for the entire blinded
1214 /// path.
1215 #[no_mangle]
1216 pub extern "C" fn BlindedPayInfo_get_cltv_expiry_delta(this_ptr: &BlindedPayInfo) -> u16 {
1217         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
1218         *inner_val
1219 }
1220 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for the entire blinded
1221 /// path.
1222 #[no_mangle]
1223 pub extern "C" fn BlindedPayInfo_set_cltv_expiry_delta(this_ptr: &mut BlindedPayInfo, mut val: u16) {
1224         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
1225 }
1226 /// The minimum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
1227 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
1228 /// seen by the recipient.
1229 #[no_mangle]
1230 pub extern "C" fn BlindedPayInfo_get_htlc_minimum_msat(this_ptr: &BlindedPayInfo) -> u64 {
1231         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
1232         *inner_val
1233 }
1234 /// The minimum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
1235 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
1236 /// seen by the recipient.
1237 #[no_mangle]
1238 pub extern "C" fn BlindedPayInfo_set_htlc_minimum_msat(this_ptr: &mut BlindedPayInfo, mut val: u64) {
1239         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
1240 }
1241 /// The maximum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
1242 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
1243 /// seen by the recipient.
1244 #[no_mangle]
1245 pub extern "C" fn BlindedPayInfo_get_htlc_maximum_msat(this_ptr: &BlindedPayInfo) -> u64 {
1246         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
1247         *inner_val
1248 }
1249 /// The maximum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
1250 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
1251 /// seen by the recipient.
1252 #[no_mangle]
1253 pub extern "C" fn BlindedPayInfo_set_htlc_maximum_msat(this_ptr: &mut BlindedPayInfo, mut val: u64) {
1254         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val;
1255 }
1256 /// Features set in `encrypted_data_tlv` for the `encrypted_recipient_data` TLV record in an
1257 /// onion payload.
1258 #[no_mangle]
1259 pub extern "C" fn BlindedPayInfo_get_features(this_ptr: &BlindedPayInfo) -> crate::lightning::ln::features::BlindedHopFeatures {
1260         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1261         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 }
1262 }
1263 /// Features set in `encrypted_data_tlv` for the `encrypted_recipient_data` TLV record in an
1264 /// onion payload.
1265 #[no_mangle]
1266 pub extern "C" fn BlindedPayInfo_set_features(this_ptr: &mut BlindedPayInfo, mut val: crate::lightning::ln::features::BlindedHopFeatures) {
1267         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1268 }
1269 /// Constructs a new BlindedPayInfo given each field
1270 #[must_use]
1271 #[no_mangle]
1272 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 {
1273         BlindedPayInfo { inner: ObjOps::heap_alloc(nativeBlindedPayInfo {
1274                 fee_base_msat: fee_base_msat_arg,
1275                 fee_proportional_millionths: fee_proportional_millionths_arg,
1276                 cltv_expiry_delta: cltv_expiry_delta_arg,
1277                 htlc_minimum_msat: htlc_minimum_msat_arg,
1278                 htlc_maximum_msat: htlc_maximum_msat_arg,
1279                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1280         }), is_owned: true }
1281 }
1282 impl Clone for BlindedPayInfo {
1283         fn clone(&self) -> Self {
1284                 Self {
1285                         inner: if <*mut nativeBlindedPayInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1286                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1287                         is_owned: true,
1288                 }
1289         }
1290 }
1291 #[allow(unused)]
1292 /// Used only if an object of this type is returned as a trait impl by a method
1293 pub(crate) extern "C" fn BlindedPayInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1294         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedPayInfo)).clone() })) as *mut c_void
1295 }
1296 #[no_mangle]
1297 /// Creates a copy of the BlindedPayInfo
1298 pub extern "C" fn BlindedPayInfo_clone(orig: &BlindedPayInfo) -> BlindedPayInfo {
1299         orig.clone()
1300 }
1301 /// Get a string which allows debug introspection of a BlindedPayInfo object
1302 pub extern "C" fn BlindedPayInfo_debug_str_void(o: *const c_void) -> Str {
1303         alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::invoice::BlindedPayInfo }).into()}
1304 /// Generates a non-cryptographic 64-bit hash of the BlindedPayInfo.
1305 #[no_mangle]
1306 pub extern "C" fn BlindedPayInfo_hash(o: &BlindedPayInfo) -> u64 {
1307         if o.inner.is_null() { return 0; }
1308         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1309         #[allow(deprecated)]
1310         let mut hasher = core::hash::SipHasher::new();
1311         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1312         core::hash::Hasher::finish(&hasher)
1313 }
1314 /// Checks if two BlindedPayInfos contain equal inner contents.
1315 /// This ignores pointers and is_owned flags and looks at the values in fields.
1316 /// Two objects with NULL inner values will be considered "equal" here.
1317 #[no_mangle]
1318 pub extern "C" fn BlindedPayInfo_eq(a: &BlindedPayInfo, b: &BlindedPayInfo) -> bool {
1319         if a.inner == b.inner { return true; }
1320         if a.inner.is_null() || b.inner.is_null() { return false; }
1321         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1322 }
1323 #[no_mangle]
1324 /// Serialize the BlindedPayInfo object into a byte array which can be read by BlindedPayInfo_read
1325 pub extern "C" fn BlindedPayInfo_write(obj: &crate::lightning::offers::invoice::BlindedPayInfo) -> crate::c_types::derived::CVec_u8Z {
1326         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1327 }
1328 #[allow(unused)]
1329 pub(crate) extern "C" fn BlindedPayInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1330         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedPayInfo) })
1331 }
1332 #[no_mangle]
1333 /// Read a BlindedPayInfo from a byte array, created by BlindedPayInfo_write
1334 pub extern "C" fn BlindedPayInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedPayInfoDecodeErrorZ {
1335         let res: Result<lightning::offers::invoice::BlindedPayInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1336         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() };
1337         local_res
1338 }