1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! The router finds paths within a [`NetworkGraph`] for a payment.
11 use alloc::str::FromStr;
12 use core::ffi::c_void;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
16 #[cfg(feature="no-std")]
17 use alloc::{vec::Vec, boxed::Box};
20 use lightning::routing::router::DefaultRouter as nativeDefaultRouterImport;
21 pub(crate) type nativeDefaultRouter = nativeDefaultRouterImport<&'static lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, crate::lightning::util::logger::Logger, crate::lightning::routing::scoring::LockableScore>;
23 /// A [`Router`] implemented using [`find_route`].
26 pub struct DefaultRouter {
27 /// A pointer to the opaque Rust object.
29 /// Nearly everywhere, inner must be non-null, however in places where
30 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
31 pub inner: *mut nativeDefaultRouter,
32 /// Indicates that this is the only struct which contains the same pointer.
34 /// Rust functions which take ownership of an object provided via an argument require
35 /// this to be true and invalidate the object pointed to by inner.
39 impl Drop for DefaultRouter {
41 if self.is_owned && !<*mut nativeDefaultRouter>::is_null(self.inner) {
42 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
46 /// Frees any resources used by the DefaultRouter, if is_owned is set and inner is non-NULL.
48 pub extern "C" fn DefaultRouter_free(this_obj: DefaultRouter) { }
50 /// Used only if an object of this type is returned as a trait impl by a method
51 pub(crate) extern "C" fn DefaultRouter_free_void(this_ptr: *mut c_void) {
52 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDefaultRouter) };
56 pub(crate) fn get_native_ref(&self) -> &'static nativeDefaultRouter {
57 unsafe { &*ObjOps::untweak_ptr(self.inner) }
59 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDefaultRouter {
60 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
62 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
63 pub(crate) fn take_inner(mut self) -> *mut nativeDefaultRouter {
64 assert!(self.is_owned);
65 let ret = ObjOps::untweak_ptr(self.inner);
66 self.inner = core::ptr::null_mut();
70 /// Creates a new router.
73 pub extern "C" fn DefaultRouter_new(network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut logger: crate::lightning::util::logger::Logger, mut random_seed_bytes: crate::c_types::ThirtyTwoBytes, mut scorer: crate::lightning::routing::scoring::LockableScore, mut score_params: crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> crate::lightning::routing::router::DefaultRouter {
74 let mut ret = lightning::routing::router::DefaultRouter::new(network_graph.get_native_ref(), logger, random_seed_bytes.data, scorer, *unsafe { Box::from_raw(score_params.take_inner()) });
75 crate::lightning::routing::router::DefaultRouter { inner: ObjOps::heap_alloc(ret), is_owned: true }
78 impl From<nativeDefaultRouter> for crate::lightning::routing::router::Router {
79 fn from(obj: nativeDefaultRouter) -> Self {
80 let mut rust_obj = DefaultRouter { inner: ObjOps::heap_alloc(obj), is_owned: true };
81 let mut ret = DefaultRouter_as_Router(&rust_obj);
82 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
83 rust_obj.inner = core::ptr::null_mut();
84 ret.free = Some(DefaultRouter_free_void);
88 /// Constructs a new Router which calls the relevant methods on this_arg.
89 /// This copies the `inner` pointer in this_arg and thus the returned Router must be freed before this_arg is
91 pub extern "C" fn DefaultRouter_as_Router(this_arg: &DefaultRouter) -> crate::lightning::routing::router::Router {
92 crate::lightning::routing::router::Router {
93 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
95 find_route: DefaultRouter_Router_find_route,
96 find_route_with_id: DefaultRouter_Router_find_route_with_id,
101 extern "C" fn DefaultRouter_Router_find_route(this_arg: *const c_void, mut payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
102 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[..]);
103 let mut ret = <nativeDefaultRouter as lightning::routing::router::Router<>>::find_route(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &payer.into_rust(), route_params.get_native_ref(), local_first_hops, *unsafe { Box::from_raw(inflight_htlcs.take_inner()) });
104 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() };
108 extern "C" fn DefaultRouter_Router_find_route_with_id(this_arg: *const c_void, mut payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs, mut _payment_hash: crate::c_types::ThirtyTwoBytes, mut _payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
109 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[..]);
110 let mut ret = <nativeDefaultRouter as lightning::routing::router::Router<>>::find_route_with_id(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &payer.into_rust(), route_params.get_native_ref(), local_first_hops, *unsafe { Box::from_raw(inflight_htlcs.take_inner()) }, ::lightning::ln::PaymentHash(_payment_hash.data), ::lightning::ln::channelmanager::PaymentId(_payment_id.data));
111 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() };
115 /// A trait defining behavior for routing a payment.
118 /// An opaque pointer which is passed to your function implementations as an argument.
119 /// This has no meaning in the LDK, and can be NULL or any other value.
120 pub this_arg: *mut c_void,
121 /// Finds a [`Route`] for a payment between the given `payer` and a payee.
123 /// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
124 /// and [`RouteParameters::final_value_msat`], respectively.
126 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
127 pub find_route: extern "C" fn (this_arg: *const c_void, payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CResult_RouteLightningErrorZ,
128 /// Finds a [`Route`] for a payment between the given `payer` and a payee.
130 /// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
131 /// and [`RouteParameters::final_value_msat`], respectively.
133 /// Includes a [`PaymentHash`] and a [`PaymentId`] to be able to correlate the request with a specific
136 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
137 pub find_route_with_id: extern "C" fn (this_arg: *const c_void, payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs, _payment_hash: crate::c_types::ThirtyTwoBytes, _payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_RouteLightningErrorZ,
138 /// Frees any resources associated with this object given its this_arg pointer.
139 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
140 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
142 unsafe impl Send for Router {}
143 unsafe impl Sync for Router {}
145 pub(crate) extern "C" fn Router_clone_fields(orig: &Router) -> Router {
147 this_arg: orig.this_arg,
148 find_route: Clone::clone(&orig.find_route),
149 find_route_with_id: Clone::clone(&orig.find_route_with_id),
150 free: Clone::clone(&orig.free),
154 use lightning::routing::router::Router as rustRouter;
155 impl rustRouter for Router {
156 fn find_route(&self, mut payer: &bitcoin::secp256k1::PublicKey, mut route_params: &lightning::routing::router::RouteParameters, mut first_hops: Option<&[&lightning::ln::channelmanager::ChannelDetails]>, mut inflight_htlcs: lightning::routing::router::InFlightHtlcs) -> Result<lightning::routing::router::Route, lightning::ln::msgs::LightningError> {
157 let mut local_first_hops_base = if first_hops.is_none() { SmartPtr::null() } else { SmartPtr::from_obj( { let mut local_first_hops_0 = Vec::new(); for item in (first_hops.unwrap()).iter() { local_first_hops_0.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); }; local_first_hops_0.into() }) }; let mut local_first_hops = *local_first_hops_base;
158 let mut ret = (self.find_route)(self.this_arg, crate::c_types::PublicKey::from_rust(&payer), &crate::lightning::routing::router::RouteParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((route_params as *const lightning::routing::router::RouteParameters<>) as *mut _) }, is_owned: false }, local_first_hops, crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(inflight_htlcs), is_owned: true });
159 let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
162 fn find_route_with_id(&self, mut payer: &bitcoin::secp256k1::PublicKey, mut route_params: &lightning::routing::router::RouteParameters, mut first_hops: Option<&[&lightning::ln::channelmanager::ChannelDetails]>, mut inflight_htlcs: lightning::routing::router::InFlightHtlcs, mut _payment_hash: lightning::ln::PaymentHash, mut _payment_id: lightning::ln::channelmanager::PaymentId) -> Result<lightning::routing::router::Route, lightning::ln::msgs::LightningError> {
163 let mut local_first_hops_base = if first_hops.is_none() { SmartPtr::null() } else { SmartPtr::from_obj( { let mut local_first_hops_0 = Vec::new(); for item in (first_hops.unwrap()).iter() { local_first_hops_0.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); }; local_first_hops_0.into() }) }; let mut local_first_hops = *local_first_hops_base;
164 let mut ret = (self.find_route_with_id)(self.this_arg, crate::c_types::PublicKey::from_rust(&payer), &crate::lightning::routing::router::RouteParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((route_params as *const lightning::routing::router::RouteParameters<>) as *mut _) }, is_owned: false }, local_first_hops, crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(inflight_htlcs), is_owned: true }, crate::c_types::ThirtyTwoBytes { data: _payment_hash.0 }, crate::c_types::ThirtyTwoBytes { data: _payment_id.0 });
165 let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
170 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
171 // directly as a Deref trait in higher-level structs:
172 impl core::ops::Deref for Router {
174 fn deref(&self) -> &Self {
178 /// Calls the free function if one is set
180 pub extern "C" fn Router_free(this_ptr: Router) { }
181 impl Drop for Router {
183 if let Some(f) = self.free {
189 use lightning::routing::router::ScorerAccountingForInFlightHtlcs as nativeScorerAccountingForInFlightHtlcsImport;
190 pub(crate) type nativeScorerAccountingForInFlightHtlcs = nativeScorerAccountingForInFlightHtlcsImport<'static, crate::lightning::routing::scoring::Score>;
192 /// [`Score`] implementation that factors in in-flight HTLC liquidity.
194 /// Useful for custom [`Router`] implementations to wrap their [`Score`] on-the-fly when calling
197 /// [`Score`]: crate::routing::scoring::Score
200 pub struct ScorerAccountingForInFlightHtlcs {
201 /// A pointer to the opaque Rust object.
203 /// Nearly everywhere, inner must be non-null, however in places where
204 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
205 pub inner: *mut nativeScorerAccountingForInFlightHtlcs,
206 /// Indicates that this is the only struct which contains the same pointer.
208 /// Rust functions which take ownership of an object provided via an argument require
209 /// this to be true and invalidate the object pointed to by inner.
213 impl Drop for ScorerAccountingForInFlightHtlcs {
215 if self.is_owned && !<*mut nativeScorerAccountingForInFlightHtlcs>::is_null(self.inner) {
216 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
220 /// Frees any resources used by the ScorerAccountingForInFlightHtlcs, if is_owned is set and inner is non-NULL.
222 pub extern "C" fn ScorerAccountingForInFlightHtlcs_free(this_obj: ScorerAccountingForInFlightHtlcs) { }
224 /// Used only if an object of this type is returned as a trait impl by a method
225 pub(crate) extern "C" fn ScorerAccountingForInFlightHtlcs_free_void(this_ptr: *mut c_void) {
226 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeScorerAccountingForInFlightHtlcs) };
229 impl ScorerAccountingForInFlightHtlcs {
230 pub(crate) fn get_native_ref(&self) -> &'static nativeScorerAccountingForInFlightHtlcs {
231 unsafe { &*ObjOps::untweak_ptr(self.inner) }
233 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeScorerAccountingForInFlightHtlcs {
234 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
236 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
237 pub(crate) fn take_inner(mut self) -> *mut nativeScorerAccountingForInFlightHtlcs {
238 assert!(self.is_owned);
239 let ret = ObjOps::untweak_ptr(self.inner);
240 self.inner = core::ptr::null_mut();
244 /// Initialize a new `ScorerAccountingForInFlightHtlcs`.
247 pub extern "C" fn ScorerAccountingForInFlightHtlcs_new(mut scorer: crate::lightning::routing::scoring::Score, inflight_htlcs: &crate::lightning::routing::router::InFlightHtlcs) -> crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs {
248 let mut ret = lightning::routing::router::ScorerAccountingForInFlightHtlcs::new(scorer, inflight_htlcs.get_native_ref());
249 crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
253 /// Serialize the ScorerAccountingForInFlightHtlcs object into a byte array which can be read by ScorerAccountingForInFlightHtlcs_read
254 pub extern "C" fn ScorerAccountingForInFlightHtlcs_write(obj: &crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs) -> crate::c_types::derived::CVec_u8Z {
255 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
258 pub(crate) extern "C" fn ScorerAccountingForInFlightHtlcs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
259 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeScorerAccountingForInFlightHtlcs) })
261 impl From<nativeScorerAccountingForInFlightHtlcs> for crate::lightning::routing::scoring::Score {
262 fn from(obj: nativeScorerAccountingForInFlightHtlcs) -> Self {
263 let mut rust_obj = ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(obj), is_owned: true };
264 let mut ret = ScorerAccountingForInFlightHtlcs_as_Score(&rust_obj);
265 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
266 rust_obj.inner = core::ptr::null_mut();
267 ret.free = Some(ScorerAccountingForInFlightHtlcs_free_void);
271 /// Constructs a new Score which calls the relevant methods on this_arg.
272 /// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
274 pub extern "C" fn ScorerAccountingForInFlightHtlcs_as_Score(this_arg: &ScorerAccountingForInFlightHtlcs) -> crate::lightning::routing::scoring::Score {
275 crate::lightning::routing::scoring::Score {
276 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
278 channel_penalty_msat: ScorerAccountingForInFlightHtlcs_Score_channel_penalty_msat,
279 payment_path_failed: ScorerAccountingForInFlightHtlcs_Score_payment_path_failed,
280 payment_path_successful: ScorerAccountingForInFlightHtlcs_Score_payment_path_successful,
281 probe_failed: ScorerAccountingForInFlightHtlcs_Score_probe_failed,
282 probe_successful: ScorerAccountingForInFlightHtlcs_Score_probe_successful,
283 write: ScorerAccountingForInFlightHtlcs_write_void,
288 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut usage: crate::lightning::routing::scoring::ChannelUsage, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> u64 {
289 let mut ret = <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, short_channel_id, source.get_native_ref(), target.get_native_ref(), *unsafe { Box::from_raw(usage.take_inner()) }, score_params.get_native_ref());
292 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_payment_path_failed(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path, mut short_channel_id: u64) {
293 <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, path.get_native_ref(), short_channel_id)
295 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_payment_path_successful(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path) {
296 <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, path.get_native_ref())
298 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_probe_failed(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path, mut short_channel_id: u64) {
299 <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::probe_failed(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, path.get_native_ref(), short_channel_id)
301 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_probe_successful(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path) {
302 <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::probe_successful(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, path.get_native_ref())
306 use lightning::routing::router::InFlightHtlcs as nativeInFlightHtlcsImport;
307 pub(crate) type nativeInFlightHtlcs = nativeInFlightHtlcsImport;
309 /// A data structure for tracking in-flight HTLCs. May be used during pathfinding to account for
310 /// in-use channel liquidity.
313 pub struct InFlightHtlcs {
314 /// A pointer to the opaque Rust object.
316 /// Nearly everywhere, inner must be non-null, however in places where
317 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
318 pub inner: *mut nativeInFlightHtlcs,
319 /// Indicates that this is the only struct which contains the same pointer.
321 /// Rust functions which take ownership of an object provided via an argument require
322 /// this to be true and invalidate the object pointed to by inner.
326 impl Drop for InFlightHtlcs {
328 if self.is_owned && !<*mut nativeInFlightHtlcs>::is_null(self.inner) {
329 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
333 /// Frees any resources used by the InFlightHtlcs, if is_owned is set and inner is non-NULL.
335 pub extern "C" fn InFlightHtlcs_free(this_obj: InFlightHtlcs) { }
337 /// Used only if an object of this type is returned as a trait impl by a method
338 pub(crate) extern "C" fn InFlightHtlcs_free_void(this_ptr: *mut c_void) {
339 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInFlightHtlcs) };
343 pub(crate) fn get_native_ref(&self) -> &'static nativeInFlightHtlcs {
344 unsafe { &*ObjOps::untweak_ptr(self.inner) }
346 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInFlightHtlcs {
347 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
349 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
350 pub(crate) fn take_inner(mut self) -> *mut nativeInFlightHtlcs {
351 assert!(self.is_owned);
352 let ret = ObjOps::untweak_ptr(self.inner);
353 self.inner = core::ptr::null_mut();
357 impl Clone for InFlightHtlcs {
358 fn clone(&self) -> Self {
360 inner: if <*mut nativeInFlightHtlcs>::is_null(self.inner) { core::ptr::null_mut() } else {
361 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
367 /// Used only if an object of this type is returned as a trait impl by a method
368 pub(crate) extern "C" fn InFlightHtlcs_clone_void(this_ptr: *const c_void) -> *mut c_void {
369 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInFlightHtlcs)).clone() })) as *mut c_void
372 /// Creates a copy of the InFlightHtlcs
373 pub extern "C" fn InFlightHtlcs_clone(orig: &InFlightHtlcs) -> InFlightHtlcs {
376 /// Constructs an empty `InFlightHtlcs`.
379 pub extern "C" fn InFlightHtlcs_new() -> crate::lightning::routing::router::InFlightHtlcs {
380 let mut ret = lightning::routing::router::InFlightHtlcs::new();
381 crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
384 /// Takes in a path with payer's node id and adds the path's details to `InFlightHtlcs`.
386 pub extern "C" fn InFlightHtlcs_process_path(this_arg: &mut crate::lightning::routing::router::InFlightHtlcs, path: &crate::lightning::routing::router::Path, mut payer_node_id: crate::c_types::PublicKey) {
387 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::router::nativeInFlightHtlcs)) }.process_path(path.get_native_ref(), payer_node_id.into_rust())
390 /// Adds a known HTLC given the public key of the HTLC source, target, and short channel
393 pub extern "C" fn InFlightHtlcs_add_inflight_htlc(this_arg: &mut crate::lightning::routing::router::InFlightHtlcs, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut channel_scid: u64, mut used_msat: u64) {
394 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::router::nativeInFlightHtlcs)) }.add_inflight_htlc(source.get_native_ref(), target.get_native_ref(), channel_scid, used_msat)
397 /// Returns liquidity in msat given the public key of the HTLC source, target, and short channel
401 pub extern "C" fn InFlightHtlcs_used_liquidity_msat(this_arg: &crate::lightning::routing::router::InFlightHtlcs, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut channel_scid: u64) -> crate::c_types::derived::COption_u64Z {
402 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.used_liquidity_msat(source.get_native_ref(), target.get_native_ref(), channel_scid);
403 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() }) };
408 /// Serialize the InFlightHtlcs object into a byte array which can be read by InFlightHtlcs_read
409 pub extern "C" fn InFlightHtlcs_write(obj: &crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CVec_u8Z {
410 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
413 pub(crate) extern "C" fn InFlightHtlcs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
414 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInFlightHtlcs) })
417 /// Read a InFlightHtlcs from a byte array, created by InFlightHtlcs_write
418 pub extern "C" fn InFlightHtlcs_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InFlightHtlcsDecodeErrorZ {
419 let res: Result<lightning::routing::router::InFlightHtlcs, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
420 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::InFlightHtlcs { 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() };
424 use lightning::routing::router::RouteHop as nativeRouteHopImport;
425 pub(crate) type nativeRouteHop = nativeRouteHopImport;
427 /// A hop in a route, and additional metadata about it. \"Hop\" is defined as a node and the channel
428 /// that leads to it.
431 pub struct RouteHop {
432 /// A pointer to the opaque Rust object.
434 /// Nearly everywhere, inner must be non-null, however in places where
435 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
436 pub inner: *mut nativeRouteHop,
437 /// Indicates that this is the only struct which contains the same pointer.
439 /// Rust functions which take ownership of an object provided via an argument require
440 /// this to be true and invalidate the object pointed to by inner.
444 impl Drop for RouteHop {
446 if self.is_owned && !<*mut nativeRouteHop>::is_null(self.inner) {
447 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
451 /// Frees any resources used by the RouteHop, if is_owned is set and inner is non-NULL.
453 pub extern "C" fn RouteHop_free(this_obj: RouteHop) { }
455 /// Used only if an object of this type is returned as a trait impl by a method
456 pub(crate) extern "C" fn RouteHop_free_void(this_ptr: *mut c_void) {
457 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHop) };
461 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHop {
462 unsafe { &*ObjOps::untweak_ptr(self.inner) }
464 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHop {
465 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
467 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
468 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHop {
469 assert!(self.is_owned);
470 let ret = ObjOps::untweak_ptr(self.inner);
471 self.inner = core::ptr::null_mut();
475 /// The node_id of the node at this hop.
477 pub extern "C" fn RouteHop_get_pubkey(this_ptr: &RouteHop) -> crate::c_types::PublicKey {
478 let mut inner_val = &mut this_ptr.get_native_mut_ref().pubkey;
479 crate::c_types::PublicKey::from_rust(&inner_val)
481 /// The node_id of the node at this hop.
483 pub extern "C" fn RouteHop_set_pubkey(this_ptr: &mut RouteHop, mut val: crate::c_types::PublicKey) {
484 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.pubkey = val.into_rust();
486 /// The node_announcement features of the node at this hop. For the last hop, these may be
487 /// amended to match the features present in the invoice this node generated.
489 pub extern "C" fn RouteHop_get_node_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::NodeFeatures {
490 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_features;
491 crate::lightning::ln::features::NodeFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::NodeFeatures<>) as *mut _) }, is_owned: false }
493 /// The node_announcement features of the node at this hop. For the last hop, these may be
494 /// amended to match the features present in the invoice this node generated.
496 pub extern "C" fn RouteHop_set_node_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::NodeFeatures) {
497 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_features = *unsafe { Box::from_raw(val.take_inner()) };
499 /// The channel that should be used from the previous hop to reach this node.
501 pub extern "C" fn RouteHop_get_short_channel_id(this_ptr: &RouteHop) -> u64 {
502 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
505 /// The channel that should be used from the previous hop to reach this node.
507 pub extern "C" fn RouteHop_set_short_channel_id(this_ptr: &mut RouteHop, mut val: u64) {
508 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
510 /// The channel_announcement features of the channel that should be used from the previous hop
511 /// to reach this node.
513 pub extern "C" fn RouteHop_get_channel_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::ChannelFeatures {
514 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_features;
515 crate::lightning::ln::features::ChannelFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::ChannelFeatures<>) as *mut _) }, is_owned: false }
517 /// The channel_announcement features of the channel that should be used from the previous hop
518 /// to reach this node.
520 pub extern "C" fn RouteHop_set_channel_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::ChannelFeatures) {
521 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_features = *unsafe { Box::from_raw(val.take_inner()) };
523 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
524 /// If this is the last hop in [`Path::hops`]:
525 /// * if we're sending to a [`BlindedPath`], this is the fee paid for use of the entire blinded path
526 /// * otherwise, this is the full value of this [`Path`]'s part of the payment
528 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
530 pub extern "C" fn RouteHop_get_fee_msat(this_ptr: &RouteHop) -> u64 {
531 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_msat;
534 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
535 /// If this is the last hop in [`Path::hops`]:
536 /// * if we're sending to a [`BlindedPath`], this is the fee paid for use of the entire blinded path
537 /// * otherwise, this is the full value of this [`Path`]'s part of the payment
539 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
541 pub extern "C" fn RouteHop_set_fee_msat(this_ptr: &mut RouteHop, mut val: u64) {
542 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_msat = val;
544 /// The CLTV delta added for this hop.
545 /// If this is the last hop in [`Path::hops`]:
546 /// * if we're sending to a [`BlindedPath`], this is the CLTV delta for the entire blinded path
547 /// * otherwise, this is the CLTV delta expected at the destination
549 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
551 pub extern "C" fn RouteHop_get_cltv_expiry_delta(this_ptr: &RouteHop) -> u32 {
552 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
555 /// The CLTV delta added for this hop.
556 /// If this is the last hop in [`Path::hops`]:
557 /// * if we're sending to a [`BlindedPath`], this is the CLTV delta for the entire blinded path
558 /// * otherwise, this is the CLTV delta expected at the destination
560 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
562 pub extern "C" fn RouteHop_set_cltv_expiry_delta(this_ptr: &mut RouteHop, mut val: u32) {
563 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
565 /// Constructs a new RouteHop given each field
568 pub extern "C" fn RouteHop_new(mut pubkey_arg: crate::c_types::PublicKey, mut node_features_arg: crate::lightning::ln::features::NodeFeatures, mut short_channel_id_arg: u64, mut channel_features_arg: crate::lightning::ln::features::ChannelFeatures, mut fee_msat_arg: u64, mut cltv_expiry_delta_arg: u32) -> RouteHop {
569 RouteHop { inner: ObjOps::heap_alloc(nativeRouteHop {
570 pubkey: pubkey_arg.into_rust(),
571 node_features: *unsafe { Box::from_raw(node_features_arg.take_inner()) },
572 short_channel_id: short_channel_id_arg,
573 channel_features: *unsafe { Box::from_raw(channel_features_arg.take_inner()) },
574 fee_msat: fee_msat_arg,
575 cltv_expiry_delta: cltv_expiry_delta_arg,
578 impl Clone for RouteHop {
579 fn clone(&self) -> Self {
581 inner: if <*mut nativeRouteHop>::is_null(self.inner) { core::ptr::null_mut() } else {
582 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
588 /// Used only if an object of this type is returned as a trait impl by a method
589 pub(crate) extern "C" fn RouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
590 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHop)).clone() })) as *mut c_void
593 /// Creates a copy of the RouteHop
594 pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop {
597 /// Generates a non-cryptographic 64-bit hash of the RouteHop.
599 pub extern "C" fn RouteHop_hash(o: &RouteHop) -> u64 {
600 if o.inner.is_null() { return 0; }
601 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
603 let mut hasher = core::hash::SipHasher::new();
604 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
605 core::hash::Hasher::finish(&hasher)
607 /// Checks if two RouteHops contain equal inner contents.
608 /// This ignores pointers and is_owned flags and looks at the values in fields.
609 /// Two objects with NULL inner values will be considered "equal" here.
611 pub extern "C" fn RouteHop_eq(a: &RouteHop, b: &RouteHop) -> bool {
612 if a.inner == b.inner { return true; }
613 if a.inner.is_null() || b.inner.is_null() { return false; }
614 if a.get_native_ref() == b.get_native_ref() { true } else { false }
617 /// Serialize the RouteHop object into a byte array which can be read by RouteHop_read
618 pub extern "C" fn RouteHop_write(obj: &crate::lightning::routing::router::RouteHop) -> crate::c_types::derived::CVec_u8Z {
619 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
622 pub(crate) extern "C" fn RouteHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
623 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHop) })
626 /// Read a RouteHop from a byte array, created by RouteHop_write
627 pub extern "C" fn RouteHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHopDecodeErrorZ {
628 let res: Result<lightning::routing::router::RouteHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
629 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::RouteHop { 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() };
633 use lightning::routing::router::BlindedTail as nativeBlindedTailImport;
634 pub(crate) type nativeBlindedTail = nativeBlindedTailImport;
636 /// The blinded portion of a [`Path`], if we're routing to a recipient who provided blinded paths in
637 /// their [`Bolt12Invoice`].
639 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
642 pub struct BlindedTail {
643 /// A pointer to the opaque Rust object.
645 /// Nearly everywhere, inner must be non-null, however in places where
646 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
647 pub inner: *mut nativeBlindedTail,
648 /// Indicates that this is the only struct which contains the same pointer.
650 /// Rust functions which take ownership of an object provided via an argument require
651 /// this to be true and invalidate the object pointed to by inner.
655 impl Drop for BlindedTail {
657 if self.is_owned && !<*mut nativeBlindedTail>::is_null(self.inner) {
658 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
662 /// Frees any resources used by the BlindedTail, if is_owned is set and inner is non-NULL.
664 pub extern "C" fn BlindedTail_free(this_obj: BlindedTail) { }
666 /// Used only if an object of this type is returned as a trait impl by a method
667 pub(crate) extern "C" fn BlindedTail_free_void(this_ptr: *mut c_void) {
668 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedTail) };
672 pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedTail {
673 unsafe { &*ObjOps::untweak_ptr(self.inner) }
675 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedTail {
676 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
678 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
679 pub(crate) fn take_inner(mut self) -> *mut nativeBlindedTail {
680 assert!(self.is_owned);
681 let ret = ObjOps::untweak_ptr(self.inner);
682 self.inner = core::ptr::null_mut();
686 /// The hops of the [`BlindedPath`] provided by the recipient.
688 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
690 pub extern "C" fn BlindedTail_get_hops(this_ptr: &BlindedTail) -> crate::c_types::derived::CVec_BlindedHopZ {
691 let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
692 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::blinded_path::BlindedHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::blinded_path::BlindedHop<>) as *mut _) }, is_owned: false } }); };
693 local_inner_val.into()
695 /// The hops of the [`BlindedPath`] provided by the recipient.
697 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
699 pub extern "C" fn BlindedTail_set_hops(this_ptr: &mut BlindedTail, mut val: crate::c_types::derived::CVec_BlindedHopZ) {
700 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
701 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
703 /// The blinding point of the [`BlindedPath`] provided by the recipient.
705 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
707 pub extern "C" fn BlindedTail_get_blinding_point(this_ptr: &BlindedTail) -> crate::c_types::PublicKey {
708 let mut inner_val = &mut this_ptr.get_native_mut_ref().blinding_point;
709 crate::c_types::PublicKey::from_rust(&inner_val)
711 /// The blinding point of the [`BlindedPath`] provided by the recipient.
713 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
715 pub extern "C" fn BlindedTail_set_blinding_point(this_ptr: &mut BlindedTail, mut val: crate::c_types::PublicKey) {
716 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinding_point = val.into_rust();
718 /// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
719 /// inferring the destination. May be 0.
721 pub extern "C" fn BlindedTail_get_excess_final_cltv_expiry_delta(this_ptr: &BlindedTail) -> u32 {
722 let mut inner_val = &mut this_ptr.get_native_mut_ref().excess_final_cltv_expiry_delta;
725 /// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
726 /// inferring the destination. May be 0.
728 pub extern "C" fn BlindedTail_set_excess_final_cltv_expiry_delta(this_ptr: &mut BlindedTail, mut val: u32) {
729 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.excess_final_cltv_expiry_delta = val;
731 /// The total amount paid on this [`Path`], excluding the fees.
733 pub extern "C" fn BlindedTail_get_final_value_msat(this_ptr: &BlindedTail) -> u64 {
734 let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
737 /// The total amount paid on this [`Path`], excluding the fees.
739 pub extern "C" fn BlindedTail_set_final_value_msat(this_ptr: &mut BlindedTail, mut val: u64) {
740 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
742 /// Constructs a new BlindedTail given each field
745 pub extern "C" fn BlindedTail_new(mut hops_arg: crate::c_types::derived::CVec_BlindedHopZ, mut blinding_point_arg: crate::c_types::PublicKey, mut excess_final_cltv_expiry_delta_arg: u32, mut final_value_msat_arg: u64) -> BlindedTail {
746 let mut local_hops_arg = Vec::new(); for mut item in hops_arg.into_rust().drain(..) { local_hops_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
747 BlindedTail { inner: ObjOps::heap_alloc(nativeBlindedTail {
748 hops: local_hops_arg,
749 blinding_point: blinding_point_arg.into_rust(),
750 excess_final_cltv_expiry_delta: excess_final_cltv_expiry_delta_arg,
751 final_value_msat: final_value_msat_arg,
754 impl Clone for BlindedTail {
755 fn clone(&self) -> Self {
757 inner: if <*mut nativeBlindedTail>::is_null(self.inner) { core::ptr::null_mut() } else {
758 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
764 /// Used only if an object of this type is returned as a trait impl by a method
765 pub(crate) extern "C" fn BlindedTail_clone_void(this_ptr: *const c_void) -> *mut c_void {
766 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBlindedTail)).clone() })) as *mut c_void
769 /// Creates a copy of the BlindedTail
770 pub extern "C" fn BlindedTail_clone(orig: &BlindedTail) -> BlindedTail {
773 /// Generates a non-cryptographic 64-bit hash of the BlindedTail.
775 pub extern "C" fn BlindedTail_hash(o: &BlindedTail) -> u64 {
776 if o.inner.is_null() { return 0; }
777 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
779 let mut hasher = core::hash::SipHasher::new();
780 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
781 core::hash::Hasher::finish(&hasher)
783 /// Checks if two BlindedTails contain equal inner contents.
784 /// This ignores pointers and is_owned flags and looks at the values in fields.
785 /// Two objects with NULL inner values will be considered "equal" here.
787 pub extern "C" fn BlindedTail_eq(a: &BlindedTail, b: &BlindedTail) -> bool {
788 if a.inner == b.inner { return true; }
789 if a.inner.is_null() || b.inner.is_null() { return false; }
790 if a.get_native_ref() == b.get_native_ref() { true } else { false }
793 /// Serialize the BlindedTail object into a byte array which can be read by BlindedTail_read
794 pub extern "C" fn BlindedTail_write(obj: &crate::lightning::routing::router::BlindedTail) -> crate::c_types::derived::CVec_u8Z {
795 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
798 pub(crate) extern "C" fn BlindedTail_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
799 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedTail) })
802 /// Read a BlindedTail from a byte array, created by BlindedTail_write
803 pub extern "C" fn BlindedTail_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedTailDecodeErrorZ {
804 let res: Result<lightning::routing::router::BlindedTail, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
805 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::BlindedTail { 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() };
809 use lightning::routing::router::Path as nativePathImport;
810 pub(crate) type nativePath = nativePathImport;
812 /// A path in a [`Route`] to the payment recipient. Must always be at least length one.
813 /// If no [`Path::blinded_tail`] is present, then [`Path::hops`] length may be up to 19.
817 /// A pointer to the opaque Rust object.
819 /// Nearly everywhere, inner must be non-null, however in places where
820 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
821 pub inner: *mut nativePath,
822 /// Indicates that this is the only struct which contains the same pointer.
824 /// Rust functions which take ownership of an object provided via an argument require
825 /// this to be true and invalidate the object pointed to by inner.
831 if self.is_owned && !<*mut nativePath>::is_null(self.inner) {
832 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
836 /// Frees any resources used by the Path, if is_owned is set and inner is non-NULL.
838 pub extern "C" fn Path_free(this_obj: Path) { }
840 /// Used only if an object of this type is returned as a trait impl by a method
841 pub(crate) extern "C" fn Path_free_void(this_ptr: *mut c_void) {
842 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePath) };
846 pub(crate) fn get_native_ref(&self) -> &'static nativePath {
847 unsafe { &*ObjOps::untweak_ptr(self.inner) }
849 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePath {
850 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
852 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
853 pub(crate) fn take_inner(mut self) -> *mut nativePath {
854 assert!(self.is_owned);
855 let ret = ObjOps::untweak_ptr(self.inner);
856 self.inner = core::ptr::null_mut();
860 /// The list of unblinded hops in this [`Path`]. Must be at least length one.
862 pub extern "C" fn Path_get_hops(this_ptr: &Path) -> crate::c_types::derived::CVec_RouteHopZ {
863 let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
864 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); };
865 local_inner_val.into()
867 /// The list of unblinded hops in this [`Path`]. Must be at least length one.
869 pub extern "C" fn Path_set_hops(this_ptr: &mut Path, mut val: crate::c_types::derived::CVec_RouteHopZ) {
870 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
871 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
873 /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
875 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
877 pub extern "C" fn Path_get_blinded_tail(this_ptr: &Path) -> crate::lightning::routing::router::BlindedTail {
878 let mut inner_val = &mut this_ptr.get_native_mut_ref().blinded_tail;
879 let mut local_inner_val = crate::lightning::routing::router::BlindedTail { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::router::BlindedTail<>) as *mut _ }, is_owned: false };
882 /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
884 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
886 pub extern "C" fn Path_set_blinded_tail(this_ptr: &mut Path, mut val: crate::lightning::routing::router::BlindedTail) {
887 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
888 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinded_tail = local_val;
890 /// Constructs a new Path given each field
893 pub extern "C" fn Path_new(mut hops_arg: crate::c_types::derived::CVec_RouteHopZ, mut blinded_tail_arg: crate::lightning::routing::router::BlindedTail) -> Path {
894 let mut local_hops_arg = Vec::new(); for mut item in hops_arg.into_rust().drain(..) { local_hops_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
895 let mut local_blinded_tail_arg = if blinded_tail_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(blinded_tail_arg.take_inner()) } }) };
896 Path { inner: ObjOps::heap_alloc(nativePath {
897 hops: local_hops_arg,
898 blinded_tail: local_blinded_tail_arg,
901 impl Clone for Path {
902 fn clone(&self) -> Self {
904 inner: if <*mut nativePath>::is_null(self.inner) { core::ptr::null_mut() } else {
905 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
911 /// Used only if an object of this type is returned as a trait impl by a method
912 pub(crate) extern "C" fn Path_clone_void(this_ptr: *const c_void) -> *mut c_void {
913 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePath)).clone() })) as *mut c_void
916 /// Creates a copy of the Path
917 pub extern "C" fn Path_clone(orig: &Path) -> Path {
920 /// Generates a non-cryptographic 64-bit hash of the Path.
922 pub extern "C" fn Path_hash(o: &Path) -> u64 {
923 if o.inner.is_null() { return 0; }
924 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
926 let mut hasher = core::hash::SipHasher::new();
927 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
928 core::hash::Hasher::finish(&hasher)
930 /// Checks if two Paths contain equal inner contents.
931 /// This ignores pointers and is_owned flags and looks at the values in fields.
932 /// Two objects with NULL inner values will be considered "equal" here.
934 pub extern "C" fn Path_eq(a: &Path, b: &Path) -> bool {
935 if a.inner == b.inner { return true; }
936 if a.inner.is_null() || b.inner.is_null() { return false; }
937 if a.get_native_ref() == b.get_native_ref() { true } else { false }
939 /// Gets the fees for a given path, excluding any excess paid to the recipient.
942 pub extern "C" fn Path_fee_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
943 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fee_msat();
947 /// Gets the total amount paid on this [`Path`], excluding the fees.
950 pub extern "C" fn Path_final_value_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
951 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_value_msat();
955 /// Gets the final hop's CLTV expiry delta.
958 pub extern "C" fn Path_final_cltv_expiry_delta(this_arg: &crate::lightning::routing::router::Path) -> crate::c_types::derived::COption_u32Z {
959 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_cltv_expiry_delta();
960 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { ret.unwrap() }) };
965 use lightning::routing::router::Route as nativeRouteImport;
966 pub(crate) type nativeRoute = nativeRouteImport;
968 /// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
969 /// it can take multiple paths. Each path is composed of one or more hops through the network.
973 /// A pointer to the opaque Rust object.
975 /// Nearly everywhere, inner must be non-null, however in places where
976 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
977 pub inner: *mut nativeRoute,
978 /// Indicates that this is the only struct which contains the same pointer.
980 /// Rust functions which take ownership of an object provided via an argument require
981 /// this to be true and invalidate the object pointed to by inner.
985 impl Drop for Route {
987 if self.is_owned && !<*mut nativeRoute>::is_null(self.inner) {
988 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
992 /// Frees any resources used by the Route, if is_owned is set and inner is non-NULL.
994 pub extern "C" fn Route_free(this_obj: Route) { }
996 /// Used only if an object of this type is returned as a trait impl by a method
997 pub(crate) extern "C" fn Route_free_void(this_ptr: *mut c_void) {
998 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoute) };
1002 pub(crate) fn get_native_ref(&self) -> &'static nativeRoute {
1003 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1005 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoute {
1006 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1008 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1009 pub(crate) fn take_inner(mut self) -> *mut nativeRoute {
1010 assert!(self.is_owned);
1011 let ret = ObjOps::untweak_ptr(self.inner);
1012 self.inner = core::ptr::null_mut();
1016 /// The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
1017 /// [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
1020 pub extern "C" fn Route_get_paths(this_ptr: &Route) -> crate::c_types::derived::CVec_PathZ {
1021 let mut inner_val = &mut this_ptr.get_native_mut_ref().paths;
1022 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::Path { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::Path<>) as *mut _) }, is_owned: false } }); };
1023 local_inner_val.into()
1025 /// The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
1026 /// [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
1029 pub extern "C" fn Route_set_paths(this_ptr: &mut Route, mut val: crate::c_types::derived::CVec_PathZ) {
1030 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1031 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.paths = local_val;
1033 /// The `payment_params` parameter passed via [`RouteParameters`] to [`find_route`].
1035 /// This is used by `ChannelManager` to track information which may be required for retries.
1037 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1039 pub extern "C" fn Route_get_payment_params(this_ptr: &Route) -> crate::lightning::routing::router::PaymentParameters {
1040 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_params;
1041 let mut local_inner_val = crate::lightning::routing::router::PaymentParameters { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::router::PaymentParameters<>) as *mut _ }, is_owned: false };
1044 /// The `payment_params` parameter passed via [`RouteParameters`] to [`find_route`].
1046 /// This is used by `ChannelManager` to track information which may be required for retries.
1048 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1050 pub extern "C" fn Route_set_payment_params(this_ptr: &mut Route, mut val: crate::lightning::routing::router::PaymentParameters) {
1051 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1052 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_params = local_val;
1054 /// Constructs a new Route given each field
1057 pub extern "C" fn Route_new(mut paths_arg: crate::c_types::derived::CVec_PathZ, mut payment_params_arg: crate::lightning::routing::router::PaymentParameters) -> Route {
1058 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()) } }); };
1059 let mut local_payment_params_arg = if payment_params_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(payment_params_arg.take_inner()) } }) };
1060 Route { inner: ObjOps::heap_alloc(nativeRoute {
1061 paths: local_paths_arg,
1062 payment_params: local_payment_params_arg,
1063 }), is_owned: true }
1065 impl Clone for Route {
1066 fn clone(&self) -> Self {
1068 inner: if <*mut nativeRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
1069 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1075 /// Used only if an object of this type is returned as a trait impl by a method
1076 pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_void {
1077 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoute)).clone() })) as *mut c_void
1080 /// Creates a copy of the Route
1081 pub extern "C" fn Route_clone(orig: &Route) -> Route {
1084 /// Generates a non-cryptographic 64-bit hash of the Route.
1086 pub extern "C" fn Route_hash(o: &Route) -> u64 {
1087 if o.inner.is_null() { return 0; }
1088 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1089 #[allow(deprecated)]
1090 let mut hasher = core::hash::SipHasher::new();
1091 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1092 core::hash::Hasher::finish(&hasher)
1094 /// Checks if two Routes contain equal inner contents.
1095 /// This ignores pointers and is_owned flags and looks at the values in fields.
1096 /// Two objects with NULL inner values will be considered "equal" here.
1098 pub extern "C" fn Route_eq(a: &Route, b: &Route) -> bool {
1099 if a.inner == b.inner { return true; }
1100 if a.inner.is_null() || b.inner.is_null() { return false; }
1101 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1103 /// Returns the total amount of fees paid on this [`Route`].
1105 /// This doesn't include any extra payment made to the recipient, which can happen in excess of
1106 /// the amount passed to [`find_route`]'s `route_params.final_value_msat`.
1109 pub extern "C" fn Route_get_total_fees(this_arg: &crate::lightning::routing::router::Route) -> u64 {
1110 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_fees();
1114 /// Returns the total amount paid on this [`Route`], excluding the fees. Might be more than
1115 /// requested if we had to reach htlc_minimum_msat.
1118 pub extern "C" fn Route_get_total_amount(this_arg: &crate::lightning::routing::router::Route) -> u64 {
1119 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_amount();
1124 /// Serialize the Route object into a byte array which can be read by Route_read
1125 pub extern "C" fn Route_write(obj: &crate::lightning::routing::router::Route) -> crate::c_types::derived::CVec_u8Z {
1126 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1129 pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1130 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) })
1133 /// Read a Route from a byte array, created by Route_write
1134 pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ {
1135 let res: Result<lightning::routing::router::Route, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1136 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() };
1140 use lightning::routing::router::RouteParameters as nativeRouteParametersImport;
1141 pub(crate) type nativeRouteParameters = nativeRouteParametersImport;
1143 /// Parameters needed to find a [`Route`].
1145 /// Passed to [`find_route`] and [`build_route_from_hops`].
1148 pub struct RouteParameters {
1149 /// A pointer to the opaque Rust object.
1151 /// Nearly everywhere, inner must be non-null, however in places where
1152 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1153 pub inner: *mut nativeRouteParameters,
1154 /// Indicates that this is the only struct which contains the same pointer.
1156 /// Rust functions which take ownership of an object provided via an argument require
1157 /// this to be true and invalidate the object pointed to by inner.
1161 impl Drop for RouteParameters {
1162 fn drop(&mut self) {
1163 if self.is_owned && !<*mut nativeRouteParameters>::is_null(self.inner) {
1164 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1168 /// Frees any resources used by the RouteParameters, if is_owned is set and inner is non-NULL.
1170 pub extern "C" fn RouteParameters_free(this_obj: RouteParameters) { }
1172 /// Used only if an object of this type is returned as a trait impl by a method
1173 pub(crate) extern "C" fn RouteParameters_free_void(this_ptr: *mut c_void) {
1174 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteParameters) };
1177 impl RouteParameters {
1178 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteParameters {
1179 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1181 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteParameters {
1182 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1184 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1185 pub(crate) fn take_inner(mut self) -> *mut nativeRouteParameters {
1186 assert!(self.is_owned);
1187 let ret = ObjOps::untweak_ptr(self.inner);
1188 self.inner = core::ptr::null_mut();
1192 /// The parameters of the failed payment path.
1194 pub extern "C" fn RouteParameters_get_payment_params(this_ptr: &RouteParameters) -> crate::lightning::routing::router::PaymentParameters {
1195 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_params;
1196 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 }
1198 /// The parameters of the failed payment path.
1200 pub extern "C" fn RouteParameters_set_payment_params(this_ptr: &mut RouteParameters, mut val: crate::lightning::routing::router::PaymentParameters) {
1201 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_params = *unsafe { Box::from_raw(val.take_inner()) };
1203 /// The amount in msats sent on the failed payment path.
1205 pub extern "C" fn RouteParameters_get_final_value_msat(this_ptr: &RouteParameters) -> u64 {
1206 let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
1209 /// The amount in msats sent on the failed payment path.
1211 pub extern "C" fn RouteParameters_set_final_value_msat(this_ptr: &mut RouteParameters, mut val: u64) {
1212 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
1214 /// Constructs a new RouteParameters given each field
1217 pub extern "C" fn RouteParameters_new(mut payment_params_arg: crate::lightning::routing::router::PaymentParameters, mut final_value_msat_arg: u64) -> RouteParameters {
1218 RouteParameters { inner: ObjOps::heap_alloc(nativeRouteParameters {
1219 payment_params: *unsafe { Box::from_raw(payment_params_arg.take_inner()) },
1220 final_value_msat: final_value_msat_arg,
1221 }), is_owned: true }
1223 impl Clone for RouteParameters {
1224 fn clone(&self) -> Self {
1226 inner: if <*mut nativeRouteParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1227 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1233 /// Used only if an object of this type is returned as a trait impl by a method
1234 pub(crate) extern "C" fn RouteParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1235 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteParameters)).clone() })) as *mut c_void
1238 /// Creates a copy of the RouteParameters
1239 pub extern "C" fn RouteParameters_clone(orig: &RouteParameters) -> RouteParameters {
1242 /// Checks if two RouteParameterss contain equal inner contents.
1243 /// This ignores pointers and is_owned flags and looks at the values in fields.
1244 /// Two objects with NULL inner values will be considered "equal" here.
1246 pub extern "C" fn RouteParameters_eq(a: &RouteParameters, b: &RouteParameters) -> bool {
1247 if a.inner == b.inner { return true; }
1248 if a.inner.is_null() || b.inner.is_null() { return false; }
1249 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1252 /// Serialize the RouteParameters object into a byte array which can be read by RouteParameters_read
1253 pub extern "C" fn RouteParameters_write(obj: &crate::lightning::routing::router::RouteParameters) -> crate::c_types::derived::CVec_u8Z {
1254 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1257 pub(crate) extern "C" fn RouteParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1258 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteParameters) })
1261 /// Read a RouteParameters from a byte array, created by RouteParameters_write
1262 pub extern "C" fn RouteParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteParametersDecodeErrorZ {
1263 let res: Result<lightning::routing::router::RouteParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1264 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() };
1267 /// Maximum total CTLV difference we allow for a full payment path.
1270 pub static DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = lightning::routing::router::DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
1271 /// Maximum number of paths we allow an (MPP) payment to have.
1274 pub static DEFAULT_MAX_PATH_COUNT: u8 = lightning::routing::router::DEFAULT_MAX_PATH_COUNT;
1276 use lightning::routing::router::PaymentParameters as nativePaymentParametersImport;
1277 pub(crate) type nativePaymentParameters = nativePaymentParametersImport;
1279 /// Information used to route a payment.
1282 pub struct PaymentParameters {
1283 /// A pointer to the opaque Rust object.
1285 /// Nearly everywhere, inner must be non-null, however in places where
1286 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1287 pub inner: *mut nativePaymentParameters,
1288 /// Indicates that this is the only struct which contains the same pointer.
1290 /// Rust functions which take ownership of an object provided via an argument require
1291 /// this to be true and invalidate the object pointed to by inner.
1295 impl Drop for PaymentParameters {
1296 fn drop(&mut self) {
1297 if self.is_owned && !<*mut nativePaymentParameters>::is_null(self.inner) {
1298 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1302 /// Frees any resources used by the PaymentParameters, if is_owned is set and inner is non-NULL.
1304 pub extern "C" fn PaymentParameters_free(this_obj: PaymentParameters) { }
1306 /// Used only if an object of this type is returned as a trait impl by a method
1307 pub(crate) extern "C" fn PaymentParameters_free_void(this_ptr: *mut c_void) {
1308 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentParameters) };
1311 impl PaymentParameters {
1312 pub(crate) fn get_native_ref(&self) -> &'static nativePaymentParameters {
1313 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1315 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentParameters {
1316 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1318 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1319 pub(crate) fn take_inner(mut self) -> *mut nativePaymentParameters {
1320 assert!(self.is_owned);
1321 let ret = ObjOps::untweak_ptr(self.inner);
1322 self.inner = core::ptr::null_mut();
1326 /// Information about the payee, such as their features and route hints for their channels.
1328 pub extern "C" fn PaymentParameters_get_payee(this_ptr: &PaymentParameters) -> crate::lightning::routing::router::Payee {
1329 let mut inner_val = &mut this_ptr.get_native_mut_ref().payee;
1330 crate::lightning::routing::router::Payee::from_native(inner_val)
1332 /// Information about the payee, such as their features and route hints for their channels.
1334 pub extern "C" fn PaymentParameters_set_payee(this_ptr: &mut PaymentParameters, mut val: crate::lightning::routing::router::Payee) {
1335 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payee = val.into_native();
1337 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1339 pub extern "C" fn PaymentParameters_get_expiry_time(this_ptr: &PaymentParameters) -> crate::c_types::derived::COption_u64Z {
1340 let mut inner_val = &mut this_ptr.get_native_mut_ref().expiry_time;
1341 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() }) };
1344 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1346 pub extern "C" fn PaymentParameters_set_expiry_time(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::COption_u64Z) {
1347 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1348 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.expiry_time = local_val;
1350 /// The maximum total CLTV delta we accept for the route.
1351 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1353 pub extern "C" fn PaymentParameters_get_max_total_cltv_expiry_delta(this_ptr: &PaymentParameters) -> u32 {
1354 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_cltv_expiry_delta;
1357 /// The maximum total CLTV delta we accept for the route.
1358 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1360 pub extern "C" fn PaymentParameters_set_max_total_cltv_expiry_delta(this_ptr: &mut PaymentParameters, mut val: u32) {
1361 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_cltv_expiry_delta = val;
1363 /// The maximum number of paths that may be used by (MPP) payments.
1364 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1366 pub extern "C" fn PaymentParameters_get_max_path_count(this_ptr: &PaymentParameters) -> u8 {
1367 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_path_count;
1370 /// The maximum number of paths that may be used by (MPP) payments.
1371 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1373 pub extern "C" fn PaymentParameters_set_max_path_count(this_ptr: &mut PaymentParameters, mut val: u8) {
1374 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_path_count = val;
1376 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1377 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1378 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1379 /// increasing failure probability for those paths.
1381 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1382 /// restriction have been found. While paths which meet this criteria will be searched for, it
1383 /// is ultimately up to the scorer to select them over other paths.
1385 /// A value of 0 will allow payments up to and including a channel's total announced usable
1386 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1388 /// Default value: 2
1390 pub extern "C" fn PaymentParameters_get_max_channel_saturation_power_of_half(this_ptr: &PaymentParameters) -> u8 {
1391 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_saturation_power_of_half;
1394 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1395 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1396 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1397 /// increasing failure probability for those paths.
1399 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1400 /// restriction have been found. While paths which meet this criteria will be searched for, it
1401 /// is ultimately up to the scorer to select them over other paths.
1403 /// A value of 0 will allow payments up to and including a channel's total announced usable
1404 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1406 /// Default value: 2
1408 pub extern "C" fn PaymentParameters_set_max_channel_saturation_power_of_half(this_ptr: &mut PaymentParameters, mut val: u8) {
1409 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_saturation_power_of_half = val;
1411 /// A list of SCIDs which this payment was previously attempted over and which caused the
1412 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1415 /// Returns a copy of the field.
1417 pub extern "C" fn PaymentParameters_get_previously_failed_channels(this_ptr: &PaymentParameters) -> crate::c_types::derived::CVec_u64Z {
1418 let mut inner_val = this_ptr.get_native_mut_ref().previously_failed_channels.clone();
1419 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1420 local_inner_val.into()
1422 /// A list of SCIDs which this payment was previously attempted over and which caused the
1423 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1426 pub extern "C" fn PaymentParameters_set_previously_failed_channels(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_u64Z) {
1427 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1428 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previously_failed_channels = local_val;
1430 /// Constructs a new PaymentParameters given each field
1433 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_channel_saturation_power_of_half_arg: u8, mut previously_failed_channels_arg: crate::c_types::derived::CVec_u64Z) -> PaymentParameters {
1434 let mut local_expiry_time_arg = if expiry_time_arg.is_some() { Some( { expiry_time_arg.take() }) } else { None };
1435 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 }); };
1436 PaymentParameters { inner: ObjOps::heap_alloc(nativePaymentParameters {
1437 payee: payee_arg.into_native(),
1438 expiry_time: local_expiry_time_arg,
1439 max_total_cltv_expiry_delta: max_total_cltv_expiry_delta_arg,
1440 max_path_count: max_path_count_arg,
1441 max_channel_saturation_power_of_half: max_channel_saturation_power_of_half_arg,
1442 previously_failed_channels: local_previously_failed_channels_arg,
1443 }), is_owned: true }
1445 impl Clone for PaymentParameters {
1446 fn clone(&self) -> Self {
1448 inner: if <*mut nativePaymentParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1449 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1455 /// Used only if an object of this type is returned as a trait impl by a method
1456 pub(crate) extern "C" fn PaymentParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1457 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentParameters)).clone() })) as *mut c_void
1460 /// Creates a copy of the PaymentParameters
1461 pub extern "C" fn PaymentParameters_clone(orig: &PaymentParameters) -> PaymentParameters {
1464 /// Generates a non-cryptographic 64-bit hash of the PaymentParameters.
1466 pub extern "C" fn PaymentParameters_hash(o: &PaymentParameters) -> u64 {
1467 if o.inner.is_null() { return 0; }
1468 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1469 #[allow(deprecated)]
1470 let mut hasher = core::hash::SipHasher::new();
1471 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1472 core::hash::Hasher::finish(&hasher)
1474 /// Checks if two PaymentParameterss contain equal inner contents.
1475 /// This ignores pointers and is_owned flags and looks at the values in fields.
1476 /// Two objects with NULL inner values will be considered "equal" here.
1478 pub extern "C" fn PaymentParameters_eq(a: &PaymentParameters, b: &PaymentParameters) -> bool {
1479 if a.inner == b.inner { return true; }
1480 if a.inner.is_null() || b.inner.is_null() { return false; }
1481 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1484 /// Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
1485 pub extern "C" fn PaymentParameters_write(obj: &crate::lightning::routing::router::PaymentParameters) -> crate::c_types::derived::CVec_u8Z {
1486 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1489 pub(crate) extern "C" fn PaymentParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1490 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentParameters) })
1493 /// Read a PaymentParameters from a byte array, created by PaymentParameters_write
1494 pub extern "C" fn PaymentParameters_read(ser: crate::c_types::u8slice, arg: u32) -> crate::c_types::derived::CResult_PaymentParametersDecodeErrorZ {
1496 let res: Result<lightning::routing::router::PaymentParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1497 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() };
1500 /// Creates a payee with the node id of the given `pubkey`.
1502 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1506 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 {
1507 let mut ret = lightning::routing::router::PaymentParameters::from_node_id(payee_pubkey.into_rust(), final_cltv_expiry_delta);
1508 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1511 /// Creates a payee with the node id of the given `pubkey` to use for keysend payments.
1513 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1516 /// Note that MPP keysend is not widely supported yet. The `allow_mpp` lets you choose
1517 /// whether your router will be allowed to find a multi-part route for this payment. If you
1518 /// set `allow_mpp` to true, you should ensure a payment secret is set on send, likely via
1519 /// [`RecipientOnionFields::secret_only`].
1521 /// [`RecipientOnionFields::secret_only`]: crate::ln::channelmanager::RecipientOnionFields::secret_only
1524 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 {
1525 let mut ret = lightning::routing::router::PaymentParameters::for_keysend(payee_pubkey.into_rust(), final_cltv_expiry_delta, allow_mpp);
1526 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1529 /// Creates parameters for paying to a blinded payee from the provided invoice. Sets
1530 /// [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and
1531 /// [`PaymentParameters::expiry_time`].
1534 pub extern "C" fn PaymentParameters_from_bolt12_invoice(invoice: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::routing::router::PaymentParameters {
1535 let mut ret = lightning::routing::router::PaymentParameters::from_bolt12_invoice(invoice.get_native_ref());
1536 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1539 /// The recipient of a payment, differing based on whether they've hidden their identity with route
1545 /// The recipient provided blinded paths and payinfo to reach them. The blinded paths themselves
1546 /// will be included in the final [`Route`].
1548 /// Aggregated routing info and blinded paths, for routing to the payee without knowing their
1550 route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ,
1551 /// Features supported by the payee.
1553 /// May be set from the payee's invoice. May be `None` if the invoice does not contain any
1556 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1557 features: crate::lightning::ln::features::Bolt12InvoiceFeatures,
1559 /// The recipient included these route hints in their BOLT11 invoice.
1561 /// The node id of the payee.
1562 node_id: crate::c_types::PublicKey,
1563 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
1564 route_hints: crate::c_types::derived::CVec_RouteHintZ,
1565 /// Features supported by the payee.
1567 /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
1568 /// does not contain any features.
1570 /// [`for_keysend`]: PaymentParameters::for_keysend
1572 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1573 features: crate::lightning::ln::features::Bolt11InvoiceFeatures,
1574 /// The minimum CLTV delta at the end of the route. This value must not be zero.
1575 final_cltv_expiry_delta: u32,
1578 use lightning::routing::router::Payee as PayeeImport;
1579 pub(crate) type nativePayee = PayeeImport;
1583 pub(crate) fn to_native(&self) -> nativePayee {
1585 Payee::Blinded {ref route_hints, ref features, } => {
1586 let mut route_hints_nonref = Clone::clone(route_hints);
1587 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.into_rust().drain(..) { local_route_hints_nonref.push( { let (mut orig_route_hints_nonref_0_0, mut orig_route_hints_nonref_0_1) = item.to_rust(); let mut local_route_hints_nonref_0 = (*unsafe { Box::from_raw(orig_route_hints_nonref_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_route_hints_nonref_0_1.take_inner()) }); local_route_hints_nonref_0 }); };
1588 let mut features_nonref = Clone::clone(features);
1589 let mut local_features_nonref = if features_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_nonref.take_inner()) } }) };
1590 nativePayee::Blinded {
1591 route_hints: local_route_hints_nonref,
1592 features: local_features_nonref,
1595 Payee::Clear {ref node_id, ref route_hints, ref features, ref final_cltv_expiry_delta, } => {
1596 let mut node_id_nonref = Clone::clone(node_id);
1597 let mut route_hints_nonref = Clone::clone(route_hints);
1598 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()) } }); };
1599 let mut features_nonref = Clone::clone(features);
1600 let mut local_features_nonref = if features_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_nonref.take_inner()) } }) };
1601 let mut final_cltv_expiry_delta_nonref = Clone::clone(final_cltv_expiry_delta);
1602 nativePayee::Clear {
1603 node_id: node_id_nonref.into_rust(),
1604 route_hints: local_route_hints_nonref,
1605 features: local_features_nonref,
1606 final_cltv_expiry_delta: final_cltv_expiry_delta_nonref,
1612 pub(crate) fn into_native(self) -> nativePayee {
1614 Payee::Blinded {mut route_hints, mut features, } => {
1615 let mut local_route_hints = Vec::new(); for mut item in route_hints.into_rust().drain(..) { local_route_hints.push( { let (mut orig_route_hints_0_0, mut orig_route_hints_0_1) = item.to_rust(); let mut local_route_hints_0 = (*unsafe { Box::from_raw(orig_route_hints_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_route_hints_0_1.take_inner()) }); local_route_hints_0 }); };
1616 let mut local_features = if features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features.take_inner()) } }) };
1617 nativePayee::Blinded {
1618 route_hints: local_route_hints,
1619 features: local_features,
1622 Payee::Clear {mut node_id, mut route_hints, mut features, mut final_cltv_expiry_delta, } => {
1623 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()) } }); };
1624 let mut local_features = if features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features.take_inner()) } }) };
1625 nativePayee::Clear {
1626 node_id: node_id.into_rust(),
1627 route_hints: local_route_hints,
1628 features: local_features,
1629 final_cltv_expiry_delta: final_cltv_expiry_delta,
1635 pub(crate) fn from_native(native: &nativePayee) -> Self {
1637 nativePayee::Blinded {ref route_hints, ref features, } => {
1638 let mut route_hints_nonref = Clone::clone(route_hints);
1639 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.drain(..) { local_route_hints_nonref.push( { let (mut orig_route_hints_nonref_0_0, mut orig_route_hints_nonref_0_1) = item; let mut local_route_hints_nonref_0 = (crate::lightning::offers::invoice::BlindedPayInfo { inner: ObjOps::heap_alloc(orig_route_hints_nonref_0_0), is_owned: true }, crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(orig_route_hints_nonref_0_1), is_owned: true }).into(); local_route_hints_nonref_0 }); };
1640 let mut features_nonref = Clone::clone(features);
1641 let mut local_features_nonref = crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: if features_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features_nonref.unwrap())) } }, is_owned: true };
1643 route_hints: local_route_hints_nonref.into(),
1644 features: local_features_nonref,
1647 nativePayee::Clear {ref node_id, ref route_hints, ref features, ref final_cltv_expiry_delta, } => {
1648 let mut node_id_nonref = Clone::clone(node_id);
1649 let mut route_hints_nonref = Clone::clone(route_hints);
1650 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.drain(..) { local_route_hints_nonref.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1651 let mut features_nonref = Clone::clone(features);
1652 let mut local_features_nonref = crate::lightning::ln::features::Bolt11InvoiceFeatures { inner: if features_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features_nonref.unwrap())) } }, is_owned: true };
1653 let mut final_cltv_expiry_delta_nonref = Clone::clone(final_cltv_expiry_delta);
1655 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1656 route_hints: local_route_hints_nonref.into(),
1657 features: local_features_nonref,
1658 final_cltv_expiry_delta: final_cltv_expiry_delta_nonref,
1664 pub(crate) fn native_into(native: nativePayee) -> Self {
1666 nativePayee::Blinded {mut route_hints, mut features, } => {
1667 let mut local_route_hints = Vec::new(); for mut item in route_hints.drain(..) { local_route_hints.push( { let (mut orig_route_hints_0_0, mut orig_route_hints_0_1) = item; let mut local_route_hints_0 = (crate::lightning::offers::invoice::BlindedPayInfo { inner: ObjOps::heap_alloc(orig_route_hints_0_0), is_owned: true }, crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(orig_route_hints_0_1), is_owned: true }).into(); local_route_hints_0 }); };
1668 let mut local_features = crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: if features.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features.unwrap())) } }, is_owned: true };
1670 route_hints: local_route_hints.into(),
1671 features: local_features,
1674 nativePayee::Clear {mut node_id, mut route_hints, mut features, mut final_cltv_expiry_delta, } => {
1675 let mut local_route_hints = Vec::new(); for mut item in route_hints.drain(..) { local_route_hints.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1676 let mut local_features = crate::lightning::ln::features::Bolt11InvoiceFeatures { inner: if features.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features.unwrap())) } }, is_owned: true };
1678 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1679 route_hints: local_route_hints.into(),
1680 features: local_features,
1681 final_cltv_expiry_delta: final_cltv_expiry_delta,
1687 /// Frees any resources used by the Payee
1689 pub extern "C" fn Payee_free(this_ptr: Payee) { }
1690 /// Creates a copy of the Payee
1692 pub extern "C" fn Payee_clone(orig: &Payee) -> Payee {
1696 /// Utility method to constructs a new Blinded-variant Payee
1697 pub extern "C" fn Payee_blinded(route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ, features: crate::lightning::ln::features::Bolt12InvoiceFeatures) -> Payee {
1704 /// Utility method to constructs a new Clear-variant Payee
1705 pub extern "C" fn Payee_clear(node_id: crate::c_types::PublicKey, route_hints: crate::c_types::derived::CVec_RouteHintZ, features: crate::lightning::ln::features::Bolt11InvoiceFeatures, final_cltv_expiry_delta: u32) -> Payee {
1710 final_cltv_expiry_delta,
1713 /// Generates a non-cryptographic 64-bit hash of the Payee.
1715 pub extern "C" fn Payee_hash(o: &Payee) -> u64 {
1716 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1717 #[allow(deprecated)]
1718 let mut hasher = core::hash::SipHasher::new();
1719 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1720 core::hash::Hasher::finish(&hasher)
1722 /// Checks if two Payees contain equal inner contents.
1723 /// This ignores pointers and is_owned flags and looks at the values in fields.
1725 pub extern "C" fn Payee_eq(a: &Payee, b: &Payee) -> bool {
1726 if &a.to_native() == &b.to_native() { true } else { false }
1729 use lightning::routing::router::RouteHint as nativeRouteHintImport;
1730 pub(crate) type nativeRouteHint = nativeRouteHintImport;
1732 /// A list of hops along a payment path terminating with a channel to the recipient.
1735 pub struct RouteHint {
1736 /// A pointer to the opaque Rust object.
1738 /// Nearly everywhere, inner must be non-null, however in places where
1739 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1740 pub inner: *mut nativeRouteHint,
1741 /// Indicates that this is the only struct which contains the same pointer.
1743 /// Rust functions which take ownership of an object provided via an argument require
1744 /// this to be true and invalidate the object pointed to by inner.
1748 impl Drop for RouteHint {
1749 fn drop(&mut self) {
1750 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
1751 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1755 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
1757 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
1759 /// Used only if an object of this type is returned as a trait impl by a method
1760 pub(crate) extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
1761 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHint) };
1765 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHint {
1766 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1768 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHint {
1769 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1771 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1772 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
1773 assert!(self.is_owned);
1774 let ret = ObjOps::untweak_ptr(self.inner);
1775 self.inner = core::ptr::null_mut();
1780 pub extern "C" fn RouteHint_get_a(this_ptr: &RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ {
1781 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1782 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::RouteHintHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::RouteHintHop<>) as *mut _) }, is_owned: false } }); };
1783 local_inner_val.into()
1786 pub extern "C" fn RouteHint_set_a(this_ptr: &mut RouteHint, mut val: crate::c_types::derived::CVec_RouteHintHopZ) {
1787 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1788 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = local_val;
1790 /// Constructs a new RouteHint given each field
1793 pub extern "C" fn RouteHint_new(mut a_arg: crate::c_types::derived::CVec_RouteHintHopZ) -> RouteHint {
1794 let mut local_a_arg = Vec::new(); for mut item in a_arg.into_rust().drain(..) { local_a_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1795 RouteHint { inner: ObjOps::heap_alloc(lightning::routing::router::RouteHint (
1797 )), is_owned: true }
1799 impl Clone for RouteHint {
1800 fn clone(&self) -> Self {
1802 inner: if <*mut nativeRouteHint>::is_null(self.inner) { core::ptr::null_mut() } else {
1803 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1809 /// Used only if an object of this type is returned as a trait impl by a method
1810 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
1811 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void
1814 /// Creates a copy of the RouteHint
1815 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
1818 /// Generates a non-cryptographic 64-bit hash of the RouteHint.
1820 pub extern "C" fn RouteHint_hash(o: &RouteHint) -> u64 {
1821 if o.inner.is_null() { return 0; }
1822 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1823 #[allow(deprecated)]
1824 let mut hasher = core::hash::SipHasher::new();
1825 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1826 core::hash::Hasher::finish(&hasher)
1828 /// Checks if two RouteHints contain equal inner contents.
1829 /// This ignores pointers and is_owned flags and looks at the values in fields.
1830 /// Two objects with NULL inner values will be considered "equal" here.
1832 pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool {
1833 if a.inner == b.inner { return true; }
1834 if a.inner.is_null() || b.inner.is_null() { return false; }
1835 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1838 /// Serialize the RouteHint object into a byte array which can be read by RouteHint_read
1839 pub extern "C" fn RouteHint_write(obj: &crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CVec_u8Z {
1840 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1843 pub(crate) extern "C" fn RouteHint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1844 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHint) })
1847 /// Read a RouteHint from a byte array, created by RouteHint_write
1848 pub extern "C" fn RouteHint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintDecodeErrorZ {
1849 let res: Result<lightning::routing::router::RouteHint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1850 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::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() };
1854 use lightning::routing::router::RouteHintHop as nativeRouteHintHopImport;
1855 pub(crate) type nativeRouteHintHop = nativeRouteHintHopImport;
1857 /// A channel descriptor for a hop along a payment path.
1860 pub struct RouteHintHop {
1861 /// A pointer to the opaque Rust object.
1863 /// Nearly everywhere, inner must be non-null, however in places where
1864 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1865 pub inner: *mut nativeRouteHintHop,
1866 /// Indicates that this is the only struct which contains the same pointer.
1868 /// Rust functions which take ownership of an object provided via an argument require
1869 /// this to be true and invalidate the object pointed to by inner.
1873 impl Drop for RouteHintHop {
1874 fn drop(&mut self) {
1875 if self.is_owned && !<*mut nativeRouteHintHop>::is_null(self.inner) {
1876 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1880 /// Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL.
1882 pub extern "C" fn RouteHintHop_free(this_obj: RouteHintHop) { }
1884 /// Used only if an object of this type is returned as a trait impl by a method
1885 pub(crate) extern "C" fn RouteHintHop_free_void(this_ptr: *mut c_void) {
1886 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHintHop) };
1890 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHintHop {
1891 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1893 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHintHop {
1894 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1896 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1897 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHintHop {
1898 assert!(self.is_owned);
1899 let ret = ObjOps::untweak_ptr(self.inner);
1900 self.inner = core::ptr::null_mut();
1904 /// The node_id of the non-target end of the route
1906 pub extern "C" fn RouteHintHop_get_src_node_id(this_ptr: &RouteHintHop) -> crate::c_types::PublicKey {
1907 let mut inner_val = &mut this_ptr.get_native_mut_ref().src_node_id;
1908 crate::c_types::PublicKey::from_rust(&inner_val)
1910 /// The node_id of the non-target end of the route
1912 pub extern "C" fn RouteHintHop_set_src_node_id(this_ptr: &mut RouteHintHop, mut val: crate::c_types::PublicKey) {
1913 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.src_node_id = val.into_rust();
1915 /// The short_channel_id of this channel
1917 pub extern "C" fn RouteHintHop_get_short_channel_id(this_ptr: &RouteHintHop) -> u64 {
1918 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
1921 /// The short_channel_id of this channel
1923 pub extern "C" fn RouteHintHop_set_short_channel_id(this_ptr: &mut RouteHintHop, mut val: u64) {
1924 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
1926 /// The fees which must be paid to use this channel
1928 pub extern "C" fn RouteHintHop_get_fees(this_ptr: &RouteHintHop) -> crate::lightning::routing::gossip::RoutingFees {
1929 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
1930 crate::lightning::routing::gossip::RoutingFees { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::RoutingFees<>) as *mut _) }, is_owned: false }
1932 /// The fees which must be paid to use this channel
1934 pub extern "C" fn RouteHintHop_set_fees(this_ptr: &mut RouteHintHop, mut val: crate::lightning::routing::gossip::RoutingFees) {
1935 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
1937 /// The difference in CLTV values between this node and the next node.
1939 pub extern "C" fn RouteHintHop_get_cltv_expiry_delta(this_ptr: &RouteHintHop) -> u16 {
1940 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
1943 /// The difference in CLTV values between this node and the next node.
1945 pub extern "C" fn RouteHintHop_set_cltv_expiry_delta(this_ptr: &mut RouteHintHop, mut val: u16) {
1946 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
1948 /// The minimum value, in msat, which must be relayed to the next hop.
1950 pub extern "C" fn RouteHintHop_get_htlc_minimum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
1951 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
1952 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() }) };
1955 /// The minimum value, in msat, which must be relayed to the next hop.
1957 pub extern "C" fn RouteHintHop_set_htlc_minimum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
1958 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1959 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = local_val;
1961 /// The maximum value in msat available for routing with a single HTLC.
1963 pub extern "C" fn RouteHintHop_get_htlc_maximum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
1964 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
1965 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() }) };
1968 /// The maximum value in msat available for routing with a single HTLC.
1970 pub extern "C" fn RouteHintHop_set_htlc_maximum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
1971 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1972 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
1974 /// Constructs a new RouteHintHop given each field
1977 pub extern "C" fn RouteHintHop_new(mut src_node_id_arg: crate::c_types::PublicKey, mut short_channel_id_arg: u64, mut fees_arg: crate::lightning::routing::gossip::RoutingFees, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: crate::c_types::derived::COption_u64Z, mut htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z) -> RouteHintHop {
1978 let mut local_htlc_minimum_msat_arg = if htlc_minimum_msat_arg.is_some() { Some( { htlc_minimum_msat_arg.take() }) } else { None };
1979 let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
1980 RouteHintHop { inner: ObjOps::heap_alloc(nativeRouteHintHop {
1981 src_node_id: src_node_id_arg.into_rust(),
1982 short_channel_id: short_channel_id_arg,
1983 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
1984 cltv_expiry_delta: cltv_expiry_delta_arg,
1985 htlc_minimum_msat: local_htlc_minimum_msat_arg,
1986 htlc_maximum_msat: local_htlc_maximum_msat_arg,
1987 }), is_owned: true }
1989 impl Clone for RouteHintHop {
1990 fn clone(&self) -> Self {
1992 inner: if <*mut nativeRouteHintHop>::is_null(self.inner) { core::ptr::null_mut() } else {
1993 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1999 /// Used only if an object of this type is returned as a trait impl by a method
2000 pub(crate) extern "C" fn RouteHintHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
2001 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHintHop)).clone() })) as *mut c_void
2004 /// Creates a copy of the RouteHintHop
2005 pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop {
2008 /// Generates a non-cryptographic 64-bit hash of the RouteHintHop.
2010 pub extern "C" fn RouteHintHop_hash(o: &RouteHintHop) -> u64 {
2011 if o.inner.is_null() { return 0; }
2012 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2013 #[allow(deprecated)]
2014 let mut hasher = core::hash::SipHasher::new();
2015 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2016 core::hash::Hasher::finish(&hasher)
2018 /// Checks if two RouteHintHops contain equal inner contents.
2019 /// This ignores pointers and is_owned flags and looks at the values in fields.
2020 /// Two objects with NULL inner values will be considered "equal" here.
2022 pub extern "C" fn RouteHintHop_eq(a: &RouteHintHop, b: &RouteHintHop) -> bool {
2023 if a.inner == b.inner { return true; }
2024 if a.inner.is_null() || b.inner.is_null() { return false; }
2025 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2028 /// Serialize the RouteHintHop object into a byte array which can be read by RouteHintHop_read
2029 pub extern "C" fn RouteHintHop_write(obj: &crate::lightning::routing::router::RouteHintHop) -> crate::c_types::derived::CVec_u8Z {
2030 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2033 pub(crate) extern "C" fn RouteHintHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2034 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHintHop) })
2037 /// Read a RouteHintHop from a byte array, created by RouteHintHop_write
2038 pub extern "C" fn RouteHintHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintHopDecodeErrorZ {
2039 let res: Result<lightning::routing::router::RouteHintHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2040 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::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() };
2043 /// Finds a route from us (payer) to the given target node (payee).
2045 /// If the payee provided features in their invoice, they should be provided via the `payee` field
2046 /// in the given [`RouteParameters::payment_params`].
2047 /// Without this, MPP will only be used if the payee's features are available in the network graph.
2049 /// Private routing paths between a public node and the target may be included in the `payee` field
2050 /// of [`RouteParameters::payment_params`].
2052 /// If some channels aren't announced, it may be useful to fill in `first_hops` with the results
2053 /// from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
2054 /// from `network_graph` will be ignored, and only those in `first_hops` will be used.
2056 /// The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
2057 /// However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
2058 /// `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
2062 /// Panics if first_hops contains channels without `short_channel_id`s;
2063 /// [`ChannelManager::list_usable_channels`] will never include such channels.
2065 /// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
2066 /// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
2067 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
2069 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
2071 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::Score, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
2072 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[..]);
2073 let mut ret = lightning::routing::router::find_route::<crate::lightning::util::logger::Logger, crate::lightning::util::logger::Logger, crate::lightning::routing::scoring::Score>(&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});
2074 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() };
2078 /// Construct a route from us (payer) to the target node (payee) via the given hops (which should
2079 /// exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
2081 /// Re-uses logic from `find_route`, so the restrictions described there also apply here.
2083 pub extern "C" fn build_route_from_hops(mut our_node_pubkey: crate::c_types::PublicKey, mut hops: crate::c_types::derived::CVec_PublicKeyZ, route_params: &crate::lightning::routing::router::RouteParameters, network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut logger: crate::lightning::util::logger::Logger, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
2084 let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { item.into_rust() }); };
2085 let mut ret = lightning::routing::router::build_route_from_hops::<crate::lightning::util::logger::Logger, crate::lightning::util::logger::Logger>(&our_node_pubkey.into_rust(), &local_hops[..], route_params.get_native_ref(), network_graph.get_native_ref(), logger, unsafe { &*random_seed_bytes});
2086 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() };