Update auto-generated bindings
[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::util::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::util::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 *mut 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 /// The chains that may be used when paying a requested invoice.
244 ///
245 /// From [`Offer::chains`]; `None` if the invoice was created in response to a [`Refund`].
246 ///
247 /// [`Offer::chains`]: crate::offers::offer::Offer::chains
248 #[must_use]
249 #[no_mangle]
250 pub extern "C" fn UnsignedBolt12Invoice_offer_chains(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ {
251         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_chains();
252         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::None } else { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::c_types::ThirtyTwoBytes { data: item.to_bytes() } }); }; local_ret_0.into() }) };
253         local_ret
254 }
255
256 /// The chain that must be used when paying the invoice; selected from [`offer_chains`] if the
257 /// invoice originated from an offer.
258 ///
259 /// From [`InvoiceRequest::chain`] or [`Refund::chain`].
260 ///
261 /// [`offer_chains`]: Self::offer_chains
262 /// [`InvoiceRequest::chain`]: crate::offers::invoice_request::InvoiceRequest::chain
263 #[must_use]
264 #[no_mangle]
265 pub extern "C" fn UnsignedBolt12Invoice_chain(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
266         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.chain();
267         crate::c_types::ThirtyTwoBytes { data: ret.to_bytes() }
268 }
269
270 /// Opaque bytes set by the originating [`Offer`].
271 ///
272 /// From [`Offer::metadata`]; `None` if the invoice was created in response to a [`Refund`] or
273 /// if the [`Offer`] did not set it.
274 ///
275 /// [`Offer`]: crate::offers::offer::Offer
276 /// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
277 #[must_use]
278 #[no_mangle]
279 pub extern "C" fn UnsignedBolt12Invoice_metadata(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
280         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.metadata();
281         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() }) };
282         local_ret
283 }
284
285 /// The minimum amount required for a successful payment of a single item.
286 ///
287 /// From [`Offer::amount`]; `None` if the invoice was created in response to a [`Refund`] or if
288 /// the [`Offer`] did not set it.
289 ///
290 /// [`Offer`]: crate::offers::offer::Offer
291 /// [`Offer::amount`]: crate::offers::offer::Offer::amount
292 ///
293 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
294 #[must_use]
295 #[no_mangle]
296 pub extern "C" fn UnsignedBolt12Invoice_amount(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::offers::offer::Amount {
297         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount();
298         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 };
299         local_ret
300 }
301
302 /// Features pertaining to the originating [`Offer`].
303 ///
304 /// From [`Offer::offer_features`]; `None` if the invoice was created in response to a
305 /// [`Refund`].
306 ///
307 /// [`Offer`]: crate::offers::offer::Offer
308 /// [`Offer::offer_features`]: crate::offers::offer::Offer::offer_features
309 ///
310 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
311 #[must_use]
312 #[no_mangle]
313 pub extern "C" fn UnsignedBolt12Invoice_offer_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::OfferFeatures {
314         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_features();
315         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 };
316         local_ret
317 }
318
319 /// A complete description of the purpose of the originating offer or refund.
320 ///
321 /// From [`Offer::description`] or [`Refund::description`].
322 ///
323 /// [`Offer::description`]: crate::offers::offer::Offer::description
324 #[must_use]
325 #[no_mangle]
326 pub extern "C" fn UnsignedBolt12Invoice_description(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString {
327         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
328         crate::lightning::util::string::PrintableString { inner: ObjOps::heap_alloc(ret), is_owned: true }
329 }
330
331 /// Duration since the Unix epoch when an invoice should no longer be requested.
332 ///
333 /// From [`Offer::absolute_expiry`] or [`Refund::absolute_expiry`].
334 ///
335 /// [`Offer::absolute_expiry`]: crate::offers::offer::Offer::absolute_expiry
336 #[must_use]
337 #[no_mangle]
338 pub extern "C" fn UnsignedBolt12Invoice_absolute_expiry(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_u64Z {
339         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.absolute_expiry();
340         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() }) };
341         local_ret
342 }
343
344 /// The issuer of the offer or refund.
345 ///
346 /// From [`Offer::issuer`] or [`Refund::issuer`].
347 ///
348 /// [`Offer::issuer`]: crate::offers::offer::Offer::issuer
349 ///
350 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
351 #[must_use]
352 #[no_mangle]
353 pub extern "C" fn UnsignedBolt12Invoice_issuer(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString {
354         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.issuer();
355         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 };
356         local_ret
357 }
358
359 /// Paths to the recipient originating from publicly reachable nodes.
360 ///
361 /// From [`Offer::paths`] or [`Refund::paths`].
362 ///
363 /// [`Offer::paths`]: crate::offers::offer::Offer::paths
364 #[must_use]
365 #[no_mangle]
366 pub extern "C" fn UnsignedBolt12Invoice_message_paths(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CVec_BlindedPathZ {
367         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.message_paths();
368         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 } }); };
369         local_ret.into()
370 }
371
372 /// The quantity of items supported.
373 ///
374 /// From [`Offer::supported_quantity`]; `None` if the invoice was created in response to a
375 /// [`Refund`].
376 ///
377 /// [`Offer::supported_quantity`]: crate::offers::offer::Offer::supported_quantity
378 ///
379 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
380 #[must_use]
381 #[no_mangle]
382 pub extern "C" fn UnsignedBolt12Invoice_supported_quantity(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::offers::offer::Quantity {
383         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supported_quantity();
384         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 };
385         local_ret
386 }
387
388 /// An unpredictable series of bytes from the payer.
389 ///
390 /// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
391 #[must_use]
392 #[no_mangle]
393 pub extern "C" fn UnsignedBolt12Invoice_payer_metadata(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::u8slice {
394         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_metadata();
395         let mut local_ret = crate::c_types::u8slice::from_slice(ret);
396         local_ret
397 }
398
399 /// Features pertaining to requesting an invoice.
400 ///
401 /// From [`InvoiceRequest::invoice_request_features`] or [`Refund::features`].
402 #[must_use]
403 #[no_mangle]
404 pub extern "C" fn UnsignedBolt12Invoice_invoice_request_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::InvoiceRequestFeatures {
405         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_request_features();
406         crate::lightning::ln::features::InvoiceRequestFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::InvoiceRequestFeatures<>) as *mut _) }, is_owned: false }
407 }
408
409 /// The quantity of items requested or refunded for.
410 ///
411 /// From [`InvoiceRequest::quantity`] or [`Refund::quantity`].
412 #[must_use]
413 #[no_mangle]
414 pub extern "C" fn UnsignedBolt12Invoice_quantity(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::COption_u64Z {
415         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.quantity();
416         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() }) };
417         local_ret
418 }
419
420 /// A possibly transient pubkey used to sign the invoice request or to send an invoice for a
421 /// refund in case there are no [`message_paths`].
422 ///
423 /// [`message_paths`]: Self::message_paths
424 #[must_use]
425 #[no_mangle]
426 pub extern "C" fn UnsignedBolt12Invoice_payer_id(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::PublicKey {
427         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_id();
428         crate::c_types::PublicKey::from_rust(&ret)
429 }
430
431 /// A payer-provided note reflected back in the invoice.
432 ///
433 /// From [`InvoiceRequest::payer_note`] or [`Refund::payer_note`].
434 ///
435 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
436 #[must_use]
437 #[no_mangle]
438 pub extern "C" fn UnsignedBolt12Invoice_payer_note(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::util::string::PrintableString {
439         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_note();
440         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 };
441         local_ret
442 }
443
444 /// Duration since the Unix epoch when the invoice was created.
445 #[must_use]
446 #[no_mangle]
447 pub extern "C" fn UnsignedBolt12Invoice_created_at(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 {
448         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.created_at();
449         ret.as_secs()
450 }
451
452 /// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
453 /// should no longer be paid.
454 #[must_use]
455 #[no_mangle]
456 pub extern "C" fn UnsignedBolt12Invoice_relative_expiry(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 {
457         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.relative_expiry();
458         ret.as_secs()
459 }
460
461 /// Whether the invoice has expired.
462 #[must_use]
463 #[no_mangle]
464 pub extern "C" fn UnsignedBolt12Invoice_is_expired(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> bool {
465         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
466         ret
467 }
468
469 /// SHA256 hash of the payment preimage that will be given in return for paying the invoice.
470 #[must_use]
471 #[no_mangle]
472 pub extern "C" fn UnsignedBolt12Invoice_payment_hash(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
473         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
474         crate::c_types::ThirtyTwoBytes { data: ret.0 }
475 }
476
477 /// The minimum amount required for a successful payment of the invoice.
478 #[must_use]
479 #[no_mangle]
480 pub extern "C" fn UnsignedBolt12Invoice_amount_msats(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> u64 {
481         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_msats();
482         ret
483 }
484
485 /// Features pertaining to paying an invoice.
486 #[must_use]
487 #[no_mangle]
488 pub extern "C" fn UnsignedBolt12Invoice_invoice_features(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::lightning::ln::features::Bolt12InvoiceFeatures {
489         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_features();
490         crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::Bolt12InvoiceFeatures<>) as *mut _) }, is_owned: false }
491 }
492
493 /// The public key corresponding to the key used to sign the invoice.
494 #[must_use]
495 #[no_mangle]
496 pub extern "C" fn UnsignedBolt12Invoice_signing_pubkey(this_arg: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::PublicKey {
497         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signing_pubkey();
498         crate::c_types::PublicKey::from_rust(&ret)
499 }
500
501 /// The chains that may be used when paying a requested invoice.
502 ///
503 /// From [`Offer::chains`]; `None` if the invoice was created in response to a [`Refund`].
504 ///
505 /// [`Offer::chains`]: crate::offers::offer::Offer::chains
506 #[must_use]
507 #[no_mangle]
508 pub extern "C" fn Bolt12Invoice_offer_chains(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ {
509         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_chains();
510         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::None } else { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::c_types::ThirtyTwoBytes { data: item.to_bytes() } }); }; local_ret_0.into() }) };
511         local_ret
512 }
513
514 /// The chain that must be used when paying the invoice; selected from [`offer_chains`] if the
515 /// invoice originated from an offer.
516 ///
517 /// From [`InvoiceRequest::chain`] or [`Refund::chain`].
518 ///
519 /// [`offer_chains`]: Self::offer_chains
520 /// [`InvoiceRequest::chain`]: crate::offers::invoice_request::InvoiceRequest::chain
521 #[must_use]
522 #[no_mangle]
523 pub extern "C" fn Bolt12Invoice_chain(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
524         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.chain();
525         crate::c_types::ThirtyTwoBytes { data: ret.to_bytes() }
526 }
527
528 /// Opaque bytes set by the originating [`Offer`].
529 ///
530 /// From [`Offer::metadata`]; `None` if the invoice was created in response to a [`Refund`] or
531 /// if the [`Offer`] did not set it.
532 ///
533 /// [`Offer`]: crate::offers::offer::Offer
534 /// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
535 #[must_use]
536 #[no_mangle]
537 pub extern "C" fn Bolt12Invoice_metadata(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
538         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.metadata();
539         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() }) };
540         local_ret
541 }
542
543 /// The minimum amount required for a successful payment of a single item.
544 ///
545 /// From [`Offer::amount`]; `None` if the invoice was created in response to a [`Refund`] or if
546 /// the [`Offer`] did not set it.
547 ///
548 /// [`Offer`]: crate::offers::offer::Offer
549 /// [`Offer::amount`]: crate::offers::offer::Offer::amount
550 ///
551 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
552 #[must_use]
553 #[no_mangle]
554 pub extern "C" fn Bolt12Invoice_amount(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::offers::offer::Amount {
555         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount();
556         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 };
557         local_ret
558 }
559
560 /// Features pertaining to the originating [`Offer`].
561 ///
562 /// From [`Offer::offer_features`]; `None` if the invoice was created in response to a
563 /// [`Refund`].
564 ///
565 /// [`Offer`]: crate::offers::offer::Offer
566 /// [`Offer::offer_features`]: crate::offers::offer::Offer::offer_features
567 ///
568 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
569 #[must_use]
570 #[no_mangle]
571 pub extern "C" fn Bolt12Invoice_offer_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::OfferFeatures {
572         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_features();
573         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 };
574         local_ret
575 }
576
577 /// A complete description of the purpose of the originating offer or refund.
578 ///
579 /// From [`Offer::description`] or [`Refund::description`].
580 ///
581 /// [`Offer::description`]: crate::offers::offer::Offer::description
582 #[must_use]
583 #[no_mangle]
584 pub extern "C" fn Bolt12Invoice_description(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString {
585         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
586         crate::lightning::util::string::PrintableString { inner: ObjOps::heap_alloc(ret), is_owned: true }
587 }
588
589 /// Duration since the Unix epoch when an invoice should no longer be requested.
590 ///
591 /// From [`Offer::absolute_expiry`] or [`Refund::absolute_expiry`].
592 ///
593 /// [`Offer::absolute_expiry`]: crate::offers::offer::Offer::absolute_expiry
594 #[must_use]
595 #[no_mangle]
596 pub extern "C" fn Bolt12Invoice_absolute_expiry(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_u64Z {
597         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.absolute_expiry();
598         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() }) };
599         local_ret
600 }
601
602 /// The issuer of the offer or refund.
603 ///
604 /// From [`Offer::issuer`] or [`Refund::issuer`].
605 ///
606 /// [`Offer::issuer`]: crate::offers::offer::Offer::issuer
607 ///
608 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
609 #[must_use]
610 #[no_mangle]
611 pub extern "C" fn Bolt12Invoice_issuer(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString {
612         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.issuer();
613         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 };
614         local_ret
615 }
616
617 /// Paths to the recipient originating from publicly reachable nodes.
618 ///
619 /// From [`Offer::paths`] or [`Refund::paths`].
620 ///
621 /// [`Offer::paths`]: crate::offers::offer::Offer::paths
622 #[must_use]
623 #[no_mangle]
624 pub extern "C" fn Bolt12Invoice_message_paths(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::CVec_BlindedPathZ {
625         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.message_paths();
626         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 } }); };
627         local_ret.into()
628 }
629
630 /// The quantity of items supported.
631 ///
632 /// From [`Offer::supported_quantity`]; `None` if the invoice was created in response to a
633 /// [`Refund`].
634 ///
635 /// [`Offer::supported_quantity`]: crate::offers::offer::Offer::supported_quantity
636 ///
637 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
638 #[must_use]
639 #[no_mangle]
640 pub extern "C" fn Bolt12Invoice_supported_quantity(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::offers::offer::Quantity {
641         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supported_quantity();
642         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 };
643         local_ret
644 }
645
646 /// An unpredictable series of bytes from the payer.
647 ///
648 /// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
649 #[must_use]
650 #[no_mangle]
651 pub extern "C" fn Bolt12Invoice_payer_metadata(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::u8slice {
652         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_metadata();
653         let mut local_ret = crate::c_types::u8slice::from_slice(ret);
654         local_ret
655 }
656
657 /// Features pertaining to requesting an invoice.
658 ///
659 /// From [`InvoiceRequest::invoice_request_features`] or [`Refund::features`].
660 #[must_use]
661 #[no_mangle]
662 pub extern "C" fn Bolt12Invoice_invoice_request_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::InvoiceRequestFeatures {
663         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_request_features();
664         crate::lightning::ln::features::InvoiceRequestFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::InvoiceRequestFeatures<>) as *mut _) }, is_owned: false }
665 }
666
667 /// The quantity of items requested or refunded for.
668 ///
669 /// From [`InvoiceRequest::quantity`] or [`Refund::quantity`].
670 #[must_use]
671 #[no_mangle]
672 pub extern "C" fn Bolt12Invoice_quantity(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::COption_u64Z {
673         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.quantity();
674         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() }) };
675         local_ret
676 }
677
678 /// A possibly transient pubkey used to sign the invoice request or to send an invoice for a
679 /// refund in case there are no [`message_paths`].
680 ///
681 /// [`message_paths`]: Self::message_paths
682 #[must_use]
683 #[no_mangle]
684 pub extern "C" fn Bolt12Invoice_payer_id(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::PublicKey {
685         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_id();
686         crate::c_types::PublicKey::from_rust(&ret)
687 }
688
689 /// A payer-provided note reflected back in the invoice.
690 ///
691 /// From [`InvoiceRequest::payer_note`] or [`Refund::payer_note`].
692 ///
693 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
694 #[must_use]
695 #[no_mangle]
696 pub extern "C" fn Bolt12Invoice_payer_note(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::util::string::PrintableString {
697         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_note();
698         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 };
699         local_ret
700 }
701
702 /// Duration since the Unix epoch when the invoice was created.
703 #[must_use]
704 #[no_mangle]
705 pub extern "C" fn Bolt12Invoice_created_at(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 {
706         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.created_at();
707         ret.as_secs()
708 }
709
710 /// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
711 /// should no longer be paid.
712 #[must_use]
713 #[no_mangle]
714 pub extern "C" fn Bolt12Invoice_relative_expiry(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 {
715         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.relative_expiry();
716         ret.as_secs()
717 }
718
719 /// Whether the invoice has expired.
720 #[must_use]
721 #[no_mangle]
722 pub extern "C" fn Bolt12Invoice_is_expired(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> bool {
723         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
724         ret
725 }
726
727 /// SHA256 hash of the payment preimage that will be given in return for paying the invoice.
728 #[must_use]
729 #[no_mangle]
730 pub extern "C" fn Bolt12Invoice_payment_hash(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
731         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
732         crate::c_types::ThirtyTwoBytes { data: ret.0 }
733 }
734
735 /// The minimum amount required for a successful payment of the invoice.
736 #[must_use]
737 #[no_mangle]
738 pub extern "C" fn Bolt12Invoice_amount_msats(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> u64 {
739         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_msats();
740         ret
741 }
742
743 /// Features pertaining to paying an invoice.
744 #[must_use]
745 #[no_mangle]
746 pub extern "C" fn Bolt12Invoice_invoice_features(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::ln::features::Bolt12InvoiceFeatures {
747         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.invoice_features();
748         crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::Bolt12InvoiceFeatures<>) as *mut _) }, is_owned: false }
749 }
750
751 /// The public key corresponding to the key used to sign the invoice.
752 #[must_use]
753 #[no_mangle]
754 pub extern "C" fn Bolt12Invoice_signing_pubkey(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::PublicKey {
755         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signing_pubkey();
756         crate::c_types::PublicKey::from_rust(&ret)
757 }
758
759 /// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
760 #[must_use]
761 #[no_mangle]
762 pub extern "C" fn Bolt12Invoice_signature(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::SchnorrSignature {
763         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
764         crate::c_types::SchnorrSignature::from_rust(&ret)
765 }
766
767 /// Hash that was used for signing the invoice.
768 #[must_use]
769 #[no_mangle]
770 pub extern "C" fn Bolt12Invoice_signable_hash(this_arg: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::ThirtyTwoBytes {
771         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
772         crate::c_types::ThirtyTwoBytes { data: ret }
773 }
774
775 /// Verifies that the invoice was for a request or refund created using the given key. Returns
776 /// the associated [`PaymentId`] to use when sending the payment.
777 #[must_use]
778 #[no_mangle]
779 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 {
780         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.verify(key.get_native_ref(), secp256k1::global::SECP256K1);
781         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() };
782         local_ret
783 }
784
785 #[no_mangle]
786 /// Serialize the UnsignedBolt12Invoice object into a byte array which can be read by UnsignedBolt12Invoice_read
787 pub extern "C" fn UnsignedBolt12Invoice_write(obj: &crate::lightning::offers::invoice::UnsignedBolt12Invoice) -> crate::c_types::derived::CVec_u8Z {
788         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
789 }
790 #[no_mangle]
791 pub(crate) extern "C" fn UnsignedBolt12Invoice_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
792         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedBolt12Invoice) })
793 }
794 #[no_mangle]
795 /// Serialize the Bolt12Invoice object into a byte array which can be read by Bolt12Invoice_read
796 pub extern "C" fn Bolt12Invoice_write(obj: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::c_types::derived::CVec_u8Z {
797         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
798 }
799 #[no_mangle]
800 pub(crate) extern "C" fn Bolt12Invoice_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
801         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBolt12Invoice) })
802 }
803
804 use lightning::offers::invoice::BlindedPayInfo as nativeBlindedPayInfoImport;
805 pub(crate) type nativeBlindedPayInfo = nativeBlindedPayInfoImport;
806
807 /// Information needed to route a payment across a [`BlindedPath`].
808 #[must_use]
809 #[repr(C)]
810 pub struct BlindedPayInfo {
811         /// A pointer to the opaque Rust object.
812
813         /// Nearly everywhere, inner must be non-null, however in places where
814         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
815         pub inner: *mut nativeBlindedPayInfo,
816         /// Indicates that this is the only struct which contains the same pointer.
817
818         /// Rust functions which take ownership of an object provided via an argument require
819         /// this to be true and invalidate the object pointed to by inner.
820         pub is_owned: bool,
821 }
822
823 impl Drop for BlindedPayInfo {
824         fn drop(&mut self) {
825                 if self.is_owned && !<*mut nativeBlindedPayInfo>::is_null(self.inner) {
826                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
827                 }
828         }
829 }
830 /// Frees any resources used by the BlindedPayInfo, if is_owned is set and inner is non-NULL.
831 #[no_mangle]
832 pub extern "C" fn BlindedPayInfo_free(this_obj: BlindedPayInfo) { }
833 #[allow(unused)]
834 /// Used only if an object of this type is returned as a trait impl by a method
835 pub(crate) extern "C" fn BlindedPayInfo_free_void(this_ptr: *mut c_void) {
836         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedPayInfo) };
837 }
838 #[allow(unused)]
839 impl BlindedPayInfo {
840         pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedPayInfo {
841                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
842         }
843         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedPayInfo {
844                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
845         }
846         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
847         pub(crate) fn take_inner(mut self) -> *mut nativeBlindedPayInfo {
848                 assert!(self.is_owned);
849                 let ret = ObjOps::untweak_ptr(self.inner);
850                 self.inner = core::ptr::null_mut();
851                 ret
852         }
853 }
854 /// Base fee charged (in millisatoshi) for the entire blinded path.
855 #[no_mangle]
856 pub extern "C" fn BlindedPayInfo_get_fee_base_msat(this_ptr: &BlindedPayInfo) -> u32 {
857         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
858         *inner_val
859 }
860 /// Base fee charged (in millisatoshi) for the entire blinded path.
861 #[no_mangle]
862 pub extern "C" fn BlindedPayInfo_set_fee_base_msat(this_ptr: &mut BlindedPayInfo, mut val: u32) {
863         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
864 }
865 /// Liquidity fee charged (in millionths of the amount transferred) for the entire blinded path
866 /// (i.e., 10,000 is 1%).
867 #[no_mangle]
868 pub extern "C" fn BlindedPayInfo_get_fee_proportional_millionths(this_ptr: &BlindedPayInfo) -> u32 {
869         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
870         *inner_val
871 }
872 /// Liquidity fee charged (in millionths of the amount transferred) for the entire blinded path
873 /// (i.e., 10,000 is 1%).
874 #[no_mangle]
875 pub extern "C" fn BlindedPayInfo_set_fee_proportional_millionths(this_ptr: &mut BlindedPayInfo, mut val: u32) {
876         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
877 }
878 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for the entire blinded
879 /// path.
880 #[no_mangle]
881 pub extern "C" fn BlindedPayInfo_get_cltv_expiry_delta(this_ptr: &BlindedPayInfo) -> u16 {
882         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
883         *inner_val
884 }
885 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for the entire blinded
886 /// path.
887 #[no_mangle]
888 pub extern "C" fn BlindedPayInfo_set_cltv_expiry_delta(this_ptr: &mut BlindedPayInfo, mut val: u16) {
889         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
890 }
891 /// The minimum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
892 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
893 /// seen by the recipient.
894 #[no_mangle]
895 pub extern "C" fn BlindedPayInfo_get_htlc_minimum_msat(this_ptr: &BlindedPayInfo) -> u64 {
896         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
897         *inner_val
898 }
899 /// The minimum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
900 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
901 /// seen by the recipient.
902 #[no_mangle]
903 pub extern "C" fn BlindedPayInfo_set_htlc_minimum_msat(this_ptr: &mut BlindedPayInfo, mut val: u64) {
904         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
905 }
906 /// The maximum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
907 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
908 /// seen by the recipient.
909 #[no_mangle]
910 pub extern "C" fn BlindedPayInfo_get_htlc_maximum_msat(this_ptr: &BlindedPayInfo) -> u64 {
911         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
912         *inner_val
913 }
914 /// The maximum HTLC value (in millisatoshi) that is acceptable to all channel peers on the
915 /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as
916 /// seen by the recipient.
917 #[no_mangle]
918 pub extern "C" fn BlindedPayInfo_set_htlc_maximum_msat(this_ptr: &mut BlindedPayInfo, mut val: u64) {
919         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val;
920 }
921 /// Features set in `encrypted_data_tlv` for the `encrypted_recipient_data` TLV record in an
922 /// onion payload.
923 #[no_mangle]
924 pub extern "C" fn BlindedPayInfo_get_features(this_ptr: &BlindedPayInfo) -> crate::lightning::ln::features::BlindedHopFeatures {
925         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
926         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 }
927 }
928 /// Features set in `encrypted_data_tlv` for the `encrypted_recipient_data` TLV record in an
929 /// onion payload.
930 #[no_mangle]
931 pub extern "C" fn BlindedPayInfo_set_features(this_ptr: &mut BlindedPayInfo, mut val: crate::lightning::ln::features::BlindedHopFeatures) {
932         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
933 }
934 /// Constructs a new BlindedPayInfo given each field
935 #[must_use]
936 #[no_mangle]
937 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 {
938         BlindedPayInfo { inner: ObjOps::heap_alloc(nativeBlindedPayInfo {
939                 fee_base_msat: fee_base_msat_arg,
940                 fee_proportional_millionths: fee_proportional_millionths_arg,
941                 cltv_expiry_delta: cltv_expiry_delta_arg,
942                 htlc_minimum_msat: htlc_minimum_msat_arg,
943                 htlc_maximum_msat: htlc_maximum_msat_arg,
944                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
945         }), is_owned: true }
946 }
947 impl Clone for BlindedPayInfo {
948         fn clone(&self) -> Self {
949                 Self {
950                         inner: if <*mut nativeBlindedPayInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
951                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
952                         is_owned: true,
953                 }
954         }
955 }
956 #[allow(unused)]
957 /// Used only if an object of this type is returned as a trait impl by a method
958 pub(crate) extern "C" fn BlindedPayInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
959         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBlindedPayInfo)).clone() })) as *mut c_void
960 }
961 #[no_mangle]
962 /// Creates a copy of the BlindedPayInfo
963 pub extern "C" fn BlindedPayInfo_clone(orig: &BlindedPayInfo) -> BlindedPayInfo {
964         orig.clone()
965 }
966 /// Generates a non-cryptographic 64-bit hash of the BlindedPayInfo.
967 #[no_mangle]
968 pub extern "C" fn BlindedPayInfo_hash(o: &BlindedPayInfo) -> u64 {
969         if o.inner.is_null() { return 0; }
970         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
971         #[allow(deprecated)]
972         let mut hasher = core::hash::SipHasher::new();
973         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
974         core::hash::Hasher::finish(&hasher)
975 }
976 /// Checks if two BlindedPayInfos contain equal inner contents.
977 /// This ignores pointers and is_owned flags and looks at the values in fields.
978 /// Two objects with NULL inner values will be considered "equal" here.
979 #[no_mangle]
980 pub extern "C" fn BlindedPayInfo_eq(a: &BlindedPayInfo, b: &BlindedPayInfo) -> bool {
981         if a.inner == b.inner { return true; }
982         if a.inner.is_null() || b.inner.is_null() { return false; }
983         if a.get_native_ref() == b.get_native_ref() { true } else { false }
984 }
985 #[no_mangle]
986 /// Serialize the BlindedPayInfo object into a byte array which can be read by BlindedPayInfo_read
987 pub extern "C" fn BlindedPayInfo_write(obj: &crate::lightning::offers::invoice::BlindedPayInfo) -> crate::c_types::derived::CVec_u8Z {
988         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
989 }
990 #[no_mangle]
991 pub(crate) extern "C" fn BlindedPayInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
992         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedPayInfo) })
993 }
994 #[no_mangle]
995 /// Read a BlindedPayInfo from a byte array, created by BlindedPayInfo_write
996 pub extern "C" fn BlindedPayInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedPayInfoDecodeErrorZ {
997         let res: Result<lightning::offers::invoice::BlindedPayInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
998         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() };
999         local_res
1000 }