1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! Data structures and methods for constructing [`BlindedPath`]s to send a payment over.
11 //! [`BlindedPath`]: crate::blinded_path::BlindedPath
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};
23 use lightning::blinded_path::payment::ForwardNode as nativeForwardNodeImport;
24 pub(crate) type nativeForwardNode = nativeForwardNodeImport;
26 /// An intermediate node, its outbound channel, and relay parameters.
29 pub struct ForwardNode {
30 /// A pointer to the opaque Rust object.
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.
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.
42 impl Drop for ForwardNode {
44 if self.is_owned && !<*mut nativeForwardNode>::is_null(self.inner) {
45 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
49 /// Frees any resources used by the ForwardNode, if is_owned is set and inner is non-NULL.
51 pub extern "C" fn ForwardNode_free(this_obj: ForwardNode) { }
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) };
59 pub(crate) fn get_native_ref(&self) -> &'static nativeForwardNode {
60 unsafe { &*ObjOps::untweak_ptr(self.inner) }
62 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeForwardNode {
63 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
73 /// The TLVs for this node's [`BlindedHop`], where the fee parameters contained within are also
74 /// used for [`BlindedPayInfo`] construction.
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 }
80 /// The TLVs for this node's [`BlindedHop`], where the fee parameters contained within are also
81 /// used for [`BlindedPayInfo`] construction.
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()) };
86 /// This node's pubkey.
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)
92 /// This node's pubkey.
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();
97 /// The maximum value, in msat, that may be accepted by this node.
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;
103 /// The maximum value, in msat, that may be accepted by this node.
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;
108 /// Constructs a new ForwardNode given each field
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,
118 impl Clone for ForwardNode {
119 fn clone(&self) -> 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()) },
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
133 /// Creates a copy of the ForwardNode
134 pub extern "C" fn ForwardNode_clone(orig: &ForwardNode) -> ForwardNode {
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()}
141 use lightning::blinded_path::payment::ForwardTlvs as nativeForwardTlvsImport;
142 pub(crate) type nativeForwardTlvs = nativeForwardTlvsImport;
144 /// Data to construct a [`BlindedHop`] for forwarding a payment.
147 pub struct ForwardTlvs {
148 /// A pointer to the opaque Rust object.
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.
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.
160 impl Drop for ForwardTlvs {
162 if self.is_owned && !<*mut nativeForwardTlvs>::is_null(self.inner) {
163 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
167 /// Frees any resources used by the ForwardTlvs, if is_owned is set and inner is non-NULL.
169 pub extern "C" fn ForwardTlvs_free(this_obj: ForwardTlvs) { }
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) };
177 pub(crate) fn get_native_ref(&self) -> &'static nativeForwardTlvs {
178 unsafe { &*ObjOps::untweak_ptr(self.inner) }
180 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeForwardTlvs {
181 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
191 /// The short channel id this payment should be forwarded out over.
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;
197 /// The short channel id this payment should be forwarded out over.
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;
202 /// Payment parameters for relaying over [`Self::short_channel_id`].
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 }
208 /// Payment parameters for relaying over [`Self::short_channel_id`].
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()) };
213 /// Payment constraints for relaying over [`Self::short_channel_id`].
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 }
219 /// Payment constraints for relaying over [`Self::short_channel_id`].
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()) };
224 /// Supported and required features when relaying a payment onion containing this object's
225 /// corresponding [`BlindedHop::encrypted_payload`].
227 /// [`BlindedHop::encrypted_payload`]: crate::blinded_path::BlindedHop::encrypted_payload
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 }
233 /// Supported and required features when relaying a payment onion containing this object's
234 /// corresponding [`BlindedHop::encrypted_payload`].
236 /// [`BlindedHop::encrypted_payload`]: crate::blinded_path::BlindedHop::encrypted_payload
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()) };
241 /// Constructs a new ForwardTlvs given each field
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()) },
252 impl Clone for ForwardTlvs {
253 fn clone(&self) -> 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()) },
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
267 /// Creates a copy of the ForwardTlvs
268 pub extern "C" fn ForwardTlvs_clone(orig: &ForwardTlvs) -> ForwardTlvs {
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()}
275 use lightning::blinded_path::payment::ReceiveTlvs as nativeReceiveTlvsImport;
276 pub(crate) type nativeReceiveTlvs = nativeReceiveTlvsImport;
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.
282 pub struct ReceiveTlvs {
283 /// A pointer to the opaque Rust object.
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.
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.
295 impl Drop for ReceiveTlvs {
297 if self.is_owned && !<*mut nativeReceiveTlvs>::is_null(self.inner) {
298 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
302 /// Frees any resources used by the ReceiveTlvs, if is_owned is set and inner is non-NULL.
304 pub extern "C" fn ReceiveTlvs_free(this_obj: ReceiveTlvs) { }
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) };
312 pub(crate) fn get_native_ref(&self) -> &'static nativeReceiveTlvs {
313 unsafe { &*ObjOps::untweak_ptr(self.inner) }
315 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReceiveTlvs {
316 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
326 /// Used to authenticate the sender of a payment to the receiver and tie MPP HTLCs together.
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;
332 /// Used to authenticate the sender of a payment to the receiver and tie MPP HTLCs together.
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);
337 /// Constraints for the receiver of this payment.
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 }
343 /// Constraints for the receiver of this payment.
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()) };
348 /// Context for the receiver of this payment.
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)
354 /// Context for the receiver of this payment.
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();
359 /// Constructs a new ReceiveTlvs given each field
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(),
369 impl Clone for ReceiveTlvs {
370 fn clone(&self) -> 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()) },
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
384 /// Creates a copy of the ReceiveTlvs
385 pub extern "C" fn ReceiveTlvs_clone(orig: &ReceiveTlvs) -> ReceiveTlvs {
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()}
392 use lightning::blinded_path::payment::PaymentRelay as nativePaymentRelayImport;
393 pub(crate) type nativePaymentRelay = nativePaymentRelayImport;
395 /// Parameters for relaying over a given [`BlindedHop`].
397 /// [`BlindedHop`]: crate::blinded_path::BlindedHop
400 pub struct PaymentRelay {
401 /// A pointer to the opaque Rust object.
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.
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.
413 impl Drop for PaymentRelay {
415 if self.is_owned && !<*mut nativePaymentRelay>::is_null(self.inner) {
416 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
420 /// Frees any resources used by the PaymentRelay, if is_owned is set and inner is non-NULL.
422 pub extern "C" fn PaymentRelay_free(this_obj: PaymentRelay) { }
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) };
430 pub(crate) fn get_native_ref(&self) -> &'static nativePaymentRelay {
431 unsafe { &*ObjOps::untweak_ptr(self.inner) }
433 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentRelay {
434 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
444 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for this [`BlindedHop`].
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;
450 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for this [`BlindedHop`].
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;
455 /// Liquidity fee charged (in millionths of the amount transferred) for relaying a payment over
456 /// this [`BlindedHop`], (i.e., 10,000 is 1%).
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;
462 /// Liquidity fee charged (in millionths of the amount transferred) for relaying a payment over
463 /// this [`BlindedHop`], (i.e., 10,000 is 1%).
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;
468 /// Base fee charged (in millisatoshi) for relaying a payment over this [`BlindedHop`].
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;
474 /// Base fee charged (in millisatoshi) for relaying a payment over this [`BlindedHop`].
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;
479 /// Constructs a new PaymentRelay given each field
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,
489 impl Clone for PaymentRelay {
490 fn clone(&self) -> 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()) },
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
504 /// Creates a copy of the PaymentRelay
505 pub extern "C" fn PaymentRelay_clone(orig: &PaymentRelay) -> PaymentRelay {
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()}
512 use lightning::blinded_path::payment::PaymentConstraints as nativePaymentConstraintsImport;
513 pub(crate) type nativePaymentConstraints = nativePaymentConstraintsImport;
515 /// Constraints for relaying over a given [`BlindedHop`].
517 /// [`BlindedHop`]: crate::blinded_path::BlindedHop
520 pub struct PaymentConstraints {
521 /// A pointer to the opaque Rust object.
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.
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.
533 impl Drop for PaymentConstraints {
535 if self.is_owned && !<*mut nativePaymentConstraints>::is_null(self.inner) {
536 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
540 /// Frees any resources used by the PaymentConstraints, if is_owned is set and inner is non-NULL.
542 pub extern "C" fn PaymentConstraints_free(this_obj: PaymentConstraints) { }
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) };
549 impl PaymentConstraints {
550 pub(crate) fn get_native_ref(&self) -> &'static nativePaymentConstraints {
551 unsafe { &*ObjOps::untweak_ptr(self.inner) }
553 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentConstraints {
554 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
564 /// The maximum total CLTV that is acceptable when relaying a payment over this [`BlindedHop`].
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;
570 /// The maximum total CLTV that is acceptable when relaying a payment over this [`BlindedHop`].
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;
575 /// The minimum value, in msat, that may be accepted by the node corresponding to this
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;
582 /// The minimum value, in msat, that may be accepted by the node corresponding to this
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;
588 /// Constructs a new PaymentConstraints given each field
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,
597 impl Clone for PaymentConstraints {
598 fn clone(&self) -> 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()) },
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
612 /// Creates a copy of the PaymentConstraints
613 pub extern "C" fn PaymentConstraints_clone(orig: &PaymentConstraints) -> PaymentConstraints {
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`].
622 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
623 /// [`PaymentPurpose`]: crate::events::PaymentPurpose
627 pub enum PaymentContext {
628 /// The payment context was unknown.
630 crate::lightning::blinded_path::payment::UnknownPaymentContext),
631 /// The payment was made for an invoice requested from a BOLT 12 [`Offer`].
633 /// [`Offer`]: crate::offers::offer::Offer
635 crate::lightning::blinded_path::payment::Bolt12OfferContext),
636 /// The payment was made for an invoice sent for a BOLT 12 [`Refund`].
638 /// [`Refund`]: crate::offers::refund::Refund
640 crate::lightning::blinded_path::payment::Bolt12RefundContext),
642 use lightning::blinded_path::payment::PaymentContext as PaymentContextImport;
643 pub(crate) type nativePaymentContext = PaymentContextImport;
645 impl PaymentContext {
647 pub(crate) fn to_native(&self) -> nativePaymentContext {
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()) },
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()) },
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()) },
670 pub(crate) fn into_native(self) -> nativePaymentContext {
672 PaymentContext::Unknown (mut a, ) => {
673 nativePaymentContext::Unknown (
674 *unsafe { Box::from_raw(a.take_inner()) },
677 PaymentContext::Bolt12Offer (mut a, ) => {
678 nativePaymentContext::Bolt12Offer (
679 *unsafe { Box::from_raw(a.take_inner()) },
682 PaymentContext::Bolt12Refund (mut a, ) => {
683 nativePaymentContext::Bolt12Refund (
684 *unsafe { Box::from_raw(a.take_inner()) },
690 pub(crate) fn from_native(native: &PaymentContextImport) -> Self {
691 let native = unsafe { &*(native as *const _ as *const c_void as *const nativePaymentContext) };
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 },
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 },
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 },
714 pub(crate) fn native_into(native: nativePaymentContext) -> Self {
716 nativePaymentContext::Unknown (mut a, ) => {
717 PaymentContext::Unknown (
718 crate::lightning::blinded_path::payment::UnknownPaymentContext { inner: ObjOps::heap_alloc(a), is_owned: true },
721 nativePaymentContext::Bolt12Offer (mut a, ) => {
722 PaymentContext::Bolt12Offer (
723 crate::lightning::blinded_path::payment::Bolt12OfferContext { inner: ObjOps::heap_alloc(a), is_owned: true },
726 nativePaymentContext::Bolt12Refund (mut a, ) => {
727 PaymentContext::Bolt12Refund (
728 crate::lightning::blinded_path::payment::Bolt12RefundContext { inner: ObjOps::heap_alloc(a), is_owned: true },
734 /// Frees any resources used by the PaymentContext
736 pub extern "C" fn PaymentContext_free(this_ptr: PaymentContext) { }
737 /// Creates a copy of the PaymentContext
739 pub extern "C" fn PaymentContext_clone(orig: &PaymentContext) -> PaymentContext {
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
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) };
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, )
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, )
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, )
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.
773 pub extern "C" fn PaymentContext_eq(a: &PaymentContext, b: &PaymentContext) -> bool {
774 if &a.to_native() == &b.to_native() { true } else { false }
777 use lightning::blinded_path::payment::UnknownPaymentContext as nativeUnknownPaymentContextImport;
778 pub(crate) type nativeUnknownPaymentContext = nativeUnknownPaymentContextImport;
780 /// An unknown payment context.
783 pub struct UnknownPaymentContext {
784 /// A pointer to the opaque Rust object.
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.
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.
796 impl Drop for UnknownPaymentContext {
798 if self.is_owned && !<*mut nativeUnknownPaymentContext>::is_null(self.inner) {
799 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
803 /// Frees any resources used by the UnknownPaymentContext, if is_owned is set and inner is non-NULL.
805 pub extern "C" fn UnknownPaymentContext_free(this_obj: UnknownPaymentContext) { }
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) };
812 impl UnknownPaymentContext {
813 pub(crate) fn get_native_ref(&self) -> &'static nativeUnknownPaymentContext {
814 unsafe { &*ObjOps::untweak_ptr(self.inner) }
816 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeUnknownPaymentContext {
817 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
827 impl Clone for UnknownPaymentContext {
828 fn clone(&self) -> 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()) },
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
842 /// Creates a copy of the UnknownPaymentContext
843 pub extern "C" fn UnknownPaymentContext_clone(orig: &UnknownPaymentContext) -> UnknownPaymentContext {
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.
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 }
859 use lightning::blinded_path::payment::Bolt12OfferContext as nativeBolt12OfferContextImport;
860 pub(crate) type nativeBolt12OfferContext = nativeBolt12OfferContextImport;
862 /// The context of a payment made for an invoice requested from a BOLT 12 [`Offer`].
864 /// [`Offer`]: crate::offers::offer::Offer
867 pub struct Bolt12OfferContext {
868 /// A pointer to the opaque Rust object.
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.
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.
880 impl Drop for Bolt12OfferContext {
882 if self.is_owned && !<*mut nativeBolt12OfferContext>::is_null(self.inner) {
883 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
887 /// Frees any resources used by the Bolt12OfferContext, if is_owned is set and inner is non-NULL.
889 pub extern "C" fn Bolt12OfferContext_free(this_obj: Bolt12OfferContext) { }
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) };
896 impl Bolt12OfferContext {
897 pub(crate) fn get_native_ref(&self) -> &'static nativeBolt12OfferContext {
898 unsafe { &*ObjOps::untweak_ptr(self.inner) }
900 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt12OfferContext {
901 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
911 /// The identifier of the [`Offer`].
913 /// [`Offer`]: crate::offers::offer::Offer
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 }
919 /// The identifier of the [`Offer`].
921 /// [`Offer`]: crate::offers::offer::Offer
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()) };
926 /// Fields from an [`InvoiceRequest`] sent for a [`Bolt12Invoice`].
928 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
929 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
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 }
935 /// Fields from an [`InvoiceRequest`] sent for a [`Bolt12Invoice`].
937 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
938 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
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()) };
943 /// Constructs a new Bolt12OfferContext given each field
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()) },
952 impl Clone for Bolt12OfferContext {
953 fn clone(&self) -> 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()) },
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
967 /// Creates a copy of the Bolt12OfferContext
968 pub extern "C" fn Bolt12OfferContext_clone(orig: &Bolt12OfferContext) -> Bolt12OfferContext {
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.
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 }
984 use lightning::blinded_path::payment::Bolt12RefundContext as nativeBolt12RefundContextImport;
985 pub(crate) type nativeBolt12RefundContext = nativeBolt12RefundContextImport;
987 /// The context of a payment made for an invoice sent for a BOLT 12 [`Refund`].
989 /// [`Refund`]: crate::offers::refund::Refund
992 pub struct Bolt12RefundContext {
993 /// A pointer to the opaque Rust object.
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.
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.
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)) };
1012 /// Frees any resources used by the Bolt12RefundContext, if is_owned is set and inner is non-NULL.
1014 pub extern "C" fn Bolt12RefundContext_free(this_obj: Bolt12RefundContext) { }
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) };
1021 impl Bolt12RefundContext {
1022 pub(crate) fn get_native_ref(&self) -> &'static nativeBolt12RefundContext {
1023 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1025 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt12RefundContext {
1026 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
1036 /// Constructs a new Bolt12RefundContext given each field
1039 pub extern "C" fn Bolt12RefundContext_new() -> Bolt12RefundContext {
1040 Bolt12RefundContext { inner: ObjOps::heap_alloc(nativeBolt12RefundContext {
1041 }), is_owned: true }
1043 impl Clone for Bolt12RefundContext {
1044 fn clone(&self) -> 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()) },
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
1058 /// Creates a copy of the Bolt12RefundContext
1059 pub extern "C" fn Bolt12RefundContext_clone(orig: &Bolt12RefundContext) -> Bolt12RefundContext {
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.
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 }
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())
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) })
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())
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) })
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())
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) })
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() };
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())
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) })
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() };
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())
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) })
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() };
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())
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) })
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() };
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())
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) })
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() };
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())
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) })
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() };