+ inner: if <*mut nativeRouteParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
+ ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
+ is_owned: true,
+ }
+ }
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn RouteParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRouteParameters)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the RouteParameters
+pub extern "C" fn RouteParameters_clone(orig: &RouteParameters) -> RouteParameters {
+ orig.clone()
+}
+/// Get a string which allows debug introspection of a RouteParameters object
+pub extern "C" fn RouteParameters_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::RouteParameters }).into()}
+/// Generates a non-cryptographic 64-bit hash of the RouteParameters.
+#[no_mangle]
+pub extern "C" fn RouteParameters_hash(o: &RouteParameters) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
+/// Checks if two RouteParameterss contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+/// Two objects with NULL inner values will be considered "equal" here.
+#[no_mangle]
+pub extern "C" fn RouteParameters_eq(a: &RouteParameters, b: &RouteParameters) -> bool {
+ if a.inner == b.inner { return true; }
+ if a.inner.is_null() || b.inner.is_null() { return false; }
+ if a.get_native_ref() == b.get_native_ref() { true } else { false }
+}
+/// Constructs [`RouteParameters`] from the given [`PaymentParameters`] and a payment amount.
+///
+/// [`Self::max_total_routing_fee_msat`] defaults to 1% of the payment amount + 50 sats
+#[must_use]
+#[no_mangle]
+pub extern "C" fn RouteParameters_from_payment_params_and_value(mut payment_params: crate::lightning::routing::router::PaymentParameters, mut final_value_msat: u64) -> crate::lightning::routing::router::RouteParameters {
+ let mut ret = lightning::routing::router::RouteParameters::from_payment_params_and_value(*unsafe { Box::from_raw(payment_params.take_inner()) }, final_value_msat);
+ crate::lightning::routing::router::RouteParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
+}
+
+/// Sets the maximum number of hops that can be included in a payment path, based on the provided
+/// [`RecipientOnionFields`] and blinded paths.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn RouteParameters_set_max_path_length(this_arg: &mut crate::lightning::routing::router::RouteParameters, recipient_onion: &crate::lightning::ln::outbound_payment::RecipientOnionFields, mut is_keysend: bool, mut best_block_height: u32) -> crate::c_types::derived::CResult_NoneNoneZ {
+ let mut ret = unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::router::nativeRouteParameters)) }.set_max_path_length(recipient_onion.get_native_ref(), is_keysend, best_block_height);
+ let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
+ local_ret
+}
+
+#[no_mangle]
+/// Serialize the RouteParameters object into a byte array which can be read by RouteParameters_read
+pub extern "C" fn RouteParameters_write(obj: &crate::lightning::routing::router::RouteParameters) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
+}
+#[allow(unused)]
+pub(crate) extern "C" fn RouteParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::routing::router::nativeRouteParameters) })
+}
+#[no_mangle]
+/// Read a RouteParameters from a byte array, created by RouteParameters_write
+pub extern "C" fn RouteParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteParametersDecodeErrorZ {
+ let res: Result<lightning::routing::router::RouteParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
+ let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::RouteParameters { 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() };
+ local_res
+}
+/// Maximum total CTLV difference we allow for a full payment path.
+
+#[no_mangle]
+pub static DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = lightning::routing::router::DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
+/// Maximum number of paths we allow an (MPP) payment to have.
+
+#[no_mangle]
+pub static DEFAULT_MAX_PATH_COUNT: u8 = lightning::routing::router::DEFAULT_MAX_PATH_COUNT;
+/// Estimated maximum number of hops that can be included in a payment path. May be inaccurate if
+/// payment metadata, custom TLVs, or blinded paths are included in the payment.
+
+#[no_mangle]
+pub static MAX_PATH_LENGTH_ESTIMATE: u8 = lightning::routing::router::MAX_PATH_LENGTH_ESTIMATE;
+
+use lightning::routing::router::PaymentParameters as nativePaymentParametersImport;
+pub(crate) type nativePaymentParameters = nativePaymentParametersImport;
+
+/// Information used to route a payment.
+#[must_use]
+#[repr(C)]
+pub struct PaymentParameters {
+ /// A pointer to the opaque Rust object.
+
+ /// Nearly everywhere, inner must be non-null, however in places where
+ /// the Rust equivalent takes an Option, it may be set to null to indicate None.
+ pub inner: *mut nativePaymentParameters,
+ /// Indicates that this is the only struct which contains the same pointer.
+
+ /// Rust functions which take ownership of an object provided via an argument require
+ /// this to be true and invalidate the object pointed to by inner.
+ pub is_owned: bool,
+}
+
+impl core::ops::Deref for PaymentParameters {
+ type Target = nativePaymentParameters;
+ fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } }
+}
+unsafe impl core::marker::Send for PaymentParameters { }
+unsafe impl core::marker::Sync for PaymentParameters { }
+impl Drop for PaymentParameters {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativePaymentParameters>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the PaymentParameters, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn PaymentParameters_free(this_obj: PaymentParameters) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn PaymentParameters_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentParameters) };
+}
+#[allow(unused)]
+impl PaymentParameters {
+ pub(crate) fn get_native_ref(&self) -> &'static nativePaymentParameters {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentParameters {
+ unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
+ }
+ /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
+ pub(crate) fn take_inner(mut self) -> *mut nativePaymentParameters {
+ assert!(self.is_owned);
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
+ ret
+ }
+ pub(crate) fn as_ref_to(&self) -> Self {
+ Self { inner: self.inner, is_owned: false }
+ }
+}
+/// Information about the payee, such as their features and route hints for their channels.
+#[no_mangle]
+pub extern "C" fn PaymentParameters_get_payee(this_ptr: &PaymentParameters) -> crate::lightning::routing::router::Payee {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().payee;
+ crate::lightning::routing::router::Payee::from_native(inner_val)
+}
+/// Information about the payee, such as their features and route hints for their channels.
+#[no_mangle]
+pub extern "C" fn PaymentParameters_set_payee(this_ptr: &mut PaymentParameters, mut val: crate::lightning::routing::router::Payee) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payee = val.into_native();
+}
+/// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
+#[no_mangle]
+pub extern "C" fn PaymentParameters_get_expiry_time(this_ptr: &PaymentParameters) -> crate::c_types::derived::COption_u64Z {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().expiry_time;
+ let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
+ local_inner_val
+}
+/// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
+#[no_mangle]
+pub extern "C" fn PaymentParameters_set_expiry_time(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::COption_u64Z) {
+ let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.expiry_time = local_val;
+}
+/// The maximum total CLTV delta we accept for the route.
+/// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
+#[no_mangle]
+pub extern "C" fn PaymentParameters_get_max_total_cltv_expiry_delta(this_ptr: &PaymentParameters) -> u32 {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_cltv_expiry_delta;
+ *inner_val
+}
+/// The maximum total CLTV delta we accept for the route.
+/// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
+#[no_mangle]
+pub extern "C" fn PaymentParameters_set_max_total_cltv_expiry_delta(this_ptr: &mut PaymentParameters, mut val: u32) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_cltv_expiry_delta = val;
+}
+/// The maximum number of paths that may be used by (MPP) payments.
+/// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
+#[no_mangle]
+pub extern "C" fn PaymentParameters_get_max_path_count(this_ptr: &PaymentParameters) -> u8 {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().max_path_count;
+ *inner_val
+}
+/// The maximum number of paths that may be used by (MPP) payments.
+/// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
+#[no_mangle]
+pub extern "C" fn PaymentParameters_set_max_path_count(this_ptr: &mut PaymentParameters, mut val: u8) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_path_count = val;
+}
+/// The maximum number of [`Path::hops`] in any returned path.
+/// Defaults to [`MAX_PATH_LENGTH_ESTIMATE`].
+#[no_mangle]
+pub extern "C" fn PaymentParameters_get_max_path_length(this_ptr: &PaymentParameters) -> u8 {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().max_path_length;
+ *inner_val
+}
+/// The maximum number of [`Path::hops`] in any returned path.
+/// Defaults to [`MAX_PATH_LENGTH_ESTIMATE`].
+#[no_mangle]
+pub extern "C" fn PaymentParameters_set_max_path_length(this_ptr: &mut PaymentParameters, mut val: u8) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_path_length = val;
+}
+/// Selects the maximum share of a channel's total capacity which will be sent over a channel,
+/// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
+/// a lower value prefers to send larger MPP parts, potentially saturating channels and
+/// increasing failure probability for those paths.
+///
+/// Note that this restriction will be relaxed during pathfinding after paths which meet this
+/// restriction have been found. While paths which meet this criteria will be searched for, it
+/// is ultimately up to the scorer to select them over other paths.
+///
+/// A value of 0 will allow payments up to and including a channel's total announced usable
+/// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
+///
+/// Default value: 2
+#[no_mangle]
+pub extern "C" fn PaymentParameters_get_max_channel_saturation_power_of_half(this_ptr: &PaymentParameters) -> u8 {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_saturation_power_of_half;
+ *inner_val
+}
+/// Selects the maximum share of a channel's total capacity which will be sent over a channel,
+/// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
+/// a lower value prefers to send larger MPP parts, potentially saturating channels and
+/// increasing failure probability for those paths.
+///
+/// Note that this restriction will be relaxed during pathfinding after paths which meet this
+/// restriction have been found. While paths which meet this criteria will be searched for, it
+/// is ultimately up to the scorer to select them over other paths.
+///
+/// A value of 0 will allow payments up to and including a channel's total announced usable
+/// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
+///
+/// Default value: 2
+#[no_mangle]
+pub extern "C" fn PaymentParameters_set_max_channel_saturation_power_of_half(this_ptr: &mut PaymentParameters, mut val: u8) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_saturation_power_of_half = val;
+}
+/// A list of SCIDs which this payment was previously attempted over and which caused the
+/// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
+/// these SCIDs.
+///
+/// Returns a copy of the field.
+#[no_mangle]
+pub extern "C" fn PaymentParameters_get_previously_failed_channels(this_ptr: &PaymentParameters) -> crate::c_types::derived::CVec_u64Z {
+ let mut inner_val = this_ptr.get_native_mut_ref().previously_failed_channels.clone();
+ let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
+ local_inner_val.into()
+}
+/// A list of SCIDs which this payment was previously attempted over and which caused the
+/// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
+/// these SCIDs.
+#[no_mangle]
+pub extern "C" fn PaymentParameters_set_previously_failed_channels(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_u64Z) {
+ let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previously_failed_channels = local_val;
+}
+/// A list of indices corresponding to blinded paths in [`Payee::Blinded::route_hints`] which this
+/// payment was previously attempted over and which caused the payment to fail. Future attempts
+/// for the same payment shouldn't be relayed through any of these blinded paths.
+///
+/// Returns a copy of the field.
+#[no_mangle]
+pub extern "C" fn PaymentParameters_get_previously_failed_blinded_path_idxs(this_ptr: &PaymentParameters) -> crate::c_types::derived::CVec_u64Z {
+ let mut inner_val = this_ptr.get_native_mut_ref().previously_failed_blinded_path_idxs.clone();
+ let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
+ local_inner_val.into()
+}
+/// A list of indices corresponding to blinded paths in [`Payee::Blinded::route_hints`] which this
+/// payment was previously attempted over and which caused the payment to fail. Future attempts
+/// for the same payment shouldn't be relayed through any of these blinded paths.
+#[no_mangle]
+pub extern "C" fn PaymentParameters_set_previously_failed_blinded_path_idxs(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_u64Z) {
+ let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previously_failed_blinded_path_idxs = local_val;
+}
+/// Constructs a new PaymentParameters given each field
+#[must_use]
+#[no_mangle]
+pub extern "C" fn PaymentParameters_new(mut payee_arg: crate::lightning::routing::router::Payee, mut expiry_time_arg: crate::c_types::derived::COption_u64Z, mut max_total_cltv_expiry_delta_arg: u32, mut max_path_count_arg: u8, mut max_path_length_arg: u8, mut max_channel_saturation_power_of_half_arg: u8, mut previously_failed_channels_arg: crate::c_types::derived::CVec_u64Z, mut previously_failed_blinded_path_idxs_arg: crate::c_types::derived::CVec_u64Z) -> PaymentParameters {
+ let mut local_expiry_time_arg = if expiry_time_arg.is_some() { Some( { expiry_time_arg.take() }) } else { None };
+ let mut local_previously_failed_channels_arg = Vec::new(); for mut item in previously_failed_channels_arg.into_rust().drain(..) { local_previously_failed_channels_arg.push( { item }); };
+ let mut local_previously_failed_blinded_path_idxs_arg = Vec::new(); for mut item in previously_failed_blinded_path_idxs_arg.into_rust().drain(..) { local_previously_failed_blinded_path_idxs_arg.push( { item }); };
+ PaymentParameters { inner: ObjOps::heap_alloc(nativePaymentParameters {
+ payee: payee_arg.into_native(),
+ expiry_time: local_expiry_time_arg,
+ max_total_cltv_expiry_delta: max_total_cltv_expiry_delta_arg,
+ max_path_count: max_path_count_arg,
+ max_path_length: max_path_length_arg,
+ max_channel_saturation_power_of_half: max_channel_saturation_power_of_half_arg,
+ previously_failed_channels: local_previously_failed_channels_arg,
+ previously_failed_blinded_path_idxs: local_previously_failed_blinded_path_idxs_arg,
+ }), is_owned: true }
+}
+impl Clone for PaymentParameters {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativePaymentParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
+ ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
+ is_owned: true,
+ }
+ }
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn PaymentParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePaymentParameters)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the PaymentParameters
+pub extern "C" fn PaymentParameters_clone(orig: &PaymentParameters) -> PaymentParameters {
+ orig.clone()
+}
+/// Get a string which allows debug introspection of a PaymentParameters object
+pub extern "C" fn PaymentParameters_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::PaymentParameters }).into()}
+/// Generates a non-cryptographic 64-bit hash of the PaymentParameters.
+#[no_mangle]
+pub extern "C" fn PaymentParameters_hash(o: &PaymentParameters) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
+/// Checks if two PaymentParameterss contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+/// Two objects with NULL inner values will be considered "equal" here.
+#[no_mangle]
+pub extern "C" fn PaymentParameters_eq(a: &PaymentParameters, b: &PaymentParameters) -> bool {
+ if a.inner == b.inner { return true; }
+ if a.inner.is_null() || b.inner.is_null() { return false; }
+ if a.get_native_ref() == b.get_native_ref() { true } else { false }
+}
+#[no_mangle]
+/// Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
+pub extern "C" fn PaymentParameters_write(obj: &crate::lightning::routing::router::PaymentParameters) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
+}
+#[allow(unused)]
+pub(crate) extern "C" fn PaymentParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::routing::router::nativePaymentParameters) })
+}
+#[no_mangle]
+/// Read a PaymentParameters from a byte array, created by PaymentParameters_write
+pub extern "C" fn PaymentParameters_read(ser: crate::c_types::u8slice, arg: u32) -> crate::c_types::derived::CResult_PaymentParametersDecodeErrorZ {
+ let arg_conv = arg;
+ let res: Result<lightning::routing::router::PaymentParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
+ let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::PaymentParameters { 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() };
+ local_res
+}
+/// Creates a payee with the node id of the given `pubkey`.
+///
+/// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
+/// provided.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn PaymentParameters_from_node_id(mut payee_pubkey: crate::c_types::PublicKey, mut final_cltv_expiry_delta: u32) -> crate::lightning::routing::router::PaymentParameters {
+ let mut ret = lightning::routing::router::PaymentParameters::from_node_id(payee_pubkey.into_rust(), final_cltv_expiry_delta);
+ crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
+}
+
+/// Creates a payee with the node id of the given `pubkey` to use for keysend payments.
+///
+/// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
+/// provided.
+///
+/// Note that MPP keysend is not widely supported yet. The `allow_mpp` lets you choose
+/// whether your router will be allowed to find a multi-part route for this payment. If you
+/// set `allow_mpp` to true, you should ensure a payment secret is set on send, likely via
+/// [`RecipientOnionFields::secret_only`].
+///
+/// [`RecipientOnionFields::secret_only`]: crate::ln::channelmanager::RecipientOnionFields::secret_only
+#[must_use]
+#[no_mangle]
+pub extern "C" fn PaymentParameters_for_keysend(mut payee_pubkey: crate::c_types::PublicKey, mut final_cltv_expiry_delta: u32, mut allow_mpp: bool) -> crate::lightning::routing::router::PaymentParameters {
+ let mut ret = lightning::routing::router::PaymentParameters::for_keysend(payee_pubkey.into_rust(), final_cltv_expiry_delta, allow_mpp);
+ crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
+}
+
+/// Creates parameters for paying to a blinded payee from the provided invoice. Sets
+/// [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and
+/// [`PaymentParameters::expiry_time`].
+#[must_use]
+#[no_mangle]
+pub extern "C" fn PaymentParameters_from_bolt12_invoice(invoice: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::routing::router::PaymentParameters {
+ let mut ret = lightning::routing::router::PaymentParameters::from_bolt12_invoice(invoice.get_native_ref());
+ crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
+}
+
+/// Creates parameters for paying to a blinded payee from the provided blinded route hints.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn PaymentParameters_blinded(mut blinded_route_hints: crate::c_types::derived::CVec_BlindedPaymentPathZ) -> crate::lightning::routing::router::PaymentParameters {
+ let mut local_blinded_route_hints = Vec::new(); for mut item in blinded_route_hints.into_rust().drain(..) { local_blinded_route_hints.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
+ let mut ret = lightning::routing::router::PaymentParameters::blinded(local_blinded_route_hints);
+ crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
+}
+
+/// The recipient of a payment, differing based on whether they've hidden their identity with route
+/// blinding.
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum Payee {
+ /// The recipient provided blinded paths and payinfo to reach them. The blinded paths themselves
+ /// will be included in the final [`Route`].
+ Blinded {
+ /// Aggregated routing info and blinded paths, for routing to the payee without knowing their
+ /// node id.
+ route_hints: crate::c_types::derived::CVec_BlindedPaymentPathZ,
+ /// Features supported by the payee.
+ ///
+ /// May be set from the payee's invoice. May be `None` if the invoice does not contain any
+ /// features.
+ ///
+ /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
+ features: crate::lightning_types::features::Bolt12InvoiceFeatures,
+ },
+ /// The recipient included these route hints in their BOLT11 invoice.
+ Clear {
+ /// The node id of the payee.
+ node_id: crate::c_types::PublicKey,
+ /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
+ route_hints: crate::c_types::derived::CVec_RouteHintZ,
+ /// Features supported by the payee.
+ ///
+ /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
+ /// does not contain any features.
+ ///
+ /// [`for_keysend`]: PaymentParameters::for_keysend
+ ///
+ /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
+ features: crate::lightning_types::features::Bolt11InvoiceFeatures,
+ /// The minimum CLTV delta at the end of the route. This value must not be zero.
+ final_cltv_expiry_delta: u32,
+ },
+}
+use lightning::routing::router::Payee as PayeeImport;
+pub(crate) type nativePayee = PayeeImport;
+
+impl Payee {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativePayee {
+ match self {
+ Payee::Blinded {ref route_hints, ref features, } => {
+ let mut route_hints_nonref = Clone::clone(route_hints);
+ let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.into_rust().drain(..) { local_route_hints_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
+ let mut features_nonref = Clone::clone(features);
+ let mut local_features_nonref = if features_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_nonref.take_inner()) } }) };
+ nativePayee::Blinded {
+ route_hints: local_route_hints_nonref,
+ features: local_features_nonref,
+ }
+ },
+ Payee::Clear {ref node_id, ref route_hints, ref features, ref final_cltv_expiry_delta, } => {
+ let mut node_id_nonref = Clone::clone(node_id);
+ let mut route_hints_nonref = Clone::clone(route_hints);
+ let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.into_rust().drain(..) { local_route_hints_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
+ let mut features_nonref = Clone::clone(features);
+ let mut local_features_nonref = if features_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_nonref.take_inner()) } }) };
+ let mut final_cltv_expiry_delta_nonref = Clone::clone(final_cltv_expiry_delta);
+ nativePayee::Clear {
+ node_id: node_id_nonref.into_rust(),
+ route_hints: local_route_hints_nonref,
+ features: local_features_nonref,
+ final_cltv_expiry_delta: final_cltv_expiry_delta_nonref,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativePayee {
+ match self {
+ Payee::Blinded {mut route_hints, mut features, } => {
+ let mut local_route_hints = Vec::new(); for mut item in route_hints.into_rust().drain(..) { local_route_hints.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
+ let mut local_features = if features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features.take_inner()) } }) };
+ nativePayee::Blinded {
+ route_hints: local_route_hints,
+ features: local_features,
+ }
+ },
+ Payee::Clear {mut node_id, mut route_hints, mut features, mut final_cltv_expiry_delta, } => {
+ let mut local_route_hints = Vec::new(); for mut item in route_hints.into_rust().drain(..) { local_route_hints.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
+ let mut local_features = if features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features.take_inner()) } }) };
+ nativePayee::Clear {
+ node_id: node_id.into_rust(),
+ route_hints: local_route_hints,
+ features: local_features,
+ final_cltv_expiry_delta: final_cltv_expiry_delta,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &PayeeImport) -> Self {
+ let native = unsafe { &*(native as *const _ as *const c_void as *const nativePayee) };
+ match native {
+ nativePayee::Blinded {ref route_hints, ref features, } => {
+ let mut route_hints_nonref = Clone::clone(route_hints);
+ let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.drain(..) { local_route_hints_nonref.push( { crate::lightning::blinded_path::payment::BlindedPaymentPath { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
+ let mut features_nonref = Clone::clone(features);
+ let mut local_features_nonref = crate::lightning_types::features::Bolt12InvoiceFeatures { inner: if features_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features_nonref.unwrap())) } }, is_owned: true };
+ Payee::Blinded {
+ route_hints: local_route_hints_nonref.into(),
+ features: local_features_nonref,
+ }
+ },
+ nativePayee::Clear {ref node_id, ref route_hints, ref features, ref final_cltv_expiry_delta, } => {
+ let mut node_id_nonref = Clone::clone(node_id);
+ let mut route_hints_nonref = Clone::clone(route_hints);
+ let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.drain(..) { local_route_hints_nonref.push( { crate::lightning_types::routing::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
+ let mut features_nonref = Clone::clone(features);
+ let mut local_features_nonref = crate::lightning_types::features::Bolt11InvoiceFeatures { inner: if features_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features_nonref.unwrap())) } }, is_owned: true };
+ let mut final_cltv_expiry_delta_nonref = Clone::clone(final_cltv_expiry_delta);
+ Payee::Clear {
+ node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
+ route_hints: local_route_hints_nonref.into(),
+ features: local_features_nonref,
+ final_cltv_expiry_delta: final_cltv_expiry_delta_nonref,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativePayee) -> Self {
+ match native {
+ nativePayee::Blinded {mut route_hints, mut features, } => {
+ let mut local_route_hints = Vec::new(); for mut item in route_hints.drain(..) { local_route_hints.push( { crate::lightning::blinded_path::payment::BlindedPaymentPath { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
+ let mut local_features = crate::lightning_types::features::Bolt12InvoiceFeatures { inner: if features.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features.unwrap())) } }, is_owned: true };
+ Payee::Blinded {
+ route_hints: local_route_hints.into(),
+ features: local_features,
+ }
+ },
+ nativePayee::Clear {mut node_id, mut route_hints, mut features, mut final_cltv_expiry_delta, } => {
+ let mut local_route_hints = Vec::new(); for mut item in route_hints.drain(..) { local_route_hints.push( { crate::lightning_types::routing::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
+ let mut local_features = crate::lightning_types::features::Bolt11InvoiceFeatures { inner: if features.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features.unwrap())) } }, is_owned: true };
+ Payee::Clear {
+ node_id: crate::c_types::PublicKey::from_rust(&node_id),
+ route_hints: local_route_hints.into(),
+ features: local_features,
+ final_cltv_expiry_delta: final_cltv_expiry_delta,
+ }
+ },
+ }
+ }
+}
+/// Frees any resources used by the Payee
+#[no_mangle]
+pub extern "C" fn Payee_free(this_ptr: Payee) { }
+/// Creates a copy of the Payee
+#[no_mangle]
+pub extern "C" fn Payee_clone(orig: &Payee) -> Payee {
+ orig.clone()
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn Payee_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Payee)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn Payee_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut Payee) };
+}
+#[no_mangle]
+/// Utility method to constructs a new Blinded-variant Payee
+pub extern "C" fn Payee_blinded(route_hints: crate::c_types::derived::CVec_BlindedPaymentPathZ, features: crate::lightning_types::features::Bolt12InvoiceFeatures) -> Payee {
+ Payee::Blinded {
+ route_hints,
+ features,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new Clear-variant Payee
+pub extern "C" fn Payee_clear(node_id: crate::c_types::PublicKey, route_hints: crate::c_types::derived::CVec_RouteHintZ, features: crate::lightning_types::features::Bolt11InvoiceFeatures, final_cltv_expiry_delta: u32) -> Payee {
+ Payee::Clear {
+ node_id,
+ route_hints,
+ features,
+ final_cltv_expiry_delta,
+ }
+}
+/// Get a string which allows debug introspection of a Payee object
+pub extern "C" fn Payee_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::Payee }).into()}
+/// Generates a non-cryptographic 64-bit hash of the Payee.
+#[no_mangle]
+pub extern "C" fn Payee_hash(o: &Payee) -> u64 {
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(&o.to_native(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
+/// Checks if two Payees contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn Payee_eq(a: &Payee, b: &Payee) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+#[no_mangle]
+/// Serialize the RouteHint object into a byte array which can be read by RouteHint_read
+pub extern "C" fn RouteHint_write(obj: &crate::lightning_types::routing::RouteHint) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
+}
+#[allow(unused)]
+pub(crate) extern "C" fn RouteHint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning_types::routing::nativeRouteHint) })
+}
+#[no_mangle]
+/// Read a RouteHint from a byte array, created by RouteHint_write
+pub extern "C" fn RouteHint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintDecodeErrorZ {
+ let res: Result<lightning_types::routing::RouteHint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
+ let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_types::routing::RouteHint { 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() };
+ local_res
+}
+#[no_mangle]
+/// Serialize the RouteHintHop object into a byte array which can be read by RouteHintHop_read
+pub extern "C" fn RouteHintHop_write(obj: &crate::lightning_types::routing::RouteHintHop) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
+}
+#[allow(unused)]
+pub(crate) extern "C" fn RouteHintHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning_types::routing::nativeRouteHintHop) })
+}
+#[no_mangle]
+/// Read a RouteHintHop from a byte array, created by RouteHintHop_write
+pub extern "C" fn RouteHintHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintHopDecodeErrorZ {
+ let res: Result<lightning_types::routing::RouteHintHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
+ let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning_types::routing::RouteHintHop { 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() };
+ local_res
+}
+
+use lightning::routing::router::FirstHopCandidate as nativeFirstHopCandidateImport;
+pub(crate) type nativeFirstHopCandidate = nativeFirstHopCandidateImport<'static, >;
+
+/// A [`CandidateRouteHop::FirstHop`] entry.
+#[must_use]
+#[repr(C)]
+pub struct FirstHopCandidate {
+ /// A pointer to the opaque Rust object.
+
+ /// Nearly everywhere, inner must be non-null, however in places where
+ /// the Rust equivalent takes an Option, it may be set to null to indicate None.
+ pub inner: *mut nativeFirstHopCandidate,
+ /// Indicates that this is the only struct which contains the same pointer.
+
+ /// Rust functions which take ownership of an object provided via an argument require
+ /// this to be true and invalidate the object pointed to by inner.
+ pub is_owned: bool,
+}
+
+impl core::ops::Deref for FirstHopCandidate {
+ type Target = nativeFirstHopCandidate;
+ fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } }
+}
+unsafe impl core::marker::Send for FirstHopCandidate { }
+unsafe impl core::marker::Sync for FirstHopCandidate { }
+impl Drop for FirstHopCandidate {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativeFirstHopCandidate>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the FirstHopCandidate, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn FirstHopCandidate_free(this_obj: FirstHopCandidate) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn FirstHopCandidate_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeFirstHopCandidate) };
+}
+#[allow(unused)]
+impl FirstHopCandidate {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeFirstHopCandidate {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFirstHopCandidate {
+ unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
+ }
+ /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
+ pub(crate) fn take_inner(mut self) -> *mut nativeFirstHopCandidate {
+ assert!(self.is_owned);
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
+ ret
+ }
+ pub(crate) fn as_ref_to(&self) -> Self {
+ Self { inner: self.inner, is_owned: false }
+ }
+}
+impl Clone for FirstHopCandidate {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativeFirstHopCandidate>::is_null(self.inner) { core::ptr::null_mut() } else {
+ ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
+ is_owned: true,
+ }
+ }
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn FirstHopCandidate_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeFirstHopCandidate)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the FirstHopCandidate
+pub extern "C" fn FirstHopCandidate_clone(orig: &FirstHopCandidate) -> FirstHopCandidate {
+ orig.clone()
+}
+/// Get a string which allows debug introspection of a FirstHopCandidate object
+pub extern "C" fn FirstHopCandidate_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::FirstHopCandidate }).into()}
+
+use lightning::routing::router::PublicHopCandidate as nativePublicHopCandidateImport;
+pub(crate) type nativePublicHopCandidate = nativePublicHopCandidateImport<'static, >;
+
+/// A [`CandidateRouteHop::PublicHop`] entry.
+#[must_use]
+#[repr(C)]
+pub struct PublicHopCandidate {
+ /// A pointer to the opaque Rust object.
+
+ /// Nearly everywhere, inner must be non-null, however in places where
+ /// the Rust equivalent takes an Option, it may be set to null to indicate None.
+ pub inner: *mut nativePublicHopCandidate,
+ /// Indicates that this is the only struct which contains the same pointer.
+
+ /// Rust functions which take ownership of an object provided via an argument require
+ /// this to be true and invalidate the object pointed to by inner.
+ pub is_owned: bool,
+}
+
+impl core::ops::Deref for PublicHopCandidate {
+ type Target = nativePublicHopCandidate;
+ fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } }
+}
+unsafe impl core::marker::Send for PublicHopCandidate { }
+unsafe impl core::marker::Sync for PublicHopCandidate { }
+impl Drop for PublicHopCandidate {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativePublicHopCandidate>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the PublicHopCandidate, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn PublicHopCandidate_free(this_obj: PublicHopCandidate) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn PublicHopCandidate_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativePublicHopCandidate) };
+}
+#[allow(unused)]
+impl PublicHopCandidate {
+ pub(crate) fn get_native_ref(&self) -> &'static nativePublicHopCandidate {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePublicHopCandidate {
+ unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
+ }
+ /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
+ pub(crate) fn take_inner(mut self) -> *mut nativePublicHopCandidate {
+ assert!(self.is_owned);
+ let ret = ObjOps::untweak_ptr(self.inner);
+ self.inner = core::ptr::null_mut();
+ ret
+ }
+ pub(crate) fn as_ref_to(&self) -> Self {
+ Self { inner: self.inner, is_owned: false }
+ }
+}
+/// The short channel ID of the channel, i.e. the identifier by which we refer to this
+/// channel.
+#[no_mangle]
+pub extern "C" fn PublicHopCandidate_get_short_channel_id(this_ptr: &PublicHopCandidate) -> u64 {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
+ *inner_val
+}
+/// The short channel ID of the channel, i.e. the identifier by which we refer to this
+/// channel.
+#[no_mangle]
+pub extern "C" fn PublicHopCandidate_set_short_channel_id(this_ptr: &mut PublicHopCandidate, mut val: u64) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
+}
+impl Clone for PublicHopCandidate {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativePublicHopCandidate>::is_null(self.inner) { core::ptr::null_mut() } else {