+/// Note that route_params_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Route_new(mut paths_arg: crate::c_types::derived::CVec_PathZ, mut route_params_arg: crate::lightning::routing::router::RouteParameters) -> Route {
+ let mut local_paths_arg = Vec::new(); for mut item in paths_arg.into_rust().drain(..) { local_paths_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
+ let mut local_route_params_arg = if route_params_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(route_params_arg.take_inner()) } }) };
+ Route { inner: ObjOps::heap_alloc(nativeRoute {
+ paths: local_paths_arg,
+ route_params: local_route_params_arg,
+ }), is_owned: true }
+}
+impl Clone for Route {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativeRoute>::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 Route_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRoute)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the Route
+pub extern "C" fn Route_clone(orig: &Route) -> Route {
+ orig.clone()
+}
+/// Get a string which allows debug introspection of a Route object
+pub extern "C" fn Route_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::Route }).into()}
+/// Generates a non-cryptographic 64-bit hash of the Route.
+#[no_mangle]
+pub extern "C" fn Route_hash(o: &Route) -> 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 Routes 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 Route_eq(a: &Route, b: &Route) -> 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 }
+}
+/// Returns the total amount of fees paid on this [`Route`].
+///
+/// For objects serialized with LDK 0.0.117 and after, this includes any extra payment made to
+/// the recipient, which can happen in excess of the amount passed to [`find_route`] via
+/// [`RouteParameters::final_value_msat`], if we had to reach the [`htlc_minimum_msat`] limits.
+///
+/// [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Route_get_total_fees(this_arg: &crate::lightning::routing::router::Route) -> u64 {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_fees();
+ ret
+}
+
+/// Returns the total amount paid on this [`Route`], excluding the fees.
+///
+/// Might be more than requested as part of the given [`RouteParameters::final_value_msat`] if
+/// we had to reach the [`htlc_minimum_msat`] limits.
+///
+/// [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
+#[must_use]
+#[no_mangle]
+pub extern "C" fn Route_get_total_amount(this_arg: &crate::lightning::routing::router::Route) -> u64 {
+ let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_amount();
+ ret
+}
+
+#[no_mangle]
+/// Get the string representation of a Route object
+pub extern "C" fn Route_to_str(o: &crate::lightning::routing::router::Route) -> Str {
+ alloc::format!("{}", o.get_native_ref()).into()
+}
+#[no_mangle]
+/// Serialize the Route object into a byte array which can be read by Route_read
+pub extern "C" fn Route_write(obj: &crate::lightning::routing::router::Route) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
+}
+#[allow(unused)]
+pub(crate) extern "C" fn Route_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::nativeRoute) })
+}
+#[no_mangle]
+/// Read a Route from a byte array, created by Route_write
+pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ {
+ let res: Result<lightning::routing::router::Route, 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::Route { 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::RouteParameters as nativeRouteParametersImport;
+pub(crate) type nativeRouteParameters = nativeRouteParametersImport;
+
+/// Parameters needed to find a [`Route`].
+///
+/// Passed to [`find_route`] and [`build_route_from_hops`].
+#[must_use]
+#[repr(C)]
+pub struct RouteParameters {
+ /// 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 nativeRouteParameters,
+ /// 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 RouteParameters {
+ type Target = nativeRouteParameters;
+ fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } }
+}
+unsafe impl core::marker::Send for RouteParameters { }
+unsafe impl core::marker::Sync for RouteParameters { }
+impl Drop for RouteParameters {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativeRouteParameters>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the RouteParameters, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn RouteParameters_free(this_obj: RouteParameters) { }
+#[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_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteParameters) };
+}
+#[allow(unused)]
+impl RouteParameters {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeRouteParameters {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteParameters {
+ 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 nativeRouteParameters {
+ 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 parameters of the failed payment path.
+#[no_mangle]
+pub extern "C" fn RouteParameters_get_payment_params(this_ptr: &RouteParameters) -> crate::lightning::routing::router::PaymentParameters {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_params;
+ crate::lightning::routing::router::PaymentParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::router::PaymentParameters<>) as *mut _) }, is_owned: false }
+}
+/// The parameters of the failed payment path.
+#[no_mangle]
+pub extern "C" fn RouteParameters_set_payment_params(this_ptr: &mut RouteParameters, mut val: crate::lightning::routing::router::PaymentParameters) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_params = *unsafe { Box::from_raw(val.take_inner()) };
+}
+/// The amount in msats sent on the failed payment path.
+#[no_mangle]
+pub extern "C" fn RouteParameters_get_final_value_msat(this_ptr: &RouteParameters) -> u64 {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
+ *inner_val
+}
+/// The amount in msats sent on the failed payment path.
+#[no_mangle]
+pub extern "C" fn RouteParameters_set_final_value_msat(this_ptr: &mut RouteParameters, mut val: u64) {
+ unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
+}
+/// The maximum total fees, in millisatoshi, that may accrue during route finding.
+///
+/// This limit also applies to the total fees that may arise while retrying failed payment
+/// paths.
+///
+/// Note that values below a few sats may result in some paths being spuriously ignored.
+#[no_mangle]
+pub extern "C" fn RouteParameters_get_max_total_routing_fee_msat(this_ptr: &RouteParameters) -> crate::c_types::derived::COption_u64Z {
+ let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_routing_fee_msat;
+ 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
+}
+/// The maximum total fees, in millisatoshi, that may accrue during route finding.
+///
+/// This limit also applies to the total fees that may arise while retrying failed payment
+/// paths.
+///
+/// Note that values below a few sats may result in some paths being spuriously ignored.
+#[no_mangle]
+pub extern "C" fn RouteParameters_set_max_total_routing_fee_msat(this_ptr: &mut RouteParameters, 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) }.max_total_routing_fee_msat = local_val;
+}
+/// Constructs a new RouteParameters given each field
+#[must_use]
+#[no_mangle]
+pub extern "C" fn RouteParameters_new(mut payment_params_arg: crate::lightning::routing::router::PaymentParameters, mut final_value_msat_arg: u64, mut max_total_routing_fee_msat_arg: crate::c_types::derived::COption_u64Z) -> RouteParameters {
+ let mut local_max_total_routing_fee_msat_arg = if max_total_routing_fee_msat_arg.is_some() { Some( { max_total_routing_fee_msat_arg.take() }) } else { None };
+ RouteParameters { inner: ObjOps::heap_alloc(nativeRouteParameters {
+ payment_params: *unsafe { Box::from_raw(payment_params_arg.take_inner()) },
+ final_value_msat: final_value_msat_arg,
+ max_total_routing_fee_msat: local_max_total_routing_fee_msat_arg,
+ }), is_owned: true }
+}
+impl Clone for RouteParameters {
+ fn clone(&self) -> Self {
+ Self {
+ 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 {
+ 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 PublicHopCandidate_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePublicHopCandidate)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the PublicHopCandidate
+pub extern "C" fn PublicHopCandidate_clone(orig: &PublicHopCandidate) -> PublicHopCandidate {
+ orig.clone()
+}
+/// Get a string which allows debug introspection of a PublicHopCandidate object
+pub extern "C" fn PublicHopCandidate_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::PublicHopCandidate }).into()}
+
+use lightning::routing::router::PrivateHopCandidate as nativePrivateHopCandidateImport;
+pub(crate) type nativePrivateHopCandidate = nativePrivateHopCandidateImport<'static, >;
+
+/// A [`CandidateRouteHop::PrivateHop`] entry.
+#[must_use]
+#[repr(C)]
+pub struct PrivateHopCandidate {
+ /// 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 nativePrivateHopCandidate,
+ /// 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 PrivateHopCandidate {
+ type Target = nativePrivateHopCandidate;
+ fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } }
+}
+unsafe impl core::marker::Send for PrivateHopCandidate { }
+unsafe impl core::marker::Sync for PrivateHopCandidate { }
+impl Drop for PrivateHopCandidate {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativePrivateHopCandidate>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the PrivateHopCandidate, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn PrivateHopCandidate_free(this_obj: PrivateHopCandidate) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn PrivateHopCandidate_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativePrivateHopCandidate) };
+}
+#[allow(unused)]
+impl PrivateHopCandidate {
+ pub(crate) fn get_native_ref(&self) -> &'static nativePrivateHopCandidate {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateHopCandidate {
+ 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 nativePrivateHopCandidate {
+ 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 PrivateHopCandidate {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativePrivateHopCandidate>::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 PrivateHopCandidate_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePrivateHopCandidate)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the PrivateHopCandidate
+pub extern "C" fn PrivateHopCandidate_clone(orig: &PrivateHopCandidate) -> PrivateHopCandidate {
+ orig.clone()
+}
+/// Get a string which allows debug introspection of a PrivateHopCandidate object
+pub extern "C" fn PrivateHopCandidate_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::PrivateHopCandidate }).into()}
+
+use lightning::routing::router::BlindedPathCandidate as nativeBlindedPathCandidateImport;
+pub(crate) type nativeBlindedPathCandidate = nativeBlindedPathCandidateImport<'static, >;
+
+/// A [`CandidateRouteHop::Blinded`] entry.
+#[must_use]
+#[repr(C)]
+pub struct BlindedPathCandidate {
+ /// 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 nativeBlindedPathCandidate,
+ /// 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 BlindedPathCandidate {
+ type Target = nativeBlindedPathCandidate;
+ fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } }
+}
+unsafe impl core::marker::Send for BlindedPathCandidate { }
+unsafe impl core::marker::Sync for BlindedPathCandidate { }
+impl Drop for BlindedPathCandidate {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativeBlindedPathCandidate>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the BlindedPathCandidate, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn BlindedPathCandidate_free(this_obj: BlindedPathCandidate) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn BlindedPathCandidate_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedPathCandidate) };
+}
+#[allow(unused)]
+impl BlindedPathCandidate {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedPathCandidate {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedPathCandidate {
+ 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 nativeBlindedPathCandidate {
+ 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 BlindedPathCandidate {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativeBlindedPathCandidate>::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 BlindedPathCandidate_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedPathCandidate)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the BlindedPathCandidate
+pub extern "C" fn BlindedPathCandidate_clone(orig: &BlindedPathCandidate) -> BlindedPathCandidate {
+ orig.clone()
+}
+/// Get a string which allows debug introspection of a BlindedPathCandidate object
+pub extern "C" fn BlindedPathCandidate_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::BlindedPathCandidate }).into()}
+
+use lightning::routing::router::OneHopBlindedPathCandidate as nativeOneHopBlindedPathCandidateImport;
+pub(crate) type nativeOneHopBlindedPathCandidate = nativeOneHopBlindedPathCandidateImport<'static, >;
+
+/// A [`CandidateRouteHop::OneHopBlinded`] entry.
+#[must_use]
+#[repr(C)]
+pub struct OneHopBlindedPathCandidate {
+ /// 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 nativeOneHopBlindedPathCandidate,
+ /// 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 OneHopBlindedPathCandidate {
+ type Target = nativeOneHopBlindedPathCandidate;
+ fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } }
+}
+unsafe impl core::marker::Send for OneHopBlindedPathCandidate { }
+unsafe impl core::marker::Sync for OneHopBlindedPathCandidate { }
+impl Drop for OneHopBlindedPathCandidate {
+ fn drop(&mut self) {
+ if self.is_owned && !<*mut nativeOneHopBlindedPathCandidate>::is_null(self.inner) {
+ let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
+ }
+ }
+}
+/// Frees any resources used by the OneHopBlindedPathCandidate, if is_owned is set and inner is non-NULL.
+#[no_mangle]
+pub extern "C" fn OneHopBlindedPathCandidate_free(this_obj: OneHopBlindedPathCandidate) { }
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn OneHopBlindedPathCandidate_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOneHopBlindedPathCandidate) };
+}
+#[allow(unused)]
+impl OneHopBlindedPathCandidate {
+ pub(crate) fn get_native_ref(&self) -> &'static nativeOneHopBlindedPathCandidate {
+ unsafe { &*ObjOps::untweak_ptr(self.inner) }
+ }
+ pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOneHopBlindedPathCandidate {
+ 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 nativeOneHopBlindedPathCandidate {
+ 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 OneHopBlindedPathCandidate {
+ fn clone(&self) -> Self {
+ Self {
+ inner: if <*mut nativeOneHopBlindedPathCandidate>::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 OneHopBlindedPathCandidate_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOneHopBlindedPathCandidate)).clone() })) as *mut c_void
+}
+#[no_mangle]
+/// Creates a copy of the OneHopBlindedPathCandidate
+pub extern "C" fn OneHopBlindedPathCandidate_clone(orig: &OneHopBlindedPathCandidate) -> OneHopBlindedPathCandidate {
+ orig.clone()
+}
+/// Get a string which allows debug introspection of a OneHopBlindedPathCandidate object
+pub extern "C" fn OneHopBlindedPathCandidate_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::OneHopBlindedPathCandidate }).into()}
+/// A wrapper around the various hop representations.
+///
+/// Can be used to examine the properties of a hop,
+/// potentially to decide whether to include it in a route.
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum CandidateRouteHop {
+ /// A hop from the payer, where the outbound liquidity is known.
+ FirstHop(
+ crate::lightning::routing::router::FirstHopCandidate),
+ /// A hop found in the [`ReadOnlyNetworkGraph`].
+ PublicHop(
+ crate::lightning::routing::router::PublicHopCandidate),
+ /// A private hop communicated by the payee, generally via a BOLT 11 invoice.
+ ///
+ /// Because BOLT 11 route hints can take multiple hops to get to the destination, this may not
+ /// terminate at the payee.
+ PrivateHop(
+ crate::lightning::routing::router::PrivateHopCandidate),
+ /// A blinded path which starts with an introduction point and ultimately terminates with the
+ /// payee.
+ ///
+ /// Because we don't know the payee's identity, [`CandidateRouteHop::target`] will return
+ /// `None` in this state.
+ ///
+ /// Because blinded paths are \"all or nothing\", and we cannot use just one part of a blinded
+ /// path, the full path is treated as a single [`CandidateRouteHop`].
+ Blinded(
+ crate::lightning::routing::router::BlindedPathCandidate),
+ /// Similar to [`Self::Blinded`], but the path here only has one hop.
+ ///
+ /// While we treat this similarly to [`CandidateRouteHop::Blinded`] in many respects (e.g.
+ /// returning `None` from [`CandidateRouteHop::target`]), in this case we do actually know the
+ /// payee's identity - it's the introduction point!
+ ///
+ /// [`BlindedPayInfo`] provided for 1-hop blinded paths is ignored because it is meant to apply
+ /// to the hops *between* the introduction node and the destination.
+ ///
+ /// This primarily exists to track that we need to included a blinded path at the end of our
+ /// [`Route`], even though it doesn't actually add an additional hop in the payment.
+ ///
+ /// [`BlindedPayInfo`]: crate::blinded_path::payment::BlindedPayInfo
+ OneHopBlinded(
+ crate::lightning::routing::router::OneHopBlindedPathCandidate),
+}
+use lightning::routing::router::CandidateRouteHop as CandidateRouteHopImport;
+pub(crate) type nativeCandidateRouteHop = CandidateRouteHopImport<'static, >;
+
+impl CandidateRouteHop {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeCandidateRouteHop {
+ match self {
+ CandidateRouteHop::FirstHop (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeCandidateRouteHop::FirstHop (
+ *unsafe { Box::from_raw(a_nonref.take_inner()) },
+ )
+ },
+ CandidateRouteHop::PublicHop (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeCandidateRouteHop::PublicHop (
+ *unsafe { Box::from_raw(a_nonref.take_inner()) },
+ )
+ },
+ CandidateRouteHop::PrivateHop (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeCandidateRouteHop::PrivateHop (
+ *unsafe { Box::from_raw(a_nonref.take_inner()) },
+ )
+ },
+ CandidateRouteHop::Blinded (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeCandidateRouteHop::Blinded (
+ *unsafe { Box::from_raw(a_nonref.take_inner()) },
+ )
+ },
+ CandidateRouteHop::OneHopBlinded (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeCandidateRouteHop::OneHopBlinded (
+ *unsafe { Box::from_raw(a_nonref.take_inner()) },
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeCandidateRouteHop {
+ match self {
+ CandidateRouteHop::FirstHop (mut a, ) => {
+ nativeCandidateRouteHop::FirstHop (
+ *unsafe { Box::from_raw(a.take_inner()) },
+ )
+ },
+ CandidateRouteHop::PublicHop (mut a, ) => {
+ nativeCandidateRouteHop::PublicHop (
+ *unsafe { Box::from_raw(a.take_inner()) },
+ )
+ },
+ CandidateRouteHop::PrivateHop (mut a, ) => {
+ nativeCandidateRouteHop::PrivateHop (
+ *unsafe { Box::from_raw(a.take_inner()) },
+ )
+ },
+ CandidateRouteHop::Blinded (mut a, ) => {
+ nativeCandidateRouteHop::Blinded (
+ *unsafe { Box::from_raw(a.take_inner()) },
+ )
+ },
+ CandidateRouteHop::OneHopBlinded (mut a, ) => {
+ nativeCandidateRouteHop::OneHopBlinded (
+ *unsafe { Box::from_raw(a.take_inner()) },
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &CandidateRouteHopImport<'_, >) -> Self {
+ let native = unsafe { &*(native as *const _ as *const c_void as *const nativeCandidateRouteHop) };
+ match native {
+ nativeCandidateRouteHop::FirstHop (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ CandidateRouteHop::FirstHop (
+ crate::lightning::routing::router::FirstHopCandidate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
+ )
+ },
+ nativeCandidateRouteHop::PublicHop (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ CandidateRouteHop::PublicHop (
+ crate::lightning::routing::router::PublicHopCandidate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
+ )
+ },
+ nativeCandidateRouteHop::PrivateHop (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ CandidateRouteHop::PrivateHop (
+ crate::lightning::routing::router::PrivateHopCandidate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
+ )
+ },
+ nativeCandidateRouteHop::Blinded (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ CandidateRouteHop::Blinded (
+ crate::lightning::routing::router::BlindedPathCandidate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
+ )
+ },
+ nativeCandidateRouteHop::OneHopBlinded (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ CandidateRouteHop::OneHopBlinded (
+ crate::lightning::routing::router::OneHopBlindedPathCandidate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeCandidateRouteHop) -> Self {
+ match native {
+ nativeCandidateRouteHop::FirstHop (mut a, ) => {
+ CandidateRouteHop::FirstHop (
+ crate::lightning::routing::router::FirstHopCandidate { inner: ObjOps::heap_alloc(a), is_owned: true },
+ )
+ },
+ nativeCandidateRouteHop::PublicHop (mut a, ) => {
+ CandidateRouteHop::PublicHop (
+ crate::lightning::routing::router::PublicHopCandidate { inner: ObjOps::heap_alloc(a), is_owned: true },
+ )
+ },
+ nativeCandidateRouteHop::PrivateHop (mut a, ) => {
+ CandidateRouteHop::PrivateHop (
+ crate::lightning::routing::router::PrivateHopCandidate { inner: ObjOps::heap_alloc(a), is_owned: true },
+ )
+ },
+ nativeCandidateRouteHop::Blinded (mut a, ) => {
+ CandidateRouteHop::Blinded (
+ crate::lightning::routing::router::BlindedPathCandidate { inner: ObjOps::heap_alloc(a), is_owned: true },
+ )
+ },
+ nativeCandidateRouteHop::OneHopBlinded (mut a, ) => {
+ CandidateRouteHop::OneHopBlinded (
+ crate::lightning::routing::router::OneHopBlindedPathCandidate { inner: ObjOps::heap_alloc(a), is_owned: true },
+ )
+ },
+ }
+ }
+}
+/// Frees any resources used by the CandidateRouteHop
+#[no_mangle]
+pub extern "C" fn CandidateRouteHop_free(this_ptr: CandidateRouteHop) { }
+/// Creates a copy of the CandidateRouteHop
+#[no_mangle]
+pub extern "C" fn CandidateRouteHop_clone(orig: &CandidateRouteHop) -> CandidateRouteHop {
+ 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 CandidateRouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const CandidateRouteHop)).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 CandidateRouteHop_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut CandidateRouteHop) };
+}
+#[no_mangle]
+/// Utility method to constructs a new FirstHop-variant CandidateRouteHop
+pub extern "C" fn CandidateRouteHop_first_hop(a: crate::lightning::routing::router::FirstHopCandidate) -> CandidateRouteHop {
+ CandidateRouteHop::FirstHop(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new PublicHop-variant CandidateRouteHop
+pub extern "C" fn CandidateRouteHop_public_hop(a: crate::lightning::routing::router::PublicHopCandidate) -> CandidateRouteHop {
+ CandidateRouteHop::PublicHop(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new PrivateHop-variant CandidateRouteHop
+pub extern "C" fn CandidateRouteHop_private_hop(a: crate::lightning::routing::router::PrivateHopCandidate) -> CandidateRouteHop {
+ CandidateRouteHop::PrivateHop(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new Blinded-variant CandidateRouteHop
+pub extern "C" fn CandidateRouteHop_blinded(a: crate::lightning::routing::router::BlindedPathCandidate) -> CandidateRouteHop {
+ CandidateRouteHop::Blinded(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new OneHopBlinded-variant CandidateRouteHop
+pub extern "C" fn CandidateRouteHop_one_hop_blinded(a: crate::lightning::routing::router::OneHopBlindedPathCandidate) -> CandidateRouteHop {
+ CandidateRouteHop::OneHopBlinded(a, )
+}
+/// Get a string which allows debug introspection of a CandidateRouteHop object
+pub extern "C" fn CandidateRouteHop_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::CandidateRouteHop }).into()}
+/// Returns the globally unique short channel ID for this hop, if one is known.
+///
+/// This only returns `Some` if the channel is public (either our own, or one we've learned
+/// from the public network graph), and thus the short channel ID we have for this channel is
+/// globally unique and identifies this channel in a global namespace.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn CandidateRouteHop_globally_unique_short_channel_id(this_arg: &crate::lightning::routing::router::CandidateRouteHop) -> crate::c_types::derived::COption_u64Z {
+ let mut ret = this_arg.to_native().globally_unique_short_channel_id();
+ let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap() }) };
+ local_ret
+}
+
+/// Returns the required difference in HTLC CLTV expiry between the [`Self::source`] and the
+/// next-hop for an HTLC taking this hop.
+///
+/// This is the time that the node(s) in this hop have to claim the HTLC on-chain if the
+/// next-hop goes on chain with a payment preimage.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn CandidateRouteHop_cltv_expiry_delta(this_arg: &crate::lightning::routing::router::CandidateRouteHop) -> u32 {
+ let mut ret = this_arg.to_native().cltv_expiry_delta();
+ ret
+}
+
+/// Returns the minimum amount that can be sent over this hop, in millisatoshis.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn CandidateRouteHop_htlc_minimum_msat(this_arg: &crate::lightning::routing::router::CandidateRouteHop) -> u64 {
+ let mut ret = this_arg.to_native().htlc_minimum_msat();
+ ret
+}
+
+/// Returns the fees that must be paid to route an HTLC over this channel.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn CandidateRouteHop_fees(this_arg: &crate::lightning::routing::router::CandidateRouteHop) -> crate::lightning_types::routing::RoutingFees {
+ let mut ret = this_arg.to_native().fees();
+ crate::lightning_types::routing::RoutingFees { inner: ObjOps::heap_alloc(ret), is_owned: true }
+}
+
+/// Returns the source node id of current hop.
+///
+/// Source node id refers to the node forwarding the HTLC through this hop.
+///
+/// For [`Self::FirstHop`] we return payer's node id.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn CandidateRouteHop_source(this_arg: &crate::lightning::routing::router::CandidateRouteHop) -> crate::lightning::routing::gossip::NodeId {
+ let mut ret = this_arg.to_native().source();
+ crate::lightning::routing::gossip::NodeId { inner: ObjOps::heap_alloc(ret), is_owned: true }
+}
+
+/// Returns the target node id of this hop, if known.
+///
+/// Target node id refers to the node receiving the HTLC after this hop.
+///
+/// For [`Self::Blinded`] we return `None` because the ultimate destination after the blinded
+/// path is unknown.
+///
+/// For [`Self::OneHopBlinded`] we return `None` because the target is the same as the source,
+/// and such a return value would be somewhat nonsensical.
+///
+/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
+#[must_use]
+#[no_mangle]
+pub extern "C" fn CandidateRouteHop_target(this_arg: &crate::lightning::routing::router::CandidateRouteHop) -> crate::lightning::routing::gossip::NodeId {
+ let mut ret = this_arg.to_native().target();
+ let mut local_ret = crate::lightning::routing::gossip::NodeId { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true };
+ local_ret
+}
+
+/// Finds a route from us (payer) to the given target node (payee).
+///
+/// If the payee provided features in their invoice, they should be provided via the `payee` field
+/// in the given [`RouteParameters::payment_params`].
+/// Without this, MPP will only be used if the payee's features are available in the network graph.
+///
+/// Private routing paths between a public node and the target may be included in the `payee` field
+/// of [`RouteParameters::payment_params`].
+///
+/// If some channels aren't announced, it may be useful to fill in `first_hops` with the results
+/// from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
+/// from `network_graph` will be ignored, and only those in `first_hops` will be used.
+///
+/// The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
+/// However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
+/// `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
+///
+/// # Panics
+///
+/// Panics if first_hops contains channels without `short_channel_id`s;
+/// [`ChannelManager::list_usable_channels`] will never include such channels.
+///
+/// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
+/// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
+/// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
+///
+/// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
+#[no_mangle]
+pub extern "C" fn find_route(mut our_node_pubkey: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, network_graph: &crate::lightning::routing::gossip::NetworkGraph, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut logger: crate::lightning::util::logger::Logger, scorer: &crate::lightning::routing::scoring::ScoreLookUp, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
+ let mut local_first_hops_base = if first_hops == core::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { item.get_native_ref() }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]);
+ let mut ret = lightning::routing::router::find_route::<crate::lightning::util::logger::Logger, crate::lightning::util::logger::Logger, crate::lightning::routing::scoring::ScoreLookUp, >(&our_node_pubkey.into_rust(), route_params.get_native_ref(), network_graph.get_native_ref(), local_first_hops, logger, scorer, score_params.get_native_ref(), unsafe { &*random_seed_bytes});
+ let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
+ local_ret
+}
+
+/// Construct a route from us (payer) to the target node (payee) via the given hops (which should
+/// exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.