Update auto-generated bindings to LDK 0.0.121
[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::{Infallible, TryFrom};
25 //! use lightning::offers::invoice_request::InvoiceRequest;
26 //! use lightning::offers::refund::Refund;
27 //! use lightning::util::ser::Writeable;
28 //!
29 //! # use lightning::ln::PaymentHash;
30 //! # use lightning::offers::invoice::BlindedPayInfo;
31 //! # use lightning::blinded_path::BlindedPath;
32 //! #
33 //! # fn create_payment_paths() -> Vec<(BlindedPayInfo, BlindedPath)> { unimplemented!() }
34 //! # fn create_payment_hash() -> PaymentHash { unimplemented!() }
35 //! #
36 //! # fn parse_invoice_request(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::Bolt12ParseError> {
37 //! let payment_paths = create_payment_paths();
38 //! let payment_hash = create_payment_hash();
39 //! let secp_ctx = Secp256k1::new();
40 //! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32])?);
41 //! let pubkey = PublicKey::from(keys);
42 //! let wpubkey_hash = bitcoin::key::PublicKey::new(pubkey).wpubkey_hash().unwrap();
43 //! let mut buffer = Vec::new();
44 //!
45 //! // Invoice for the \"offer to be paid\" flow.
46 //! InvoiceRequest::try_from(bytes)?
47 //!
48 //!    .respond_with(payment_paths, payment_hash)?
49 //!
50 //!     .relative_expiry(3600)
51 //!     .allow_mpp()
52 //!     .fallback_v0_p2wpkh(&wpubkey_hash)
53 //!     .build()?
54 //!     .sign::<_, Infallible>(
55 //!         |message| Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
56 //!     )
57 //!     .expect(\"failed verifying signature\")
58 //!     .write(&mut buffer)
59 //!     .unwrap();
60 //! # Ok(())
61 //! # }
62 //!
63 //! # fn parse_refund(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::Bolt12ParseError> {
64 //! # let payment_paths = create_payment_paths();
65 //! # let payment_hash = create_payment_hash();
66 //! # let secp_ctx = Secp256k1::new();
67 //! # let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32])?);
68 //! # let pubkey = PublicKey::from(keys);
69 //! # let wpubkey_hash = bitcoin::key::PublicKey::new(pubkey).wpubkey_hash().unwrap();
70 //! # let mut buffer = Vec::new();
71 //!
72 //! // Invoice for the \"offer for money\" flow.
73 //! \"lnr1qcp4256ypq\"
74 //!     .parse::<Refund>()?
75 //!
76 //!    .respond_with(payment_paths, payment_hash, pubkey)?
77 //!
78 //!     .relative_expiry(3600)
79 //!     .allow_mpp()
80 //!     .fallback_v0_p2wpkh(&wpubkey_hash)
81 //!     .build()?
82 //!     .sign::<_, Infallible>(
83 //!         |message| Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
84 //!     )
85 //!     .expect(\"failed verifying signature\")
86 //!     .write(&mut buffer)
87 //!     .unwrap();
88 //! # Ok(())
89 //! # }
90 //!
91 //! ```
92
93 use alloc::str::FromStr;
94 use alloc::string::String;
95 use core::ffi::c_void;
96 use core::convert::Infallible;
97 use bitcoin::hashes::Hash;
98 use crate::c_types::*;
99 #[cfg(feature="no-std")]
100 use alloc::{vec::Vec, boxed::Box};
101
102
103 use lightning::offers::invoice::UnsignedBolt12Invoice as nativeUnsignedBolt12InvoiceImport;
104 pub(crate) type nativeUnsignedBolt12Invoice = nativeUnsignedBolt12InvoiceImport;
105
106 /// A semantically valid [`Bolt12Invoice`] that hasn't been signed.
107 ///
108 /// # Serialization
109 ///
110 /// This is serialized as a TLV stream, which includes TLV records from the originating message. As
111 /// such, it may include unknown, odd TLV records.
112 #[must_use]
113 #[repr(C)]
114 pub struct UnsignedBolt12Invoice {
115         /// A pointer to the opaque Rust object.
116
117         /// Nearly everywhere, inner must be non-null, however in places where
118         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
119         pub inner: *mut nativeUnsignedBolt12Invoice,
120         /// Indicates that this is the only struct which contains the same pointer.
121
122         /// Rust functions which take ownership of an object provided via an argument require
123         /// this to be true and invalidate the object pointed to by inner.
124         pub is_owned: bool,
125 }
126
127 impl Drop for UnsignedBolt12Invoice {
128         fn drop(&mut self) {
129                 if self.is_owned && !<*mut nativeUnsignedBolt12Invoice>::is_null(self.inner) {
130                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
131                 }
132         }
133 }
134 /// Frees any resources used by the UnsignedBolt12Invoice, if is_owned is set and inner is non-NULL.
135 #[no_mangle]
136 pub extern "C" fn UnsignedBolt12Invoice_free(this_obj: UnsignedBolt12Invoice) { }
137 #[allow(unused)]
138 /// Used only if an object of this type is returned as a trait impl by a method
139 pub(crate) extern "C" fn UnsignedBolt12Invoice_free_void(this_ptr: *mut c_void) {
140         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUnsignedBolt12Invoice) };
141 }
142 #[allow(unused)]
143 impl UnsignedBolt12Invoice {
144         pub(crate) fn get_native_ref(&self) -> &'static nativeUnsignedBolt12Invoice {
145                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
146         }
147         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUnsignedBolt12Invoice {
148                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
149         }
150         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
151         pub(crate) fn take_inner(mut self) -> *mut nativeUnsignedBolt12Invoice {
152                 assert!(self.is_owned);
153                 let ret = ObjOps::untweak_ptr(self.inner);
154                 self.inner = core::ptr::null_mut();
155                 ret
156         }
157 }
158 /// Returns the [`TaggedHash`] of the invoice to sign.
159 #[must_use]
160 #[no_mangle]
161 pub extern "C" fn UnsignedBolt12Invoice_tagged_hash(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::offers::merkle::TaggedHash {
162         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.tagged_hash();
163         crate::lightning::offers::merkle::TaggedHash { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::offers::merkle::TaggedHash<>) as *mut _) }, is_owned: false }
164 }
165
166
167 use lightning::offers::invoice::Bolt12Invoice as nativeBolt12InvoiceImport;
168 pub(crate) type nativeBolt12Invoice = nativeBolt12InvoiceImport;
169
170 /// A `Bolt12Invoice` is a payment request, typically corresponding to an [`Offer`] or a [`Refund`].
171 ///
172 /// An invoice may be sent in response to an [`InvoiceRequest`] in the case of an offer or sent
173 /// directly after scanning a refund. It includes all the information needed to pay a recipient.
174 ///
175 /// [`Offer`]: crate::offers::offer::Offer
176 /// [`Refund`]: crate::offers::refund::Refund
177 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
178 #[must_use]
179 #[repr(C)]
180 pub struct Bolt12Invoice {
181         /// A pointer to the opaque Rust object.
182
183         /// Nearly everywhere, inner must be non-null, however in places where
184         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
185         pub inner: *mut nativeBolt12Invoice,
186         /// Indicates that this is the only struct which contains the same pointer.
187
188         /// Rust functions which take ownership of an object provided via an argument require
189         /// this to be true and invalidate the object pointed to by inner.
190         pub is_owned: bool,
191 }
192
193 impl Drop for Bolt12Invoice {
194         fn drop(&mut self) {
195                 if self.is_owned && !<*mut nativeBolt12Invoice>::is_null(self.inner) {
196                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
197                 }
198         }
199 }
200 /// Frees any resources used by the Bolt12Invoice, if is_owned is set and inner is non-NULL.
201 #[no_mangle]
202 pub extern "C" fn Bolt12Invoice_free(this_obj: Bolt12Invoice) { }
203 #[allow(unused)]
204 /// Used only if an object of this type is returned as a trait impl by a method
205 pub(crate) extern "C" fn Bolt12Invoice_free_void(this_ptr: *mut c_void) {
206         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt12Invoice) };
207 }
208 #[allow(unused)]
209 impl Bolt12Invoice {
210         pub(crate) fn get_native_ref(&self) -> &'static nativeBolt12Invoice {
211                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
212         }
213         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt12Invoice {
214                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
215         }
216         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
217         pub(crate) fn take_inner(mut self) -> *mut nativeBolt12Invoice {
218                 assert!(self.is_owned);
219                 let ret = ObjOps::untweak_ptr(self.inner);
220                 self.inner = core::ptr::null_mut();
221                 ret
222         }
223 }
224 impl Clone for Bolt12Invoice {
225         fn clone(&self) -> Self {
226                 Self {
227                         inner: if <*mut nativeBolt12Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
228                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
229                         is_owned: true,
230                 }
231         }
232 }
233 #[allow(unused)]
234 /// Used only if an object of this type is returned as a trait impl by a method
235 pub(crate) extern "C" fn Bolt12Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
236         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt12Invoice)).clone() })) as *mut c_void
237 }
238 #[no_mangle]
239 /// Creates a copy of the Bolt12Invoice
240 pub extern "C" fn Bolt12Invoice_clone(orig: &Bolt12Invoice) -> Bolt12Invoice {
241         orig.clone()
242 }
243 /// Get a string which allows debug introspection of a Bolt12Invoice object
244 pub extern "C" fn Bolt12Invoice_debug_str_void(o: *const c_void) -> Str {
245         alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::invoice::Bolt12Invoice }).into()}
246 /// The chains that may be used when paying a requested invoice.
247 ///
248 /// From [`Offer::chains`]; `None` if the invoice was created in response to a [`Refund`].
249 ///
250 /// [`Offer::chains`]: crate::offers::offer::Offer::chains
251 #[must_use]
252 #[no_mangle]
253 pub extern "C" fn UnsignedBolt12Invoice_offer_chains(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ {
254         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_chains();
255         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() }) };
256         local_ret
257 }
258
259 /// The chain that must be used when paying the invoice; selected from [`offer_chains`] if the
260 /// invoice originated from an offer.
261 ///
262 /// From [`InvoiceRequest::chain`] or [`Refund::chain`].
263 ///
264 /// [`offer_chains`]: Self::offer_chains
265 /// [`InvoiceRequest::chain`]: crate::offers::invoice_request::InvoiceRequest::chain
266 #[must_use]
267 #[no_mangle]
268 pub extern "C" fn UnsignedBolt12Invoice_chain(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
269         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.chain();
270         crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() }
271 }
272
273 /// Opaque bytes set by the originating [`Offer`].
274 ///
275 /// From [`Offer::metadata`]; `None` if the invoice was created in response to a [`Refund`] or
276 /// if the [`Offer`] did not set it.
277 ///
278 /// [`Offer`]: crate::offers::offer::Offer
279 /// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
280 #[must_use]
281 #[no_mangle]
282 pub extern "C" fn UnsignedBolt12Invoice_metadata(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
283         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.metadata();
284         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() }) };
285         local_ret
286 }
287
288 /// The minimum amount required for a successful payment of a single item.
289 ///
290 /// From [`Offer::amount`]; `None` if the invoice was created in response to a [`Refund`] or if
291 /// the [`Offer`] did not set it.
292 ///
293 /// [`Offer`]: crate::offers::offer::Offer
294 /// [`Offer::amount`]: crate::offers::offer::Offer::amount
295 ///
296 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
297 #[must_use]
298 #[no_mangle]
299 pub extern "C" fn UnsignedBolt12Invoice_amount(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::offers::offer::Amount {
300         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount();
301         let mut local_ret = crate::lightning::offers::offer::Amount { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::offers::offer::Amount<>) as *mut _ }, is_owned: false };
302         local_ret
303 }
304
305 /// Features pertaining to the originating [`Offer`].
306 ///
307 /// From [`Offer::offer_features`]; `None` if the invoice was created in response to a
308 /// [`Refund`].
309 ///
310 /// [`Offer`]: crate::offers::offer::Offer
311 /// [`Offer::offer_features`]: crate::offers::offer::Offer::offer_features
312 ///
313 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
314 #[must_use]
315 #[no_mangle]
316 pub extern "C" fn UnsignedBolt12Invoice_offer_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::OfferFeatures {
317         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_features();
318         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 };
319         local_ret
320 }
321
322 /// A complete description of the purpose of the originating offer or refund.
323 ///
324 /// From [`Offer::description`] or [`Refund::description`].
325 ///
326 /// [`Offer::description`]: crate::offers::offer::Offer::description
327 #[must_use]
328 #[no_mangle]
329 pub extern "C" fn UnsignedBolt12Invoice_description(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString {
330         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
331         crate::lightning::util::string::PrintableString { inner: ObjOps::heap_alloc(ret), is_owned: true }
332 }
333
334 /// Duration since the Unix epoch when an invoice should no longer be requested.
335 ///
336 /// From [`Offer::absolute_expiry`] or [`Refund::absolute_expiry`].
337 ///
338 /// [`Offer::absolute_expiry`]: crate::offers::offer::Offer::absolute_expiry
339 #[must_use]
340 #[no_mangle]
341 pub extern "C" fn UnsignedBolt12Invoice_absolute_expiry(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_u64Z {
342         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.absolute_expiry();
343         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() }) };
344         local_ret
345 }
346
347 /// The issuer of the offer or refund.
348 ///
349 /// From [`Offer::issuer`] or [`Refund::issuer`].
350 ///
351 /// [`Offer::issuer`]: crate::offers::offer::Offer::issuer
352 ///
353 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
354 #[must_use]
355 #[no_mangle]
356 pub extern "C" fn UnsignedBolt12Invoice_issuer(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString {
357         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.issuer();
358         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 };
359         local_ret
360 }
361
362 /// Paths to the recipient originating from publicly reachable nodes.
363 ///
364 /// From [`Offer::paths`] or [`Refund::paths`].
365 ///
366 /// [`Offer::paths`]: crate::offers::offer::Offer::paths
367 #[must_use]
368 #[no_mangle]
369 pub extern "C" fn UnsignedBolt12Invoice_message_paths(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CVec_BlindedPathZ {
370         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.message_paths();
371         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 } }); };
372         local_ret.into()
373 }
374
375 /// The quantity of items supported.
376 ///
377 /// From [`Offer::supported_quantity`]; `None` if the invoice was created in response to a
378 /// [`Refund`].
379 ///
380 /// [`Offer::supported_quantity`]: crate::offers::offer::Offer::supported_quantity
381 ///
382 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
383 #[must_use]
384 #[no_mangle]
385 pub extern "C" fn UnsignedBolt12Invoice_supported_quantity(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::offers::offer::Quantity {
386         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supported_quantity();
387         let mut local_ret = crate::lightning::offers::offer::Quantity { inner: if ret.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true };
388         local_ret
389 }
390
391 /// An unpredictable series of bytes from the payer.
392 ///
393 /// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
394 #[must_use]
395 #[no_mangle]
396 pub extern "C" fn UnsignedBolt12Invoice_payer_metadata(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::u8slice {
397         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_metadata();
398         let mut local_ret = crate::c_types::u8slice::from_slice(ret);
399         local_ret
400 }
401
402 /// Features pertaining to requesting an invoice.
403 ///
404 /// From [`InvoiceRequest::invoice_request_features`] or [`Refund::features`].
405 #[must_use]
406 #[no_mangle]
407 pub extern "C" fn UnsignedBolt12Invoice_invoice_request_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::InvoiceRequestFeatures {
408         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_request_features();
409         crate::lightning::ln::features::InvoiceRequestFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::InvoiceRequestFeatures<>) as *mut _) }, is_owned: false }
410 }
411
412 /// The quantity of items requested or refunded for.
413 ///
414 /// From [`InvoiceRequest::quantity`] or [`Refund::quantity`].
415 #[must_use]
416 #[no_mangle]
417 pub extern "C" fn UnsignedBolt12Invoice_quantity(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_u64Z {
418         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.quantity();
419         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() }) };
420         local_ret
421 }
422
423 /// A possibly transient pubkey used to sign the invoice request or to send an invoice for a
424 /// refund in case there are no [`message_paths`].
425 ///
426 /// [`message_paths`]: Self::message_paths
427 #[must_use]
428 #[no_mangle]
429 pub extern "C" fn UnsignedBolt12Invoice_payer_id(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::PublicKey {
430         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_id();
431         crate::c_types::PublicKey::from_rust(&ret)
432 }
433
434 /// A payer-provided note reflected back in the invoice.
435 ///
436 /// From [`InvoiceRequest::payer_note`] or [`Refund::payer_note`].
437 ///
438 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
439 #[must_use]
440 #[no_mangle]
441 pub extern "C" fn UnsignedBolt12Invoice_payer_note(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString {
442         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_note();
443         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 };
444         local_ret
445 }
446
447 /// Duration since the Unix epoch when the invoice was created.
448 #[must_use]
449 #[no_mangle]
450 pub extern "C" fn UnsignedBolt12Invoice_created_at(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 {
451         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.created_at();
452         ret.as_secs()
453 }
454
455 /// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
456 /// should no longer be paid.
457 #[must_use]
458 #[no_mangle]
459 pub extern "C" fn UnsignedBolt12Invoice_relative_expiry(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 {
460         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.relative_expiry();
461         ret.as_secs()
462 }
463
464 /// Whether the invoice has expired.
465 #[must_use]
466 #[no_mangle]
467 pub extern "C" fn UnsignedBolt12Invoice_is_expired(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> bool {
468         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
469         ret
470 }
471
472 /// SHA256 hash of the payment preimage that will be given in return for paying the invoice.
473 #[must_use]
474 #[no_mangle]
475 pub extern "C" fn UnsignedBolt12Invoice_payment_hash(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
476         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
477         crate::c_types::ThirtyTwoBytes { data: ret.0 }
478 }
479
480 /// The minimum amount required for a successful payment of the invoice.
481 #[must_use]
482 #[no_mangle]
483 pub extern "C" fn UnsignedBolt12Invoice_amount_msats(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 {
484         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_msats();
485         ret
486 }
487
488 /// Features pertaining to paying an invoice.
489 #[must_use]
490 #[no_mangle]
491 pub extern "C" fn UnsignedBolt12Invoice_invoice_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::Bolt12InvoiceFeatures {
492         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_features();
493         crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::Bolt12InvoiceFeatures<>) as *mut _) }, is_owned: false }
494 }
495
496 /// The public key corresponding to the key used to sign the invoice.
497 #[must_use]
498 #[no_mangle]
499 pub extern "C" fn UnsignedBolt12Invoice_signing_pubkey(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::PublicKey {
500         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signing_pubkey();
501         crate::c_types::PublicKey::from_rust(&ret)
502 }
503
504 /// The chains that may be used when paying a requested invoice.
505 ///
506 /// From [`Offer::chains`]; `None` if the invoice was created in response to a [`Refund`].
507 ///
508 /// [`Offer::chains`]: crate::offers::offer::Offer::chains
509 #[must_use]
510 #[no_mangle]
511 pub extern "C" fn Bolt12Invoice_offer_chains(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ {
512         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_chains();
513         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() }) };
514         local_ret
515 }
516
517 /// The chain that must be used when paying the invoice; selected from [`offer_chains`] if the
518 /// invoice originated from an offer.
519 ///
520 /// From [`InvoiceRequest::chain`] or [`Refund::chain`].
521 ///
522 /// [`offer_chains`]: Self::offer_chains
523 /// [`InvoiceRequest::chain`]: crate::offers::invoice_request::InvoiceRequest::chain
524 #[must_use]
525 #[no_mangle]
526 pub extern "C" fn Bolt12Invoice_chain(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
527         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.chain();
528         crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() }
529 }
530
531 /// Opaque bytes set by the originating [`Offer`].
532 ///
533 /// From [`Offer::metadata`]; `None` if the invoice was created in response to a [`Refund`] or
534 /// if the [`Offer`] did not set it.
535 ///
536 /// [`Offer`]: crate::offers::offer::Offer
537 /// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
538 #[must_use]
539 #[no_mangle]
540 pub extern "C" fn Bolt12Invoice_metadata(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
541         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.metadata();
542         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() }) };
543         local_ret
544 }
545
546 /// The minimum amount required for a successful payment of a single item.
547 ///
548 /// From [`Offer::amount`]; `None` if the invoice was created in response to a [`Refund`] or if
549 /// the [`Offer`] did not set it.
550 ///
551 /// [`Offer`]: crate::offers::offer::Offer
552 /// [`Offer::amount`]: crate::offers::offer::Offer::amount
553 ///
554 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
555 #[must_use]
556 #[no_mangle]
557 pub extern "C" fn Bolt12Invoice_amount(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::offers::offer::Amount {
558         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount();
559         let mut local_ret = crate::lightning::offers::offer::Amount { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::offers::offer::Amount<>) as *mut _ }, is_owned: false };
560         local_ret
561 }
562
563 /// Features pertaining to the originating [`Offer`].
564 ///
565 /// From [`Offer::offer_features`]; `None` if the invoice was created in response to a
566 /// [`Refund`].
567 ///
568 /// [`Offer`]: crate::offers::offer::Offer
569 /// [`Offer::offer_features`]: crate::offers::offer::Offer::offer_features
570 ///
571 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
572 #[must_use]
573 #[no_mangle]
574 pub extern "C" fn Bolt12Invoice_offer_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::OfferFeatures {
575         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_features();
576         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 };
577         local_ret
578 }
579
580 /// A complete description of the purpose of the originating offer or refund.
581 ///
582 /// From [`Offer::description`] or [`Refund::description`].
583 ///
584 /// [`Offer::description`]: crate::offers::offer::Offer::description
585 #[must_use]
586 #[no_mangle]
587 pub extern "C" fn Bolt12Invoice_description(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString {
588         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
589         crate::lightning::util::string::PrintableString { inner: ObjOps::heap_alloc(ret), is_owned: true }
590 }
591
592 /// Duration since the Unix epoch when an invoice should no longer be requested.
593 ///
594 /// From [`Offer::absolute_expiry`] or [`Refund::absolute_expiry`].
595 ///
596 /// [`Offer::absolute_expiry`]: crate::offers::offer::Offer::absolute_expiry
597 #[must_use]
598 #[no_mangle]
599 pub extern "C" fn Bolt12Invoice_absolute_expiry(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_u64Z {
600         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.absolute_expiry();
601         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() }) };
602         local_ret
603 }
604
605 /// The issuer of the offer or refund.
606 ///
607 /// From [`Offer::issuer`] or [`Refund::issuer`].
608 ///
609 /// [`Offer::issuer`]: crate::offers::offer::Offer::issuer
610 ///
611 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
612 #[must_use]
613 #[no_mangle]
614 pub extern "C" fn Bolt12Invoice_issuer(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString {
615         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.issuer();
616         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 };
617         local_ret
618 }
619
620 /// Paths to the recipient originating from publicly reachable nodes.
621 ///
622 /// From [`Offer::paths`] or [`Refund::paths`].
623 ///
624 /// [`Offer::paths`]: crate::offers::offer::Offer::paths
625 #[must_use]
626 #[no_mangle]
627 pub extern "C" fn Bolt12Invoice_message_paths(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::CVec_BlindedPathZ {
628         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.message_paths();
629         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 } }); };
630         local_ret.into()
631 }
632
633 /// The quantity of items supported.
634 ///
635 /// From [`Offer::supported_quantity`]; `None` if the invoice was created in response to a
636 /// [`Refund`].
637 ///
638 /// [`Offer::supported_quantity`]: crate::offers::offer::Offer::supported_quantity
639 ///
640 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
641 #[must_use]
642 #[no_mangle]
643 pub extern "C" fn Bolt12Invoice_supported_quantity(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::offers::offer::Quantity {
644         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supported_quantity();
645         let mut local_ret = crate::lightning::offers::offer::Quantity { inner: if ret.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true };
646         local_ret
647 }
648
649 /// An unpredictable series of bytes from the payer.
650 ///
651 /// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
652 #[must_use]
653 #[no_mangle]
654 pub extern "C" fn Bolt12Invoice_payer_metadata(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::u8slice {
655         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_metadata();
656         let mut local_ret = crate::c_types::u8slice::from_slice(ret);
657         local_ret
658 }
659
660 /// Features pertaining to requesting an invoice.
661 ///
662 /// From [`InvoiceRequest::invoice_request_features`] or [`Refund::features`].
663 #[must_use]
664 #[no_mangle]
665 pub extern "C" fn Bolt12Invoice_invoice_request_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::InvoiceRequestFeatures {
666         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_request_features();
667         crate::lightning::ln::features::InvoiceRequestFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::InvoiceRequestFeatures<>) as *mut _) }, is_owned: false }
668 }
669
670 /// The quantity of items requested or refunded for.
671 ///
672 /// From [`InvoiceRequest::quantity`] or [`Refund::quantity`].
673 #[must_use]
674 #[no_mangle]
675 pub extern "C" fn Bolt12Invoice_quantity(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_u64Z {
676         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.quantity();
677         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() }) };
678         local_ret
679 }
680
681 /// A possibly transient pubkey used to sign the invoice request or to send an invoice for a
682 /// refund in case there are no [`message_paths`].
683 ///
684 /// [`message_paths`]: Self::message_paths
685 #[must_use]
686 #[no_mangle]
687 pub extern "C" fn Bolt12Invoice_payer_id(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::PublicKey {
688         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_id();
689         crate::c_types::PublicKey::from_rust(&ret)
690 }
691
692 /// A payer-provided note reflected back in the invoice.
693 ///
694 /// From [`InvoiceRequest::payer_note`] or [`Refund::payer_note`].
695 ///
696 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
697 #[must_use]
698 #[no_mangle]
699 pub extern "C" fn Bolt12Invoice_payer_note(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString {
700         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_note();
701         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 };
702         local_ret
703 }
704
705 /// Duration since the Unix epoch when the invoice was created.
706 #[must_use]
707 #[no_mangle]
708 pub extern "C" fn Bolt12Invoice_created_at(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 {
709         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.created_at();
710         ret.as_secs()
711 }
712
713 /// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
714 /// should no longer be paid.
715 #[must_use]
716 #[no_mangle]
717 pub extern "C" fn Bolt12Invoice_relative_expiry(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 {
718         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.relative_expiry();
719         ret.as_secs()
720 }
721
722 /// Whether the invoice has expired.
723 #[must_use]
724 #[no_mangle]
725 pub extern "C" fn Bolt12Invoice_is_expired(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> bool {
726         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
727         ret
728 }
729
730 /// SHA256 hash of the payment preimage that will be given in return for paying the invoice.
731 #[must_use]
732 #[no_mangle]
733 pub extern "C" fn Bolt12Invoice_payment_hash(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
734         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
735         crate::c_types::ThirtyTwoBytes { data: ret.0 }
736 }
737
738 /// The minimum amount required for a successful payment of the invoice.
739 #[must_use]
740 #[no_mangle]
741 pub extern "C" fn Bolt12Invoice_amount_msats(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 {
742         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_msats();
743         ret
744 }
745
746 /// Features pertaining to paying an invoice.
747 #[must_use]
748 #[no_mangle]
749 pub extern "C" fn Bolt12Invoice_invoice_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::Bolt12InvoiceFeatures {
750         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_features();
751         crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::Bolt12InvoiceFeatures<>) as *mut _) }, is_owned: false }
752 }
753
754 /// The public key corresponding to the key used to sign the invoice.
755 #[must_use]
756 #[no_mangle]
757 pub extern "C" fn Bolt12Invoice_signing_pubkey(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::PublicKey {
758         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signing_pubkey();
759         crate::c_types::PublicKey::from_rust(&ret)
760 }
761
762 /// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
763 #[must_use]
764 #[no_mangle]
765 pub extern "C" fn Bolt12Invoice_signature(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::SchnorrSignature {
766         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
767         crate::c_types::SchnorrSignature::from_rust(&ret)
768 }
769
770 /// Hash that was used for signing the invoice.
771 #[must_use]
772 #[no_mangle]
773 pub extern "C" fn Bolt12Invoice_signable_hash(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
774         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
775         crate::c_types::ThirtyTwoBytes { data: ret }
776 }
777
778 /// Verifies that the invoice was for a request or refund created using the given key. Returns
779 /// the associated [`PaymentId`] to use when sending the payment.
780 #[must_use]
781 #[no_mangle]
782 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 {
783         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.verify(key.get_native_ref(), secp256k1::global::SECP256K1);
784         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() };
785         local_ret
786 }
787
788 #[no_mangle]
789 /// Serialize the UnsignedBolt12Invoice object into a byte array which can be read by UnsignedBolt12Invoice_read
790 pub extern "C" fn UnsignedBolt12Invoice_write(obj: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CVec_u8Z {
791         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
792 }
793 #[allow(unused)]
794 pub(crate) extern "C" fn UnsignedBolt12Invoice_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
795         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedBolt12Invoice) })
796 }
797 #[no_mangle]
798 /// Serialize the Bolt12Invoice object into a byte array which can be read by Bolt12Invoice_read
799 pub extern "C" fn Bolt12Invoice_write(obj: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::CVec_u8Z {
800         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
801 }
802 #[allow(unused)]
803 pub(crate) extern "C" fn Bolt12Invoice_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
804         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBolt12Invoice) })
805 }
806
807 use lightning::offers::invoice::BlindedPayInfo as nativeBlindedPayInfoImport;
808 pub(crate) type nativeBlindedPayInfo = nativeBlindedPayInfoImport;
809
810 /// Information needed to route a payment across a [`BlindedPath`].
811 #[must_use]
812 #[repr(C)]
813 pub struct BlindedPayInfo {
814         /// A pointer to the opaque Rust object.
815
816         /// Nearly everywhere, inner must be non-null, however in places where
817         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
818         pub inner: *mut nativeBlindedPayInfo,
819         /// Indicates that this is the only struct which contains the same pointer.
820
821         /// Rust functions which take ownership of an object provided via an argument require
822         /// this to be true and invalidate the object pointed to by inner.
823         pub is_owned: bool,
824 }
825
826 impl Drop for BlindedPayInfo {
827         fn drop(&mut self) {
828                 if self.is_owned && !<*mut nativeBlindedPayInfo>::is_null(self.inner) {
829                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
830                 }
831         }
832 }
833 /// Frees any resources used by the BlindedPayInfo, if is_owned is set and inner is non-NULL.
834 #[no_mangle]
835 pub extern "C" fn BlindedPayInfo_free(this_obj: BlindedPayInfo) { }
836 #[allow(unused)]
837 /// Used only if an object of this type is returned as a trait impl by a method
838 pub(crate) extern "C" fn BlindedPayInfo_free_void(this_ptr: *mut c_void) {
839         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedPayInfo) };
840 }
841 #[allow(unused)]
842 impl BlindedPayInfo {
843         pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedPayInfo {
844                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
845         }
846         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedPayInfo {
847                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
848         }
849         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
850         pub(crate) fn take_inner(mut self) -> *mut nativeBlindedPayInfo {
851                 assert!(self.is_owned);
852                 let ret = ObjOps::untweak_ptr(self.inner);
853                 self.inner = core::ptr::null_mut();
854                 ret
855         }
856 }
857 /// Base fee charged (in millisatoshi) for the entire blinded path.
858 #[no_mangle]
859 pub extern "C" fn BlindedPayInfo_get_fee_base_msat(this_ptr: &BlindedPayInfo) -> u32 {
860         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
861         *inner_val
862 }
863 /// Base fee charged (in millisatoshi) for the entire blinded path.
864 #[no_mangle]
865 pub extern "C" fn BlindedPayInfo_set_fee_base_msat(this_ptr: &mut BlindedPayInfo, mut val: u32) {
866         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
867 }
868 /// Liquidity fee charged (in millionths of the amount transferred) for the entire blinded path
869 /// (i.e., 10,000 is 1%).
870 #[no_mangle]
871 pub extern "C" fn BlindedPayInfo_get_fee_proportional_millionths(this_ptr: &BlindedPayInfo) -> u32 {
872         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
873         *inner_val
874 }
875 /// Liquidity fee charged (in millionths of the amount transferred) for the entire blinded path
876 /// (i.e., 10,000 is 1%).
877 #[no_mangle]
878 pub extern "C" fn BlindedPayInfo_set_fee_proportional_millionths(this_ptr: &mut BlindedPayInfo, mut val: u32) {
879         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
880 }
881 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for the entire blinded
882 /// path.
883 #[no_mangle]
884 pub extern "C" fn BlindedPayInfo_get_cltv_expiry_delta(this_ptr: &BlindedPayInfo) -> u16 {
885         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
886         *inner_val
887 }
888 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for the entire blinded
889 /// path.
890 #[no_mangle]
891 pub extern "C" fn BlindedPayInfo_set_cltv_expiry_delta(this_ptr: &mut BlindedPayInfo, mut val: u16) {
892         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
893 }
894 /// The minimum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
895 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
896 /// seen by the recipient.
897 #[no_mangle]
898 pub extern "C" fn BlindedPayInfo_get_htlc_minimum_msat(this_ptr: &BlindedPayInfo) -> u64 {
899         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
900         *inner_val
901 }
902 /// The minimum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
903 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
904 /// seen by the recipient.
905 #[no_mangle]
906 pub extern "C" fn BlindedPayInfo_set_htlc_minimum_msat(this_ptr: &mut BlindedPayInfo, mut val: u64) {
907         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
908 }
909 /// The maximum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
910 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
911 /// seen by the recipient.
912 #[no_mangle]
913 pub extern "C" fn BlindedPayInfo_get_htlc_maximum_msat(this_ptr: &BlindedPayInfo) -> u64 {
914         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
915         *inner_val
916 }
917 /// The maximum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
918 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
919 /// seen by the recipient.
920 #[no_mangle]
921 pub extern "C" fn BlindedPayInfo_set_htlc_maximum_msat(this_ptr: &mut BlindedPayInfo, mut val: u64) {
922         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val;
923 }
924 /// Features set in `encrypted_data_tlv` for the `encrypted_recipient_data` TLV record in an
925 /// onion payload.
926 #[no_mangle]
927 pub extern "C" fn BlindedPayInfo_get_features(this_ptr: &BlindedPayInfo) -> crate::lightning::ln::features::BlindedHopFeatures {
928         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
929         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 }
930 }
931 /// Features set in `encrypted_data_tlv` for the `encrypted_recipient_data` TLV record in an
932 /// onion payload.
933 #[no_mangle]
934 pub extern "C" fn BlindedPayInfo_set_features(this_ptr: &mut BlindedPayInfo, mut val: crate::lightning::ln::features::BlindedHopFeatures) {
935         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
936 }
937 /// Constructs a new BlindedPayInfo given each field
938 #[must_use]
939 #[no_mangle]
940 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 {
941         BlindedPayInfo { inner: ObjOps::heap_alloc(nativeBlindedPayInfo {
942                 fee_base_msat: fee_base_msat_arg,
943                 fee_proportional_millionths: fee_proportional_millionths_arg,
944                 cltv_expiry_delta: cltv_expiry_delta_arg,
945                 htlc_minimum_msat: htlc_minimum_msat_arg,
946                 htlc_maximum_msat: htlc_maximum_msat_arg,
947                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
948         }), is_owned: true }
949 }
950 impl Clone for BlindedPayInfo {
951         fn clone(&self) -> Self {
952                 Self {
953                         inner: if <*mut nativeBlindedPayInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
954                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
955                         is_owned: true,
956                 }
957         }
958 }
959 #[allow(unused)]
960 /// Used only if an object of this type is returned as a trait impl by a method
961 pub(crate) extern "C" fn BlindedPayInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
962         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedPayInfo)).clone() })) as *mut c_void
963 }
964 #[no_mangle]
965 /// Creates a copy of the BlindedPayInfo
966 pub extern "C" fn BlindedPayInfo_clone(orig: &BlindedPayInfo) -> BlindedPayInfo {
967         orig.clone()
968 }
969 /// Get a string which allows debug introspection of a BlindedPayInfo object
970 pub extern "C" fn BlindedPayInfo_debug_str_void(o: *const c_void) -> Str {
971         alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::invoice::BlindedPayInfo }).into()}
972 /// Generates a non-cryptographic 64-bit hash of the BlindedPayInfo.
973 #[no_mangle]
974 pub extern "C" fn BlindedPayInfo_hash(o: &BlindedPayInfo) -> u64 {
975         if o.inner.is_null() { return 0; }
976         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
977         #[allow(deprecated)]
978         let mut hasher = core::hash::SipHasher::new();
979         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
980         core::hash::Hasher::finish(&hasher)
981 }
982 /// Checks if two BlindedPayInfos contain equal inner contents.
983 /// This ignores pointers and is_owned flags and looks at the values in fields.
984 /// Two objects with NULL inner values will be considered "equal" here.
985 #[no_mangle]
986 pub extern "C" fn BlindedPayInfo_eq(a: &BlindedPayInfo, b: &BlindedPayInfo) -> bool {
987         if a.inner == b.inner { return true; }
988         if a.inner.is_null() || b.inner.is_null() { return false; }
989         if a.get_native_ref() == b.get_native_ref() { true } else { false }
990 }
991 #[no_mangle]
992 /// Serialize the BlindedPayInfo object into a byte array which can be read by BlindedPayInfo_read
993 pub extern "C" fn BlindedPayInfo_write(obj: &crate::lightning::offers::invoice::BlindedPayInfo) -> crate::c_types::derived::CVec_u8Z {
994         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
995 }
996 #[allow(unused)]
997 pub(crate) extern "C" fn BlindedPayInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
998         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedPayInfo) })
999 }
1000 #[no_mangle]
1001 /// Read a BlindedPayInfo from a byte array, created by BlindedPayInfo_write
1002 pub extern "C" fn BlindedPayInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedPayInfoDecodeErrorZ {
1003         let res: Result<lightning::offers::invoice::BlindedPayInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1004         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() };
1005         local_res
1006 }