1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! Data structures and encoding for `offer` messages.
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.
18 //! extern crate bitcoin;
19 //! extern crate core;
20 //! extern crate lightning;
22 //! use core::convert::TryFrom;
23 //! use core::num::NonZeroU64;
24 //! use core::time::Duration;
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};
31 //! # use lightning::blinded_path::BlindedPath;
32 //! # #[cfg(feature = \"std\")]
33 //! # use std::time::SystemTime;
35 //! # fn create_blinded_path() -> BlindedPath { unimplemented!() }
36 //! # fn create_another_blinded_path() -> BlindedPath { unimplemented!() }
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);
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())
55 //! // Encode as a bech32 string for use in a QR code.
56 //! let encoded_offer = offer.to_string();
58 //! // Parse from a bech32 string after scanning from a QR code.
59 //! let offer = encoded_offer.parse::<Offer>()?;
61 //! // Encode offer as raw bytes.
62 //! let mut bytes = Vec::new();
63 //! offer.write(&mut bytes).unwrap();
65 //! // Decode raw bytes into an offer.
66 //! let offer = Offer::try_from(bytes)?;
73 //! If constructing an [`Offer`] for use with a [`ChannelManager`], use
74 //! [`ChannelManager::create_offer_builder`] instead of [`OfferBuilder::new`].
76 //! [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
77 //! [`ChannelManager::create_offer_builder`]: crate::ln::channelmanager::ChannelManager::create_offer_builder
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};
89 use lightning::offers::offer::OfferId as nativeOfferIdImport;
90 pub(crate) type nativeOfferId = nativeOfferIdImport;
92 /// An identifier for an [`Offer`] built using [`DerivedMetadata`].
96 /// A pointer to the opaque Rust object.
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.
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.
108 impl Drop for OfferId {
110 if self.is_owned && !<*mut nativeOfferId>::is_null(self.inner) {
111 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
115 /// Frees any resources used by the OfferId, if is_owned is set and inner is non-NULL.
117 pub extern "C" fn OfferId_free(this_obj: OfferId) { }
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) };
125 pub(crate) fn get_native_ref(&self) -> &'static nativeOfferId {
126 unsafe { &*ObjOps::untweak_ptr(self.inner) }
128 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOfferId {
129 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
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;
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;
148 /// Constructs a new OfferId given each field
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 (
156 impl Clone for OfferId {
157 fn clone(&self) -> 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()) },
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
171 /// Creates a copy of the OfferId
172 pub extern "C" fn OfferId_clone(orig: &OfferId) -> OfferId {
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.
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 }
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())
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) })
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() };
204 use lightning::offers::offer::OfferWithExplicitMetadataBuilder as nativeOfferWithExplicitMetadataBuilderImport;
205 pub(crate) type nativeOfferWithExplicitMetadataBuilder = nativeOfferWithExplicitMetadataBuilderImport<'static, >;
207 /// Builds an [`Offer`] for the \"offer to be paid\" flow.
209 /// See [module-level documentation] for usage.
211 /// [module-level documentation]: self
214 pub struct OfferWithExplicitMetadataBuilder {
215 /// A pointer to the opaque Rust object.
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.
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.
227 impl Drop for OfferWithExplicitMetadataBuilder {
229 if self.is_owned && !<*mut nativeOfferWithExplicitMetadataBuilder>::is_null(self.inner) {
230 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
234 /// Frees any resources used by the OfferWithExplicitMetadataBuilder, if is_owned is set and inner is non-NULL.
236 pub extern "C" fn OfferWithExplicitMetadataBuilder_free(this_obj: OfferWithExplicitMetadataBuilder) { }
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) };
243 impl OfferWithExplicitMetadataBuilder {
244 pub(crate) fn get_native_ref(&self) -> &'static nativeOfferWithExplicitMetadataBuilder {
245 unsafe { &*ObjOps::untweak_ptr(self.inner) }
247 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOfferWithExplicitMetadataBuilder {
248 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
258 impl Clone for OfferWithExplicitMetadataBuilder {
259 fn clone(&self) -> 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()) },
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
273 /// Creates a copy of the OfferWithExplicitMetadataBuilder
274 pub extern "C" fn OfferWithExplicitMetadataBuilder_clone(orig: &OfferWithExplicitMetadataBuilder) -> OfferWithExplicitMetadataBuilder {
278 use lightning::offers::offer::OfferWithDerivedMetadataBuilder as nativeOfferWithDerivedMetadataBuilderImport;
279 pub(crate) type nativeOfferWithDerivedMetadataBuilder = nativeOfferWithDerivedMetadataBuilderImport<'static, >;
281 /// Builds an [`Offer`] for the \"offer to be paid\" flow.
283 /// See [module-level documentation] for usage.
285 /// [module-level documentation]: self
288 pub struct OfferWithDerivedMetadataBuilder {
289 /// A pointer to the opaque Rust object.
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.
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.
301 impl Drop for OfferWithDerivedMetadataBuilder {
303 if self.is_owned && !<*mut nativeOfferWithDerivedMetadataBuilder>::is_null(self.inner) {
304 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
308 /// Frees any resources used by the OfferWithDerivedMetadataBuilder, if is_owned is set and inner is non-NULL.
310 pub extern "C" fn OfferWithDerivedMetadataBuilder_free(this_obj: OfferWithDerivedMetadataBuilder) { }
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) };
317 impl OfferWithDerivedMetadataBuilder {
318 pub(crate) fn get_native_ref(&self) -> &'static nativeOfferWithDerivedMetadataBuilder {
319 unsafe { &*ObjOps::untweak_ptr(self.inner) }
321 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOfferWithDerivedMetadataBuilder {
322 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
332 impl Clone for OfferWithDerivedMetadataBuilder {
333 fn clone(&self) -> 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()) },
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
347 /// Creates a copy of the OfferWithDerivedMetadataBuilder
348 pub extern "C" fn OfferWithDerivedMetadataBuilder_clone(orig: &OfferWithDerivedMetadataBuilder) -> OfferWithDerivedMetadataBuilder {
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.
354 /// Use a different pubkey per offer to avoid correlating offers.
358 /// If constructing an [`Offer`] for use with a [`ChannelManager`], use
359 /// [`ChannelManager::create_offer_builder`] instead of [`OfferBuilder::new`].
361 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
362 /// [`ChannelManager::create_offer_builder`]: crate::ln::channelmanager::ChannelManager::create_offer_builder
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 }
370 /// Sets the [`Offer::metadata`] to the given bytes.
372 /// Successive calls to this method will override the previous setting.
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() };
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.
385 /// See [`Offer::chains`] on how this relates to the payment currency.
387 /// Successive calls to this method will add another chain hash.
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());
395 /// Sets the [`Offer::amount`] as an [`Amount::Bitcoin`].
397 /// Successive calls to this method will override the previous setting.
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);
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`].
408 /// Successive calls to this method will override the previous setting.
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));
416 /// Sets the [`Offer::description`].
418 /// Successive calls to this method will override the previous setting.
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());
426 /// Sets the [`Offer::issuer`].
428 /// Successive calls to this method will override the previous setting.
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());
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.
439 /// Successive calls to this method will add another blinded path. Caller is responsible for not
440 /// adding duplicate paths.
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()) });
448 /// Sets the quantity of items for [`Offer::supported_quantity`]. If not called, defaults to
449 /// [`Quantity::One`].
451 /// Successive calls to this method will override the previous setting.
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());
459 /// Builds an [`Offer`] from the builder's settings.
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() };
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.
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
477 /// [`InvoiceRequest::verify`]: crate::offers::invoice_request::InvoiceRequest::verify
478 /// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
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 }
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.
489 /// See [`Offer::chains`] on how this relates to the payment currency.
491 /// Successive calls to this method will add another chain hash.
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());
499 /// Sets the [`Offer::amount`] as an [`Amount::Bitcoin`].
501 /// Successive calls to this method will override the previous setting.
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);
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`].
512 /// Successive calls to this method will override the previous setting.
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));
520 /// Sets the [`Offer::description`].
522 /// Successive calls to this method will override the previous setting.
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());
530 /// Sets the [`Offer::issuer`].
532 /// Successive calls to this method will override the previous setting.
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());
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.
543 /// Successive calls to this method will add another blinded path. Caller is responsible for not
544 /// adding duplicate paths.
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()) });
552 /// Sets the quantity of items for [`Offer::supported_quantity`]. If not called, defaults to
553 /// [`Quantity::One`].
555 /// Successive calls to this method will override the previous setting.
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());
563 /// Builds an [`Offer`] from the builder's settings.
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() };
573 use lightning::offers::offer::Offer as nativeOfferImport;
574 pub(crate) type nativeOffer = nativeOfferImport;
576 /// An `Offer` is a potentially long-lived proposal for payment of a good or service.
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`].
582 /// Offers may be denominated in currency other than bitcoin but are ultimately paid using the
585 /// Through the use of [`BlindedPath`]s, offers provide recipient privacy.
587 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
588 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
592 /// A pointer to the opaque Rust object.
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.
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.
604 impl Drop for Offer {
606 if self.is_owned && !<*mut nativeOffer>::is_null(self.inner) {
607 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
611 /// Frees any resources used by the Offer, if is_owned is set and inner is non-NULL.
613 pub extern "C" fn Offer_free(this_obj: Offer) { }
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) };
621 pub(crate) fn get_native_ref(&self) -> &'static nativeOffer {
622 unsafe { &*ObjOps::untweak_ptr(self.inner) }
624 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOffer {
625 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
635 impl Clone for Offer {
636 fn clone(&self) -> 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()) },
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
650 /// Creates a copy of the Offer
651 pub extern "C" fn Offer_clone(orig: &Offer) -> Offer {
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.
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() } }); };
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`.
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() }) };
678 /// The minimum amount required for a successful payment of a single item.
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()) }) };
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.
690 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
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 };
699 /// Features pertaining to the offer.
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 }
707 /// Duration since the Unix epoch when an invoice should no longer be requested.
709 /// If `None`, the offer does not expire.
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() }) };
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.
721 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
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 };
730 /// Paths to the recipient originating from publicly reachable nodes. Blinded paths provide
731 /// recipient privacy by obfuscating its node id.
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 } }); };
740 /// The quantity of items supported.
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)
748 /// The public key used by the recipient to sign invoices.
750 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
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())) } };
759 /// Returns the id of the offer.
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 }
767 /// Returns whether the given chain is supported by the offer.
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));
775 /// Whether the offer has expired.
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();
783 /// Whether the offer has expired given the duration since the Unix epoch.
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));
791 /// Returns whether the given quantity is valid for the offer.
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);
799 /// Returns whether a quantity is expected in an [`InvoiceRequest`] for the offer.
801 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
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();
809 /// Similar to [`Offer::request_invoice`] except it:
810 /// - derives the [`InvoiceRequest::payer_id`] such that a different key can be used for each
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.
818 /// Useful to protect the sender's privacy.
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
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() };
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.
835 /// Useful for recurring payments using the same `payer_id` with different invoices.
837 /// [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
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() };
846 /// Creates an [`InvoiceRequestBuilder`] for the offer with the given `metadata` and `payer_id`,
847 /// which will be reflected in the `Bolt12Invoice` response.
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.
853 /// This should not leak any information such as by using a simple BIP-32 derivation path.
854 /// Otherwise, payments may be correlated.
856 /// Errors if the offer contains unknown required features.
858 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
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() };
868 /// Generates a non-cryptographic 64-bit hash of the Offer.
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
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)
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())
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) })
887 /// The minimum amount required for an item in an [`Offer`], denominated in either bitcoin or
888 /// another currency.
893 /// An amount of bitcoin.
895 /// The amount in millisatoshi.
898 /// An amount of currency specified using ISO 4712.
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).
906 use lightning::offers::offer::Amount as AmountImport;
907 pub(crate) type nativeAmount = AmountImport;
911 pub(crate) fn to_native(&self) -> nativeAmount {
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,
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,
930 pub(crate) fn into_native(self) -> nativeAmount {
932 Amount::Bitcoin {mut amount_msats, } => {
933 nativeAmount::Bitcoin {
934 amount_msats: amount_msats,
937 Amount::Currency {mut iso4217_code, mut amount, } => {
938 nativeAmount::Currency {
939 iso4217_code: iso4217_code.data,
946 pub(crate) fn from_native(native: &AmountImport) -> Self {
947 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeAmount) };
949 nativeAmount::Bitcoin {ref amount_msats, } => {
950 let mut amount_msats_nonref = Clone::clone(amount_msats);
952 amount_msats: amount_msats_nonref,
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);
959 iso4217_code: crate::c_types::ThreeBytes { data: iso4217_code_nonref },
960 amount: amount_nonref,
966 pub(crate) fn native_into(native: nativeAmount) -> Self {
968 nativeAmount::Bitcoin {mut amount_msats, } => {
970 amount_msats: amount_msats,
973 nativeAmount::Currency {mut iso4217_code, mut amount, } => {
975 iso4217_code: crate::c_types::ThreeBytes { data: iso4217_code },
982 /// Frees any resources used by the Amount
984 pub extern "C" fn Amount_free(this_ptr: Amount) { }
985 /// Creates a copy of the Amount
987 pub extern "C" fn Amount_clone(orig: &Amount) -> Amount {
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
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) };
1001 /// Utility method to constructs a new Bitcoin-variant Amount
1002 pub extern "C" fn Amount_bitcoin(amount_msats: u64) -> Amount {
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 {
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`].
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).
1026 /// May be used with `NonZeroU64::new(1)` but prefer to use [`Quantity::One`] if only one item
1030 /// One or more items. Use when more than one item can be requested without any limit.
1032 /// Only one item. Use when only a single item can be requested.
1035 use lightning::offers::offer::Quantity as QuantityImport;
1036 pub(crate) type nativeQuantity = QuantityImport;
1040 pub(crate) fn to_native(&self) -> nativeQuantity {
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"),
1048 Quantity::Unbounded => nativeQuantity::Unbounded,
1049 Quantity::One => nativeQuantity::One,
1053 pub(crate) fn into_native(self) -> nativeQuantity {
1055 Quantity::Bounded (mut a, ) => {
1056 nativeQuantity::Bounded (
1057 core::num::NonZeroU64::new(a).expect("Value must be non-zero"),
1060 Quantity::Unbounded => nativeQuantity::Unbounded,
1061 Quantity::One => nativeQuantity::One,
1065 pub(crate) fn from_native(native: &QuantityImport) -> Self {
1066 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeQuantity) };
1068 nativeQuantity::Bounded (ref a, ) => {
1069 let mut a_nonref = Clone::clone(a);
1074 nativeQuantity::Unbounded => Quantity::Unbounded,
1075 nativeQuantity::One => Quantity::One,
1079 pub(crate) fn native_into(native: nativeQuantity) -> Self {
1081 nativeQuantity::Bounded (mut a, ) => {
1086 nativeQuantity::Unbounded => Quantity::Unbounded,
1087 nativeQuantity::One => Quantity::One,
1091 /// Frees any resources used by the Quantity
1093 pub extern "C" fn Quantity_free(this_ptr: Quantity) { }
1094 /// Creates a copy of the Quantity
1096 pub extern "C" fn Quantity_clone(orig: &Quantity) -> Quantity {
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
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) };
1110 /// Utility method to constructs a new Bounded-variant Quantity
1111 pub extern "C" fn Quantity_bounded(a: u64) -> Quantity {
1112 Quantity::Bounded(a, )
1115 /// Utility method to constructs a new Unbounded-variant Quantity
1116 pub extern "C" fn Quantity_unbounded() -> Quantity {
1117 Quantity::Unbounded}
1119 /// Utility method to constructs a new One-variant Quantity
1120 pub extern "C" fn Quantity_one() -> Quantity {
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()}
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()) {
1130 crate::c_types::CResultTempl::ok(
1131 crate::lightning::offers::offer::Offer { inner: ObjOps::heap_alloc(r), is_owned: true }
1135 crate::c_types::CResultTempl::err(
1136 crate::lightning::offers::parse::Bolt12ParseError { inner: ObjOps::heap_alloc(e), is_owned: true }