Pin compiler_builtins to 0.1.109 when building std
[ldk-c-bindings] / lightning-c-bindings / src / lightning / offers / refund.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 refunds.
10 //!
11 //! A [`Refund`] is an \"offer for money\" and is typically constructed by a merchant and presented
12 //! directly to the customer. The recipient responds with a [`Bolt12Invoice`] to be paid.
13 //!
14 //! This is an [`InvoiceRequest`] produced *not* in response to an [`Offer`].
15 //!
16 //! [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
17 //! [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
18 //! [`Offer`]: crate::offers::offer::Offer
19 //!
20 //! # Example
21 //!
22 //! ```
23 //! extern crate bitcoin;
24 //! extern crate core;
25 //! extern crate lightning;
26 //!
27 //! use core::convert::TryFrom;
28 //! use core::time::Duration;
29 //!
30 //! use bitcoin::network::constants::Network;
31 //! use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
32 //! use lightning::offers::parse::Bolt12ParseError;
33 //! use lightning::offers::refund::{Refund, RefundBuilder};
34 //! use lightning::util::ser::{Readable, Writeable};
35 //!
36 //! # use lightning::blinded_path::BlindedPath;
37 //! # #[cfg(feature = \"std\")]
38 //! # use std::time::SystemTime;
39 //! #
40 //! # fn create_blinded_path() -> BlindedPath { unimplemented!() }
41 //! # fn create_another_blinded_path() -> BlindedPath { unimplemented!() }
42 //! #
43 //! # #[cfg(feature = \"std\")]
44 //! # fn build() -> Result<(), Bolt12ParseError> {
45 //! let secp_ctx = Secp256k1::new();
46 //! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
47 //! let pubkey = PublicKey::from(keys);
48 //!
49 //! let expiration = SystemTime::now() + Duration::from_secs(24 * 60 * 60);
50 //! let refund = RefundBuilder::new(vec![1; 32], pubkey, 20_000)?
51 //!     .description(\"coffee, large\".to_string())
52 //!     .absolute_expiry(expiration.duration_since(SystemTime::UNIX_EPOCH).unwrap())
53 //!     .issuer(\"Foo Bar\".to_string())
54 //!     .path(create_blinded_path())
55 //!     .path(create_another_blinded_path())
56 //!     .chain(Network::Bitcoin)
57 //!     .payer_note(\"refund for order #12345\".to_string())
58 //!     .build()?;
59 //!
60 //! // Encode as a bech32 string for use in a QR code.
61 //! let encoded_refund = refund.to_string();
62 //!
63 //! // Parse from a bech32 string after scanning from a QR code.
64 //! let refund = encoded_refund.parse::<Refund>()?;
65 //!
66 //! // Encode refund as raw bytes.
67 //! let mut bytes = Vec::new();
68 //! refund.write(&mut bytes).unwrap();
69 //!
70 //! // Decode raw bytes into an refund.
71 //! let refund = Refund::try_from(bytes)?;
72 //! # Ok(())
73 //! # }
74 //! ```
75 //!
76 //! # Note
77 //!
78 //! If constructing a [`Refund`] for use with a [`ChannelManager`], use
79 //! [`ChannelManager::create_refund_builder`] instead of [`RefundBuilder::new`].
80 //!
81 //! [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
82 //! [`ChannelManager::create_refund_builder`]: crate::ln::channelmanager::ChannelManager::create_refund_builder
83
84 use alloc::str::FromStr;
85 use alloc::string::String;
86 use core::ffi::c_void;
87 use core::convert::Infallible;
88 use bitcoin::hashes::Hash;
89 use crate::c_types::*;
90 #[cfg(feature="no-std")]
91 use alloc::{vec::Vec, boxed::Box};
92
93
94 use lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder as nativeRefundMaybeWithDerivedMetadataBuilderImport;
95 pub(crate) type nativeRefundMaybeWithDerivedMetadataBuilder = nativeRefundMaybeWithDerivedMetadataBuilderImport<'static, >;
96
97 /// Builds a [`Refund`] for the \"offer for money\" flow.
98 ///
99 /// See [module-level documentation] for usage.
100 ///
101 /// [module-level documentation]: self
102 #[must_use]
103 #[repr(C)]
104 pub struct RefundMaybeWithDerivedMetadataBuilder {
105         /// A pointer to the opaque Rust object.
106
107         /// Nearly everywhere, inner must be non-null, however in places where
108         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
109         pub inner: *mut nativeRefundMaybeWithDerivedMetadataBuilder,
110         /// Indicates that this is the only struct which contains the same pointer.
111
112         /// Rust functions which take ownership of an object provided via an argument require
113         /// this to be true and invalidate the object pointed to by inner.
114         pub is_owned: bool,
115 }
116
117 impl Drop for RefundMaybeWithDerivedMetadataBuilder {
118         fn drop(&mut self) {
119                 if self.is_owned && !<*mut nativeRefundMaybeWithDerivedMetadataBuilder>::is_null(self.inner) {
120                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
121                 }
122         }
123 }
124 /// Frees any resources used by the RefundMaybeWithDerivedMetadataBuilder, if is_owned is set and inner is non-NULL.
125 #[no_mangle]
126 pub extern "C" fn RefundMaybeWithDerivedMetadataBuilder_free(this_obj: RefundMaybeWithDerivedMetadataBuilder) { }
127 #[allow(unused)]
128 /// Used only if an object of this type is returned as a trait impl by a method
129 pub(crate) extern "C" fn RefundMaybeWithDerivedMetadataBuilder_free_void(this_ptr: *mut c_void) {
130         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRefundMaybeWithDerivedMetadataBuilder) };
131 }
132 #[allow(unused)]
133 impl RefundMaybeWithDerivedMetadataBuilder {
134         pub(crate) fn get_native_ref(&self) -> &'static nativeRefundMaybeWithDerivedMetadataBuilder {
135                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
136         }
137         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRefundMaybeWithDerivedMetadataBuilder {
138                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
139         }
140         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
141         pub(crate) fn take_inner(mut self) -> *mut nativeRefundMaybeWithDerivedMetadataBuilder {
142                 assert!(self.is_owned);
143                 let ret = ObjOps::untweak_ptr(self.inner);
144                 self.inner = core::ptr::null_mut();
145                 ret
146         }
147 }
148 impl Clone for RefundMaybeWithDerivedMetadataBuilder {
149         fn clone(&self) -> Self {
150                 Self {
151                         inner: if <*mut nativeRefundMaybeWithDerivedMetadataBuilder>::is_null(self.inner) { core::ptr::null_mut() } else {
152                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
153                         is_owned: true,
154                 }
155         }
156 }
157 #[allow(unused)]
158 /// Used only if an object of this type is returned as a trait impl by a method
159 pub(crate) extern "C" fn RefundMaybeWithDerivedMetadataBuilder_clone_void(this_ptr: *const c_void) -> *mut c_void {
160         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRefundMaybeWithDerivedMetadataBuilder)).clone() })) as *mut c_void
161 }
162 #[no_mangle]
163 /// Creates a copy of the RefundMaybeWithDerivedMetadataBuilder
164 pub extern "C" fn RefundMaybeWithDerivedMetadataBuilder_clone(orig: &RefundMaybeWithDerivedMetadataBuilder) -> RefundMaybeWithDerivedMetadataBuilder {
165         orig.clone()
166 }
167 /// Creates a new builder for a refund using the [`Refund::payer_id`] for the public node id to
168 /// send to if no [`Refund::paths`] are set. Otherwise, it may be a transient pubkey.
169 ///
170 /// Additionally, sets the required (empty) [`Refund::description`], [`Refund::payer_metadata`],
171 /// and [`Refund::amount_msats`].
172 ///
173 /// # Note
174 ///
175 /// If constructing a [`Refund`] for use with a [`ChannelManager`], use
176 /// [`ChannelManager::create_refund_builder`] instead of [`RefundBuilder::new`].
177 ///
178 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
179 /// [`ChannelManager::create_refund_builder`]: crate::ln::channelmanager::ChannelManager::create_refund_builder
180 #[must_use]
181 #[no_mangle]
182 pub extern "C" fn RefundMaybeWithDerivedMetadataBuilder_new(mut metadata: crate::c_types::derived::CVec_u8Z, mut payer_id: crate::c_types::PublicKey, mut amount_msats: u64) -> crate::c_types::derived::CResult_RefundMaybeWithDerivedMetadataBuilderBolt12SemanticErrorZ {
183         let mut local_metadata = Vec::new(); for mut item in metadata.into_rust().drain(..) { local_metadata.push( { item }); };
184         let mut ret = lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder::new(local_metadata, payer_id.into_rust(), amount_msats);
185         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder { 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() };
186         local_ret
187 }
188
189 /// Similar to [`RefundBuilder::new`] except, if [`RefundBuilder::path`] is called, the payer id
190 /// is derived from the given [`ExpandedKey`] and nonce. This provides sender privacy by using a
191 /// different payer id for each refund, assuming a different nonce is used.  Otherwise, the
192 /// provided `node_id` is used for the payer id.
193 ///
194 /// Also, sets the metadata when [`RefundBuilder::build`] is called such that it can be used to
195 /// verify that an [`InvoiceRequest`] was produced for the refund given an [`ExpandedKey`].
196 ///
197 /// The `payment_id` is encrypted in the metadata and should be unique. This ensures that only
198 /// one invoice will be paid for the refund and that payments can be uniquely identified.
199 ///
200 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
201 /// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
202 #[must_use]
203 #[no_mangle]
204 pub extern "C" fn RefundMaybeWithDerivedMetadataBuilder_deriving_payer_id(mut node_id: crate::c_types::PublicKey, expanded_key: &crate::lightning::ln::inbound_payment::ExpandedKey, mut entropy_source: crate::lightning::sign::EntropySource, mut amount_msats: u64, mut payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_RefundMaybeWithDerivedMetadataBuilderBolt12SemanticErrorZ {
205         let mut ret = lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder::deriving_payer_id(node_id.into_rust(), expanded_key.get_native_ref(), entropy_source, secp256k1::global::SECP256K1, amount_msats, ::lightning::ln::channelmanager::PaymentId(payment_id.data));
206         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder { 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() };
207         local_ret
208 }
209
210 /// Sets the [`Refund::description`].
211 ///
212 /// Successive calls to this method will override the previous setting.
213 #[must_use]
214 #[no_mangle]
215 pub extern "C" fn RefundMaybeWithDerivedMetadataBuilder_description(mut this_arg: crate::lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder, mut description: crate::c_types::Str) {
216         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).description(description.into_string());
217         () /*ret*/
218 }
219
220 /// Sets the [`Refund::absolute_expiry`] as seconds since the Unix epoch. Any expiry that has
221 /// already passed is valid and can be checked for using [`Refund::is_expired`].
222 ///
223 /// Successive calls to this method will override the previous setting.
224 #[must_use]
225 #[no_mangle]
226 pub extern "C" fn RefundMaybeWithDerivedMetadataBuilder_absolute_expiry(mut this_arg: crate::lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder, mut absolute_expiry: u64) {
227         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).absolute_expiry(core::time::Duration::from_secs(absolute_expiry));
228         () /*ret*/
229 }
230
231 /// Sets the [`Refund::issuer`].
232 ///
233 /// Successive calls to this method will override the previous setting.
234 #[must_use]
235 #[no_mangle]
236 pub extern "C" fn RefundMaybeWithDerivedMetadataBuilder_issuer(mut this_arg: crate::lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder, mut issuer: crate::c_types::Str) {
237         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).issuer(issuer.into_string());
238         () /*ret*/
239 }
240
241 /// Adds a blinded path to [`Refund::paths`]. Must include at least one path if only connected
242 /// by private channels or if [`Refund::payer_id`] is not a public node id.
243 ///
244 /// Successive calls to this method will add another blinded path. Caller is responsible for not
245 /// adding duplicate paths.
246 #[must_use]
247 #[no_mangle]
248 pub extern "C" fn RefundMaybeWithDerivedMetadataBuilder_path(mut this_arg: crate::lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder, mut path: crate::lightning::blinded_path::BlindedPath) {
249         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).path(*unsafe { Box::from_raw(path.take_inner()) });
250         () /*ret*/
251 }
252
253 /// Sets the [`Refund::chain`] of the given [`Network`] for paying an invoice. If not
254 /// called, [`Network::Bitcoin`] is assumed.
255 ///
256 /// Successive calls to this method will override the previous setting.
257 #[must_use]
258 #[no_mangle]
259 pub extern "C" fn RefundMaybeWithDerivedMetadataBuilder_chain(mut this_arg: crate::lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder, mut network: crate::bitcoin::network::Network) {
260         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).chain(network.into_bitcoin());
261         () /*ret*/
262 }
263
264 /// Sets [`Refund::quantity`] of items. This is purely for informational purposes. It is useful
265 /// when the refund pertains to a [`Bolt12Invoice`] that paid for more than one item from an
266 /// [`Offer`] as specified by [`InvoiceRequest::quantity`].
267 ///
268 /// Successive calls to this method will override the previous setting.
269 ///
270 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
271 /// [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity
272 /// [`Offer`]: crate::offers::offer::Offer
273 #[must_use]
274 #[no_mangle]
275 pub extern "C" fn RefundMaybeWithDerivedMetadataBuilder_quantity(mut this_arg: crate::lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder, mut quantity: u64) {
276         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).quantity(quantity);
277         () /*ret*/
278 }
279
280 /// Sets the [`Refund::payer_note`].
281 ///
282 /// Successive calls to this method will override the previous setting.
283 #[must_use]
284 #[no_mangle]
285 pub extern "C" fn RefundMaybeWithDerivedMetadataBuilder_payer_note(mut this_arg: crate::lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder, mut payer_note: crate::c_types::Str) {
286         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).payer_note(payer_note.into_string());
287         () /*ret*/
288 }
289
290 /// Builds a [`Refund`] after checking for valid semantics.
291 #[must_use]
292 #[no_mangle]
293 pub extern "C" fn RefundMaybeWithDerivedMetadataBuilder_build(mut this_arg: crate::lightning::offers::refund::RefundMaybeWithDerivedMetadataBuilder) -> crate::c_types::derived::CResult_RefundBolt12SemanticErrorZ {
294         let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).build();
295         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::offers::refund::Refund { 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() };
296         local_ret
297 }
298
299
300 use lightning::offers::refund::Refund as nativeRefundImport;
301 pub(crate) type nativeRefund = nativeRefundImport;
302
303 /// A `Refund` is a request to send an [`Bolt12Invoice`] without a preceding [`Offer`].
304 ///
305 /// Typically, after an invoice is paid, the recipient may publish a refund allowing the sender to
306 /// recoup their funds. A refund may be used more generally as an \"offer for money\", such as with a
307 /// bitcoin ATM.
308 ///
309 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
310 /// [`Offer`]: crate::offers::offer::Offer
311 #[must_use]
312 #[repr(C)]
313 pub struct Refund {
314         /// A pointer to the opaque Rust object.
315
316         /// Nearly everywhere, inner must be non-null, however in places where
317         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
318         pub inner: *mut nativeRefund,
319         /// Indicates that this is the only struct which contains the same pointer.
320
321         /// Rust functions which take ownership of an object provided via an argument require
322         /// this to be true and invalidate the object pointed to by inner.
323         pub is_owned: bool,
324 }
325
326 impl Drop for Refund {
327         fn drop(&mut self) {
328                 if self.is_owned && !<*mut nativeRefund>::is_null(self.inner) {
329                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
330                 }
331         }
332 }
333 /// Frees any resources used by the Refund, if is_owned is set and inner is non-NULL.
334 #[no_mangle]
335 pub extern "C" fn Refund_free(this_obj: Refund) { }
336 #[allow(unused)]
337 /// Used only if an object of this type is returned as a trait impl by a method
338 pub(crate) extern "C" fn Refund_free_void(this_ptr: *mut c_void) {
339         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRefund) };
340 }
341 #[allow(unused)]
342 impl Refund {
343         pub(crate) fn get_native_ref(&self) -> &'static nativeRefund {
344                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
345         }
346         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRefund {
347                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
348         }
349         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
350         pub(crate) fn take_inner(mut self) -> *mut nativeRefund {
351                 assert!(self.is_owned);
352                 let ret = ObjOps::untweak_ptr(self.inner);
353                 self.inner = core::ptr::null_mut();
354                 ret
355         }
356 }
357 impl Clone for Refund {
358         fn clone(&self) -> Self {
359                 Self {
360                         inner: if <*mut nativeRefund>::is_null(self.inner) { core::ptr::null_mut() } else {
361                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
362                         is_owned: true,
363                 }
364         }
365 }
366 #[allow(unused)]
367 /// Used only if an object of this type is returned as a trait impl by a method
368 pub(crate) extern "C" fn Refund_clone_void(this_ptr: *const c_void) -> *mut c_void {
369         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRefund)).clone() })) as *mut c_void
370 }
371 #[no_mangle]
372 /// Creates a copy of the Refund
373 pub extern "C" fn Refund_clone(orig: &Refund) -> Refund {
374         orig.clone()
375 }
376 /// Get a string which allows debug introspection of a Refund object
377 pub extern "C" fn Refund_debug_str_void(o: *const c_void) -> Str {
378         alloc::format!("{:?}", unsafe { o as *const crate::lightning::offers::refund::Refund }).into()}
379 /// A complete description of the purpose of the refund. Intended to be displayed to the user
380 /// but with the caveat that it has not been verified in any way.
381 #[must_use]
382 #[no_mangle]
383 pub extern "C" fn Refund_description(this_arg: &crate::lightning::offers::refund::Refund) -> crate::lightning::util::string::PrintableString {
384         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
385         crate::lightning::util::string::PrintableString { inner: ObjOps::heap_alloc(ret), is_owned: true }
386 }
387
388 /// Duration since the Unix epoch when an invoice should no longer be sent.
389 ///
390 /// If `None`, the refund does not expire.
391 #[must_use]
392 #[no_mangle]
393 pub extern "C" fn Refund_absolute_expiry(this_arg: &crate::lightning::offers::refund::Refund) -> crate::c_types::derived::COption_u64Z {
394         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.absolute_expiry();
395         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() }) };
396         local_ret
397 }
398
399 /// Whether the refund has expired.
400 #[must_use]
401 #[no_mangle]
402 pub extern "C" fn Refund_is_expired(this_arg: &crate::lightning::offers::refund::Refund) -> bool {
403         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
404         ret
405 }
406
407 /// Whether the refund has expired given the duration since the Unix epoch.
408 #[must_use]
409 #[no_mangle]
410 pub extern "C" fn Refund_is_expired_no_std(this_arg: &crate::lightning::offers::refund::Refund, mut duration_since_epoch: u64) -> bool {
411         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired_no_std(core::time::Duration::from_secs(duration_since_epoch));
412         ret
413 }
414
415 /// The issuer of the refund, possibly beginning with `user@domain` or `domain`. Intended to be
416 /// displayed to the user but with the caveat that it has not been verified in any way.
417 ///
418 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
419 #[must_use]
420 #[no_mangle]
421 pub extern "C" fn Refund_issuer(this_arg: &crate::lightning::offers::refund::Refund) -> crate::lightning::util::string::PrintableString {
422         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.issuer();
423         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 };
424         local_ret
425 }
426
427 /// Paths to the sender originating from publicly reachable nodes. Blinded paths provide sender
428 /// privacy by obfuscating its node id.
429 #[must_use]
430 #[no_mangle]
431 pub extern "C" fn Refund_paths(this_arg: &crate::lightning::offers::refund::Refund) -> crate::c_types::derived::CVec_BlindedPathZ {
432         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.paths();
433         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 } }); };
434         local_ret.into()
435 }
436
437 /// An unpredictable series of bytes, typically containing information about the derivation of
438 /// [`payer_id`].
439 ///
440 /// [`payer_id`]: Self::payer_id
441 #[must_use]
442 #[no_mangle]
443 pub extern "C" fn Refund_payer_metadata(this_arg: &crate::lightning::offers::refund::Refund) -> crate::c_types::u8slice {
444         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_metadata();
445         let mut local_ret = crate::c_types::u8slice::from_slice(ret);
446         local_ret
447 }
448
449 /// A chain that the refund is valid for.
450 #[must_use]
451 #[no_mangle]
452 pub extern "C" fn Refund_chain(this_arg: &crate::lightning::offers::refund::Refund) -> crate::c_types::ThirtyTwoBytes {
453         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.chain();
454         crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() }
455 }
456
457 /// The amount to refund in msats (i.e., the minimum lightning-payable unit for [`chain`]).
458 ///
459 /// [`chain`]: Self::chain
460 #[must_use]
461 #[no_mangle]
462 pub extern "C" fn Refund_amount_msats(this_arg: &crate::lightning::offers::refund::Refund) -> u64 {
463         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_msats();
464         ret
465 }
466
467 /// Features pertaining to requesting an invoice.
468 #[must_use]
469 #[no_mangle]
470 pub extern "C" fn Refund_features(this_arg: &crate::lightning::offers::refund::Refund) -> crate::lightning::ln::features::InvoiceRequestFeatures {
471         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
472         crate::lightning::ln::features::InvoiceRequestFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::ln::features::InvoiceRequestFeatures<>) as *mut _) }, is_owned: false }
473 }
474
475 /// The quantity of an item that refund is for.
476 #[must_use]
477 #[no_mangle]
478 pub extern "C" fn Refund_quantity(this_arg: &crate::lightning::offers::refund::Refund) -> crate::c_types::derived::COption_u64Z {
479         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.quantity();
480         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() }) };
481         local_ret
482 }
483
484 /// A public node id to send to in the case where there are no [`paths`]. Otherwise, a possibly
485 /// transient pubkey.
486 ///
487 /// [`paths`]: Self::paths
488 #[must_use]
489 #[no_mangle]
490 pub extern "C" fn Refund_payer_id(this_arg: &crate::lightning::offers::refund::Refund) -> crate::c_types::PublicKey {
491         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_id();
492         crate::c_types::PublicKey::from_rust(&ret)
493 }
494
495 /// Payer provided note to include in the invoice.
496 ///
497 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
498 #[must_use]
499 #[no_mangle]
500 pub extern "C" fn Refund_payer_note(this_arg: &crate::lightning::offers::refund::Refund) -> crate::lightning::util::string::PrintableString {
501         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payer_note();
502         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 };
503         local_ret
504 }
505
506 /// Generates a non-cryptographic 64-bit hash of the Refund.
507 #[no_mangle]
508 pub extern "C" fn Refund_hash(o: &Refund) -> u64 {
509         if o.inner.is_null() { return 0; }
510         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
511         #[allow(deprecated)]
512         let mut hasher = core::hash::SipHasher::new();
513         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
514         core::hash::Hasher::finish(&hasher)
515 }
516 #[no_mangle]
517 /// Serialize the Refund object into a byte array which can be read by Refund_read
518 pub extern "C" fn Refund_write(obj: &crate::lightning::offers::refund::Refund) -> crate::c_types::derived::CVec_u8Z {
519         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
520 }
521 #[allow(unused)]
522 pub(crate) extern "C" fn Refund_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
523         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRefund) })
524 }
525 #[no_mangle]
526 /// Read a Refund object from a string
527 pub extern "C" fn Refund_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_RefundBolt12ParseErrorZ {
528         match lightning::offers::refund::Refund::from_str(s.into_str()) {
529                 Ok(r) => {
530                         crate::c_types::CResultTempl::ok(
531                                 crate::lightning::offers::refund::Refund { inner: ObjOps::heap_alloc(r), is_owned: true }
532                         )
533                 },
534                 Err(e) => {
535                         crate::c_types::CResultTempl::err(
536                                 crate::lightning::offers::parse::Bolt12ParseError { inner: ObjOps::heap_alloc(e), is_owned: true }
537                         )
538                 },
539         }.into()
540 }