Pin compiler_builtins to 0.1.109 when building std
[ldk-c-bindings] / lightning-c-bindings / src / lightning / blinded_path / payment.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 methods for constructing [`BlindedPath`]s to send a payment over.
10 //!
11 //! [`BlindedPath`]: crate::blinded_path::BlindedPath
12
13 use alloc::str::FromStr;
14 use alloc::string::String;
15 use core::ffi::c_void;
16 use core::convert::Infallible;
17 use bitcoin::hashes::Hash;
18 use crate::c_types::*;
19 #[cfg(feature="no-std")]
20 use alloc::{vec::Vec, boxed::Box};
21
22
23 use lightning::blinded_path::payment::ForwardNode as nativeForwardNodeImport;
24 pub(crate) type nativeForwardNode = nativeForwardNodeImport;
25
26 /// An intermediate node, its outbound channel, and relay parameters.
27 #[must_use]
28 #[repr(C)]
29 pub struct ForwardNode {
30         /// A pointer to the opaque Rust object.
31
32         /// Nearly everywhere, inner must be non-null, however in places where
33         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
34         pub inner: *mut nativeForwardNode,
35         /// Indicates that this is the only struct which contains the same pointer.
36
37         /// Rust functions which take ownership of an object provided via an argument require
38         /// this to be true and invalidate the object pointed to by inner.
39         pub is_owned: bool,
40 }
41
42 impl Drop for ForwardNode {
43         fn drop(&mut self) {
44                 if self.is_owned && !<*mut nativeForwardNode>::is_null(self.inner) {
45                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
46                 }
47         }
48 }
49 /// Frees any resources used by the ForwardNode, if is_owned is set and inner is non-NULL.
50 #[no_mangle]
51 pub extern "C" fn ForwardNode_free(this_obj: ForwardNode) { }
52 #[allow(unused)]
53 /// Used only if an object of this type is returned as a trait impl by a method
54 pub(crate) extern "C" fn ForwardNode_free_void(this_ptr: *mut c_void) {
55         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeForwardNode) };
56 }
57 #[allow(unused)]
58 impl ForwardNode {
59         pub(crate) fn get_native_ref(&self) -> &'static nativeForwardNode {
60                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
61         }
62         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeForwardNode {
63                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
64         }
65         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
66         pub(crate) fn take_inner(mut self) -> *mut nativeForwardNode {
67                 assert!(self.is_owned);
68                 let ret = ObjOps::untweak_ptr(self.inner);
69                 self.inner = core::ptr::null_mut();
70                 ret
71         }
72 }
73 /// The TLVs for this node's [`BlindedHop`], where the fee parameters contained within are also
74 /// used for [`BlindedPayInfo`] construction.
75 #[no_mangle]
76 pub extern "C" fn ForwardNode_get_tlvs(this_ptr: &ForwardNode) -> crate::lightning::blinded_path::payment::ForwardTlvs {
77         let mut inner_val = &mut this_ptr.get_native_mut_ref().tlvs;
78         crate::lightning::blinded_path::payment::ForwardTlvs { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::blinded_path::payment::ForwardTlvs<>) as *mut _) }, is_owned: false }
79 }
80 /// The TLVs for this node's [`BlindedHop`], where the fee parameters contained within are also
81 /// used for [`BlindedPayInfo`] construction.
82 #[no_mangle]
83 pub extern "C" fn ForwardNode_set_tlvs(this_ptr: &mut ForwardNode, mut val: crate::lightning::blinded_path::payment::ForwardTlvs) {
84         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.tlvs = *unsafe { Box::from_raw(val.take_inner()) };
85 }
86 /// This node's pubkey.
87 #[no_mangle]
88 pub extern "C" fn ForwardNode_get_node_id(this_ptr: &ForwardNode) -> crate::c_types::PublicKey {
89         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id;
90         crate::c_types::PublicKey::from_rust(&inner_val)
91 }
92 /// This node's pubkey.
93 #[no_mangle]
94 pub extern "C" fn ForwardNode_set_node_id(this_ptr: &mut ForwardNode, mut val: crate::c_types::PublicKey) {
95         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id = val.into_rust();
96 }
97 /// The maximum value, in msat, that may be accepted by this node.
98 #[no_mangle]
99 pub extern "C" fn ForwardNode_get_htlc_maximum_msat(this_ptr: &ForwardNode) -> u64 {
100         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
101         *inner_val
102 }
103 /// The maximum value, in msat, that may be accepted by this node.
104 #[no_mangle]
105 pub extern "C" fn ForwardNode_set_htlc_maximum_msat(this_ptr: &mut ForwardNode, mut val: u64) {
106         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val;
107 }
108 /// Constructs a new ForwardNode given each field
109 #[must_use]
110 #[no_mangle]
111 pub extern "C" fn ForwardNode_new(mut tlvs_arg: crate::lightning::blinded_path::payment::ForwardTlvs, mut node_id_arg: crate::c_types::PublicKey, mut htlc_maximum_msat_arg: u64) -> ForwardNode {
112         ForwardNode { inner: ObjOps::heap_alloc(nativeForwardNode {
113                 tlvs: *unsafe { Box::from_raw(tlvs_arg.take_inner()) },
114                 node_id: node_id_arg.into_rust(),
115                 htlc_maximum_msat: htlc_maximum_msat_arg,
116         }), is_owned: true }
117 }
118 impl Clone for ForwardNode {
119         fn clone(&self) -> Self {
120                 Self {
121                         inner: if <*mut nativeForwardNode>::is_null(self.inner) { core::ptr::null_mut() } else {
122                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
123                         is_owned: true,
124                 }
125         }
126 }
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 ForwardNode_clone_void(this_ptr: *const c_void) -> *mut c_void {
130         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeForwardNode)).clone() })) as *mut c_void
131 }
132 #[no_mangle]
133 /// Creates a copy of the ForwardNode
134 pub extern "C" fn ForwardNode_clone(orig: &ForwardNode) -> ForwardNode {
135         orig.clone()
136 }
137 /// Get a string which allows debug introspection of a ForwardNode object
138 pub extern "C" fn ForwardNode_debug_str_void(o: *const c_void) -> Str {
139         alloc::format!("{:?}", unsafe { o as *const crate::lightning::blinded_path::payment::ForwardNode }).into()}
140
141 use lightning::blinded_path::payment::ForwardTlvs as nativeForwardTlvsImport;
142 pub(crate) type nativeForwardTlvs = nativeForwardTlvsImport;
143
144 /// Data to construct a [`BlindedHop`] for forwarding a payment.
145 #[must_use]
146 #[repr(C)]
147 pub struct ForwardTlvs {
148         /// A pointer to the opaque Rust object.
149
150         /// Nearly everywhere, inner must be non-null, however in places where
151         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
152         pub inner: *mut nativeForwardTlvs,
153         /// Indicates that this is the only struct which contains the same pointer.
154
155         /// Rust functions which take ownership of an object provided via an argument require
156         /// this to be true and invalidate the object pointed to by inner.
157         pub is_owned: bool,
158 }
159
160 impl Drop for ForwardTlvs {
161         fn drop(&mut self) {
162                 if self.is_owned && !<*mut nativeForwardTlvs>::is_null(self.inner) {
163                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
164                 }
165         }
166 }
167 /// Frees any resources used by the ForwardTlvs, if is_owned is set and inner is non-NULL.
168 #[no_mangle]
169 pub extern "C" fn ForwardTlvs_free(this_obj: ForwardTlvs) { }
170 #[allow(unused)]
171 /// Used only if an object of this type is returned as a trait impl by a method
172 pub(crate) extern "C" fn ForwardTlvs_free_void(this_ptr: *mut c_void) {
173         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeForwardTlvs) };
174 }
175 #[allow(unused)]
176 impl ForwardTlvs {
177         pub(crate) fn get_native_ref(&self) -> &'static nativeForwardTlvs {
178                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
179         }
180         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeForwardTlvs {
181                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
182         }
183         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
184         pub(crate) fn take_inner(mut self) -> *mut nativeForwardTlvs {
185                 assert!(self.is_owned);
186                 let ret = ObjOps::untweak_ptr(self.inner);
187                 self.inner = core::ptr::null_mut();
188                 ret
189         }
190 }
191 /// The short channel id this payment should be forwarded out over.
192 #[no_mangle]
193 pub extern "C" fn ForwardTlvs_get_short_channel_id(this_ptr: &ForwardTlvs) -> u64 {
194         let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
195         *inner_val
196 }
197 /// The short channel id this payment should be forwarded out over.
198 #[no_mangle]
199 pub extern "C" fn ForwardTlvs_set_short_channel_id(this_ptr: &mut ForwardTlvs, mut val: u64) {
200         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
201 }
202 /// Payment parameters for relaying over [`Self::short_channel_id`].
203 #[no_mangle]
204 pub extern "C" fn ForwardTlvs_get_payment_relay(this_ptr: &ForwardTlvs) -> crate::lightning::blinded_path::payment::PaymentRelay {
205         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_relay;
206         crate::lightning::blinded_path::payment::PaymentRelay { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::blinded_path::payment::PaymentRelay<>) as *mut _) }, is_owned: false }
207 }
208 /// Payment parameters for relaying over [`Self::short_channel_id`].
209 #[no_mangle]
210 pub extern "C" fn ForwardTlvs_set_payment_relay(this_ptr: &mut ForwardTlvs, mut val: crate::lightning::blinded_path::payment::PaymentRelay) {
211         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_relay = *unsafe { Box::from_raw(val.take_inner()) };
212 }
213 /// Payment constraints for relaying over [`Self::short_channel_id`].
214 #[no_mangle]
215 pub extern "C" fn ForwardTlvs_get_payment_constraints(this_ptr: &ForwardTlvs) -> crate::lightning::blinded_path::payment::PaymentConstraints {
216         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_constraints;
217         crate::lightning::blinded_path::payment::PaymentConstraints { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::blinded_path::payment::PaymentConstraints<>) as *mut _) }, is_owned: false }
218 }
219 /// Payment constraints for relaying over [`Self::short_channel_id`].
220 #[no_mangle]
221 pub extern "C" fn ForwardTlvs_set_payment_constraints(this_ptr: &mut ForwardTlvs, mut val: crate::lightning::blinded_path::payment::PaymentConstraints) {
222         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_constraints = *unsafe { Box::from_raw(val.take_inner()) };
223 }
224 /// Supported and required features when relaying a payment onion containing this object's
225 /// corresponding [`BlindedHop::encrypted_payload`].
226 ///
227 /// [`BlindedHop::encrypted_payload`]: crate::blinded_path::BlindedHop::encrypted_payload
228 #[no_mangle]
229 pub extern "C" fn ForwardTlvs_get_features(this_ptr: &ForwardTlvs) -> crate::lightning::ln::features::BlindedHopFeatures {
230         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
231         crate::lightning::ln::features::BlindedHopFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::BlindedHopFeatures<>) as *mut _) }, is_owned: false }
232 }
233 /// Supported and required features when relaying a payment onion containing this object's
234 /// corresponding [`BlindedHop::encrypted_payload`].
235 ///
236 /// [`BlindedHop::encrypted_payload`]: crate::blinded_path::BlindedHop::encrypted_payload
237 #[no_mangle]
238 pub extern "C" fn ForwardTlvs_set_features(this_ptr: &mut ForwardTlvs, mut val: crate::lightning::ln::features::BlindedHopFeatures) {
239         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
240 }
241 /// Constructs a new ForwardTlvs given each field
242 #[must_use]
243 #[no_mangle]
244 pub extern "C" fn ForwardTlvs_new(mut short_channel_id_arg: u64, mut payment_relay_arg: crate::lightning::blinded_path::payment::PaymentRelay, mut payment_constraints_arg: crate::lightning::blinded_path::payment::PaymentConstraints, mut features_arg: crate::lightning::ln::features::BlindedHopFeatures) -> ForwardTlvs {
245         ForwardTlvs { inner: ObjOps::heap_alloc(nativeForwardTlvs {
246                 short_channel_id: short_channel_id_arg,
247                 payment_relay: *unsafe { Box::from_raw(payment_relay_arg.take_inner()) },
248                 payment_constraints: *unsafe { Box::from_raw(payment_constraints_arg.take_inner()) },
249                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
250         }), is_owned: true }
251 }
252 impl Clone for ForwardTlvs {
253         fn clone(&self) -> Self {
254                 Self {
255                         inner: if <*mut nativeForwardTlvs>::is_null(self.inner) { core::ptr::null_mut() } else {
256                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
257                         is_owned: true,
258                 }
259         }
260 }
261 #[allow(unused)]
262 /// Used only if an object of this type is returned as a trait impl by a method
263 pub(crate) extern "C" fn ForwardTlvs_clone_void(this_ptr: *const c_void) -> *mut c_void {
264         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeForwardTlvs)).clone() })) as *mut c_void
265 }
266 #[no_mangle]
267 /// Creates a copy of the ForwardTlvs
268 pub extern "C" fn ForwardTlvs_clone(orig: &ForwardTlvs) -> ForwardTlvs {
269         orig.clone()
270 }
271 /// Get a string which allows debug introspection of a ForwardTlvs object
272 pub extern "C" fn ForwardTlvs_debug_str_void(o: *const c_void) -> Str {
273         alloc::format!("{:?}", unsafe { o as *const crate::lightning::blinded_path::payment::ForwardTlvs }).into()}
274
275 use lightning::blinded_path::payment::ReceiveTlvs as nativeReceiveTlvsImport;
276 pub(crate) type nativeReceiveTlvs = nativeReceiveTlvsImport;
277
278 /// Data to construct a [`BlindedHop`] for receiving a payment. This payload is custom to LDK and
279 /// may not be valid if received by another lightning implementation.
280 #[must_use]
281 #[repr(C)]
282 pub struct ReceiveTlvs {
283         /// A pointer to the opaque Rust object.
284
285         /// Nearly everywhere, inner must be non-null, however in places where
286         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
287         pub inner: *mut nativeReceiveTlvs,
288         /// Indicates that this is the only struct which contains the same pointer.
289
290         /// Rust functions which take ownership of an object provided via an argument require
291         /// this to be true and invalidate the object pointed to by inner.
292         pub is_owned: bool,
293 }
294
295 impl Drop for ReceiveTlvs {
296         fn drop(&mut self) {
297                 if self.is_owned && !<*mut nativeReceiveTlvs>::is_null(self.inner) {
298                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
299                 }
300         }
301 }
302 /// Frees any resources used by the ReceiveTlvs, if is_owned is set and inner is non-NULL.
303 #[no_mangle]
304 pub extern "C" fn ReceiveTlvs_free(this_obj: ReceiveTlvs) { }
305 #[allow(unused)]
306 /// Used only if an object of this type is returned as a trait impl by a method
307 pub(crate) extern "C" fn ReceiveTlvs_free_void(this_ptr: *mut c_void) {
308         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeReceiveTlvs) };
309 }
310 #[allow(unused)]
311 impl ReceiveTlvs {
312         pub(crate) fn get_native_ref(&self) -> &'static nativeReceiveTlvs {
313                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
314         }
315         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReceiveTlvs {
316                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
317         }
318         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
319         pub(crate) fn take_inner(mut self) -> *mut nativeReceiveTlvs {
320                 assert!(self.is_owned);
321                 let ret = ObjOps::untweak_ptr(self.inner);
322                 self.inner = core::ptr::null_mut();
323                 ret
324         }
325 }
326 /// Used to authenticate the sender of a payment to the receiver and tie MPP HTLCs together.
327 #[no_mangle]
328 pub extern "C" fn ReceiveTlvs_get_payment_secret(this_ptr: &ReceiveTlvs) -> *const [u8; 32] {
329         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_secret;
330         &inner_val.0
331 }
332 /// Used to authenticate the sender of a payment to the receiver and tie MPP HTLCs together.
333 #[no_mangle]
334 pub extern "C" fn ReceiveTlvs_set_payment_secret(this_ptr: &mut ReceiveTlvs, mut val: crate::c_types::ThirtyTwoBytes) {
335         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_secret = ::lightning::ln::types::PaymentSecret(val.data);
336 }
337 /// Constraints for the receiver of this payment.
338 #[no_mangle]
339 pub extern "C" fn ReceiveTlvs_get_payment_constraints(this_ptr: &ReceiveTlvs) -> crate::lightning::blinded_path::payment::PaymentConstraints {
340         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_constraints;
341         crate::lightning::blinded_path::payment::PaymentConstraints { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::blinded_path::payment::PaymentConstraints<>) as *mut _) }, is_owned: false }
342 }
343 /// Constraints for the receiver of this payment.
344 #[no_mangle]
345 pub extern "C" fn ReceiveTlvs_set_payment_constraints(this_ptr: &mut ReceiveTlvs, mut val: crate::lightning::blinded_path::payment::PaymentConstraints) {
346         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_constraints = *unsafe { Box::from_raw(val.take_inner()) };
347 }
348 /// Context for the receiver of this payment.
349 #[no_mangle]
350 pub extern "C" fn ReceiveTlvs_get_payment_context(this_ptr: &ReceiveTlvs) -> crate::lightning::blinded_path::payment::PaymentContext {
351         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_context;
352         crate::lightning::blinded_path::payment::PaymentContext::from_native(inner_val)
353 }
354 /// Context for the receiver of this payment.
355 #[no_mangle]
356 pub extern "C" fn ReceiveTlvs_set_payment_context(this_ptr: &mut ReceiveTlvs, mut val: crate::lightning::blinded_path::payment::PaymentContext) {
357         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_context = val.into_native();
358 }
359 /// Constructs a new ReceiveTlvs given each field
360 #[must_use]
361 #[no_mangle]
362 pub extern "C" fn ReceiveTlvs_new(mut payment_secret_arg: crate::c_types::ThirtyTwoBytes, mut payment_constraints_arg: crate::lightning::blinded_path::payment::PaymentConstraints, mut payment_context_arg: crate::lightning::blinded_path::payment::PaymentContext) -> ReceiveTlvs {
363         ReceiveTlvs { inner: ObjOps::heap_alloc(nativeReceiveTlvs {
364                 payment_secret: ::lightning::ln::types::PaymentSecret(payment_secret_arg.data),
365                 payment_constraints: *unsafe { Box::from_raw(payment_constraints_arg.take_inner()) },
366                 payment_context: payment_context_arg.into_native(),
367         }), is_owned: true }
368 }
369 impl Clone for ReceiveTlvs {
370         fn clone(&self) -> Self {
371                 Self {
372                         inner: if <*mut nativeReceiveTlvs>::is_null(self.inner) { core::ptr::null_mut() } else {
373                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
374                         is_owned: true,
375                 }
376         }
377 }
378 #[allow(unused)]
379 /// Used only if an object of this type is returned as a trait impl by a method
380 pub(crate) extern "C" fn ReceiveTlvs_clone_void(this_ptr: *const c_void) -> *mut c_void {
381         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeReceiveTlvs)).clone() })) as *mut c_void
382 }
383 #[no_mangle]
384 /// Creates a copy of the ReceiveTlvs
385 pub extern "C" fn ReceiveTlvs_clone(orig: &ReceiveTlvs) -> ReceiveTlvs {
386         orig.clone()
387 }
388 /// Get a string which allows debug introspection of a ReceiveTlvs object
389 pub extern "C" fn ReceiveTlvs_debug_str_void(o: *const c_void) -> Str {
390         alloc::format!("{:?}", unsafe { o as *const crate::lightning::blinded_path::payment::ReceiveTlvs }).into()}
391
392 use lightning::blinded_path::payment::PaymentRelay as nativePaymentRelayImport;
393 pub(crate) type nativePaymentRelay = nativePaymentRelayImport;
394
395 /// Parameters for relaying over a given [`BlindedHop`].
396 ///
397 /// [`BlindedHop`]: crate::blinded_path::BlindedHop
398 #[must_use]
399 #[repr(C)]
400 pub struct PaymentRelay {
401         /// A pointer to the opaque Rust object.
402
403         /// Nearly everywhere, inner must be non-null, however in places where
404         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
405         pub inner: *mut nativePaymentRelay,
406         /// Indicates that this is the only struct which contains the same pointer.
407
408         /// Rust functions which take ownership of an object provided via an argument require
409         /// this to be true and invalidate the object pointed to by inner.
410         pub is_owned: bool,
411 }
412
413 impl Drop for PaymentRelay {
414         fn drop(&mut self) {
415                 if self.is_owned && !<*mut nativePaymentRelay>::is_null(self.inner) {
416                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
417                 }
418         }
419 }
420 /// Frees any resources used by the PaymentRelay, if is_owned is set and inner is non-NULL.
421 #[no_mangle]
422 pub extern "C" fn PaymentRelay_free(this_obj: PaymentRelay) { }
423 #[allow(unused)]
424 /// Used only if an object of this type is returned as a trait impl by a method
425 pub(crate) extern "C" fn PaymentRelay_free_void(this_ptr: *mut c_void) {
426         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentRelay) };
427 }
428 #[allow(unused)]
429 impl PaymentRelay {
430         pub(crate) fn get_native_ref(&self) -> &'static nativePaymentRelay {
431                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
432         }
433         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentRelay {
434                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
435         }
436         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
437         pub(crate) fn take_inner(mut self) -> *mut nativePaymentRelay {
438                 assert!(self.is_owned);
439                 let ret = ObjOps::untweak_ptr(self.inner);
440                 self.inner = core::ptr::null_mut();
441                 ret
442         }
443 }
444 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for this [`BlindedHop`].
445 #[no_mangle]
446 pub extern "C" fn PaymentRelay_get_cltv_expiry_delta(this_ptr: &PaymentRelay) -> u16 {
447         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
448         *inner_val
449 }
450 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for this [`BlindedHop`].
451 #[no_mangle]
452 pub extern "C" fn PaymentRelay_set_cltv_expiry_delta(this_ptr: &mut PaymentRelay, mut val: u16) {
453         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
454 }
455 /// Liquidity fee charged (in millionths of the amount transferred) for relaying a payment over
456 /// this [`BlindedHop`], (i.e., 10,000 is 1%).
457 #[no_mangle]
458 pub extern "C" fn PaymentRelay_get_fee_proportional_millionths(this_ptr: &PaymentRelay) -> u32 {
459         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
460         *inner_val
461 }
462 /// Liquidity fee charged (in millionths of the amount transferred) for relaying a payment over
463 /// this [`BlindedHop`], (i.e., 10,000 is 1%).
464 #[no_mangle]
465 pub extern "C" fn PaymentRelay_set_fee_proportional_millionths(this_ptr: &mut PaymentRelay, mut val: u32) {
466         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
467 }
468 /// Base fee charged (in millisatoshi) for relaying a payment over this [`BlindedHop`].
469 #[no_mangle]
470 pub extern "C" fn PaymentRelay_get_fee_base_msat(this_ptr: &PaymentRelay) -> u32 {
471         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
472         *inner_val
473 }
474 /// Base fee charged (in millisatoshi) for relaying a payment over this [`BlindedHop`].
475 #[no_mangle]
476 pub extern "C" fn PaymentRelay_set_fee_base_msat(this_ptr: &mut PaymentRelay, mut val: u32) {
477         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
478 }
479 /// Constructs a new PaymentRelay given each field
480 #[must_use]
481 #[no_mangle]
482 pub extern "C" fn PaymentRelay_new(mut cltv_expiry_delta_arg: u16, mut fee_proportional_millionths_arg: u32, mut fee_base_msat_arg: u32) -> PaymentRelay {
483         PaymentRelay { inner: ObjOps::heap_alloc(nativePaymentRelay {
484                 cltv_expiry_delta: cltv_expiry_delta_arg,
485                 fee_proportional_millionths: fee_proportional_millionths_arg,
486                 fee_base_msat: fee_base_msat_arg,
487         }), is_owned: true }
488 }
489 impl Clone for PaymentRelay {
490         fn clone(&self) -> Self {
491                 Self {
492                         inner: if <*mut nativePaymentRelay>::is_null(self.inner) { core::ptr::null_mut() } else {
493                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
494                         is_owned: true,
495                 }
496         }
497 }
498 #[allow(unused)]
499 /// Used only if an object of this type is returned as a trait impl by a method
500 pub(crate) extern "C" fn PaymentRelay_clone_void(this_ptr: *const c_void) -> *mut c_void {
501         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePaymentRelay)).clone() })) as *mut c_void
502 }
503 #[no_mangle]
504 /// Creates a copy of the PaymentRelay
505 pub extern "C" fn PaymentRelay_clone(orig: &PaymentRelay) -> PaymentRelay {
506         orig.clone()
507 }
508 /// Get a string which allows debug introspection of a PaymentRelay object
509 pub extern "C" fn PaymentRelay_debug_str_void(o: *const c_void) -> Str {
510         alloc::format!("{:?}", unsafe { o as *const crate::lightning::blinded_path::payment::PaymentRelay }).into()}
511
512 use lightning::blinded_path::payment::PaymentConstraints as nativePaymentConstraintsImport;
513 pub(crate) type nativePaymentConstraints = nativePaymentConstraintsImport;
514
515 /// Constraints for relaying over a given [`BlindedHop`].
516 ///
517 /// [`BlindedHop`]: crate::blinded_path::BlindedHop
518 #[must_use]
519 #[repr(C)]
520 pub struct PaymentConstraints {
521         /// A pointer to the opaque Rust object.
522
523         /// Nearly everywhere, inner must be non-null, however in places where
524         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
525         pub inner: *mut nativePaymentConstraints,
526         /// Indicates that this is the only struct which contains the same pointer.
527
528         /// Rust functions which take ownership of an object provided via an argument require
529         /// this to be true and invalidate the object pointed to by inner.
530         pub is_owned: bool,
531 }
532
533 impl Drop for PaymentConstraints {
534         fn drop(&mut self) {
535                 if self.is_owned && !<*mut nativePaymentConstraints>::is_null(self.inner) {
536                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
537                 }
538         }
539 }
540 /// Frees any resources used by the PaymentConstraints, if is_owned is set and inner is non-NULL.
541 #[no_mangle]
542 pub extern "C" fn PaymentConstraints_free(this_obj: PaymentConstraints) { }
543 #[allow(unused)]
544 /// Used only if an object of this type is returned as a trait impl by a method
545 pub(crate) extern "C" fn PaymentConstraints_free_void(this_ptr: *mut c_void) {
546         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentConstraints) };
547 }
548 #[allow(unused)]
549 impl PaymentConstraints {
550         pub(crate) fn get_native_ref(&self) -> &'static nativePaymentConstraints {
551                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
552         }
553         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentConstraints {
554                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
555         }
556         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
557         pub(crate) fn take_inner(mut self) -> *mut nativePaymentConstraints {
558                 assert!(self.is_owned);
559                 let ret = ObjOps::untweak_ptr(self.inner);
560                 self.inner = core::ptr::null_mut();
561                 ret
562         }
563 }
564 /// The maximum total CLTV that is acceptable when relaying a payment over this [`BlindedHop`].
565 #[no_mangle]
566 pub extern "C" fn PaymentConstraints_get_max_cltv_expiry(this_ptr: &PaymentConstraints) -> u32 {
567         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_cltv_expiry;
568         *inner_val
569 }
570 /// The maximum total CLTV that is acceptable when relaying a payment over this [`BlindedHop`].
571 #[no_mangle]
572 pub extern "C" fn PaymentConstraints_set_max_cltv_expiry(this_ptr: &mut PaymentConstraints, mut val: u32) {
573         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_cltv_expiry = val;
574 }
575 /// The minimum value, in msat, that may be accepted by the node corresponding to this
576 /// [`BlindedHop`].
577 #[no_mangle]
578 pub extern "C" fn PaymentConstraints_get_htlc_minimum_msat(this_ptr: &PaymentConstraints) -> u64 {
579         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
580         *inner_val
581 }
582 /// The minimum value, in msat, that may be accepted by the node corresponding to this
583 /// [`BlindedHop`].
584 #[no_mangle]
585 pub extern "C" fn PaymentConstraints_set_htlc_minimum_msat(this_ptr: &mut PaymentConstraints, mut val: u64) {
586         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
587 }
588 /// Constructs a new PaymentConstraints given each field
589 #[must_use]
590 #[no_mangle]
591 pub extern "C" fn PaymentConstraints_new(mut max_cltv_expiry_arg: u32, mut htlc_minimum_msat_arg: u64) -> PaymentConstraints {
592         PaymentConstraints { inner: ObjOps::heap_alloc(nativePaymentConstraints {
593                 max_cltv_expiry: max_cltv_expiry_arg,
594                 htlc_minimum_msat: htlc_minimum_msat_arg,
595         }), is_owned: true }
596 }
597 impl Clone for PaymentConstraints {
598         fn clone(&self) -> Self {
599                 Self {
600                         inner: if <*mut nativePaymentConstraints>::is_null(self.inner) { core::ptr::null_mut() } else {
601                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
602                         is_owned: true,
603                 }
604         }
605 }
606 #[allow(unused)]
607 /// Used only if an object of this type is returned as a trait impl by a method
608 pub(crate) extern "C" fn PaymentConstraints_clone_void(this_ptr: *const c_void) -> *mut c_void {
609         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePaymentConstraints)).clone() })) as *mut c_void
610 }
611 #[no_mangle]
612 /// Creates a copy of the PaymentConstraints
613 pub extern "C" fn PaymentConstraints_clone(orig: &PaymentConstraints) -> PaymentConstraints {
614         orig.clone()
615 }
616 /// Get a string which allows debug introspection of a PaymentConstraints object
617 pub extern "C" fn PaymentConstraints_debug_str_void(o: *const c_void) -> Str {
618         alloc::format!("{:?}", unsafe { o as *const crate::lightning::blinded_path::payment::PaymentConstraints }).into()}
619 /// The context of an inbound payment, which is included in a [`BlindedPath`] via [`ReceiveTlvs`]
620 /// and surfaced in [`PaymentPurpose`].
621 ///
622 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
623 /// [`PaymentPurpose`]: crate::events::PaymentPurpose
624 #[derive(Clone)]
625 #[must_use]
626 #[repr(C)]
627 pub enum PaymentContext {
628         /// The payment context was unknown.
629         Unknown(
630                 crate::lightning::blinded_path::payment::UnknownPaymentContext),
631         /// The payment was made for an invoice requested from a BOLT 12 [`Offer`].
632         ///
633         /// [`Offer`]: crate::offers::offer::Offer
634         Bolt12Offer(
635                 crate::lightning::blinded_path::payment::Bolt12OfferContext),
636         /// The payment was made for an invoice sent for a BOLT 12 [`Refund`].
637         ///
638         /// [`Refund`]: crate::offers::refund::Refund
639         Bolt12Refund(
640                 crate::lightning::blinded_path::payment::Bolt12RefundContext),
641 }
642 use lightning::blinded_path::payment::PaymentContext as PaymentContextImport;
643 pub(crate) type nativePaymentContext = PaymentContextImport;
644
645 impl PaymentContext {
646         #[allow(unused)]
647         pub(crate) fn to_native(&self) -> nativePaymentContext {
648                 match self {
649                         PaymentContext::Unknown (ref a, ) => {
650                                 let mut a_nonref = Clone::clone(a);
651                                 nativePaymentContext::Unknown (
652                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
653                                 )
654                         },
655                         PaymentContext::Bolt12Offer (ref a, ) => {
656                                 let mut a_nonref = Clone::clone(a);
657                                 nativePaymentContext::Bolt12Offer (
658                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
659                                 )
660                         },
661                         PaymentContext::Bolt12Refund (ref a, ) => {
662                                 let mut a_nonref = Clone::clone(a);
663                                 nativePaymentContext::Bolt12Refund (
664                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
665                                 )
666                         },
667                 }
668         }
669         #[allow(unused)]
670         pub(crate) fn into_native(self) -> nativePaymentContext {
671                 match self {
672                         PaymentContext::Unknown (mut a, ) => {
673                                 nativePaymentContext::Unknown (
674                                         *unsafe { Box::from_raw(a.take_inner()) },
675                                 )
676                         },
677                         PaymentContext::Bolt12Offer (mut a, ) => {
678                                 nativePaymentContext::Bolt12Offer (
679                                         *unsafe { Box::from_raw(a.take_inner()) },
680                                 )
681                         },
682                         PaymentContext::Bolt12Refund (mut a, ) => {
683                                 nativePaymentContext::Bolt12Refund (
684                                         *unsafe { Box::from_raw(a.take_inner()) },
685                                 )
686                         },
687                 }
688         }
689         #[allow(unused)]
690         pub(crate) fn from_native(native: &PaymentContextImport) -> Self {
691                 let native = unsafe { &*(native as *const _ as *const c_void as *const nativePaymentContext) };
692                 match native {
693                         nativePaymentContext::Unknown (ref a, ) => {
694                                 let mut a_nonref = Clone::clone(a);
695                                 PaymentContext::Unknown (
696                                         crate::lightning::blinded_path::payment::UnknownPaymentContext { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
697                                 )
698                         },
699                         nativePaymentContext::Bolt12Offer (ref a, ) => {
700                                 let mut a_nonref = Clone::clone(a);
701                                 PaymentContext::Bolt12Offer (
702                                         crate::lightning::blinded_path::payment::Bolt12OfferContext { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
703                                 )
704                         },
705                         nativePaymentContext::Bolt12Refund (ref a, ) => {
706                                 let mut a_nonref = Clone::clone(a);
707                                 PaymentContext::Bolt12Refund (
708                                         crate::lightning::blinded_path::payment::Bolt12RefundContext { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
709                                 )
710                         },
711                 }
712         }
713         #[allow(unused)]
714         pub(crate) fn native_into(native: nativePaymentContext) -> Self {
715                 match native {
716                         nativePaymentContext::Unknown (mut a, ) => {
717                                 PaymentContext::Unknown (
718                                         crate::lightning::blinded_path::payment::UnknownPaymentContext { inner: ObjOps::heap_alloc(a), is_owned: true },
719                                 )
720                         },
721                         nativePaymentContext::Bolt12Offer (mut a, ) => {
722                                 PaymentContext::Bolt12Offer (
723                                         crate::lightning::blinded_path::payment::Bolt12OfferContext { inner: ObjOps::heap_alloc(a), is_owned: true },
724                                 )
725                         },
726                         nativePaymentContext::Bolt12Refund (mut a, ) => {
727                                 PaymentContext::Bolt12Refund (
728                                         crate::lightning::blinded_path::payment::Bolt12RefundContext { inner: ObjOps::heap_alloc(a), is_owned: true },
729                                 )
730                         },
731                 }
732         }
733 }
734 /// Frees any resources used by the PaymentContext
735 #[no_mangle]
736 pub extern "C" fn PaymentContext_free(this_ptr: PaymentContext) { }
737 /// Creates a copy of the PaymentContext
738 #[no_mangle]
739 pub extern "C" fn PaymentContext_clone(orig: &PaymentContext) -> PaymentContext {
740         orig.clone()
741 }
742 #[allow(unused)]
743 /// Used only if an object of this type is returned as a trait impl by a method
744 pub(crate) extern "C" fn PaymentContext_clone_void(this_ptr: *const c_void) -> *mut c_void {
745         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const PaymentContext)).clone() })) as *mut c_void
746 }
747 #[allow(unused)]
748 /// Used only if an object of this type is returned as a trait impl by a method
749 pub(crate) extern "C" fn PaymentContext_free_void(this_ptr: *mut c_void) {
750         let _ = unsafe { Box::from_raw(this_ptr as *mut PaymentContext) };
751 }
752 #[no_mangle]
753 /// Utility method to constructs a new Unknown-variant PaymentContext
754 pub extern "C" fn PaymentContext_unknown(a: crate::lightning::blinded_path::payment::UnknownPaymentContext) -> PaymentContext {
755         PaymentContext::Unknown(a, )
756 }
757 #[no_mangle]
758 /// Utility method to constructs a new Bolt12Offer-variant PaymentContext
759 pub extern "C" fn PaymentContext_bolt12_offer(a: crate::lightning::blinded_path::payment::Bolt12OfferContext) -> PaymentContext {
760         PaymentContext::Bolt12Offer(a, )
761 }
762 #[no_mangle]
763 /// Utility method to constructs a new Bolt12Refund-variant PaymentContext
764 pub extern "C" fn PaymentContext_bolt12_refund(a: crate::lightning::blinded_path::payment::Bolt12RefundContext) -> PaymentContext {
765         PaymentContext::Bolt12Refund(a, )
766 }
767 /// Get a string which allows debug introspection of a PaymentContext object
768 pub extern "C" fn PaymentContext_debug_str_void(o: *const c_void) -> Str {
769         alloc::format!("{:?}", unsafe { o as *const crate::lightning::blinded_path::payment::PaymentContext }).into()}
770 /// Checks if two PaymentContexts contain equal inner contents.
771 /// This ignores pointers and is_owned flags and looks at the values in fields.
772 #[no_mangle]
773 pub extern "C" fn PaymentContext_eq(a: &PaymentContext, b: &PaymentContext) -> bool {
774         if &a.to_native() == &b.to_native() { true } else { false }
775 }
776
777 use lightning::blinded_path::payment::UnknownPaymentContext as nativeUnknownPaymentContextImport;
778 pub(crate) type nativeUnknownPaymentContext = nativeUnknownPaymentContextImport;
779
780 /// An unknown payment context.
781 #[must_use]
782 #[repr(C)]
783 pub struct UnknownPaymentContext {
784         /// A pointer to the opaque Rust object.
785
786         /// Nearly everywhere, inner must be non-null, however in places where
787         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
788         pub inner: *mut nativeUnknownPaymentContext,
789         /// Indicates that this is the only struct which contains the same pointer.
790
791         /// Rust functions which take ownership of an object provided via an argument require
792         /// this to be true and invalidate the object pointed to by inner.
793         pub is_owned: bool,
794 }
795
796 impl Drop for UnknownPaymentContext {
797         fn drop(&mut self) {
798                 if self.is_owned && !<*mut nativeUnknownPaymentContext>::is_null(self.inner) {
799                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
800                 }
801         }
802 }
803 /// Frees any resources used by the UnknownPaymentContext, if is_owned is set and inner is non-NULL.
804 #[no_mangle]
805 pub extern "C" fn UnknownPaymentContext_free(this_obj: UnknownPaymentContext) { }
806 #[allow(unused)]
807 /// Used only if an object of this type is returned as a trait impl by a method
808 pub(crate) extern "C" fn UnknownPaymentContext_free_void(this_ptr: *mut c_void) {
809         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUnknownPaymentContext) };
810 }
811 #[allow(unused)]
812 impl UnknownPaymentContext {
813         pub(crate) fn get_native_ref(&self) -> &'static nativeUnknownPaymentContext {
814                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
815         }
816         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUnknownPaymentContext {
817                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
818         }
819         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
820         pub(crate) fn take_inner(mut self) -> *mut nativeUnknownPaymentContext {
821                 assert!(self.is_owned);
822                 let ret = ObjOps::untweak_ptr(self.inner);
823                 self.inner = core::ptr::null_mut();
824                 ret
825         }
826 }
827 impl Clone for UnknownPaymentContext {
828         fn clone(&self) -> Self {
829                 Self {
830                         inner: if <*mut nativeUnknownPaymentContext>::is_null(self.inner) { core::ptr::null_mut() } else {
831                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
832                         is_owned: true,
833                 }
834         }
835 }
836 #[allow(unused)]
837 /// Used only if an object of this type is returned as a trait impl by a method
838 pub(crate) extern "C" fn UnknownPaymentContext_clone_void(this_ptr: *const c_void) -> *mut c_void {
839         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUnknownPaymentContext)).clone() })) as *mut c_void
840 }
841 #[no_mangle]
842 /// Creates a copy of the UnknownPaymentContext
843 pub extern "C" fn UnknownPaymentContext_clone(orig: &UnknownPaymentContext) -> UnknownPaymentContext {
844         orig.clone()
845 }
846 /// Get a string which allows debug introspection of a UnknownPaymentContext object
847 pub extern "C" fn UnknownPaymentContext_debug_str_void(o: *const c_void) -> Str {
848         alloc::format!("{:?}", unsafe { o as *const crate::lightning::blinded_path::payment::UnknownPaymentContext }).into()}
849 /// Checks if two UnknownPaymentContexts contain equal inner contents.
850 /// This ignores pointers and is_owned flags and looks at the values in fields.
851 /// Two objects with NULL inner values will be considered "equal" here.
852 #[no_mangle]
853 pub extern "C" fn UnknownPaymentContext_eq(a: &UnknownPaymentContext, b: &UnknownPaymentContext) -> bool {
854         if a.inner == b.inner { return true; }
855         if a.inner.is_null() || b.inner.is_null() { return false; }
856         if a.get_native_ref() == b.get_native_ref() { true } else { false }
857 }
858
859 use lightning::blinded_path::payment::Bolt12OfferContext as nativeBolt12OfferContextImport;
860 pub(crate) type nativeBolt12OfferContext = nativeBolt12OfferContextImport;
861
862 /// The context of a payment made for an invoice requested from a BOLT 12 [`Offer`].
863 ///
864 /// [`Offer`]: crate::offers::offer::Offer
865 #[must_use]
866 #[repr(C)]
867 pub struct Bolt12OfferContext {
868         /// A pointer to the opaque Rust object.
869
870         /// Nearly everywhere, inner must be non-null, however in places where
871         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
872         pub inner: *mut nativeBolt12OfferContext,
873         /// Indicates that this is the only struct which contains the same pointer.
874
875         /// Rust functions which take ownership of an object provided via an argument require
876         /// this to be true and invalidate the object pointed to by inner.
877         pub is_owned: bool,
878 }
879
880 impl Drop for Bolt12OfferContext {
881         fn drop(&mut self) {
882                 if self.is_owned && !<*mut nativeBolt12OfferContext>::is_null(self.inner) {
883                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
884                 }
885         }
886 }
887 /// Frees any resources used by the Bolt12OfferContext, if is_owned is set and inner is non-NULL.
888 #[no_mangle]
889 pub extern "C" fn Bolt12OfferContext_free(this_obj: Bolt12OfferContext) { }
890 #[allow(unused)]
891 /// Used only if an object of this type is returned as a trait impl by a method
892 pub(crate) extern "C" fn Bolt12OfferContext_free_void(this_ptr: *mut c_void) {
893         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt12OfferContext) };
894 }
895 #[allow(unused)]
896 impl Bolt12OfferContext {
897         pub(crate) fn get_native_ref(&self) -> &'static nativeBolt12OfferContext {
898                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
899         }
900         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt12OfferContext {
901                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
902         }
903         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
904         pub(crate) fn take_inner(mut self) -> *mut nativeBolt12OfferContext {
905                 assert!(self.is_owned);
906                 let ret = ObjOps::untweak_ptr(self.inner);
907                 self.inner = core::ptr::null_mut();
908                 ret
909         }
910 }
911 /// The identifier of the [`Offer`].
912 ///
913 /// [`Offer`]: crate::offers::offer::Offer
914 #[no_mangle]
915 pub extern "C" fn Bolt12OfferContext_get_offer_id(this_ptr: &Bolt12OfferContext) -> crate::lightning::offers::offer::OfferId {
916         let mut inner_val = &mut this_ptr.get_native_mut_ref().offer_id;
917         crate::lightning::offers::offer::OfferId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::offers::offer::OfferId<>) as *mut _) }, is_owned: false }
918 }
919 /// The identifier of the [`Offer`].
920 ///
921 /// [`Offer`]: crate::offers::offer::Offer
922 #[no_mangle]
923 pub extern "C" fn Bolt12OfferContext_set_offer_id(this_ptr: &mut Bolt12OfferContext, mut val: crate::lightning::offers::offer::OfferId) {
924         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.offer_id = *unsafe { Box::from_raw(val.take_inner()) };
925 }
926 /// Fields from an [`InvoiceRequest`] sent for a [`Bolt12Invoice`].
927 ///
928 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
929 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
930 #[no_mangle]
931 pub extern "C" fn Bolt12OfferContext_get_invoice_request(this_ptr: &Bolt12OfferContext) -> crate::lightning::offers::invoice_request::InvoiceRequestFields {
932         let mut inner_val = &mut this_ptr.get_native_mut_ref().invoice_request;
933         crate::lightning::offers::invoice_request::InvoiceRequestFields { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::offers::invoice_request::InvoiceRequestFields<>) as *mut _) }, is_owned: false }
934 }
935 /// Fields from an [`InvoiceRequest`] sent for a [`Bolt12Invoice`].
936 ///
937 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
938 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
939 #[no_mangle]
940 pub extern "C" fn Bolt12OfferContext_set_invoice_request(this_ptr: &mut Bolt12OfferContext, mut val: crate::lightning::offers::invoice_request::InvoiceRequestFields) {
941         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.invoice_request = *unsafe { Box::from_raw(val.take_inner()) };
942 }
943 /// Constructs a new Bolt12OfferContext given each field
944 #[must_use]
945 #[no_mangle]
946 pub extern "C" fn Bolt12OfferContext_new(mut offer_id_arg: crate::lightning::offers::offer::OfferId, mut invoice_request_arg: crate::lightning::offers::invoice_request::InvoiceRequestFields) -> Bolt12OfferContext {
947         Bolt12OfferContext { inner: ObjOps::heap_alloc(nativeBolt12OfferContext {
948                 offer_id: *unsafe { Box::from_raw(offer_id_arg.take_inner()) },
949                 invoice_request: *unsafe { Box::from_raw(invoice_request_arg.take_inner()) },
950         }), is_owned: true }
951 }
952 impl Clone for Bolt12OfferContext {
953         fn clone(&self) -> Self {
954                 Self {
955                         inner: if <*mut nativeBolt12OfferContext>::is_null(self.inner) { core::ptr::null_mut() } else {
956                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
957                         is_owned: true,
958                 }
959         }
960 }
961 #[allow(unused)]
962 /// Used only if an object of this type is returned as a trait impl by a method
963 pub(crate) extern "C" fn Bolt12OfferContext_clone_void(this_ptr: *const c_void) -> *mut c_void {
964         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt12OfferContext)).clone() })) as *mut c_void
965 }
966 #[no_mangle]
967 /// Creates a copy of the Bolt12OfferContext
968 pub extern "C" fn Bolt12OfferContext_clone(orig: &Bolt12OfferContext) -> Bolt12OfferContext {
969         orig.clone()
970 }
971 /// Get a string which allows debug introspection of a Bolt12OfferContext object
972 pub extern "C" fn Bolt12OfferContext_debug_str_void(o: *const c_void) -> Str {
973         alloc::format!("{:?}", unsafe { o as *const crate::lightning::blinded_path::payment::Bolt12OfferContext }).into()}
974 /// Checks if two Bolt12OfferContexts contain equal inner contents.
975 /// This ignores pointers and is_owned flags and looks at the values in fields.
976 /// Two objects with NULL inner values will be considered "equal" here.
977 #[no_mangle]
978 pub extern "C" fn Bolt12OfferContext_eq(a: &Bolt12OfferContext, b: &Bolt12OfferContext) -> bool {
979         if a.inner == b.inner { return true; }
980         if a.inner.is_null() || b.inner.is_null() { return false; }
981         if a.get_native_ref() == b.get_native_ref() { true } else { false }
982 }
983
984 use lightning::blinded_path::payment::Bolt12RefundContext as nativeBolt12RefundContextImport;
985 pub(crate) type nativeBolt12RefundContext = nativeBolt12RefundContextImport;
986
987 /// The context of a payment made for an invoice sent for a BOLT 12 [`Refund`].
988 ///
989 /// [`Refund`]: crate::offers::refund::Refund
990 #[must_use]
991 #[repr(C)]
992 pub struct Bolt12RefundContext {
993         /// A pointer to the opaque Rust object.
994
995         /// Nearly everywhere, inner must be non-null, however in places where
996         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
997         pub inner: *mut nativeBolt12RefundContext,
998         /// Indicates that this is the only struct which contains the same pointer.
999
1000         /// Rust functions which take ownership of an object provided via an argument require
1001         /// this to be true and invalidate the object pointed to by inner.
1002         pub is_owned: bool,
1003 }
1004
1005 impl Drop for Bolt12RefundContext {
1006         fn drop(&mut self) {
1007                 if self.is_owned && !<*mut nativeBolt12RefundContext>::is_null(self.inner) {
1008                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1009                 }
1010         }
1011 }
1012 /// Frees any resources used by the Bolt12RefundContext, if is_owned is set and inner is non-NULL.
1013 #[no_mangle]
1014 pub extern "C" fn Bolt12RefundContext_free(this_obj: Bolt12RefundContext) { }
1015 #[allow(unused)]
1016 /// Used only if an object of this type is returned as a trait impl by a method
1017 pub(crate) extern "C" fn Bolt12RefundContext_free_void(this_ptr: *mut c_void) {
1018         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt12RefundContext) };
1019 }
1020 #[allow(unused)]
1021 impl Bolt12RefundContext {
1022         pub(crate) fn get_native_ref(&self) -> &'static nativeBolt12RefundContext {
1023                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1024         }
1025         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt12RefundContext {
1026                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1027         }
1028         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1029         pub(crate) fn take_inner(mut self) -> *mut nativeBolt12RefundContext {
1030                 assert!(self.is_owned);
1031                 let ret = ObjOps::untweak_ptr(self.inner);
1032                 self.inner = core::ptr::null_mut();
1033                 ret
1034         }
1035 }
1036 /// Constructs a new Bolt12RefundContext given each field
1037 #[must_use]
1038 #[no_mangle]
1039 pub extern "C" fn Bolt12RefundContext_new() -> Bolt12RefundContext {
1040         Bolt12RefundContext { inner: ObjOps::heap_alloc(nativeBolt12RefundContext {
1041         }), is_owned: true }
1042 }
1043 impl Clone for Bolt12RefundContext {
1044         fn clone(&self) -> Self {
1045                 Self {
1046                         inner: if <*mut nativeBolt12RefundContext>::is_null(self.inner) { core::ptr::null_mut() } else {
1047                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1048                         is_owned: true,
1049                 }
1050         }
1051 }
1052 #[allow(unused)]
1053 /// Used only if an object of this type is returned as a trait impl by a method
1054 pub(crate) extern "C" fn Bolt12RefundContext_clone_void(this_ptr: *const c_void) -> *mut c_void {
1055         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt12RefundContext)).clone() })) as *mut c_void
1056 }
1057 #[no_mangle]
1058 /// Creates a copy of the Bolt12RefundContext
1059 pub extern "C" fn Bolt12RefundContext_clone(orig: &Bolt12RefundContext) -> Bolt12RefundContext {
1060         orig.clone()
1061 }
1062 /// Get a string which allows debug introspection of a Bolt12RefundContext object
1063 pub extern "C" fn Bolt12RefundContext_debug_str_void(o: *const c_void) -> Str {
1064         alloc::format!("{:?}", unsafe { o as *const crate::lightning::blinded_path::payment::Bolt12RefundContext }).into()}
1065 /// Checks if two Bolt12RefundContexts contain equal inner contents.
1066 /// This ignores pointers and is_owned flags and looks at the values in fields.
1067 /// Two objects with NULL inner values will be considered "equal" here.
1068 #[no_mangle]
1069 pub extern "C" fn Bolt12RefundContext_eq(a: &Bolt12RefundContext, b: &Bolt12RefundContext) -> bool {
1070         if a.inner == b.inner { return true; }
1071         if a.inner.is_null() || b.inner.is_null() { return false; }
1072         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1073 }
1074 #[no_mangle]
1075 /// Serialize the ForwardTlvs object into a byte array which can be read by ForwardTlvs_read
1076 pub extern "C" fn ForwardTlvs_write(obj: &crate::lightning::blinded_path::payment::ForwardTlvs) -> crate::c_types::derived::CVec_u8Z {
1077         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1078 }
1079 #[allow(unused)]
1080 pub(crate) extern "C" fn ForwardTlvs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1081         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeForwardTlvs) })
1082 }
1083 #[no_mangle]
1084 /// Serialize the ReceiveTlvs object into a byte array which can be read by ReceiveTlvs_read
1085 pub extern "C" fn ReceiveTlvs_write(obj: &crate::lightning::blinded_path::payment::ReceiveTlvs) -> crate::c_types::derived::CVec_u8Z {
1086         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1087 }
1088 #[allow(unused)]
1089 pub(crate) extern "C" fn ReceiveTlvs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1090         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeReceiveTlvs) })
1091 }
1092 #[no_mangle]
1093 /// Serialize the PaymentRelay object into a byte array which can be read by PaymentRelay_read
1094 pub extern "C" fn PaymentRelay_write(obj: &crate::lightning::blinded_path::payment::PaymentRelay) -> crate::c_types::derived::CVec_u8Z {
1095         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1096 }
1097 #[allow(unused)]
1098 pub(crate) extern "C" fn PaymentRelay_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1099         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentRelay) })
1100 }
1101 #[no_mangle]
1102 /// Read a PaymentRelay from a byte array, created by PaymentRelay_write
1103 pub extern "C" fn PaymentRelay_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentRelayDecodeErrorZ {
1104         let res: Result<lightning::blinded_path::payment::PaymentRelay, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1105         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::blinded_path::payment::PaymentRelay { 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() };
1106         local_res
1107 }
1108 #[no_mangle]
1109 /// Serialize the PaymentConstraints object into a byte array which can be read by PaymentConstraints_read
1110 pub extern "C" fn PaymentConstraints_write(obj: &crate::lightning::blinded_path::payment::PaymentConstraints) -> crate::c_types::derived::CVec_u8Z {
1111         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1112 }
1113 #[allow(unused)]
1114 pub(crate) extern "C" fn PaymentConstraints_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1115         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentConstraints) })
1116 }
1117 #[no_mangle]
1118 /// Read a PaymentConstraints from a byte array, created by PaymentConstraints_write
1119 pub extern "C" fn PaymentConstraints_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentConstraintsDecodeErrorZ {
1120         let res: Result<lightning::blinded_path::payment::PaymentConstraints, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1121         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::blinded_path::payment::PaymentConstraints { 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() };
1122         local_res
1123 }
1124 #[no_mangle]
1125 /// Serialize the PaymentContext object into a byte array which can be read by PaymentContext_read
1126 pub extern "C" fn PaymentContext_write(obj: &crate::lightning::blinded_path::payment::PaymentContext) -> crate::c_types::derived::CVec_u8Z {
1127         crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
1128 }
1129 #[allow(unused)]
1130 pub(crate) extern "C" fn PaymentContext_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1131         PaymentContext_write(unsafe { &*(obj as *const PaymentContext) })
1132 }
1133 #[no_mangle]
1134 /// Read a PaymentContext from a byte array, created by PaymentContext_write
1135 pub extern "C" fn PaymentContext_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentContextDecodeErrorZ {
1136         let res: Result<lightning::blinded_path::payment::PaymentContext, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1137         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::blinded_path::payment::PaymentContext::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1138         local_res
1139 }
1140 #[no_mangle]
1141 /// Serialize the UnknownPaymentContext object into a byte array which can be read by UnknownPaymentContext_read
1142 pub extern "C" fn UnknownPaymentContext_write(obj: &crate::lightning::blinded_path::payment::UnknownPaymentContext) -> crate::c_types::derived::CVec_u8Z {
1143         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1144 }
1145 #[allow(unused)]
1146 pub(crate) extern "C" fn UnknownPaymentContext_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1147         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnknownPaymentContext) })
1148 }
1149 #[no_mangle]
1150 /// Read a UnknownPaymentContext from a byte array, created by UnknownPaymentContext_write
1151 pub extern "C" fn UnknownPaymentContext_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UnknownPaymentContextDecodeErrorZ {
1152         let res: Result<lightning::blinded_path::payment::UnknownPaymentContext, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1153         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::blinded_path::payment::UnknownPaymentContext { 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() };
1154         local_res
1155 }
1156 #[no_mangle]
1157 /// Serialize the Bolt12OfferContext object into a byte array which can be read by Bolt12OfferContext_read
1158 pub extern "C" fn Bolt12OfferContext_write(obj: &crate::lightning::blinded_path::payment::Bolt12OfferContext) -> crate::c_types::derived::CVec_u8Z {
1159         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1160 }
1161 #[allow(unused)]
1162 pub(crate) extern "C" fn Bolt12OfferContext_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1163         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBolt12OfferContext) })
1164 }
1165 #[no_mangle]
1166 /// Read a Bolt12OfferContext from a byte array, created by Bolt12OfferContext_write
1167 pub extern "C" fn Bolt12OfferContext_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_Bolt12OfferContextDecodeErrorZ {
1168         let res: Result<lightning::blinded_path::payment::Bolt12OfferContext, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1169         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::blinded_path::payment::Bolt12OfferContext { 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() };
1170         local_res
1171 }
1172 #[no_mangle]
1173 /// Serialize the Bolt12RefundContext object into a byte array which can be read by Bolt12RefundContext_read
1174 pub extern "C" fn Bolt12RefundContext_write(obj: &crate::lightning::blinded_path::payment::Bolt12RefundContext) -> crate::c_types::derived::CVec_u8Z {
1175         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1176 }
1177 #[allow(unused)]
1178 pub(crate) extern "C" fn Bolt12RefundContext_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1179         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBolt12RefundContext) })
1180 }
1181 #[no_mangle]
1182 /// Read a Bolt12RefundContext from a byte array, created by Bolt12RefundContext_write
1183 pub extern "C" fn Bolt12RefundContext_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_Bolt12RefundContextDecodeErrorZ {
1184         let res: Result<lightning::blinded_path::payment::Bolt12RefundContext, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1185         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::blinded_path::payment::Bolt12RefundContext { 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() };
1186         local_res
1187 }