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::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 /// Constructs a new ReceiveTlvs given each field
351 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 {
352 ReceiveTlvs { inner: ObjOps::heap_alloc(nativeReceiveTlvs {
353 payment_secret: ::lightning::ln::PaymentSecret(payment_secret_arg.data),
354 payment_constraints: *unsafe { Box::from_raw(payment_constraints_arg.take_inner()) },
357 impl Clone for ReceiveTlvs {
358 fn clone(&self) -> Self {
360 inner: if <*mut nativeReceiveTlvs>::is_null(self.inner) { core::ptr::null_mut() } else {
361 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
367 /// Used only if an object of this type is returned as a trait impl by a method
368 pub(crate) extern "C" fn ReceiveTlvs_clone_void(this_ptr: *const c_void) -> *mut c_void {
369 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeReceiveTlvs)).clone() })) as *mut c_void
372 /// Creates a copy of the ReceiveTlvs
373 pub extern "C" fn ReceiveTlvs_clone(orig: &ReceiveTlvs) -> ReceiveTlvs {
376 /// Get a string which allows debug introspection of a ReceiveTlvs object
377 pub extern "C" fn ReceiveTlvs_debug_str_void(o: *const c_void) -> Str {
378 alloc::format!("{:?}", unsafe { o as *const crate::lightning::blinded_path::payment::ReceiveTlvs }).into()}
380 use lightning::blinded_path::payment::PaymentRelay as nativePaymentRelayImport;
381 pub(crate) type nativePaymentRelay = nativePaymentRelayImport;
383 /// Parameters for relaying over a given [`BlindedHop`].
385 /// [`BlindedHop`]: crate::blinded_path::BlindedHop
388 pub struct PaymentRelay {
389 /// A pointer to the opaque Rust object.
391 /// Nearly everywhere, inner must be non-null, however in places where
392 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
393 pub inner: *mut nativePaymentRelay,
394 /// Indicates that this is the only struct which contains the same pointer.
396 /// Rust functions which take ownership of an object provided via an argument require
397 /// this to be true and invalidate the object pointed to by inner.
401 impl Drop for PaymentRelay {
403 if self.is_owned && !<*mut nativePaymentRelay>::is_null(self.inner) {
404 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
408 /// Frees any resources used by the PaymentRelay, if is_owned is set and inner is non-NULL.
410 pub extern "C" fn PaymentRelay_free(this_obj: PaymentRelay) { }
412 /// Used only if an object of this type is returned as a trait impl by a method
413 pub(crate) extern "C" fn PaymentRelay_free_void(this_ptr: *mut c_void) {
414 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentRelay) };
418 pub(crate) fn get_native_ref(&self) -> &'static nativePaymentRelay {
419 unsafe { &*ObjOps::untweak_ptr(self.inner) }
421 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentRelay {
422 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
424 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
425 pub(crate) fn take_inner(mut self) -> *mut nativePaymentRelay {
426 assert!(self.is_owned);
427 let ret = ObjOps::untweak_ptr(self.inner);
428 self.inner = core::ptr::null_mut();
432 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for this [`BlindedHop`].
434 pub extern "C" fn PaymentRelay_get_cltv_expiry_delta(this_ptr: &PaymentRelay) -> u16 {
435 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
438 /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for this [`BlindedHop`].
440 pub extern "C" fn PaymentRelay_set_cltv_expiry_delta(this_ptr: &mut PaymentRelay, mut val: u16) {
441 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
443 /// Liquidity fee charged (in millionths of the amount transferred) for relaying a payment over
444 /// this [`BlindedHop`], (i.e., 10,000 is 1%).
446 pub extern "C" fn PaymentRelay_get_fee_proportional_millionths(this_ptr: &PaymentRelay) -> u32 {
447 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_proportional_millionths;
450 /// Liquidity fee charged (in millionths of the amount transferred) for relaying a payment over
451 /// this [`BlindedHop`], (i.e., 10,000 is 1%).
453 pub extern "C" fn PaymentRelay_set_fee_proportional_millionths(this_ptr: &mut PaymentRelay, mut val: u32) {
454 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val;
456 /// Base fee charged (in millisatoshi) for relaying a payment over this [`BlindedHop`].
458 pub extern "C" fn PaymentRelay_get_fee_base_msat(this_ptr: &PaymentRelay) -> u32 {
459 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_base_msat;
462 /// Base fee charged (in millisatoshi) for relaying a payment over this [`BlindedHop`].
464 pub extern "C" fn PaymentRelay_set_fee_base_msat(this_ptr: &mut PaymentRelay, mut val: u32) {
465 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_base_msat = val;
467 /// Constructs a new PaymentRelay given each field
470 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 {
471 PaymentRelay { inner: ObjOps::heap_alloc(nativePaymentRelay {
472 cltv_expiry_delta: cltv_expiry_delta_arg,
473 fee_proportional_millionths: fee_proportional_millionths_arg,
474 fee_base_msat: fee_base_msat_arg,
477 impl Clone for PaymentRelay {
478 fn clone(&self) -> Self {
480 inner: if <*mut nativePaymentRelay>::is_null(self.inner) { core::ptr::null_mut() } else {
481 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
487 /// Used only if an object of this type is returned as a trait impl by a method
488 pub(crate) extern "C" fn PaymentRelay_clone_void(this_ptr: *const c_void) -> *mut c_void {
489 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePaymentRelay)).clone() })) as *mut c_void
492 /// Creates a copy of the PaymentRelay
493 pub extern "C" fn PaymentRelay_clone(orig: &PaymentRelay) -> PaymentRelay {
496 /// Get a string which allows debug introspection of a PaymentRelay object
497 pub extern "C" fn PaymentRelay_debug_str_void(o: *const c_void) -> Str {
498 alloc::format!("{:?}", unsafe { o as *const crate::lightning::blinded_path::payment::PaymentRelay }).into()}
500 use lightning::blinded_path::payment::PaymentConstraints as nativePaymentConstraintsImport;
501 pub(crate) type nativePaymentConstraints = nativePaymentConstraintsImport;
503 /// Constraints for relaying over a given [`BlindedHop`].
505 /// [`BlindedHop`]: crate::blinded_path::BlindedHop
508 pub struct PaymentConstraints {
509 /// A pointer to the opaque Rust object.
511 /// Nearly everywhere, inner must be non-null, however in places where
512 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
513 pub inner: *mut nativePaymentConstraints,
514 /// Indicates that this is the only struct which contains the same pointer.
516 /// Rust functions which take ownership of an object provided via an argument require
517 /// this to be true and invalidate the object pointed to by inner.
521 impl Drop for PaymentConstraints {
523 if self.is_owned && !<*mut nativePaymentConstraints>::is_null(self.inner) {
524 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
528 /// Frees any resources used by the PaymentConstraints, if is_owned is set and inner is non-NULL.
530 pub extern "C" fn PaymentConstraints_free(this_obj: PaymentConstraints) { }
532 /// Used only if an object of this type is returned as a trait impl by a method
533 pub(crate) extern "C" fn PaymentConstraints_free_void(this_ptr: *mut c_void) {
534 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentConstraints) };
537 impl PaymentConstraints {
538 pub(crate) fn get_native_ref(&self) -> &'static nativePaymentConstraints {
539 unsafe { &*ObjOps::untweak_ptr(self.inner) }
541 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentConstraints {
542 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
544 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
545 pub(crate) fn take_inner(mut self) -> *mut nativePaymentConstraints {
546 assert!(self.is_owned);
547 let ret = ObjOps::untweak_ptr(self.inner);
548 self.inner = core::ptr::null_mut();
552 /// The maximum total CLTV that is acceptable when relaying a payment over this [`BlindedHop`].
554 pub extern "C" fn PaymentConstraints_get_max_cltv_expiry(this_ptr: &PaymentConstraints) -> u32 {
555 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_cltv_expiry;
558 /// The maximum total CLTV that is acceptable when relaying a payment over this [`BlindedHop`].
560 pub extern "C" fn PaymentConstraints_set_max_cltv_expiry(this_ptr: &mut PaymentConstraints, mut val: u32) {
561 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_cltv_expiry = val;
563 /// The minimum value, in msat, that may be accepted by the node corresponding to this
566 pub extern "C" fn PaymentConstraints_get_htlc_minimum_msat(this_ptr: &PaymentConstraints) -> u64 {
567 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
570 /// The minimum value, in msat, that may be accepted by the node corresponding to this
573 pub extern "C" fn PaymentConstraints_set_htlc_minimum_msat(this_ptr: &mut PaymentConstraints, mut val: u64) {
574 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
576 /// Constructs a new PaymentConstraints given each field
579 pub extern "C" fn PaymentConstraints_new(mut max_cltv_expiry_arg: u32, mut htlc_minimum_msat_arg: u64) -> PaymentConstraints {
580 PaymentConstraints { inner: ObjOps::heap_alloc(nativePaymentConstraints {
581 max_cltv_expiry: max_cltv_expiry_arg,
582 htlc_minimum_msat: htlc_minimum_msat_arg,
585 impl Clone for PaymentConstraints {
586 fn clone(&self) -> Self {
588 inner: if <*mut nativePaymentConstraints>::is_null(self.inner) { core::ptr::null_mut() } else {
589 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
595 /// Used only if an object of this type is returned as a trait impl by a method
596 pub(crate) extern "C" fn PaymentConstraints_clone_void(this_ptr: *const c_void) -> *mut c_void {
597 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePaymentConstraints)).clone() })) as *mut c_void
600 /// Creates a copy of the PaymentConstraints
601 pub extern "C" fn PaymentConstraints_clone(orig: &PaymentConstraints) -> PaymentConstraints {
604 /// Get a string which allows debug introspection of a PaymentConstraints object
605 pub extern "C" fn PaymentConstraints_debug_str_void(o: *const c_void) -> Str {
606 alloc::format!("{:?}", unsafe { o as *const crate::lightning::blinded_path::payment::PaymentConstraints }).into()}
608 /// Serialize the ForwardTlvs object into a byte array which can be read by ForwardTlvs_read
609 pub extern "C" fn ForwardTlvs_write(obj: &crate::lightning::blinded_path::payment::ForwardTlvs) -> crate::c_types::derived::CVec_u8Z {
610 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
613 pub(crate) extern "C" fn ForwardTlvs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
614 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeForwardTlvs) })
617 /// Serialize the ReceiveTlvs object into a byte array which can be read by ReceiveTlvs_read
618 pub extern "C" fn ReceiveTlvs_write(obj: &crate::lightning::blinded_path::payment::ReceiveTlvs) -> crate::c_types::derived::CVec_u8Z {
619 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
622 pub(crate) extern "C" fn ReceiveTlvs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
623 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeReceiveTlvs) })
626 /// Serialize the PaymentRelay object into a byte array which can be read by PaymentRelay_read
627 pub extern "C" fn PaymentRelay_write(obj: &crate::lightning::blinded_path::payment::PaymentRelay) -> crate::c_types::derived::CVec_u8Z {
628 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
631 pub(crate) extern "C" fn PaymentRelay_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
632 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentRelay) })
635 /// Read a PaymentRelay from a byte array, created by PaymentRelay_write
636 pub extern "C" fn PaymentRelay_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentRelayDecodeErrorZ {
637 let res: Result<lightning::blinded_path::payment::PaymentRelay, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
638 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() };
642 /// Serialize the PaymentConstraints object into a byte array which can be read by PaymentConstraints_read
643 pub extern "C" fn PaymentConstraints_write(obj: &crate::lightning::blinded_path::payment::PaymentConstraints) -> crate::c_types::derived::CVec_u8Z {
644 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
647 pub(crate) extern "C" fn PaymentConstraints_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
648 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentConstraints) })
651 /// Read a PaymentConstraints from a byte array, created by PaymentConstraints_write
652 pub extern "C" fn PaymentConstraints_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentConstraintsDecodeErrorZ {
653 let res: Result<lightning::blinded_path::payment::PaymentConstraints, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
654 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() };