Pin compiler_builtins to 0.1.109 when building std
[ldk-c-bindings] / lightning-c-bindings / src / lightning / offers / offer.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 `offer` messages.
10 //!
11 //! An [`Offer`] represents an \"offer to be paid.\" It is typically constructed by a merchant and
12 //! published as a QR code to be scanned by a customer. The customer uses the offer to request an
13 //! invoice from the merchant to be paid.
14 //!
15 //! # Example
16 //!
17 //! ```
18 //! extern crate bitcoin;
19 //! extern crate core;
20 //! extern crate lightning;
21 //!
22 //! use core::convert::TryFrom;
23 //! use core::num::NonZeroU64;
24 //! use core::time::Duration;
25 //!
26 //! use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
27 //! use lightning::offers::offer::{Offer, OfferBuilder, Quantity};
28 //! use lightning::offers::parse::Bolt12ParseError;
29 //! use lightning::util::ser::{Readable, Writeable};
30 //!
31 //! # use lightning::blinded_path::BlindedPath;
32 //! # #[cfg(feature = \"std\")]
33 //! # use std::time::SystemTime;
34 //! #
35 //! # fn create_blinded_path() -> BlindedPath { unimplemented!() }
36 //! # fn create_another_blinded_path() -> BlindedPath { unimplemented!() }
37 //! #
38 //! # #[cfg(feature = \"std\")]
39 //! # fn build() -> Result<(), Bolt12ParseError> {
40 //! let secp_ctx = Secp256k1::new();
41 //! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
42 //! let pubkey = PublicKey::from(keys);
43 //!
44 //! let expiration = SystemTime::now() + Duration::from_secs(24 * 60 * 60);
45 //! let offer = OfferBuilder::new(pubkey)
46 //!     .description(\"coffee, large\".to_string())
47 //!     .amount_msats(20_000)
48 //!     .supported_quantity(Quantity::Unbounded)
49 //!     .absolute_expiry(expiration.duration_since(SystemTime::UNIX_EPOCH).unwrap())
50 //!     .issuer(\"Foo Bar\".to_string())
51 //!     .path(create_blinded_path())
52 //!     .path(create_another_blinded_path())
53 //!     .build()?;
54 //!
55 //! // Encode as a bech32 string for use in a QR code.
56 //! let encoded_offer = offer.to_string();
57 //!
58 //! // Parse from a bech32 string after scanning from a QR code.
59 //! let offer = encoded_offer.parse::<Offer>()?;
60 //!
61 //! // Encode offer as raw bytes.
62 //! let mut bytes = Vec::new();
63 //! offer.write(&mut bytes).unwrap();
64 //!
65 //! // Decode raw bytes into an offer.
66 //! let offer = Offer::try_from(bytes)?;
67 //! # Ok(())
68 //! # }
69 //! ```
70 //!
71 //! # Note
72 //!
73 //! If constructing an [`Offer`] for use with a [`ChannelManager`], use
74 //! [`ChannelManager::create_offer_builder`] instead of [`OfferBuilder::new`].
75 //!
76 //! [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
77 //! [`ChannelManager::create_offer_builder`]: crate::ln::channelmanager::ChannelManager::create_offer_builder
78
79 use alloc::str::FromStr;
80 use alloc::string::String;
81 use core::ffi::c_void;
82 use core::convert::Infallible;
83 use bitcoin::hashes::Hash;
84 use crate::c_types::*;
85 #[cfg(feature="no-std")]
86 use alloc::{vec::Vec, boxed::Box};
87
88
89 use lightning::offers::offer::OfferId as nativeOfferIdImport;
90 pub(crate) type nativeOfferId = nativeOfferIdImport;
91
92 /// An identifier for an [`Offer`] built using [`DerivedMetadata`].
93 #[must_use]
94 #[repr(C)]
95 pub struct OfferId {
96         /// A pointer to the opaque Rust object.
97
98         /// Nearly everywhere, inner must be non-null, however in places where
99         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
100         pub inner: *mut nativeOfferId,
101         /// Indicates that this is the only struct which contains the same pointer.
102
103         /// Rust functions which take ownership of an object provided via an argument require
104         /// this to be true and invalidate the object pointed to by inner.
105         pub is_owned: bool,
106 }
107
108 impl Drop for OfferId {
109         fn drop(&mut self) {
110                 if self.is_owned && !<*mut nativeOfferId>::is_null(self.inner) {
111                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
112                 }
113         }
114 }
115 /// Frees any resources used by the OfferId, if is_owned is set and inner is non-NULL.
116 #[no_mangle]
117 pub extern "C" fn OfferId_free(this_obj: OfferId) { }
118 #[allow(unused)]
119 /// Used only if an object of this type is returned as a trait impl by a method
120 pub(crate) extern "C" fn OfferId_free_void(this_ptr: *mut c_void) {
121         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOfferId) };
122 }
123 #[allow(unused)]
124 impl OfferId {
125         pub(crate) fn get_native_ref(&self) -> &'static nativeOfferId {
126                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
127         }
128         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOfferId {
129                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
130         }
131         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
132         pub(crate) fn take_inner(mut self) -> *mut nativeOfferId {
133                 assert!(self.is_owned);
134                 let ret = ObjOps::untweak_ptr(self.inner);
135                 self.inner = core::ptr::null_mut();
136                 ret
137         }
138 }
139 #[no_mangle]
140 pub extern "C" fn OfferId_get_a(this_ptr: &OfferId) -> *const [u8; 32] {
141         let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
142         inner_val
143 }
144 #[no_mangle]
145 pub extern "C" fn OfferId_set_a(this_ptr: &mut OfferId, mut val: crate::c_types::ThirtyTwoBytes) {
146         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.data;
147 }
148 /// Constructs a new OfferId given each field
149 #[must_use]
150 #[no_mangle]
151 pub extern "C" fn OfferId_new(mut a_arg: crate::c_types::ThirtyTwoBytes) -> OfferId {
152         OfferId { inner: ObjOps::heap_alloc(lightning::offers::offer::OfferId (
153                 a_arg.data,
154         )), is_owned: true }
155 }
156 impl Clone for OfferId {
157         fn clone(&self) -> Self {
158                 Self {
159                         inner: if <*mut nativeOfferId>::is_null(self.inner) { core::ptr::null_mut() } else {
160                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
161                         is_owned: true,
162                 }
163         }
164 }
165 #[allow(unused)]
166 /// Used only if an object of this type is returned as a trait impl by a method
167 pub(crate) extern "C" fn OfferId_clone_void(this_ptr: *const c_void) -> *mut c_void {
168         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOfferId)).clone() })) as *mut c_void
169 }
170 #[no_mangle]
171 /// Creates a copy of the OfferId
172 pub extern "C" fn OfferId_clone(orig: &OfferId) -> OfferId {
173         orig.clone()
174 }
175 /// Get a string which allows debug introspection of a OfferId object
176 pub extern "C" fn OfferId_debug_str_void(o: *const c_void) -> Str {
177         alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::offer::OfferId }).into()}
178 /// Checks if two OfferIds contain equal inner contents.
179 /// This ignores pointers and is_owned flags and looks at the values in fields.
180 /// Two objects with NULL inner values will be considered "equal" here.
181 #[no_mangle]
182 pub extern "C" fn OfferId_eq(a: &OfferId, b: &OfferId) -> bool {
183         if a.inner == b.inner { return true; }
184         if a.inner.is_null() || b.inner.is_null() { return false; }
185         if a.get_native_ref() == b.get_native_ref() { true } else { false }
186 }
187 #[no_mangle]
188 /// Serialize the OfferId object into a byte array which can be read by OfferId_read
189 pub extern "C" fn OfferId_write(obj: &crate::lightning::offers::offer::OfferId) -> crate::c_types::derived::CVec_u8Z {
190         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
191 }
192 #[allow(unused)]
193 pub(crate) extern "C" fn OfferId_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
194         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOfferId) })
195 }
196 #[no_mangle]
197 /// Read a OfferId from a byte array, created by OfferId_write
198 pub extern "C" fn OfferId_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_OfferIdDecodeErrorZ {
199         let res: Result<lightning::offers::offer::OfferId, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
200         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::offer::OfferId { 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() };
201         local_res
202 }
203
204 use lightning::offers::offer::OfferWithExplicitMetadataBuilder as nativeOfferWithExplicitMetadataBuilderImport;
205 pub(crate) type nativeOfferWithExplicitMetadataBuilder = nativeOfferWithExplicitMetadataBuilderImport<'static, >;
206
207 /// Builds an [`Offer`] for the \"offer to be paid\" flow.
208 ///
209 /// See [module-level documentation] for usage.
210 ///
211 /// [module-level documentation]: self
212 #[must_use]
213 #[repr(C)]
214 pub struct OfferWithExplicitMetadataBuilder {
215         /// A pointer to the opaque Rust object.
216
217         /// Nearly everywhere, inner must be non-null, however in places where
218         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
219         pub inner: *mut nativeOfferWithExplicitMetadataBuilder,
220         /// Indicates that this is the only struct which contains the same pointer.
221
222         /// Rust functions which take ownership of an object provided via an argument require
223         /// this to be true and invalidate the object pointed to by inner.
224         pub is_owned: bool,
225 }
226
227 impl Drop for OfferWithExplicitMetadataBuilder {
228         fn drop(&mut self) {
229                 if self.is_owned && !<*mut nativeOfferWithExplicitMetadataBuilder>::is_null(self.inner) {
230                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
231                 }
232         }
233 }
234 /// Frees any resources used by the OfferWithExplicitMetadataBuilder, if is_owned is set and inner is non-NULL.
235 #[no_mangle]
236 pub extern "C" fn OfferWithExplicitMetadataBuilder_free(this_obj: OfferWithExplicitMetadataBuilder) { }
237 #[allow(unused)]
238 /// Used only if an object of this type is returned as a trait impl by a method
239 pub(crate) extern "C" fn OfferWithExplicitMetadataBuilder_free_void(this_ptr: *mut c_void) {
240         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOfferWithExplicitMetadataBuilder) };
241 }
242 #[allow(unused)]
243 impl OfferWithExplicitMetadataBuilder {
244         pub(crate) fn get_native_ref(&self) -> &'static nativeOfferWithExplicitMetadataBuilder {
245                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
246         }
247         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOfferWithExplicitMetadataBuilder {
248                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
249         }
250         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
251         pub(crate) fn take_inner(mut self) -> *mut nativeOfferWithExplicitMetadataBuilder {
252                 assert!(self.is_owned);
253                 let ret = ObjOps::untweak_ptr(self.inner);
254                 self.inner = core::ptr::null_mut();
255                 ret
256         }
257 }
258 impl Clone for OfferWithExplicitMetadataBuilder {
259         fn clone(&self) -> Self {
260                 Self {
261                         inner: if <*mut nativeOfferWithExplicitMetadataBuilder>::is_null(self.inner) { core::ptr::null_mut() } else {
262                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
263                         is_owned: true,
264                 }
265         }
266 }
267 #[allow(unused)]
268 /// Used only if an object of this type is returned as a trait impl by a method
269 pub(crate) extern "C" fn OfferWithExplicitMetadataBuilder_clone_void(this_ptr: *const c_void) -> *mut c_void {
270         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOfferWithExplicitMetadataBuilder)).clone() })) as *mut c_void
271 }
272 #[no_mangle]
273 /// Creates a copy of the OfferWithExplicitMetadataBuilder
274 pub extern "C" fn OfferWithExplicitMetadataBuilder_clone(orig: &OfferWithExplicitMetadataBuilder) -> OfferWithExplicitMetadataBuilder {
275         orig.clone()
276 }
277
278 use lightning::offers::offer::OfferWithDerivedMetadataBuilder as nativeOfferWithDerivedMetadataBuilderImport;
279 pub(crate) type nativeOfferWithDerivedMetadataBuilder = nativeOfferWithDerivedMetadataBuilderImport<'static, >;
280
281 /// Builds an [`Offer`] for the \"offer to be paid\" flow.
282 ///
283 /// See [module-level documentation] for usage.
284 ///
285 /// [module-level documentation]: self
286 #[must_use]
287 #[repr(C)]
288 pub struct OfferWithDerivedMetadataBuilder {
289         /// A pointer to the opaque Rust object.
290
291         /// Nearly everywhere, inner must be non-null, however in places where
292         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
293         pub inner: *mut nativeOfferWithDerivedMetadataBuilder,
294         /// Indicates that this is the only struct which contains the same pointer.
295
296         /// Rust functions which take ownership of an object provided via an argument require
297         /// this to be true and invalidate the object pointed to by inner.
298         pub is_owned: bool,
299 }
300
301 impl Drop for OfferWithDerivedMetadataBuilder {
302         fn drop(&mut self) {
303                 if self.is_owned && !<*mut nativeOfferWithDerivedMetadataBuilder>::is_null(self.inner) {
304                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
305                 }
306         }
307 }
308 /// Frees any resources used by the OfferWithDerivedMetadataBuilder, if is_owned is set and inner is non-NULL.
309 #[no_mangle]
310 pub extern "C" fn OfferWithDerivedMetadataBuilder_free(this_obj: OfferWithDerivedMetadataBuilder) { }
311 #[allow(unused)]
312 /// Used only if an object of this type is returned as a trait impl by a method
313 pub(crate) extern "C" fn OfferWithDerivedMetadataBuilder_free_void(this_ptr: *mut c_void) {
314         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOfferWithDerivedMetadataBuilder) };
315 }
316 #[allow(unused)]
317 impl OfferWithDerivedMetadataBuilder {
318         pub(crate) fn get_native_ref(&self) -> &'static nativeOfferWithDerivedMetadataBuilder {
319                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
320         }
321         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOfferWithDerivedMetadataBuilder {
322                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
323         }
324         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
325         pub(crate) fn take_inner(mut self) -> *mut nativeOfferWithDerivedMetadataBuilder {
326                 assert!(self.is_owned);
327                 let ret = ObjOps::untweak_ptr(self.inner);
328                 self.inner = core::ptr::null_mut();
329                 ret
330         }
331 }
332 impl Clone for OfferWithDerivedMetadataBuilder {
333         fn clone(&self) -> Self {
334                 Self {
335                         inner: if <*mut nativeOfferWithDerivedMetadataBuilder>::is_null(self.inner) { core::ptr::null_mut() } else {
336                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
337                         is_owned: true,
338                 }
339         }
340 }
341 #[allow(unused)]
342 /// Used only if an object of this type is returned as a trait impl by a method
343 pub(crate) extern "C" fn OfferWithDerivedMetadataBuilder_clone_void(this_ptr: *const c_void) -> *mut c_void {
344         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOfferWithDerivedMetadataBuilder)).clone() })) as *mut c_void
345 }
346 #[no_mangle]
347 /// Creates a copy of the OfferWithDerivedMetadataBuilder
348 pub extern "C" fn OfferWithDerivedMetadataBuilder_clone(orig: &OfferWithDerivedMetadataBuilder) -> OfferWithDerivedMetadataBuilder {
349         orig.clone()
350 }
351 /// Creates a new builder for an offer using the [`Offer::signing_pubkey`] for signing invoices.
352 /// The associated secret key must be remembered while the offer is valid.
353 ///
354 /// Use a different pubkey per offer to avoid correlating offers.
355 ///
356 /// # Note
357 ///
358 /// If constructing an [`Offer`] for use with a [`ChannelManager`], use
359 /// [`ChannelManager::create_offer_builder`] instead of [`OfferBuilder::new`].
360 ///
361 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
362 /// [`ChannelManager::create_offer_builder`]: crate::ln::channelmanager::ChannelManager::create_offer_builder
363 #[must_use]
364 #[no_mangle]
365 pub extern "C" fn OfferWithExplicitMetadataBuilder_new(mut signing_pubkey: crate::c_types::PublicKey) -> crate::lightning::offers::offer::OfferWithExplicitMetadataBuilder {
366         let mut ret = lightning::offers::offer::OfferWithExplicitMetadataBuilder::new(signing_pubkey.into_rust());
367         crate::lightning::offers::offer::OfferWithExplicitMetadataBuilder { inner: ObjOps::heap_alloc(ret), is_owned: true }
368 }
369
370 /// Sets the [`Offer::metadata`] to the given bytes.
371 ///
372 /// Successive calls to this method will override the previous setting.
373 #[must_use]
374 #[no_mangle]
375 pub extern "C" fn OfferWithExplicitMetadataBuilder_metadata(mut this_arg: crate::lightning::offers::offer::OfferWithExplicitMetadataBuilder, mut metadata: crate::c_types::derived::CVec_u8Z) -> crate::c_types::derived::CResult_NoneBolt12SemanticErrorZ {
376         let mut local_metadata = Vec::new(); for mut item in metadata.into_rust().drain(..) { local_metadata.push( { item }); };
377         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).metadata(local_metadata);
378         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() };
379         local_ret
380 }
381
382 /// Adds the chain hash of the given [`Network`] to [`Offer::chains`]. If not called,
383 /// the chain hash of [`Network::Bitcoin`] is assumed to be the only one supported.
384 ///
385 /// See [`Offer::chains`] on how this relates to the payment currency.
386 ///
387 /// Successive calls to this method will add another chain hash.
388 #[must_use]
389 #[no_mangle]
390 pub extern "C" fn OfferWithExplicitMetadataBuilder_chain(mut this_arg: crate::lightning::offers::offer::OfferWithExplicitMetadataBuilder, mut network: crate::bitcoin::network::Network) {
391         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).chain(network.into_bitcoin());
392         () /*ret*/
393 }
394
395 /// Sets the [`Offer::amount`] as an [`Amount::Bitcoin`].
396 ///
397 /// Successive calls to this method will override the previous setting.
398 #[must_use]
399 #[no_mangle]
400 pub extern "C" fn OfferWithExplicitMetadataBuilder_amount_msats(mut this_arg: crate::lightning::offers::offer::OfferWithExplicitMetadataBuilder, mut amount_msats: u64) {
401         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).amount_msats(amount_msats);
402         () /*ret*/
403 }
404
405 /// Sets the [`Offer::absolute_expiry`] as seconds since the Unix epoch. Any expiry that has
406 /// already passed is valid and can be checked for using [`Offer::is_expired`].
407 ///
408 /// Successive calls to this method will override the previous setting.
409 #[must_use]
410 #[no_mangle]
411 pub extern "C" fn OfferWithExplicitMetadataBuilder_absolute_expiry(mut this_arg: crate::lightning::offers::offer::OfferWithExplicitMetadataBuilder, mut absolute_expiry: u64) {
412         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).absolute_expiry(core::time::Duration::from_secs(absolute_expiry));
413         () /*ret*/
414 }
415
416 /// Sets the [`Offer::description`].
417 ///
418 /// Successive calls to this method will override the previous setting.
419 #[must_use]
420 #[no_mangle]
421 pub extern "C" fn OfferWithExplicitMetadataBuilder_description(mut this_arg: crate::lightning::offers::offer::OfferWithExplicitMetadataBuilder, mut description: crate::c_types::Str) {
422         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).description(description.into_string());
423         () /*ret*/
424 }
425
426 /// Sets the [`Offer::issuer`].
427 ///
428 /// Successive calls to this method will override the previous setting.
429 #[must_use]
430 #[no_mangle]
431 pub extern "C" fn OfferWithExplicitMetadataBuilder_issuer(mut this_arg: crate::lightning::offers::offer::OfferWithExplicitMetadataBuilder, mut issuer: crate::c_types::Str) {
432         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).issuer(issuer.into_string());
433         () /*ret*/
434 }
435
436 /// Adds a blinded path to [`Offer::paths`]. Must include at least one path if only connected by
437 /// private channels or if [`Offer::signing_pubkey`] is not a public node id.
438 ///
439 /// Successive calls to this method will add another blinded path. Caller is responsible for not
440 /// adding duplicate paths.
441 #[must_use]
442 #[no_mangle]
443 pub extern "C" fn OfferWithExplicitMetadataBuilder_path(mut this_arg: crate::lightning::offers::offer::OfferWithExplicitMetadataBuilder, mut path: crate::lightning::blinded_path::BlindedPath) {
444         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).path(*unsafe { Box::from_raw(path.take_inner()) });
445         () /*ret*/
446 }
447
448 /// Sets the quantity of items for [`Offer::supported_quantity`]. If not called, defaults to
449 /// [`Quantity::One`].
450 ///
451 /// Successive calls to this method will override the previous setting.
452 #[must_use]
453 #[no_mangle]
454 pub extern "C" fn OfferWithExplicitMetadataBuilder_supported_quantity(mut this_arg: crate::lightning::offers::offer::OfferWithExplicitMetadataBuilder, mut quantity: crate::lightning::offers::offer::Quantity) {
455         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).supported_quantity(quantity.into_native());
456         () /*ret*/
457 }
458
459 /// Builds an [`Offer`] from the builder's settings.
460 #[must_use]
461 #[no_mangle]
462 pub extern "C" fn OfferWithExplicitMetadataBuilder_build(mut this_arg: crate::lightning::offers::offer::OfferWithExplicitMetadataBuilder) -> crate::c_types::derived::CResult_OfferBolt12SemanticErrorZ {
463         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).build();
464         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::offer::Offer { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() };
465         local_ret
466 }
467
468 /// Similar to [`OfferBuilder::new`] except, if [`OfferBuilder::path`] is called, the signing
469 /// pubkey is derived from the given [`ExpandedKey`] and [`EntropySource`]. This provides
470 /// recipient privacy by using a different signing pubkey for each offer. Otherwise, the
471 /// provided `node_id` is used for the signing pubkey.
472 ///
473 /// Also, sets the metadata when [`OfferBuilder::build`] is called such that it can be used by
474 /// [`InvoiceRequest::verify`] to determine if the request was produced for the offer given an
475 /// [`ExpandedKey`].
476 ///
477 /// [`InvoiceRequest::verify`]: crate::offers::invoice_request::InvoiceRequest::verify
478 /// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
479 #[must_use]
480 #[no_mangle]
481 pub extern "C" fn OfferWithDerivedMetadataBuilder_deriving_signing_pubkey(mut node_id: crate::c_types::PublicKey, expanded_key: &crate::lightning::ln::inbound_payment::ExpandedKey, mut entropy_source: crate::lightning::sign::EntropySource) -> crate::lightning::offers::offer::OfferWithDerivedMetadataBuilder {
482         let mut ret = lightning::offers::offer::OfferWithDerivedMetadataBuilder::deriving_signing_pubkey(node_id.into_rust(), expanded_key.get_native_ref(), entropy_source, secp256k1::global::SECP256K1);
483         crate::lightning::offers::offer::OfferWithDerivedMetadataBuilder { inner: ObjOps::heap_alloc(ret), is_owned: true }
484 }
485
486 /// Adds the chain hash of the given [`Network`] to [`Offer::chains`]. If not called,
487 /// the chain hash of [`Network::Bitcoin`] is assumed to be the only one supported.
488 ///
489 /// See [`Offer::chains`] on how this relates to the payment currency.
490 ///
491 /// Successive calls to this method will add another chain hash.
492 #[must_use]
493 #[no_mangle]
494 pub extern "C" fn OfferWithDerivedMetadataBuilder_chain(mut this_arg: crate::lightning::offers::offer::OfferWithDerivedMetadataBuilder, mut network: crate::bitcoin::network::Network) {
495         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).chain(network.into_bitcoin());
496         () /*ret*/
497 }
498
499 /// Sets the [`Offer::amount`] as an [`Amount::Bitcoin`].
500 ///
501 /// Successive calls to this method will override the previous setting.
502 #[must_use]
503 #[no_mangle]
504 pub extern "C" fn OfferWithDerivedMetadataBuilder_amount_msats(mut this_arg: crate::lightning::offers::offer::OfferWithDerivedMetadataBuilder, mut amount_msats: u64) {
505         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).amount_msats(amount_msats);
506         () /*ret*/
507 }
508
509 /// Sets the [`Offer::absolute_expiry`] as seconds since the Unix epoch. Any expiry that has
510 /// already passed is valid and can be checked for using [`Offer::is_expired`].
511 ///
512 /// Successive calls to this method will override the previous setting.
513 #[must_use]
514 #[no_mangle]
515 pub extern "C" fn OfferWithDerivedMetadataBuilder_absolute_expiry(mut this_arg: crate::lightning::offers::offer::OfferWithDerivedMetadataBuilder, mut absolute_expiry: u64) {
516         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).absolute_expiry(core::time::Duration::from_secs(absolute_expiry));
517         () /*ret*/
518 }
519
520 /// Sets the [`Offer::description`].
521 ///
522 /// Successive calls to this method will override the previous setting.
523 #[must_use]
524 #[no_mangle]
525 pub extern "C" fn OfferWithDerivedMetadataBuilder_description(mut this_arg: crate::lightning::offers::offer::OfferWithDerivedMetadataBuilder, mut description: crate::c_types::Str) {
526         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).description(description.into_string());
527         () /*ret*/
528 }
529
530 /// Sets the [`Offer::issuer`].
531 ///
532 /// Successive calls to this method will override the previous setting.
533 #[must_use]
534 #[no_mangle]
535 pub extern "C" fn OfferWithDerivedMetadataBuilder_issuer(mut this_arg: crate::lightning::offers::offer::OfferWithDerivedMetadataBuilder, mut issuer: crate::c_types::Str) {
536         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).issuer(issuer.into_string());
537         () /*ret*/
538 }
539
540 /// Adds a blinded path to [`Offer::paths`]. Must include at least one path if only connected by
541 /// private channels or if [`Offer::signing_pubkey`] is not a public node id.
542 ///
543 /// Successive calls to this method will add another blinded path. Caller is responsible for not
544 /// adding duplicate paths.
545 #[must_use]
546 #[no_mangle]
547 pub extern "C" fn OfferWithDerivedMetadataBuilder_path(mut this_arg: crate::lightning::offers::offer::OfferWithDerivedMetadataBuilder, mut path: crate::lightning::blinded_path::BlindedPath) {
548         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).path(*unsafe { Box::from_raw(path.take_inner()) });
549         () /*ret*/
550 }
551
552 /// Sets the quantity of items for [`Offer::supported_quantity`]. If not called, defaults to
553 /// [`Quantity::One`].
554 ///
555 /// Successive calls to this method will override the previous setting.
556 #[must_use]
557 #[no_mangle]
558 pub extern "C" fn OfferWithDerivedMetadataBuilder_supported_quantity(mut this_arg: crate::lightning::offers::offer::OfferWithDerivedMetadataBuilder, mut quantity: crate::lightning::offers::offer::Quantity) {
559         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).supported_quantity(quantity.into_native());
560         () /*ret*/
561 }
562
563 /// Builds an [`Offer`] from the builder's settings.
564 #[must_use]
565 #[no_mangle]
566 pub extern "C" fn OfferWithDerivedMetadataBuilder_build(mut this_arg: crate::lightning::offers::offer::OfferWithDerivedMetadataBuilder) -> crate::c_types::derived::CResult_OfferBolt12SemanticErrorZ {
567         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).build();
568         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::offer::Offer { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() };
569         local_ret
570 }
571
572
573 use lightning::offers::offer::Offer as nativeOfferImport;
574 pub(crate) type nativeOffer = nativeOfferImport;
575
576 /// An `Offer` is a potentially long-lived proposal for payment of a good or service.
577 ///
578 /// An offer is a precursor to an [`InvoiceRequest`]. A merchant publishes an offer from which a
579 /// customer may request an [`Bolt12Invoice`] for a specific quantity and using an amount sufficient
580 /// to cover that quantity (i.e., at least `quantity * amount`). See [`Offer::amount`].
581 ///
582 /// Offers may be denominated in currency other than bitcoin but are ultimately paid using the
583 /// latter.
584 ///
585 /// Through the use of [`BlindedPath`]s, offers provide recipient privacy.
586 ///
587 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
588 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
589 #[must_use]
590 #[repr(C)]
591 pub struct Offer {
592         /// A pointer to the opaque Rust object.
593
594         /// Nearly everywhere, inner must be non-null, however in places where
595         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
596         pub inner: *mut nativeOffer,
597         /// Indicates that this is the only struct which contains the same pointer.
598
599         /// Rust functions which take ownership of an object provided via an argument require
600         /// this to be true and invalidate the object pointed to by inner.
601         pub is_owned: bool,
602 }
603
604 impl Drop for Offer {
605         fn drop(&mut self) {
606                 if self.is_owned && !<*mut nativeOffer>::is_null(self.inner) {
607                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
608                 }
609         }
610 }
611 /// Frees any resources used by the Offer, if is_owned is set and inner is non-NULL.
612 #[no_mangle]
613 pub extern "C" fn Offer_free(this_obj: Offer) { }
614 #[allow(unused)]
615 /// Used only if an object of this type is returned as a trait impl by a method
616 pub(crate) extern "C" fn Offer_free_void(this_ptr: *mut c_void) {
617         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOffer) };
618 }
619 #[allow(unused)]
620 impl Offer {
621         pub(crate) fn get_native_ref(&self) -> &'static nativeOffer {
622                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
623         }
624         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOffer {
625                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
626         }
627         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
628         pub(crate) fn take_inner(mut self) -> *mut nativeOffer {
629                 assert!(self.is_owned);
630                 let ret = ObjOps::untweak_ptr(self.inner);
631                 self.inner = core::ptr::null_mut();
632                 ret
633         }
634 }
635 impl Clone for Offer {
636         fn clone(&self) -> Self {
637                 Self {
638                         inner: if <*mut nativeOffer>::is_null(self.inner) { core::ptr::null_mut() } else {
639                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
640                         is_owned: true,
641                 }
642         }
643 }
644 #[allow(unused)]
645 /// Used only if an object of this type is returned as a trait impl by a method
646 pub(crate) extern "C" fn Offer_clone_void(this_ptr: *const c_void) -> *mut c_void {
647         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOffer)).clone() })) as *mut c_void
648 }
649 #[no_mangle]
650 /// Creates a copy of the Offer
651 pub extern "C" fn Offer_clone(orig: &Offer) -> Offer {
652         orig.clone()
653 }
654 /// Get a string which allows debug introspection of a Offer object
655 pub extern "C" fn Offer_debug_str_void(o: *const c_void) -> Str {
656         alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::offer::Offer }).into()}
657 /// The chains that may be used when paying a requested invoice (e.g., bitcoin mainnet).
658 /// Payments must be denominated in units of the minimal lightning-payable unit (e.g., msats)
659 /// for the selected chain.
660 #[must_use]
661 #[no_mangle]
662 pub extern "C" fn Offer_chains(this_arg: &crate::lightning::offers::offer::Offer) -> crate::c_types::derived::CVec_ThirtyTwoBytesZ {
663         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.chains();
664         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: *item.as_ref() } }); };
665         local_ret.into()
666 }
667
668 /// Opaque bytes set by the originator. Useful for authentication and validating fields since it
669 /// is reflected in `invoice_request` messages along with all the other fields from the `offer`.
670 #[must_use]
671 #[no_mangle]
672 pub extern "C" fn Offer_metadata(this_arg: &crate::lightning::offers::offer::Offer) -> crate::c_types::derived::COption_CVec_u8ZZ {
673         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.metadata();
674         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() }) };
675         local_ret
676 }
677
678 /// The minimum amount required for a successful payment of a single item.
679 #[must_use]
680 #[no_mangle]
681 pub extern "C" fn Offer_amount(this_arg: &crate::lightning::offers::offer::Offer) -> crate::c_types::derived::COption_AmountZ {
682         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount();
683         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_AmountZ::None } else { crate::c_types::derived::COption_AmountZ::Some( { crate::lightning::offers::offer::Amount::native_into(ret.unwrap()) }) };
684         local_ret
685 }
686
687 /// A complete description of the purpose of the payment. Intended to be displayed to the user
688 /// but with the caveat that it has not been verified in any way.
689 ///
690 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
691 #[must_use]
692 #[no_mangle]
693 pub extern "C" fn Offer_description(this_arg: &crate::lightning::offers::offer::Offer) -> crate::lightning::util::string::PrintableString {
694         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
695         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 };
696         local_ret
697 }
698
699 /// Features pertaining to the offer.
700 #[must_use]
701 #[no_mangle]
702 pub extern "C" fn Offer_offer_features(this_arg: &crate::lightning::offers::offer::Offer) -> crate::lightning::ln::features::OfferFeatures {
703         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.offer_features();
704         crate::lightning::ln::features::OfferFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::OfferFeatures<>) as *mut _) }, is_owned: false }
705 }
706
707 /// Duration since the Unix epoch when an invoice should no longer be requested.
708 ///
709 /// If `None`, the offer does not expire.
710 #[must_use]
711 #[no_mangle]
712 pub extern "C" fn Offer_absolute_expiry(this_arg: &crate::lightning::offers::offer::Offer) -> crate::c_types::derived::COption_u64Z {
713         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.absolute_expiry();
714         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() }) };
715         local_ret
716 }
717
718 /// The issuer of the offer, possibly beginning with `user@domain` or `domain`. Intended to be
719 /// displayed to the user but with the caveat that it has not been verified in any way.
720 ///
721 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
722 #[must_use]
723 #[no_mangle]
724 pub extern "C" fn Offer_issuer(this_arg: &crate::lightning::offers::offer::Offer) -> crate::lightning::util::string::PrintableString {
725         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.issuer();
726         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 };
727         local_ret
728 }
729
730 /// Paths to the recipient originating from publicly reachable nodes. Blinded paths provide
731 /// recipient privacy by obfuscating its node id.
732 #[must_use]
733 #[no_mangle]
734 pub extern "C" fn Offer_paths(this_arg: &crate::lightning::offers::offer::Offer) -> crate::c_types::derived::CVec_BlindedPathZ {
735         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.paths();
736         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 } }); };
737         local_ret.into()
738 }
739
740 /// The quantity of items supported.
741 #[must_use]
742 #[no_mangle]
743 pub extern "C" fn Offer_supported_quantity(this_arg: &crate::lightning::offers::offer::Offer) -> crate::lightning::offers::offer::Quantity {
744         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supported_quantity();
745         crate::lightning::offers::offer::Quantity::native_into(ret)
746 }
747
748 /// The public key used by the recipient to sign invoices.
749 ///
750 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
751 #[must_use]
752 #[no_mangle]
753 pub extern "C" fn Offer_signing_pubkey(this_arg: &crate::lightning::offers::offer::Offer) -> crate::c_types::PublicKey {
754         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signing_pubkey();
755         let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else {  { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
756         local_ret
757 }
758
759 /// Returns the id of the offer.
760 #[must_use]
761 #[no_mangle]
762 pub extern "C" fn Offer_id(this_arg: &crate::lightning::offers::offer::Offer) -> crate::lightning::offers::offer::OfferId {
763         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.id();
764         crate::lightning::offers::offer::OfferId { inner: ObjOps::heap_alloc(ret), is_owned: true }
765 }
766
767 /// Returns whether the given chain is supported by the offer.
768 #[must_use]
769 #[no_mangle]
770 pub extern "C" fn Offer_supports_chain(this_arg: &crate::lightning::offers::offer::Offer, mut chain: crate::c_types::ThirtyTwoBytes) -> bool {
771         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supports_chain(::bitcoin::blockdata::constants::ChainHash::from(&chain.data));
772         ret
773 }
774
775 /// Whether the offer has expired.
776 #[must_use]
777 #[no_mangle]
778 pub extern "C" fn Offer_is_expired(this_arg: &crate::lightning::offers::offer::Offer) -> bool {
779         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
780         ret
781 }
782
783 /// Whether the offer has expired given the duration since the Unix epoch.
784 #[must_use]
785 #[no_mangle]
786 pub extern "C" fn Offer_is_expired_no_std(this_arg: &crate::lightning::offers::offer::Offer, mut duration_since_epoch: u64) -> bool {
787         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired_no_std(core::time::Duration::from_secs(duration_since_epoch));
788         ret
789 }
790
791 /// Returns whether the given quantity is valid for the offer.
792 #[must_use]
793 #[no_mangle]
794 pub extern "C" fn Offer_is_valid_quantity(this_arg: &crate::lightning::offers::offer::Offer, mut quantity: u64) -> bool {
795         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_valid_quantity(quantity);
796         ret
797 }
798
799 /// Returns whether a quantity is expected in an [`InvoiceRequest`] for the offer.
800 ///
801 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
802 #[must_use]
803 #[no_mangle]
804 pub extern "C" fn Offer_expects_quantity(this_arg: &crate::lightning::offers::offer::Offer) -> bool {
805         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expects_quantity();
806         ret
807 }
808
809 /// Similar to [`Offer::request_invoice`] except it:
810 /// - derives the [`InvoiceRequest::payer_id`] such that a different key can be used for each
811 ///   request,
812 /// - sets [`InvoiceRequest::payer_metadata`] when [`InvoiceRequestBuilder::build`] is called
813 ///   such that it can be used by [`Bolt12Invoice::verify`] to determine if the invoice was
814 ///   requested using a base [`ExpandedKey`] from which the payer id was derived, and
815 /// - includes the [`PaymentId`] encrypted in [`InvoiceRequest::payer_metadata`] so that it can
816 ///   be used when sending the payment for the requested invoice.
817 ///
818 /// Useful to protect the sender's privacy.
819 ///
820 /// [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
821 /// [`InvoiceRequest::payer_metadata`]: crate::offers::invoice_request::InvoiceRequest::payer_metadata
822 /// [`Bolt12Invoice::verify`]: crate::offers::invoice::Bolt12Invoice::verify
823 /// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
824 #[must_use]
825 #[no_mangle]
826 pub extern "C" fn Offer_request_invoice_deriving_payer_id(this_arg: &crate::lightning::offers::offer::Offer, expanded_key: &crate::lightning::ln::inbound_payment::ExpandedKey, mut entropy_source: crate::lightning::sign::EntropySource, mut payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_InvoiceRequestWithDerivedPayerIdBuilderBolt12SemanticErrorZ {
827         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.request_invoice_deriving_payer_id(expanded_key.get_native_ref(), entropy_source, secp256k1::global::SECP256K1, ::lightning::ln::channelmanager::PaymentId(payment_id.data));
828         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::invoice_request::InvoiceRequestWithDerivedPayerIdBuilder { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() };
829         local_ret
830 }
831
832 /// Similar to [`Offer::request_invoice_deriving_payer_id`] except uses `payer_id` for the
833 /// [`InvoiceRequest::payer_id`] instead of deriving a different key for each request.
834 ///
835 /// Useful for recurring payments using the same `payer_id` with different invoices.
836 ///
837 /// [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
838 #[must_use]
839 #[no_mangle]
840 pub extern "C" fn Offer_request_invoice_deriving_metadata(this_arg: &crate::lightning::offers::offer::Offer, mut payer_id: crate::c_types::PublicKey, expanded_key: &crate::lightning::ln::inbound_payment::ExpandedKey, mut entropy_source: crate::lightning::sign::EntropySource, mut payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ {
841         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.request_invoice_deriving_metadata(payer_id.into_rust(), expanded_key.get_native_ref(), entropy_source, ::lightning::ln::channelmanager::PaymentId(payment_id.data));
842         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::invoice_request::InvoiceRequestWithExplicitPayerIdBuilder { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() };
843         local_ret
844 }
845
846 /// Creates an [`InvoiceRequestBuilder`] for the offer with the given `metadata` and `payer_id`,
847 /// which will be reflected in the `Bolt12Invoice` response.
848 ///
849 /// The `metadata` is useful for including information about the derivation of `payer_id` such
850 /// that invoice response handling can be stateless. Also serves as payer-provided entropy while
851 /// hashing in the signature calculation.
852 ///
853 /// This should not leak any information such as by using a simple BIP-32 derivation path.
854 /// Otherwise, payments may be correlated.
855 ///
856 /// Errors if the offer contains unknown required features.
857 ///
858 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
859 #[must_use]
860 #[no_mangle]
861 pub extern "C" fn Offer_request_invoice(this_arg: &crate::lightning::offers::offer::Offer, mut metadata: crate::c_types::derived::CVec_u8Z, mut payer_id: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ {
862         let mut local_metadata = Vec::new(); for mut item in metadata.into_rust().drain(..) { local_metadata.push( { item }); };
863         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.request_invoice(local_metadata, payer_id.into_rust());
864         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::invoice_request::InvoiceRequestWithExplicitPayerIdBuilder { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::offers::parse::Bolt12SemanticError::native_into(e) }).into() };
865         local_ret
866 }
867
868 /// Generates a non-cryptographic 64-bit hash of the Offer.
869 #[no_mangle]
870 pub extern "C" fn Offer_hash(o: &Offer) -> u64 {
871         if o.inner.is_null() { return 0; }
872         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
873         #[allow(deprecated)]
874         let mut hasher = core::hash::SipHasher::new();
875         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
876         core::hash::Hasher::finish(&hasher)
877 }
878 #[no_mangle]
879 /// Serialize the Offer object into a byte array which can be read by Offer_read
880 pub extern "C" fn Offer_write(obj: &crate::lightning::offers::offer::Offer) -> crate::c_types::derived::CVec_u8Z {
881         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
882 }
883 #[allow(unused)]
884 pub(crate) extern "C" fn Offer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
885         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOffer) })
886 }
887 /// The minimum amount required for an item in an [`Offer`], denominated in either bitcoin or
888 /// another currency.
889 #[derive(Clone)]
890 #[must_use]
891 #[repr(C)]
892 pub enum Amount {
893         /// An amount of bitcoin.
894         Bitcoin {
895                 /// The amount in millisatoshi.
896                 amount_msats: u64,
897         },
898         /// An amount of currency specified using ISO 4712.
899         Currency {
900                 /// The currency that the amount is denominated in.
901                 iso4217_code: crate::c_types::ThreeBytes,
902                 /// The amount in the currency unit adjusted by the ISO 4712 exponent (e.g., USD cents).
903                 amount: u64,
904         },
905 }
906 use lightning::offers::offer::Amount as AmountImport;
907 pub(crate) type nativeAmount = AmountImport;
908
909 impl Amount {
910         #[allow(unused)]
911         pub(crate) fn to_native(&self) -> nativeAmount {
912                 match self {
913                         Amount::Bitcoin {ref amount_msats, } => {
914                                 let mut amount_msats_nonref = Clone::clone(amount_msats);
915                                 nativeAmount::Bitcoin {
916                                         amount_msats: amount_msats_nonref,
917                                 }
918                         },
919                         Amount::Currency {ref iso4217_code, ref amount, } => {
920                                 let mut iso4217_code_nonref = Clone::clone(iso4217_code);
921                                 let mut amount_nonref = Clone::clone(amount);
922                                 nativeAmount::Currency {
923                                         iso4217_code: iso4217_code_nonref.data,
924                                         amount: amount_nonref,
925                                 }
926                         },
927                 }
928         }
929         #[allow(unused)]
930         pub(crate) fn into_native(self) -> nativeAmount {
931                 match self {
932                         Amount::Bitcoin {mut amount_msats, } => {
933                                 nativeAmount::Bitcoin {
934                                         amount_msats: amount_msats,
935                                 }
936                         },
937                         Amount::Currency {mut iso4217_code, mut amount, } => {
938                                 nativeAmount::Currency {
939                                         iso4217_code: iso4217_code.data,
940                                         amount: amount,
941                                 }
942                         },
943                 }
944         }
945         #[allow(unused)]
946         pub(crate) fn from_native(native: &AmountImport) -> Self {
947                 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeAmount) };
948                 match native {
949                         nativeAmount::Bitcoin {ref amount_msats, } => {
950                                 let mut amount_msats_nonref = Clone::clone(amount_msats);
951                                 Amount::Bitcoin {
952                                         amount_msats: amount_msats_nonref,
953                                 }
954                         },
955                         nativeAmount::Currency {ref iso4217_code, ref amount, } => {
956                                 let mut iso4217_code_nonref = Clone::clone(iso4217_code);
957                                 let mut amount_nonref = Clone::clone(amount);
958                                 Amount::Currency {
959                                         iso4217_code: crate::c_types::ThreeBytes { data: iso4217_code_nonref },
960                                         amount: amount_nonref,
961                                 }
962                         },
963                 }
964         }
965         #[allow(unused)]
966         pub(crate) fn native_into(native: nativeAmount) -> Self {
967                 match native {
968                         nativeAmount::Bitcoin {mut amount_msats, } => {
969                                 Amount::Bitcoin {
970                                         amount_msats: amount_msats,
971                                 }
972                         },
973                         nativeAmount::Currency {mut iso4217_code, mut amount, } => {
974                                 Amount::Currency {
975                                         iso4217_code: crate::c_types::ThreeBytes { data: iso4217_code },
976                                         amount: amount,
977                                 }
978                         },
979                 }
980         }
981 }
982 /// Frees any resources used by the Amount
983 #[no_mangle]
984 pub extern "C" fn Amount_free(this_ptr: Amount) { }
985 /// Creates a copy of the Amount
986 #[no_mangle]
987 pub extern "C" fn Amount_clone(orig: &Amount) -> Amount {
988         orig.clone()
989 }
990 #[allow(unused)]
991 /// Used only if an object of this type is returned as a trait impl by a method
992 pub(crate) extern "C" fn Amount_clone_void(this_ptr: *const c_void) -> *mut c_void {
993         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Amount)).clone() })) as *mut c_void
994 }
995 #[allow(unused)]
996 /// Used only if an object of this type is returned as a trait impl by a method
997 pub(crate) extern "C" fn Amount_free_void(this_ptr: *mut c_void) {
998         let _ = unsafe { Box::from_raw(this_ptr as *mut Amount) };
999 }
1000 #[no_mangle]
1001 /// Utility method to constructs a new Bitcoin-variant Amount
1002 pub extern "C" fn Amount_bitcoin(amount_msats: u64) -> Amount {
1003         Amount::Bitcoin {
1004                 amount_msats,
1005         }
1006 }
1007 #[no_mangle]
1008 /// Utility method to constructs a new Currency-variant Amount
1009 pub extern "C" fn Amount_currency(iso4217_code: crate::c_types::ThreeBytes, amount: u64) -> Amount {
1010         Amount::Currency {
1011                 iso4217_code,
1012                 amount,
1013         }
1014 }
1015 /// Get a string which allows debug introspection of a Amount object
1016 pub extern "C" fn Amount_debug_str_void(o: *const c_void) -> Str {
1017         alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::offer::Amount }).into()}
1018 /// Quantity of items supported by an [`Offer`].
1019 #[derive(Clone)]
1020 #[must_use]
1021 #[repr(C)]
1022 pub enum Quantity {
1023         /// Up to a specific number of items (inclusive). Use when more than one item can be requested
1024         /// but is limited (e.g., because of per customer or inventory limits).
1025         ///
1026         /// May be used with `NonZeroU64::new(1)` but prefer to use [`Quantity::One`] if only one item
1027         /// is supported.
1028         Bounded(
1029                 u64),
1030         /// One or more items. Use when more than one item can be requested without any limit.
1031         Unbounded,
1032         /// Only one item. Use when only a single item can be requested.
1033         One,
1034 }
1035 use lightning::offers::offer::Quantity as QuantityImport;
1036 pub(crate) type nativeQuantity = QuantityImport;
1037
1038 impl Quantity {
1039         #[allow(unused)]
1040         pub(crate) fn to_native(&self) -> nativeQuantity {
1041                 match self {
1042                         Quantity::Bounded (ref a, ) => {
1043                                 let mut a_nonref = Clone::clone(a);
1044                                 nativeQuantity::Bounded (
1045                                         core::num::NonZeroU64::new(a_nonref).expect("Value must be non-zero"),
1046                                 )
1047                         },
1048                         Quantity::Unbounded => nativeQuantity::Unbounded,
1049                         Quantity::One => nativeQuantity::One,
1050                 }
1051         }
1052         #[allow(unused)]
1053         pub(crate) fn into_native(self) -> nativeQuantity {
1054                 match self {
1055                         Quantity::Bounded (mut a, ) => {
1056                                 nativeQuantity::Bounded (
1057                                         core::num::NonZeroU64::new(a).expect("Value must be non-zero"),
1058                                 )
1059                         },
1060                         Quantity::Unbounded => nativeQuantity::Unbounded,
1061                         Quantity::One => nativeQuantity::One,
1062                 }
1063         }
1064         #[allow(unused)]
1065         pub(crate) fn from_native(native: &QuantityImport) -> Self {
1066                 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeQuantity) };
1067                 match native {
1068                         nativeQuantity::Bounded (ref a, ) => {
1069                                 let mut a_nonref = Clone::clone(a);
1070                                 Quantity::Bounded (
1071                                         a_nonref.into(),
1072                                 )
1073                         },
1074                         nativeQuantity::Unbounded => Quantity::Unbounded,
1075                         nativeQuantity::One => Quantity::One,
1076                 }
1077         }
1078         #[allow(unused)]
1079         pub(crate) fn native_into(native: nativeQuantity) -> Self {
1080                 match native {
1081                         nativeQuantity::Bounded (mut a, ) => {
1082                                 Quantity::Bounded (
1083                                         a.into(),
1084                                 )
1085                         },
1086                         nativeQuantity::Unbounded => Quantity::Unbounded,
1087                         nativeQuantity::One => Quantity::One,
1088                 }
1089         }
1090 }
1091 /// Frees any resources used by the Quantity
1092 #[no_mangle]
1093 pub extern "C" fn Quantity_free(this_ptr: Quantity) { }
1094 /// Creates a copy of the Quantity
1095 #[no_mangle]
1096 pub extern "C" fn Quantity_clone(orig: &Quantity) -> Quantity {
1097         orig.clone()
1098 }
1099 #[allow(unused)]
1100 /// Used only if an object of this type is returned as a trait impl by a method
1101 pub(crate) extern "C" fn Quantity_clone_void(this_ptr: *const c_void) -> *mut c_void {
1102         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Quantity)).clone() })) as *mut c_void
1103 }
1104 #[allow(unused)]
1105 /// Used only if an object of this type is returned as a trait impl by a method
1106 pub(crate) extern "C" fn Quantity_free_void(this_ptr: *mut c_void) {
1107         let _ = unsafe { Box::from_raw(this_ptr as *mut Quantity) };
1108 }
1109 #[no_mangle]
1110 /// Utility method to constructs a new Bounded-variant Quantity
1111 pub extern "C" fn Quantity_bounded(a: u64) -> Quantity {
1112         Quantity::Bounded(a, )
1113 }
1114 #[no_mangle]
1115 /// Utility method to constructs a new Unbounded-variant Quantity
1116 pub extern "C" fn Quantity_unbounded() -> Quantity {
1117         Quantity::Unbounded}
1118 #[no_mangle]
1119 /// Utility method to constructs a new One-variant Quantity
1120 pub extern "C" fn Quantity_one() -> Quantity {
1121         Quantity::One}
1122 /// Get a string which allows debug introspection of a Quantity object
1123 pub extern "C" fn Quantity_debug_str_void(o: *const c_void) -> Str {
1124         alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::offer::Quantity }).into()}
1125 #[no_mangle]
1126 /// Read a Offer object from a string
1127 pub extern "C" fn Offer_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_OfferBolt12ParseErrorZ {
1128         match lightning::offers::offer::Offer::from_str(s.into_str()) {
1129                 Ok(r) => {
1130                         crate::c_types::CResultTempl::ok(
1131                                 crate::lightning::offers::offer::Offer { inner: ObjOps::heap_alloc(r), is_owned: true }
1132                         )
1133                 },
1134                 Err(e) => {
1135                         crate::c_types::CResultTempl::err(
1136                                 crate::lightning::offers::parse::Bolt12ParseError { inner: ObjOps::heap_alloc(e), is_owned: true }
1137                         )
1138                 },
1139         }.into()
1140 }