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 *mut nativeForwardNode)).clone() })) as *mut c_void
133 /// Creates a copy of the ForwardNode
134 pub extern "C" fn ForwardNode_clone(orig: &ForwardNode) -> ForwardNode {
138 use lightning::blinded_path::payment::ForwardTlvs as nativeForwardTlvsImport;
139 pub(crate) type nativeForwardTlvs = nativeForwardTlvsImport;
141 /// Data to construct a [`BlindedHop`] for forwarding a payment.
144 pub struct ForwardTlvs {
145 /// A pointer to the opaque Rust object.
147 /// Nearly everywhere, inner must be non-null, however in places where
148 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
149 pub inner: *mut nativeForwardTlvs,
150 /// Indicates that this is the only struct which contains the same pointer.
152 /// Rust functions which take ownership of an object provided via an argument require
153 /// this to be true and invalidate the object pointed to by inner.
157 impl Drop for ForwardTlvs {
159 if self.is_owned && !<*mut nativeForwardTlvs>::is_null(self.inner) {
160 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
164 /// Frees any resources used by the ForwardTlvs, if is_owned is set and inner is non-NULL.
166 pub extern "C" fn ForwardTlvs_free(this_obj: ForwardTlvs) { }
168 /// Used only if an object of this type is returned as a trait impl by a method
169 pub(crate) extern "C" fn ForwardTlvs_free_void(this_ptr: *mut c_void) {
170 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeForwardTlvs) };
174 pub(crate) fn get_native_ref(&self) -> &'static nativeForwardTlvs {
175 unsafe { &*ObjOps::untweak_ptr(self.inner) }
177 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeForwardTlvs {
178 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
180 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
181 pub(crate) fn take_inner(mut self) -> *mut nativeForwardTlvs {
182 assert!(self.is_owned);
183 let ret = ObjOps::untweak_ptr(self.inner);
184 self.inner = core::ptr::null_mut();
188 /// The short channel id this payment should be forwarded out over.
190 pub extern "C" fn ForwardTlvs_get_short_channel_id(this_ptr: &ForwardTlvs) -> u64 {
191 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
194 /// The short channel id this payment should be forwarded out over.
196 pub extern "C" fn ForwardTlvs_set_short_channel_id(this_ptr: &mut ForwardTlvs, mut val: u64) {
197 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
199 /// Payment parameters for relaying over [`Self::short_channel_id`].
201 pub extern "C" fn ForwardTlvs_get_payment_relay(this_ptr: &ForwardTlvs) -> crate::lightning::blinded_path::payment::PaymentRelay {
202 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_relay;
203 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 }
205 /// Payment parameters for relaying over [`Self::short_channel_id`].
207 pub extern "C" fn ForwardTlvs_set_payment_relay(this_ptr: &mut ForwardTlvs, mut val: crate::lightning::blinded_path::payment::PaymentRelay) {
208 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_relay = *unsafe { Box::from_raw(val.take_inner()) };
210 /// Payment constraints for relaying over [`Self::short_channel_id`].
212 pub extern "C" fn ForwardTlvs_get_payment_constraints(this_ptr: &ForwardTlvs) -> crate::lightning::blinded_path::payment::PaymentConstraints {
213 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_constraints;
214 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 }
216 /// Payment constraints for relaying over [`Self::short_channel_id`].
218 pub extern "C" fn ForwardTlvs_set_payment_constraints(this_ptr: &mut ForwardTlvs, mut val: crate::lightning::blinded_path::payment::PaymentConstraints) {
219 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_constraints = *unsafe { Box::from_raw(val.take_inner()) };
221 /// Supported and required features when relaying a payment onion containing this object's
222 /// corresponding [`BlindedHop::encrypted_payload`].
224 /// [`BlindedHop::encrypted_payload`]: crate::blinded_path::BlindedHop::encrypted_payload
226 pub extern "C" fn ForwardTlvs_get_features(this_ptr: &ForwardTlvs) -> crate::lightning::ln::features::BlindedHopFeatures {
227 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
228 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 }
230 /// Supported and required features when relaying a payment onion containing this object's
231 /// corresponding [`BlindedHop::encrypted_payload`].
233 /// [`BlindedHop::encrypted_payload`]: crate::blinded_path::BlindedHop::encrypted_payload
235 pub extern "C" fn ForwardTlvs_set_features(this_ptr: &mut ForwardTlvs, mut val: crate::lightning::ln::features::BlindedHopFeatures) {
236 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
238 /// Constructs a new ForwardTlvs given each field
241 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 {
242 ForwardTlvs { inner: ObjOps::heap_alloc(nativeForwardTlvs {
243 short_channel_id: short_channel_id_arg,
244 payment_relay: *unsafe { Box::from_raw(payment_relay_arg.take_inner()) },
245 payment_constraints: *unsafe { Box::from_raw(payment_constraints_arg.take_inner()) },
246 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
249 impl Clone for ForwardTlvs {
250 fn clone(&self) -> Self {
252 inner: if <*mut nativeForwardTlvs>::is_null(self.inner) { core::ptr::null_mut() } else {
253 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
259 /// Used only if an object of this type is returned as a trait impl by a method
260 pub(crate) extern "C" fn ForwardTlvs_clone_void(this_ptr: *const c_void) -> *mut c_void {
261 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeForwardTlvs)).clone() })) as *mut c_void
264 /// Creates a copy of the ForwardTlvs
265 pub extern "C" fn ForwardTlvs_clone(orig: &ForwardTlvs) -> ForwardTlvs {
269 use lightning::blinded_path::payment::ReceiveTlvs as nativeReceiveTlvsImport;
270 pub(crate) type nativeReceiveTlvs = nativeReceiveTlvsImport;
272 /// Data to construct a [`BlindedHop`] for receiving a payment. This payload is custom to LDK and
273 /// may not be valid if received by another lightning implementation.
276 pub struct ReceiveTlvs {
277 /// A pointer to the opaque Rust object.
279 /// Nearly everywhere, inner must be non-null, however in places where
280 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
281 pub inner: *mut nativeReceiveTlvs,
282 /// Indicates that this is the only struct which contains the same pointer.
284 /// Rust functions which take ownership of an object provided via an argument require
285 /// this to be true and invalidate the object pointed to by inner.
289 impl Drop for ReceiveTlvs {
291 if self.is_owned && !<*mut nativeReceiveTlvs>::is_null(self.inner) {
292 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
296 /// Frees any resources used by the ReceiveTlvs, if is_owned is set and inner is non-NULL.
298 pub extern "C" fn ReceiveTlvs_free(this_obj: ReceiveTlvs) { }
300 /// Used only if an object of this type is returned as a trait impl by a method
301 pub(crate) extern "C" fn ReceiveTlvs_free_void(this_ptr: *mut c_void) {
302 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeReceiveTlvs) };
306 pub(crate) fn get_native_ref(&self) -> &'static nativeReceiveTlvs {
307 unsafe { &*ObjOps::untweak_ptr(self.inner) }
309 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReceiveTlvs {
310 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
312 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
313 pub(crate) fn take_inner(mut self) -> *mut nativeReceiveTlvs {
314 assert!(self.is_owned);
315 let ret = ObjOps::untweak_ptr(self.inner);
316 self.inner = core::ptr::null_mut();
320 /// Used to authenticate the sender of a payment to the receiver and tie MPP HTLCs together.
322 pub extern "C" fn ReceiveTlvs_get_payment_secret(this_ptr: &ReceiveTlvs) -> *const [u8; 32] {
323 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_secret;
326 /// Used to authenticate the sender of a payment to the receiver and tie MPP HTLCs together.
328 pub extern "C" fn ReceiveTlvs_set_payment_secret(this_ptr: &mut ReceiveTlvs, mut val: crate::c_types::ThirtyTwoBytes) {
329 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_secret = ::lightning::ln::PaymentSecret(val.data);
331 /// Constraints for the receiver of this payment.
333 pub extern "C" fn ReceiveTlvs_get_payment_constraints(this_ptr: &ReceiveTlvs) -> crate::lightning::blinded_path::payment::PaymentConstraints {
334 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_constraints;
335 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 }
337 /// Constraints for the receiver of this payment.
339 pub extern "C" fn ReceiveTlvs_set_payment_constraints(this_ptr: &mut ReceiveTlvs, mut val: crate::lightning::blinded_path::payment::PaymentConstraints) {
340 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_constraints = *unsafe { Box::from_raw(val.take_inner()) };
342 /// Constructs a new ReceiveTlvs given each field
345 pub extern "C" fn ReceiveTlvs_new(mut payment_secret_arg: crate::c_types::ThirtyTwoBytes, mut payment_constraints_arg: crate::lightning::blinded_path::payment::PaymentConstraints) -> ReceiveTlvs {
346 ReceiveTlvs { inner: ObjOps::heap_alloc(nativeReceiveTlvs {
347 payment_secret: ::lightning::ln::PaymentSecret(payment_secret_arg.data),
348 payment_constraints: *unsafe { Box::from_raw(payment_constraints_arg.take_inner()) },
351 impl Clone for ReceiveTlvs {
352 fn clone(&self) -> Self {
354 inner: if <*mut nativeReceiveTlvs>::is_null(self.inner) { core::ptr::null_mut() } else {
355 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
361 /// Used only if an object of this type is returned as a trait impl by a method
362 pub(crate) extern "C" fn ReceiveTlvs_clone_void(this_ptr: *const c_void) -> *mut c_void {
363 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeReceiveTlvs)).clone() })) as *mut c_void
366 /// Creates a copy of the ReceiveTlvs
367 pub extern "C" fn ReceiveTlvs_clone(orig: &ReceiveTlvs) -> ReceiveTlvs {
371 use lightning::blinded_path::payment::PaymentRelay as nativePaymentRelayImport;
372 pub(crate) type nativePaymentRelay = nativePaymentRelayImport;
374 /// Parameters for relaying over a given [`BlindedHop`].
376 /// [`BlindedHop`]: crate::blinded_path::BlindedHop
379 pub struct PaymentRelay {
380 /// A pointer to the opaque Rust object.
382 /// Nearly everywhere, inner must be non-null, however in places where
383 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
384 pub inner: *mut nativePaymentRelay,
385 /// Indicates that this is the only struct which contains the same pointer.
387 /// Rust functions which take ownership of an object provided via an argument require
388 /// this to be true and invalidate the object pointed to by inner.
392 impl Drop for PaymentRelay {
394 if self.is_owned && !<*mut nativePaymentRelay>::is_null(self.inner) {
395 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
399 /// Frees any resources used by the PaymentRelay, if is_owned is set and inner is non-NULL.
401 pub extern "C" fn PaymentRelay_free(this_obj: PaymentRelay) { }
403 /// Used only if an object of this type is returned as a trait impl by a method
404 pub(crate) extern "C" fn PaymentRelay_free_void(this_ptr: *mut c_void) {
405 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentRelay) };
409 pub(crate) fn get_native_ref(&self) -> &'static nativePaymentRelay {
410 unsafe { &*ObjOps::untweak_ptr(self.inner) }
412 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentRelay {
413 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
415 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
416 pub(crate) fn take_inner(mut self) -> *mut nativePaymentRelay {
417 assert!(self.is_owned);
418 let ret = ObjOps::untweak_ptr(self.inner);
419 self.inner = core::ptr::null_mut();
423 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for this [`BlindedHop`].
425 pub extern "C" fn PaymentRelay_get_cltv_expiry_delta(this_ptr: &PaymentRelay) -> u16 {
426 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
429 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for this [`BlindedHop`].
431 pub extern "C" fn PaymentRelay_set_cltv_expiry_delta(this_ptr: &mut PaymentRelay, mut val: u16) {
432 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
434 /// Liquidity fee charged (in millionths of the amount transferred) for relaying a payment over
435 /// this [`BlindedHop`], (i.e., 10,000 is 1%).
437 pub extern "C" fn PaymentRelay_get_fee_proportional_millionths(this_ptr: &PaymentRelay) -> u32 {
438 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
441 /// Liquidity fee charged (in millionths of the amount transferred) for relaying a payment over
442 /// this [`BlindedHop`], (i.e., 10,000 is 1%).
444 pub extern "C" fn PaymentRelay_set_fee_proportional_millionths(this_ptr: &mut PaymentRelay, mut val: u32) {
445 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
447 /// Base fee charged (in millisatoshi) for relaying a payment over this [`BlindedHop`].
449 pub extern "C" fn PaymentRelay_get_fee_base_msat(this_ptr: &PaymentRelay) -> u32 {
450 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
453 /// Base fee charged (in millisatoshi) for relaying a payment over this [`BlindedHop`].
455 pub extern "C" fn PaymentRelay_set_fee_base_msat(this_ptr: &mut PaymentRelay, mut val: u32) {
456 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
458 /// Constructs a new PaymentRelay given each field
461 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 {
462 PaymentRelay { inner: ObjOps::heap_alloc(nativePaymentRelay {
463 cltv_expiry_delta: cltv_expiry_delta_arg,
464 fee_proportional_millionths: fee_proportional_millionths_arg,
465 fee_base_msat: fee_base_msat_arg,
468 impl Clone for PaymentRelay {
469 fn clone(&self) -> Self {
471 inner: if <*mut nativePaymentRelay>::is_null(self.inner) { core::ptr::null_mut() } else {
472 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
478 /// Used only if an object of this type is returned as a trait impl by a method
479 pub(crate) extern "C" fn PaymentRelay_clone_void(this_ptr: *const c_void) -> *mut c_void {
480 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentRelay)).clone() })) as *mut c_void
483 /// Creates a copy of the PaymentRelay
484 pub extern "C" fn PaymentRelay_clone(orig: &PaymentRelay) -> PaymentRelay {
488 use lightning::blinded_path::payment::PaymentConstraints as nativePaymentConstraintsImport;
489 pub(crate) type nativePaymentConstraints = nativePaymentConstraintsImport;
491 /// Constraints for relaying over a given [`BlindedHop`].
493 /// [`BlindedHop`]: crate::blinded_path::BlindedHop
496 pub struct PaymentConstraints {
497 /// A pointer to the opaque Rust object.
499 /// Nearly everywhere, inner must be non-null, however in places where
500 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
501 pub inner: *mut nativePaymentConstraints,
502 /// Indicates that this is the only struct which contains the same pointer.
504 /// Rust functions which take ownership of an object provided via an argument require
505 /// this to be true and invalidate the object pointed to by inner.
509 impl Drop for PaymentConstraints {
511 if self.is_owned && !<*mut nativePaymentConstraints>::is_null(self.inner) {
512 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
516 /// Frees any resources used by the PaymentConstraints, if is_owned is set and inner is non-NULL.
518 pub extern "C" fn PaymentConstraints_free(this_obj: PaymentConstraints) { }
520 /// Used only if an object of this type is returned as a trait impl by a method
521 pub(crate) extern "C" fn PaymentConstraints_free_void(this_ptr: *mut c_void) {
522 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentConstraints) };
525 impl PaymentConstraints {
526 pub(crate) fn get_native_ref(&self) -> &'static nativePaymentConstraints {
527 unsafe { &*ObjOps::untweak_ptr(self.inner) }
529 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentConstraints {
530 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
532 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
533 pub(crate) fn take_inner(mut self) -> *mut nativePaymentConstraints {
534 assert!(self.is_owned);
535 let ret = ObjOps::untweak_ptr(self.inner);
536 self.inner = core::ptr::null_mut();
540 /// The maximum total CLTV delta that is acceptable when relaying a payment over this
543 pub extern "C" fn PaymentConstraints_get_max_cltv_expiry(this_ptr: &PaymentConstraints) -> u32 {
544 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_cltv_expiry;
547 /// The maximum total CLTV delta that is acceptable when relaying a payment over this
550 pub extern "C" fn PaymentConstraints_set_max_cltv_expiry(this_ptr: &mut PaymentConstraints, mut val: u32) {
551 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_cltv_expiry = val;
553 /// The minimum value, in msat, that may be accepted by the node corresponding to this
556 pub extern "C" fn PaymentConstraints_get_htlc_minimum_msat(this_ptr: &PaymentConstraints) -> u64 {
557 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
560 /// The minimum value, in msat, that may be accepted by the node corresponding to this
563 pub extern "C" fn PaymentConstraints_set_htlc_minimum_msat(this_ptr: &mut PaymentConstraints, mut val: u64) {
564 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
566 /// Constructs a new PaymentConstraints given each field
569 pub extern "C" fn PaymentConstraints_new(mut max_cltv_expiry_arg: u32, mut htlc_minimum_msat_arg: u64) -> PaymentConstraints {
570 PaymentConstraints { inner: ObjOps::heap_alloc(nativePaymentConstraints {
571 max_cltv_expiry: max_cltv_expiry_arg,
572 htlc_minimum_msat: htlc_minimum_msat_arg,
575 impl Clone for PaymentConstraints {
576 fn clone(&self) -> Self {
578 inner: if <*mut nativePaymentConstraints>::is_null(self.inner) { core::ptr::null_mut() } else {
579 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
585 /// Used only if an object of this type is returned as a trait impl by a method
586 pub(crate) extern "C" fn PaymentConstraints_clone_void(this_ptr: *const c_void) -> *mut c_void {
587 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentConstraints)).clone() })) as *mut c_void
590 /// Creates a copy of the PaymentConstraints
591 pub extern "C" fn PaymentConstraints_clone(orig: &PaymentConstraints) -> PaymentConstraints {
595 /// Serialize the ForwardTlvs object into a byte array which can be read by ForwardTlvs_read
596 pub extern "C" fn ForwardTlvs_write(obj: &crate::lightning::blinded_path::payment::ForwardTlvs) -> crate::c_types::derived::CVec_u8Z {
597 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
600 pub(crate) extern "C" fn ForwardTlvs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
601 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeForwardTlvs) })
604 /// Serialize the ReceiveTlvs object into a byte array which can be read by ReceiveTlvs_read
605 pub extern "C" fn ReceiveTlvs_write(obj: &crate::lightning::blinded_path::payment::ReceiveTlvs) -> crate::c_types::derived::CVec_u8Z {
606 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
609 pub(crate) extern "C" fn ReceiveTlvs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
610 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeReceiveTlvs) })
613 /// Read a ReceiveTlvs from a byte array, created by ReceiveTlvs_write
614 pub extern "C" fn ReceiveTlvs_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ReceiveTlvsDecodeErrorZ {
615 let res: Result<lightning::blinded_path::payment::ReceiveTlvs, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
616 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::blinded_path::payment::ReceiveTlvs { 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() };
620 /// Serialize the PaymentRelay object into a byte array which can be read by PaymentRelay_read
621 pub extern "C" fn PaymentRelay_write(obj: &crate::lightning::blinded_path::payment::PaymentRelay) -> crate::c_types::derived::CVec_u8Z {
622 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
625 pub(crate) extern "C" fn PaymentRelay_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
626 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentRelay) })
629 /// Read a PaymentRelay from a byte array, created by PaymentRelay_write
630 pub extern "C" fn PaymentRelay_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentRelayDecodeErrorZ {
631 let res: Result<lightning::blinded_path::payment::PaymentRelay, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
632 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() };
636 /// Serialize the PaymentConstraints object into a byte array which can be read by PaymentConstraints_read
637 pub extern "C" fn PaymentConstraints_write(obj: &crate::lightning::blinded_path::payment::PaymentConstraints) -> crate::c_types::derived::CVec_u8Z {
638 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
641 pub(crate) extern "C" fn PaymentConstraints_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
642 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentConstraints) })
645 /// Read a PaymentConstraints from a byte array, created by PaymentConstraints_write
646 pub extern "C" fn PaymentConstraints_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentConstraintsDecodeErrorZ {
647 let res: Result<lightning::blinded_path::payment::PaymentConstraints, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
648 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() };