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 alloc::string::String;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
21 use lightning::routing::router::DefaultRouter as nativeDefaultRouterImport;
22 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>;
24 /// A [`Router`] implemented using [`find_route`].
27 pub struct DefaultRouter {
28 /// A pointer to the opaque Rust object.
30 /// Nearly everywhere, inner must be non-null, however in places where
31 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
32 pub inner: *mut nativeDefaultRouter,
33 /// Indicates that this is the only struct which contains the same pointer.
35 /// Rust functions which take ownership of an object provided via an argument require
36 /// this to be true and invalidate the object pointed to by inner.
40 impl Drop for DefaultRouter {
42 if self.is_owned && !<*mut nativeDefaultRouter>::is_null(self.inner) {
43 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
47 /// Frees any resources used by the DefaultRouter, if is_owned is set and inner is non-NULL.
49 pub extern "C" fn DefaultRouter_free(this_obj: DefaultRouter) { }
51 /// Used only if an object of this type is returned as a trait impl by a method
52 pub(crate) extern "C" fn DefaultRouter_free_void(this_ptr: *mut c_void) {
53 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDefaultRouter) };
57 pub(crate) fn get_native_ref(&self) -> &'static nativeDefaultRouter {
58 unsafe { &*ObjOps::untweak_ptr(self.inner) }
60 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDefaultRouter {
61 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
63 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
64 pub(crate) fn take_inner(mut self) -> *mut nativeDefaultRouter {
65 assert!(self.is_owned);
66 let ret = ObjOps::untweak_ptr(self.inner);
67 self.inner = core::ptr::null_mut();
71 /// Creates a new router.
74 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 {
75 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()) });
76 crate::lightning::routing::router::DefaultRouter { inner: ObjOps::heap_alloc(ret), is_owned: true }
79 impl From<nativeDefaultRouter> for crate::lightning::routing::router::Router {
80 fn from(obj: nativeDefaultRouter) -> Self {
81 let rust_obj = crate::lightning::routing::router::DefaultRouter { inner: ObjOps::heap_alloc(obj), is_owned: true };
82 let mut ret = DefaultRouter_as_Router(&rust_obj);
83 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
84 core::mem::forget(rust_obj);
85 ret.free = Some(DefaultRouter_free_void);
89 /// Constructs a new Router which calls the relevant methods on this_arg.
90 /// This copies the `inner` pointer in this_arg and thus the returned Router must be freed before this_arg is
92 pub extern "C" fn DefaultRouter_as_Router(this_arg: &DefaultRouter) -> crate::lightning::routing::router::Router {
93 crate::lightning::routing::router::Router {
94 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
96 find_route: DefaultRouter_Router_find_route,
97 find_route_with_id: DefaultRouter_Router_find_route_with_id,
102 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 {
103 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[..]);
104 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()) });
105 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() };
109 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 {
110 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[..]);
111 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));
112 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() };
116 /// A trait defining behavior for routing a payment.
119 /// An opaque pointer which is passed to your function implementations as an argument.
120 /// This has no meaning in the LDK, and can be NULL or any other value.
121 pub this_arg: *mut c_void,
122 /// Finds a [`Route`] for a payment between the given `payer` and a payee.
124 /// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
125 /// and [`RouteParameters::final_value_msat`], respectively.
127 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
128 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,
129 /// Finds a [`Route`] for a payment between the given `payer` and a payee.
131 /// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
132 /// and [`RouteParameters::final_value_msat`], respectively.
134 /// Includes a [`PaymentHash`] and a [`PaymentId`] to be able to correlate the request with a specific
137 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
138 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,
139 /// Frees any resources associated with this object given its this_arg pointer.
140 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
141 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
143 unsafe impl Send for Router {}
144 unsafe impl Sync for Router {}
146 pub(crate) fn Router_clone_fields(orig: &Router) -> Router {
148 this_arg: orig.this_arg,
149 find_route: Clone::clone(&orig.find_route),
150 find_route_with_id: Clone::clone(&orig.find_route_with_id),
151 free: Clone::clone(&orig.free),
155 use lightning::routing::router::Router as rustRouter;
156 impl rustRouter for Router {
157 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> {
158 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;
159 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 });
160 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()) } })};
163 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> {
164 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;
165 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 });
166 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()) } })};
171 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
172 // directly as a Deref trait in higher-level structs:
173 impl core::ops::Deref for Router {
175 fn deref(&self) -> &Self {
179 impl core::ops::DerefMut for Router {
180 fn deref_mut(&mut self) -> &mut Self {
184 /// Calls the free function if one is set
186 pub extern "C" fn Router_free(this_ptr: Router) { }
187 impl Drop for Router {
189 if let Some(f) = self.free {
195 use lightning::routing::router::ScorerAccountingForInFlightHtlcs as nativeScorerAccountingForInFlightHtlcsImport;
196 pub(crate) type nativeScorerAccountingForInFlightHtlcs = nativeScorerAccountingForInFlightHtlcsImport<'static, crate::lightning::routing::scoring::ScoreLookUp>;
198 /// [`ScoreLookUp`] implementation that factors in in-flight HTLC liquidity.
200 /// Useful for custom [`Router`] implementations to wrap their [`ScoreLookUp`] on-the-fly when calling
203 /// [`ScoreLookUp`]: crate::routing::scoring::ScoreLookUp
206 pub struct ScorerAccountingForInFlightHtlcs {
207 /// A pointer to the opaque Rust object.
209 /// Nearly everywhere, inner must be non-null, however in places where
210 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
211 pub inner: *mut nativeScorerAccountingForInFlightHtlcs,
212 /// Indicates that this is the only struct which contains the same pointer.
214 /// Rust functions which take ownership of an object provided via an argument require
215 /// this to be true and invalidate the object pointed to by inner.
219 impl Drop for ScorerAccountingForInFlightHtlcs {
221 if self.is_owned && !<*mut nativeScorerAccountingForInFlightHtlcs>::is_null(self.inner) {
222 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
226 /// Frees any resources used by the ScorerAccountingForInFlightHtlcs, if is_owned is set and inner is non-NULL.
228 pub extern "C" fn ScorerAccountingForInFlightHtlcs_free(this_obj: ScorerAccountingForInFlightHtlcs) { }
230 /// Used only if an object of this type is returned as a trait impl by a method
231 pub(crate) extern "C" fn ScorerAccountingForInFlightHtlcs_free_void(this_ptr: *mut c_void) {
232 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeScorerAccountingForInFlightHtlcs) };
235 impl ScorerAccountingForInFlightHtlcs {
236 pub(crate) fn get_native_ref(&self) -> &'static nativeScorerAccountingForInFlightHtlcs {
237 unsafe { &*ObjOps::untweak_ptr(self.inner) }
239 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeScorerAccountingForInFlightHtlcs {
240 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
242 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
243 pub(crate) fn take_inner(mut self) -> *mut nativeScorerAccountingForInFlightHtlcs {
244 assert!(self.is_owned);
245 let ret = ObjOps::untweak_ptr(self.inner);
246 self.inner = core::ptr::null_mut();
250 /// Initialize a new `ScorerAccountingForInFlightHtlcs`.
253 pub extern "C" fn ScorerAccountingForInFlightHtlcs_new(mut scorer: crate::lightning::routing::scoring::ScoreLookUp, inflight_htlcs: &crate::lightning::routing::router::InFlightHtlcs) -> crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs {
254 let mut ret = lightning::routing::router::ScorerAccountingForInFlightHtlcs::new(scorer, inflight_htlcs.get_native_ref());
255 crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
258 impl From<nativeScorerAccountingForInFlightHtlcs> for crate::lightning::routing::scoring::ScoreLookUp {
259 fn from(obj: nativeScorerAccountingForInFlightHtlcs) -> Self {
260 let rust_obj = crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(obj), is_owned: true };
261 let mut ret = ScorerAccountingForInFlightHtlcs_as_ScoreLookUp(&rust_obj);
262 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
263 core::mem::forget(rust_obj);
264 ret.free = Some(ScorerAccountingForInFlightHtlcs_free_void);
268 /// Constructs a new ScoreLookUp which calls the relevant methods on this_arg.
269 /// This copies the `inner` pointer in this_arg and thus the returned ScoreLookUp must be freed before this_arg is
271 pub extern "C" fn ScorerAccountingForInFlightHtlcs_as_ScoreLookUp(this_arg: &ScorerAccountingForInFlightHtlcs) -> crate::lightning::routing::scoring::ScoreLookUp {
272 crate::lightning::routing::scoring::ScoreLookUp {
273 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
275 channel_penalty_msat: ScorerAccountingForInFlightHtlcs_ScoreLookUp_channel_penalty_msat,
280 extern "C" fn ScorerAccountingForInFlightHtlcs_ScoreLookUp_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 {
281 let mut ret = <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::ScoreLookUp<>>::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());
286 use lightning::routing::router::InFlightHtlcs as nativeInFlightHtlcsImport;
287 pub(crate) type nativeInFlightHtlcs = nativeInFlightHtlcsImport;
289 /// A data structure for tracking in-flight HTLCs. May be used during pathfinding to account for
290 /// in-use channel liquidity.
293 pub struct InFlightHtlcs {
294 /// A pointer to the opaque Rust object.
296 /// Nearly everywhere, inner must be non-null, however in places where
297 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
298 pub inner: *mut nativeInFlightHtlcs,
299 /// Indicates that this is the only struct which contains the same pointer.
301 /// Rust functions which take ownership of an object provided via an argument require
302 /// this to be true and invalidate the object pointed to by inner.
306 impl Drop for InFlightHtlcs {
308 if self.is_owned && !<*mut nativeInFlightHtlcs>::is_null(self.inner) {
309 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
313 /// Frees any resources used by the InFlightHtlcs, if is_owned is set and inner is non-NULL.
315 pub extern "C" fn InFlightHtlcs_free(this_obj: InFlightHtlcs) { }
317 /// Used only if an object of this type is returned as a trait impl by a method
318 pub(crate) extern "C" fn InFlightHtlcs_free_void(this_ptr: *mut c_void) {
319 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInFlightHtlcs) };
323 pub(crate) fn get_native_ref(&self) -> &'static nativeInFlightHtlcs {
324 unsafe { &*ObjOps::untweak_ptr(self.inner) }
326 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInFlightHtlcs {
327 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
329 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
330 pub(crate) fn take_inner(mut self) -> *mut nativeInFlightHtlcs {
331 assert!(self.is_owned);
332 let ret = ObjOps::untweak_ptr(self.inner);
333 self.inner = core::ptr::null_mut();
337 impl Clone for InFlightHtlcs {
338 fn clone(&self) -> Self {
340 inner: if <*mut nativeInFlightHtlcs>::is_null(self.inner) { core::ptr::null_mut() } else {
341 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
347 /// Used only if an object of this type is returned as a trait impl by a method
348 pub(crate) extern "C" fn InFlightHtlcs_clone_void(this_ptr: *const c_void) -> *mut c_void {
349 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInFlightHtlcs)).clone() })) as *mut c_void
352 /// Creates a copy of the InFlightHtlcs
353 pub extern "C" fn InFlightHtlcs_clone(orig: &InFlightHtlcs) -> InFlightHtlcs {
356 /// Constructs an empty `InFlightHtlcs`.
359 pub extern "C" fn InFlightHtlcs_new() -> crate::lightning::routing::router::InFlightHtlcs {
360 let mut ret = lightning::routing::router::InFlightHtlcs::new();
361 crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
364 /// Takes in a path with payer's node id and adds the path's details to `InFlightHtlcs`.
366 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) {
367 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())
370 /// Adds a known HTLC given the public key of the HTLC source, target, and short channel
373 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) {
374 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)
377 /// Returns liquidity in msat given the public key of the HTLC source, target, and short channel
381 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 {
382 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.used_liquidity_msat(source.get_native_ref(), target.get_native_ref(), channel_scid);
383 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() }) };
388 /// Serialize the InFlightHtlcs object into a byte array which can be read by InFlightHtlcs_read
389 pub extern "C" fn InFlightHtlcs_write(obj: &crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CVec_u8Z {
390 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
393 pub(crate) extern "C" fn InFlightHtlcs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
394 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInFlightHtlcs) })
397 /// Read a InFlightHtlcs from a byte array, created by InFlightHtlcs_write
398 pub extern "C" fn InFlightHtlcs_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InFlightHtlcsDecodeErrorZ {
399 let res: Result<lightning::routing::router::InFlightHtlcs, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
400 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() };
404 use lightning::routing::router::RouteHop as nativeRouteHopImport;
405 pub(crate) type nativeRouteHop = nativeRouteHopImport;
407 /// A hop in a route, and additional metadata about it. \"Hop\" is defined as a node and the channel
408 /// that leads to it.
411 pub struct RouteHop {
412 /// A pointer to the opaque Rust object.
414 /// Nearly everywhere, inner must be non-null, however in places where
415 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
416 pub inner: *mut nativeRouteHop,
417 /// Indicates that this is the only struct which contains the same pointer.
419 /// Rust functions which take ownership of an object provided via an argument require
420 /// this to be true and invalidate the object pointed to by inner.
424 impl Drop for RouteHop {
426 if self.is_owned && !<*mut nativeRouteHop>::is_null(self.inner) {
427 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
431 /// Frees any resources used by the RouteHop, if is_owned is set and inner is non-NULL.
433 pub extern "C" fn RouteHop_free(this_obj: RouteHop) { }
435 /// Used only if an object of this type is returned as a trait impl by a method
436 pub(crate) extern "C" fn RouteHop_free_void(this_ptr: *mut c_void) {
437 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHop) };
441 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHop {
442 unsafe { &*ObjOps::untweak_ptr(self.inner) }
444 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHop {
445 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
447 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
448 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHop {
449 assert!(self.is_owned);
450 let ret = ObjOps::untweak_ptr(self.inner);
451 self.inner = core::ptr::null_mut();
455 /// The node_id of the node at this hop.
457 pub extern "C" fn RouteHop_get_pubkey(this_ptr: &RouteHop) -> crate::c_types::PublicKey {
458 let mut inner_val = &mut this_ptr.get_native_mut_ref().pubkey;
459 crate::c_types::PublicKey::from_rust(&inner_val)
461 /// The node_id of the node at this hop.
463 pub extern "C" fn RouteHop_set_pubkey(this_ptr: &mut RouteHop, mut val: crate::c_types::PublicKey) {
464 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.pubkey = val.into_rust();
466 /// The node_announcement features of the node at this hop. For the last hop, these may be
467 /// amended to match the features present in the invoice this node generated.
469 pub extern "C" fn RouteHop_get_node_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::NodeFeatures {
470 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_features;
471 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 }
473 /// The node_announcement features of the node at this hop. For the last hop, these may be
474 /// amended to match the features present in the invoice this node generated.
476 pub extern "C" fn RouteHop_set_node_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::NodeFeatures) {
477 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_features = *unsafe { Box::from_raw(val.take_inner()) };
479 /// The channel that should be used from the previous hop to reach this node.
481 pub extern "C" fn RouteHop_get_short_channel_id(this_ptr: &RouteHop) -> u64 {
482 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
485 /// The channel that should be used from the previous hop to reach this node.
487 pub extern "C" fn RouteHop_set_short_channel_id(this_ptr: &mut RouteHop, mut val: u64) {
488 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
490 /// The channel_announcement features of the channel that should be used from the previous hop
491 /// to reach this node.
493 pub extern "C" fn RouteHop_get_channel_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::ChannelFeatures {
494 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_features;
495 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 }
497 /// The channel_announcement features of the channel that should be used from the previous hop
498 /// to reach this node.
500 pub extern "C" fn RouteHop_set_channel_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::ChannelFeatures) {
501 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_features = *unsafe { Box::from_raw(val.take_inner()) };
503 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
504 /// If this is the last hop in [`Path::hops`]:
505 /// * if we're sending to a [`BlindedPath`], this is the fee paid for use of the entire blinded path
506 /// * otherwise, this is the full value of this [`Path`]'s part of the payment
508 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
510 pub extern "C" fn RouteHop_get_fee_msat(this_ptr: &RouteHop) -> u64 {
511 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_msat;
514 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
515 /// If this is the last hop in [`Path::hops`]:
516 /// * if we're sending to a [`BlindedPath`], this is the fee paid for use of the entire blinded path
517 /// * otherwise, this is the full value of this [`Path`]'s part of the payment
519 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
521 pub extern "C" fn RouteHop_set_fee_msat(this_ptr: &mut RouteHop, mut val: u64) {
522 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_msat = val;
524 /// The CLTV delta added for this hop.
525 /// If this is the last hop in [`Path::hops`]:
526 /// * if we're sending to a [`BlindedPath`], this is the CLTV delta for the entire blinded path
527 /// * otherwise, this is the CLTV delta expected at the destination
529 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
531 pub extern "C" fn RouteHop_get_cltv_expiry_delta(this_ptr: &RouteHop) -> u32 {
532 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
535 /// The CLTV delta added for this hop.
536 /// If this is the last hop in [`Path::hops`]:
537 /// * if we're sending to a [`BlindedPath`], this is the CLTV delta for the entire blinded path
538 /// * otherwise, this is the CLTV delta expected at the destination
540 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
542 pub extern "C" fn RouteHop_set_cltv_expiry_delta(this_ptr: &mut RouteHop, mut val: u32) {
543 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
545 /// Indicates whether this hop is possibly announced in the public network graph.
547 /// Will be `true` if there is a possibility that the channel is publicly known, i.e., if we
548 /// either know for sure it's announced in the public graph, or if any public channels exist
549 /// for which the given `short_channel_id` could be an alias for. Will be `false` if we believe
550 /// the channel to be unannounced.
552 /// Will be `true` for objects serialized with LDK version 0.0.116 and before.
554 pub extern "C" fn RouteHop_get_maybe_announced_channel(this_ptr: &RouteHop) -> bool {
555 let mut inner_val = &mut this_ptr.get_native_mut_ref().maybe_announced_channel;
558 /// Indicates whether this hop is possibly announced in the public network graph.
560 /// Will be `true` if there is a possibility that the channel is publicly known, i.e., if we
561 /// either know for sure it's announced in the public graph, or if any public channels exist
562 /// for which the given `short_channel_id` could be an alias for. Will be `false` if we believe
563 /// the channel to be unannounced.
565 /// Will be `true` for objects serialized with LDK version 0.0.116 and before.
567 pub extern "C" fn RouteHop_set_maybe_announced_channel(this_ptr: &mut RouteHop, mut val: bool) {
568 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.maybe_announced_channel = val;
570 /// Constructs a new RouteHop given each field
573 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, mut maybe_announced_channel_arg: bool) -> RouteHop {
574 RouteHop { inner: ObjOps::heap_alloc(nativeRouteHop {
575 pubkey: pubkey_arg.into_rust(),
576 node_features: *unsafe { Box::from_raw(node_features_arg.take_inner()) },
577 short_channel_id: short_channel_id_arg,
578 channel_features: *unsafe { Box::from_raw(channel_features_arg.take_inner()) },
579 fee_msat: fee_msat_arg,
580 cltv_expiry_delta: cltv_expiry_delta_arg,
581 maybe_announced_channel: maybe_announced_channel_arg,
584 impl Clone for RouteHop {
585 fn clone(&self) -> Self {
587 inner: if <*mut nativeRouteHop>::is_null(self.inner) { core::ptr::null_mut() } else {
588 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
594 /// Used only if an object of this type is returned as a trait impl by a method
595 pub(crate) extern "C" fn RouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
596 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRouteHop)).clone() })) as *mut c_void
599 /// Creates a copy of the RouteHop
600 pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop {
603 /// Generates a non-cryptographic 64-bit hash of the RouteHop.
605 pub extern "C" fn RouteHop_hash(o: &RouteHop) -> u64 {
606 if o.inner.is_null() { return 0; }
607 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
609 let mut hasher = core::hash::SipHasher::new();
610 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
611 core::hash::Hasher::finish(&hasher)
613 /// Checks if two RouteHops contain equal inner contents.
614 /// This ignores pointers and is_owned flags and looks at the values in fields.
615 /// Two objects with NULL inner values will be considered "equal" here.
617 pub extern "C" fn RouteHop_eq(a: &RouteHop, b: &RouteHop) -> bool {
618 if a.inner == b.inner { return true; }
619 if a.inner.is_null() || b.inner.is_null() { return false; }
620 if a.get_native_ref() == b.get_native_ref() { true } else { false }
623 /// Serialize the RouteHop object into a byte array which can be read by RouteHop_read
624 pub extern "C" fn RouteHop_write(obj: &crate::lightning::routing::router::RouteHop) -> crate::c_types::derived::CVec_u8Z {
625 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
628 pub(crate) extern "C" fn RouteHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
629 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHop) })
632 /// Read a RouteHop from a byte array, created by RouteHop_write
633 pub extern "C" fn RouteHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHopDecodeErrorZ {
634 let res: Result<lightning::routing::router::RouteHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
635 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() };
639 use lightning::routing::router::BlindedTail as nativeBlindedTailImport;
640 pub(crate) type nativeBlindedTail = nativeBlindedTailImport;
642 /// The blinded portion of a [`Path`], if we're routing to a recipient who provided blinded paths in
643 /// their [`Bolt12Invoice`].
645 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
648 pub struct BlindedTail {
649 /// A pointer to the opaque Rust object.
651 /// Nearly everywhere, inner must be non-null, however in places where
652 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
653 pub inner: *mut nativeBlindedTail,
654 /// Indicates that this is the only struct which contains the same pointer.
656 /// Rust functions which take ownership of an object provided via an argument require
657 /// this to be true and invalidate the object pointed to by inner.
661 impl Drop for BlindedTail {
663 if self.is_owned && !<*mut nativeBlindedTail>::is_null(self.inner) {
664 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
668 /// Frees any resources used by the BlindedTail, if is_owned is set and inner is non-NULL.
670 pub extern "C" fn BlindedTail_free(this_obj: BlindedTail) { }
672 /// Used only if an object of this type is returned as a trait impl by a method
673 pub(crate) extern "C" fn BlindedTail_free_void(this_ptr: *mut c_void) {
674 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedTail) };
678 pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedTail {
679 unsafe { &*ObjOps::untweak_ptr(self.inner) }
681 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedTail {
682 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
684 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
685 pub(crate) fn take_inner(mut self) -> *mut nativeBlindedTail {
686 assert!(self.is_owned);
687 let ret = ObjOps::untweak_ptr(self.inner);
688 self.inner = core::ptr::null_mut();
692 /// The hops of the [`BlindedPath`] provided by the recipient.
694 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
696 pub extern "C" fn BlindedTail_get_hops(this_ptr: &BlindedTail) -> crate::c_types::derived::CVec_BlindedHopZ {
697 let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
698 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 } }); };
699 local_inner_val.into()
701 /// The hops of the [`BlindedPath`] provided by the recipient.
703 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
705 pub extern "C" fn BlindedTail_set_hops(this_ptr: &mut BlindedTail, mut val: crate::c_types::derived::CVec_BlindedHopZ) {
706 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
707 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
709 /// The blinding point of the [`BlindedPath`] provided by the recipient.
711 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
713 pub extern "C" fn BlindedTail_get_blinding_point(this_ptr: &BlindedTail) -> crate::c_types::PublicKey {
714 let mut inner_val = &mut this_ptr.get_native_mut_ref().blinding_point;
715 crate::c_types::PublicKey::from_rust(&inner_val)
717 /// The blinding point of the [`BlindedPath`] provided by the recipient.
719 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
721 pub extern "C" fn BlindedTail_set_blinding_point(this_ptr: &mut BlindedTail, mut val: crate::c_types::PublicKey) {
722 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinding_point = val.into_rust();
724 /// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
725 /// inferring the destination. May be 0.
727 pub extern "C" fn BlindedTail_get_excess_final_cltv_expiry_delta(this_ptr: &BlindedTail) -> u32 {
728 let mut inner_val = &mut this_ptr.get_native_mut_ref().excess_final_cltv_expiry_delta;
731 /// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
732 /// inferring the destination. May be 0.
734 pub extern "C" fn BlindedTail_set_excess_final_cltv_expiry_delta(this_ptr: &mut BlindedTail, mut val: u32) {
735 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.excess_final_cltv_expiry_delta = val;
737 /// The total amount paid on this [`Path`], excluding the fees.
739 pub extern "C" fn BlindedTail_get_final_value_msat(this_ptr: &BlindedTail) -> u64 {
740 let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
743 /// The total amount paid on this [`Path`], excluding the fees.
745 pub extern "C" fn BlindedTail_set_final_value_msat(this_ptr: &mut BlindedTail, mut val: u64) {
746 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
748 /// Constructs a new BlindedTail given each field
751 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 {
752 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()) } }); };
753 BlindedTail { inner: ObjOps::heap_alloc(nativeBlindedTail {
754 hops: local_hops_arg,
755 blinding_point: blinding_point_arg.into_rust(),
756 excess_final_cltv_expiry_delta: excess_final_cltv_expiry_delta_arg,
757 final_value_msat: final_value_msat_arg,
760 impl Clone for BlindedTail {
761 fn clone(&self) -> Self {
763 inner: if <*mut nativeBlindedTail>::is_null(self.inner) { core::ptr::null_mut() } else {
764 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
770 /// Used only if an object of this type is returned as a trait impl by a method
771 pub(crate) extern "C" fn BlindedTail_clone_void(this_ptr: *const c_void) -> *mut c_void {
772 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedTail)).clone() })) as *mut c_void
775 /// Creates a copy of the BlindedTail
776 pub extern "C" fn BlindedTail_clone(orig: &BlindedTail) -> BlindedTail {
779 /// Generates a non-cryptographic 64-bit hash of the BlindedTail.
781 pub extern "C" fn BlindedTail_hash(o: &BlindedTail) -> u64 {
782 if o.inner.is_null() { return 0; }
783 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
785 let mut hasher = core::hash::SipHasher::new();
786 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
787 core::hash::Hasher::finish(&hasher)
789 /// Checks if two BlindedTails contain equal inner contents.
790 /// This ignores pointers and is_owned flags and looks at the values in fields.
791 /// Two objects with NULL inner values will be considered "equal" here.
793 pub extern "C" fn BlindedTail_eq(a: &BlindedTail, b: &BlindedTail) -> bool {
794 if a.inner == b.inner { return true; }
795 if a.inner.is_null() || b.inner.is_null() { return false; }
796 if a.get_native_ref() == b.get_native_ref() { true } else { false }
799 /// Serialize the BlindedTail object into a byte array which can be read by BlindedTail_read
800 pub extern "C" fn BlindedTail_write(obj: &crate::lightning::routing::router::BlindedTail) -> crate::c_types::derived::CVec_u8Z {
801 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
804 pub(crate) extern "C" fn BlindedTail_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
805 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedTail) })
808 /// Read a BlindedTail from a byte array, created by BlindedTail_write
809 pub extern "C" fn BlindedTail_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedTailDecodeErrorZ {
810 let res: Result<lightning::routing::router::BlindedTail, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
811 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() };
815 use lightning::routing::router::Path as nativePathImport;
816 pub(crate) type nativePath = nativePathImport;
818 /// A path in a [`Route`] to the payment recipient. Must always be at least length one.
819 /// If no [`Path::blinded_tail`] is present, then [`Path::hops`] length may be up to 19.
823 /// A pointer to the opaque Rust object.
825 /// Nearly everywhere, inner must be non-null, however in places where
826 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
827 pub inner: *mut nativePath,
828 /// Indicates that this is the only struct which contains the same pointer.
830 /// Rust functions which take ownership of an object provided via an argument require
831 /// this to be true and invalidate the object pointed to by inner.
837 if self.is_owned && !<*mut nativePath>::is_null(self.inner) {
838 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
842 /// Frees any resources used by the Path, if is_owned is set and inner is non-NULL.
844 pub extern "C" fn Path_free(this_obj: Path) { }
846 /// Used only if an object of this type is returned as a trait impl by a method
847 pub(crate) extern "C" fn Path_free_void(this_ptr: *mut c_void) {
848 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePath) };
852 pub(crate) fn get_native_ref(&self) -> &'static nativePath {
853 unsafe { &*ObjOps::untweak_ptr(self.inner) }
855 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePath {
856 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
858 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
859 pub(crate) fn take_inner(mut self) -> *mut nativePath {
860 assert!(self.is_owned);
861 let ret = ObjOps::untweak_ptr(self.inner);
862 self.inner = core::ptr::null_mut();
866 /// The list of unblinded hops in this [`Path`]. Must be at least length one.
868 pub extern "C" fn Path_get_hops(this_ptr: &Path) -> crate::c_types::derived::CVec_RouteHopZ {
869 let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
870 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 } }); };
871 local_inner_val.into()
873 /// The list of unblinded hops in this [`Path`]. Must be at least length one.
875 pub extern "C" fn Path_set_hops(this_ptr: &mut Path, mut val: crate::c_types::derived::CVec_RouteHopZ) {
876 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
877 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
879 /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
881 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
883 pub extern "C" fn Path_get_blinded_tail(this_ptr: &Path) -> crate::lightning::routing::router::BlindedTail {
884 let mut inner_val = &mut this_ptr.get_native_mut_ref().blinded_tail;
885 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 };
888 /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
890 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
892 pub extern "C" fn Path_set_blinded_tail(this_ptr: &mut Path, mut val: crate::lightning::routing::router::BlindedTail) {
893 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
894 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinded_tail = local_val;
896 /// Constructs a new Path given each field
898 /// Note that blinded_tail_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
901 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 {
902 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()) } }); };
903 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()) } }) };
904 Path { inner: ObjOps::heap_alloc(nativePath {
905 hops: local_hops_arg,
906 blinded_tail: local_blinded_tail_arg,
909 impl Clone for Path {
910 fn clone(&self) -> Self {
912 inner: if <*mut nativePath>::is_null(self.inner) { core::ptr::null_mut() } else {
913 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
919 /// Used only if an object of this type is returned as a trait impl by a method
920 pub(crate) extern "C" fn Path_clone_void(this_ptr: *const c_void) -> *mut c_void {
921 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePath)).clone() })) as *mut c_void
924 /// Creates a copy of the Path
925 pub extern "C" fn Path_clone(orig: &Path) -> Path {
928 /// Generates a non-cryptographic 64-bit hash of the Path.
930 pub extern "C" fn Path_hash(o: &Path) -> u64 {
931 if o.inner.is_null() { return 0; }
932 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
934 let mut hasher = core::hash::SipHasher::new();
935 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
936 core::hash::Hasher::finish(&hasher)
938 /// Checks if two Paths contain equal inner contents.
939 /// This ignores pointers and is_owned flags and looks at the values in fields.
940 /// Two objects with NULL inner values will be considered "equal" here.
942 pub extern "C" fn Path_eq(a: &Path, b: &Path) -> bool {
943 if a.inner == b.inner { return true; }
944 if a.inner.is_null() || b.inner.is_null() { return false; }
945 if a.get_native_ref() == b.get_native_ref() { true } else { false }
947 /// Gets the fees for a given path, excluding any excess paid to the recipient.
950 pub extern "C" fn Path_fee_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
951 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fee_msat();
955 /// Gets the total amount paid on this [`Path`], excluding the fees.
958 pub extern "C" fn Path_final_value_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
959 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_value_msat();
963 /// Gets the final hop's CLTV expiry delta.
966 pub extern "C" fn Path_final_cltv_expiry_delta(this_arg: &crate::lightning::routing::router::Path) -> crate::c_types::derived::COption_u32Z {
967 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_cltv_expiry_delta();
968 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() }) };
973 use lightning::routing::router::Route as nativeRouteImport;
974 pub(crate) type nativeRoute = nativeRouteImport;
976 /// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
977 /// it can take multiple paths. Each path is composed of one or more hops through the network.
981 /// A pointer to the opaque Rust object.
983 /// Nearly everywhere, inner must be non-null, however in places where
984 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
985 pub inner: *mut nativeRoute,
986 /// Indicates that this is the only struct which contains the same pointer.
988 /// Rust functions which take ownership of an object provided via an argument require
989 /// this to be true and invalidate the object pointed to by inner.
993 impl Drop for Route {
995 if self.is_owned && !<*mut nativeRoute>::is_null(self.inner) {
996 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1000 /// Frees any resources used by the Route, if is_owned is set and inner is non-NULL.
1002 pub extern "C" fn Route_free(this_obj: Route) { }
1004 /// Used only if an object of this type is returned as a trait impl by a method
1005 pub(crate) extern "C" fn Route_free_void(this_ptr: *mut c_void) {
1006 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoute) };
1010 pub(crate) fn get_native_ref(&self) -> &'static nativeRoute {
1011 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1013 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoute {
1014 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1016 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1017 pub(crate) fn take_inner(mut self) -> *mut nativeRoute {
1018 assert!(self.is_owned);
1019 let ret = ObjOps::untweak_ptr(self.inner);
1020 self.inner = core::ptr::null_mut();
1024 /// The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
1025 /// [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
1028 pub extern "C" fn Route_get_paths(this_ptr: &Route) -> crate::c_types::derived::CVec_PathZ {
1029 let mut inner_val = &mut this_ptr.get_native_mut_ref().paths;
1030 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 } }); };
1031 local_inner_val.into()
1033 /// The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
1034 /// [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
1037 pub extern "C" fn Route_set_paths(this_ptr: &mut Route, mut val: crate::c_types::derived::CVec_PathZ) {
1038 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1039 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.paths = local_val;
1041 /// The `route_params` parameter passed to [`find_route`].
1043 /// This is used by `ChannelManager` to track information which may be required for retries.
1045 /// Will be `None` for objects serialized with LDK versions prior to 0.0.117.
1047 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1049 pub extern "C" fn Route_get_route_params(this_ptr: &Route) -> crate::lightning::routing::router::RouteParameters {
1050 let mut inner_val = &mut this_ptr.get_native_mut_ref().route_params;
1051 let mut local_inner_val = crate::lightning::routing::router::RouteParameters { 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::RouteParameters<>) as *mut _ }, is_owned: false };
1054 /// The `route_params` parameter passed to [`find_route`].
1056 /// This is used by `ChannelManager` to track information which may be required for retries.
1058 /// Will be `None` for objects serialized with LDK versions prior to 0.0.117.
1060 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1062 pub extern "C" fn Route_set_route_params(this_ptr: &mut Route, mut val: crate::lightning::routing::router::RouteParameters) {
1063 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1064 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_params = local_val;
1066 /// Constructs a new Route given each field
1068 /// Note that route_params_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
1071 pub extern "C" fn Route_new(mut paths_arg: crate::c_types::derived::CVec_PathZ, mut route_params_arg: crate::lightning::routing::router::RouteParameters) -> Route {
1072 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()) } }); };
1073 let mut local_route_params_arg = if route_params_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(route_params_arg.take_inner()) } }) };
1074 Route { inner: ObjOps::heap_alloc(nativeRoute {
1075 paths: local_paths_arg,
1076 route_params: local_route_params_arg,
1077 }), is_owned: true }
1079 impl Clone for Route {
1080 fn clone(&self) -> Self {
1082 inner: if <*mut nativeRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
1083 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1089 /// Used only if an object of this type is returned as a trait impl by a method
1090 pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_void {
1091 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRoute)).clone() })) as *mut c_void
1094 /// Creates a copy of the Route
1095 pub extern "C" fn Route_clone(orig: &Route) -> Route {
1098 /// Generates a non-cryptographic 64-bit hash of the Route.
1100 pub extern "C" fn Route_hash(o: &Route) -> u64 {
1101 if o.inner.is_null() { return 0; }
1102 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1103 #[allow(deprecated)]
1104 let mut hasher = core::hash::SipHasher::new();
1105 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1106 core::hash::Hasher::finish(&hasher)
1108 /// Checks if two Routes contain equal inner contents.
1109 /// This ignores pointers and is_owned flags and looks at the values in fields.
1110 /// Two objects with NULL inner values will be considered "equal" here.
1112 pub extern "C" fn Route_eq(a: &Route, b: &Route) -> bool {
1113 if a.inner == b.inner { return true; }
1114 if a.inner.is_null() || b.inner.is_null() { return false; }
1115 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1117 /// Returns the total amount of fees paid on this [`Route`].
1119 /// For objects serialized with LDK 0.0.117 and after, this includes any extra payment made to
1120 /// the recipient, which can happen in excess of the amount passed to [`find_route`] via
1121 /// [`RouteParameters::final_value_msat`], if we had to reach the [`htlc_minimum_msat`] limits.
1123 /// [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
1126 pub extern "C" fn Route_get_total_fees(this_arg: &crate::lightning::routing::router::Route) -> u64 {
1127 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_fees();
1131 /// Returns the total amount paid on this [`Route`], excluding the fees.
1133 /// Might be more than requested as part of the given [`RouteParameters::final_value_msat`] if
1134 /// we had to reach the [`htlc_minimum_msat`] limits.
1136 /// [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
1139 pub extern "C" fn Route_get_total_amount(this_arg: &crate::lightning::routing::router::Route) -> u64 {
1140 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_amount();
1145 /// Serialize the Route object into a byte array which can be read by Route_read
1146 pub extern "C" fn Route_write(obj: &crate::lightning::routing::router::Route) -> crate::c_types::derived::CVec_u8Z {
1147 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1150 pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1151 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) })
1154 /// Read a Route from a byte array, created by Route_write
1155 pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ {
1156 let res: Result<lightning::routing::router::Route, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1157 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() };
1161 use lightning::routing::router::RouteParameters as nativeRouteParametersImport;
1162 pub(crate) type nativeRouteParameters = nativeRouteParametersImport;
1164 /// Parameters needed to find a [`Route`].
1166 /// Passed to [`find_route`] and [`build_route_from_hops`].
1169 pub struct RouteParameters {
1170 /// A pointer to the opaque Rust object.
1172 /// Nearly everywhere, inner must be non-null, however in places where
1173 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1174 pub inner: *mut nativeRouteParameters,
1175 /// Indicates that this is the only struct which contains the same pointer.
1177 /// Rust functions which take ownership of an object provided via an argument require
1178 /// this to be true and invalidate the object pointed to by inner.
1182 impl Drop for RouteParameters {
1183 fn drop(&mut self) {
1184 if self.is_owned && !<*mut nativeRouteParameters>::is_null(self.inner) {
1185 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1189 /// Frees any resources used by the RouteParameters, if is_owned is set and inner is non-NULL.
1191 pub extern "C" fn RouteParameters_free(this_obj: RouteParameters) { }
1193 /// Used only if an object of this type is returned as a trait impl by a method
1194 pub(crate) extern "C" fn RouteParameters_free_void(this_ptr: *mut c_void) {
1195 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteParameters) };
1198 impl RouteParameters {
1199 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteParameters {
1200 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1202 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteParameters {
1203 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1205 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1206 pub(crate) fn take_inner(mut self) -> *mut nativeRouteParameters {
1207 assert!(self.is_owned);
1208 let ret = ObjOps::untweak_ptr(self.inner);
1209 self.inner = core::ptr::null_mut();
1213 /// The parameters of the failed payment path.
1215 pub extern "C" fn RouteParameters_get_payment_params(this_ptr: &RouteParameters) -> crate::lightning::routing::router::PaymentParameters {
1216 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_params;
1217 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 }
1219 /// The parameters of the failed payment path.
1221 pub extern "C" fn RouteParameters_set_payment_params(this_ptr: &mut RouteParameters, mut val: crate::lightning::routing::router::PaymentParameters) {
1222 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_params = *unsafe { Box::from_raw(val.take_inner()) };
1224 /// The amount in msats sent on the failed payment path.
1226 pub extern "C" fn RouteParameters_get_final_value_msat(this_ptr: &RouteParameters) -> u64 {
1227 let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
1230 /// The amount in msats sent on the failed payment path.
1232 pub extern "C" fn RouteParameters_set_final_value_msat(this_ptr: &mut RouteParameters, mut val: u64) {
1233 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
1235 /// The maximum total fees, in millisatoshi, that may accrue during route finding.
1237 /// This limit also applies to the total fees that may arise while retrying failed payment
1240 /// Note that values below a few sats may result in some paths being spuriously ignored.
1242 pub extern "C" fn RouteParameters_get_max_total_routing_fee_msat(this_ptr: &RouteParameters) -> crate::c_types::derived::COption_u64Z {
1243 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_routing_fee_msat;
1244 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() }) };
1247 /// The maximum total fees, in millisatoshi, that may accrue during route finding.
1249 /// This limit also applies to the total fees that may arise while retrying failed payment
1252 /// Note that values below a few sats may result in some paths being spuriously ignored.
1254 pub extern "C" fn RouteParameters_set_max_total_routing_fee_msat(this_ptr: &mut RouteParameters, mut val: crate::c_types::derived::COption_u64Z) {
1255 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1256 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_routing_fee_msat = local_val;
1258 /// Constructs a new RouteParameters given each field
1261 pub extern "C" fn RouteParameters_new(mut payment_params_arg: crate::lightning::routing::router::PaymentParameters, mut final_value_msat_arg: u64, mut max_total_routing_fee_msat_arg: crate::c_types::derived::COption_u64Z) -> RouteParameters {
1262 let mut local_max_total_routing_fee_msat_arg = if max_total_routing_fee_msat_arg.is_some() { Some( { max_total_routing_fee_msat_arg.take() }) } else { None };
1263 RouteParameters { inner: ObjOps::heap_alloc(nativeRouteParameters {
1264 payment_params: *unsafe { Box::from_raw(payment_params_arg.take_inner()) },
1265 final_value_msat: final_value_msat_arg,
1266 max_total_routing_fee_msat: local_max_total_routing_fee_msat_arg,
1267 }), is_owned: true }
1269 impl Clone for RouteParameters {
1270 fn clone(&self) -> Self {
1272 inner: if <*mut nativeRouteParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1273 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1279 /// Used only if an object of this type is returned as a trait impl by a method
1280 pub(crate) extern "C" fn RouteParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1281 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRouteParameters)).clone() })) as *mut c_void
1284 /// Creates a copy of the RouteParameters
1285 pub extern "C" fn RouteParameters_clone(orig: &RouteParameters) -> RouteParameters {
1288 /// Generates a non-cryptographic 64-bit hash of the RouteParameters.
1290 pub extern "C" fn RouteParameters_hash(o: &RouteParameters) -> u64 {
1291 if o.inner.is_null() { return 0; }
1292 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1293 #[allow(deprecated)]
1294 let mut hasher = core::hash::SipHasher::new();
1295 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1296 core::hash::Hasher::finish(&hasher)
1298 /// Checks if two RouteParameterss contain equal inner contents.
1299 /// This ignores pointers and is_owned flags and looks at the values in fields.
1300 /// Two objects with NULL inner values will be considered "equal" here.
1302 pub extern "C" fn RouteParameters_eq(a: &RouteParameters, b: &RouteParameters) -> bool {
1303 if a.inner == b.inner { return true; }
1304 if a.inner.is_null() || b.inner.is_null() { return false; }
1305 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1307 /// Constructs [`RouteParameters`] from the given [`PaymentParameters`] and a payment amount.
1309 /// [`Self::max_total_routing_fee_msat`] defaults to 1% of the payment amount + 50 sats
1312 pub extern "C" fn RouteParameters_from_payment_params_and_value(mut payment_params: crate::lightning::routing::router::PaymentParameters, mut final_value_msat: u64) -> crate::lightning::routing::router::RouteParameters {
1313 let mut ret = lightning::routing::router::RouteParameters::from_payment_params_and_value(*unsafe { Box::from_raw(payment_params.take_inner()) }, final_value_msat);
1314 crate::lightning::routing::router::RouteParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1318 /// Serialize the RouteParameters object into a byte array which can be read by RouteParameters_read
1319 pub extern "C" fn RouteParameters_write(obj: &crate::lightning::routing::router::RouteParameters) -> crate::c_types::derived::CVec_u8Z {
1320 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1323 pub(crate) extern "C" fn RouteParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1324 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteParameters) })
1327 /// Read a RouteParameters from a byte array, created by RouteParameters_write
1328 pub extern "C" fn RouteParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteParametersDecodeErrorZ {
1329 let res: Result<lightning::routing::router::RouteParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1330 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() };
1333 /// Maximum total CTLV difference we allow for a full payment path.
1336 pub static DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = lightning::routing::router::DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
1337 /// Maximum number of paths we allow an (MPP) payment to have.
1340 pub static DEFAULT_MAX_PATH_COUNT: u8 = lightning::routing::router::DEFAULT_MAX_PATH_COUNT;
1342 use lightning::routing::router::PaymentParameters as nativePaymentParametersImport;
1343 pub(crate) type nativePaymentParameters = nativePaymentParametersImport;
1345 /// Information used to route a payment.
1348 pub struct PaymentParameters {
1349 /// A pointer to the opaque Rust object.
1351 /// Nearly everywhere, inner must be non-null, however in places where
1352 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1353 pub inner: *mut nativePaymentParameters,
1354 /// Indicates that this is the only struct which contains the same pointer.
1356 /// Rust functions which take ownership of an object provided via an argument require
1357 /// this to be true and invalidate the object pointed to by inner.
1361 impl Drop for PaymentParameters {
1362 fn drop(&mut self) {
1363 if self.is_owned && !<*mut nativePaymentParameters>::is_null(self.inner) {
1364 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1368 /// Frees any resources used by the PaymentParameters, if is_owned is set and inner is non-NULL.
1370 pub extern "C" fn PaymentParameters_free(this_obj: PaymentParameters) { }
1372 /// Used only if an object of this type is returned as a trait impl by a method
1373 pub(crate) extern "C" fn PaymentParameters_free_void(this_ptr: *mut c_void) {
1374 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentParameters) };
1377 impl PaymentParameters {
1378 pub(crate) fn get_native_ref(&self) -> &'static nativePaymentParameters {
1379 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1381 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentParameters {
1382 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1384 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1385 pub(crate) fn take_inner(mut self) -> *mut nativePaymentParameters {
1386 assert!(self.is_owned);
1387 let ret = ObjOps::untweak_ptr(self.inner);
1388 self.inner = core::ptr::null_mut();
1392 /// Information about the payee, such as their features and route hints for their channels.
1394 pub extern "C" fn PaymentParameters_get_payee(this_ptr: &PaymentParameters) -> crate::lightning::routing::router::Payee {
1395 let mut inner_val = &mut this_ptr.get_native_mut_ref().payee;
1396 crate::lightning::routing::router::Payee::from_native(inner_val)
1398 /// Information about the payee, such as their features and route hints for their channels.
1400 pub extern "C" fn PaymentParameters_set_payee(this_ptr: &mut PaymentParameters, mut val: crate::lightning::routing::router::Payee) {
1401 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payee = val.into_native();
1403 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1405 pub extern "C" fn PaymentParameters_get_expiry_time(this_ptr: &PaymentParameters) -> crate::c_types::derived::COption_u64Z {
1406 let mut inner_val = &mut this_ptr.get_native_mut_ref().expiry_time;
1407 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() }) };
1410 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1412 pub extern "C" fn PaymentParameters_set_expiry_time(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::COption_u64Z) {
1413 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1414 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.expiry_time = local_val;
1416 /// The maximum total CLTV delta we accept for the route.
1417 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1419 pub extern "C" fn PaymentParameters_get_max_total_cltv_expiry_delta(this_ptr: &PaymentParameters) -> u32 {
1420 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_cltv_expiry_delta;
1423 /// The maximum total CLTV delta we accept for the route.
1424 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1426 pub extern "C" fn PaymentParameters_set_max_total_cltv_expiry_delta(this_ptr: &mut PaymentParameters, mut val: u32) {
1427 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_cltv_expiry_delta = val;
1429 /// The maximum number of paths that may be used by (MPP) payments.
1430 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1432 pub extern "C" fn PaymentParameters_get_max_path_count(this_ptr: &PaymentParameters) -> u8 {
1433 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_path_count;
1436 /// The maximum number of paths that may be used by (MPP) payments.
1437 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1439 pub extern "C" fn PaymentParameters_set_max_path_count(this_ptr: &mut PaymentParameters, mut val: u8) {
1440 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_path_count = val;
1442 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1443 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1444 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1445 /// increasing failure probability for those paths.
1447 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1448 /// restriction have been found. While paths which meet this criteria will be searched for, it
1449 /// is ultimately up to the scorer to select them over other paths.
1451 /// A value of 0 will allow payments up to and including a channel's total announced usable
1452 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1454 /// Default value: 2
1456 pub extern "C" fn PaymentParameters_get_max_channel_saturation_power_of_half(this_ptr: &PaymentParameters) -> u8 {
1457 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_saturation_power_of_half;
1460 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1461 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1462 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1463 /// increasing failure probability for those paths.
1465 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1466 /// restriction have been found. While paths which meet this criteria will be searched for, it
1467 /// is ultimately up to the scorer to select them over other paths.
1469 /// A value of 0 will allow payments up to and including a channel's total announced usable
1470 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1472 /// Default value: 2
1474 pub extern "C" fn PaymentParameters_set_max_channel_saturation_power_of_half(this_ptr: &mut PaymentParameters, mut val: u8) {
1475 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_saturation_power_of_half = val;
1477 /// A list of SCIDs which this payment was previously attempted over and which caused the
1478 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1481 /// Returns a copy of the field.
1483 pub extern "C" fn PaymentParameters_get_previously_failed_channels(this_ptr: &PaymentParameters) -> crate::c_types::derived::CVec_u64Z {
1484 let mut inner_val = this_ptr.get_native_mut_ref().previously_failed_channels.clone();
1485 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1486 local_inner_val.into()
1488 /// A list of SCIDs which this payment was previously attempted over and which caused the
1489 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1492 pub extern "C" fn PaymentParameters_set_previously_failed_channels(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_u64Z) {
1493 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1494 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previously_failed_channels = local_val;
1496 /// Constructs a new PaymentParameters given each field
1499 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 {
1500 let mut local_expiry_time_arg = if expiry_time_arg.is_some() { Some( { expiry_time_arg.take() }) } else { None };
1501 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 }); };
1502 PaymentParameters { inner: ObjOps::heap_alloc(nativePaymentParameters {
1503 payee: payee_arg.into_native(),
1504 expiry_time: local_expiry_time_arg,
1505 max_total_cltv_expiry_delta: max_total_cltv_expiry_delta_arg,
1506 max_path_count: max_path_count_arg,
1507 max_channel_saturation_power_of_half: max_channel_saturation_power_of_half_arg,
1508 previously_failed_channels: local_previously_failed_channels_arg,
1509 }), is_owned: true }
1511 impl Clone for PaymentParameters {
1512 fn clone(&self) -> Self {
1514 inner: if <*mut nativePaymentParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1515 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1521 /// Used only if an object of this type is returned as a trait impl by a method
1522 pub(crate) extern "C" fn PaymentParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1523 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePaymentParameters)).clone() })) as *mut c_void
1526 /// Creates a copy of the PaymentParameters
1527 pub extern "C" fn PaymentParameters_clone(orig: &PaymentParameters) -> PaymentParameters {
1530 /// Generates a non-cryptographic 64-bit hash of the PaymentParameters.
1532 pub extern "C" fn PaymentParameters_hash(o: &PaymentParameters) -> u64 {
1533 if o.inner.is_null() { return 0; }
1534 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1535 #[allow(deprecated)]
1536 let mut hasher = core::hash::SipHasher::new();
1537 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1538 core::hash::Hasher::finish(&hasher)
1540 /// Checks if two PaymentParameterss contain equal inner contents.
1541 /// This ignores pointers and is_owned flags and looks at the values in fields.
1542 /// Two objects with NULL inner values will be considered "equal" here.
1544 pub extern "C" fn PaymentParameters_eq(a: &PaymentParameters, b: &PaymentParameters) -> bool {
1545 if a.inner == b.inner { return true; }
1546 if a.inner.is_null() || b.inner.is_null() { return false; }
1547 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1550 /// Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
1551 pub extern "C" fn PaymentParameters_write(obj: &crate::lightning::routing::router::PaymentParameters) -> crate::c_types::derived::CVec_u8Z {
1552 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1555 pub(crate) extern "C" fn PaymentParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1556 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentParameters) })
1559 /// Read a PaymentParameters from a byte array, created by PaymentParameters_write
1560 pub extern "C" fn PaymentParameters_read(ser: crate::c_types::u8slice, arg: u32) -> crate::c_types::derived::CResult_PaymentParametersDecodeErrorZ {
1562 let res: Result<lightning::routing::router::PaymentParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1563 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() };
1566 /// Creates a payee with the node id of the given `pubkey`.
1568 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1572 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 {
1573 let mut ret = lightning::routing::router::PaymentParameters::from_node_id(payee_pubkey.into_rust(), final_cltv_expiry_delta);
1574 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1577 /// Creates a payee with the node id of the given `pubkey` to use for keysend payments.
1579 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1582 /// Note that MPP keysend is not widely supported yet. The `allow_mpp` lets you choose
1583 /// whether your router will be allowed to find a multi-part route for this payment. If you
1584 /// set `allow_mpp` to true, you should ensure a payment secret is set on send, likely via
1585 /// [`RecipientOnionFields::secret_only`].
1587 /// [`RecipientOnionFields::secret_only`]: crate::ln::channelmanager::RecipientOnionFields::secret_only
1590 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 {
1591 let mut ret = lightning::routing::router::PaymentParameters::for_keysend(payee_pubkey.into_rust(), final_cltv_expiry_delta, allow_mpp);
1592 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1595 /// Creates parameters for paying to a blinded payee from the provided invoice. Sets
1596 /// [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and
1597 /// [`PaymentParameters::expiry_time`].
1600 pub extern "C" fn PaymentParameters_from_bolt12_invoice(invoice: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::routing::router::PaymentParameters {
1601 let mut ret = lightning::routing::router::PaymentParameters::from_bolt12_invoice(invoice.get_native_ref());
1602 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1605 /// Creates parameters for paying to a blinded payee from the provided blinded route hints.
1608 pub extern "C" fn PaymentParameters_blinded(mut blinded_route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ) -> crate::lightning::routing::router::PaymentParameters {
1609 let mut local_blinded_route_hints = Vec::new(); for mut item in blinded_route_hints.into_rust().drain(..) { local_blinded_route_hints.push( { let (mut orig_blinded_route_hints_0_0, mut orig_blinded_route_hints_0_1) = item.to_rust(); let mut local_blinded_route_hints_0 = (*unsafe { Box::from_raw(orig_blinded_route_hints_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_blinded_route_hints_0_1.take_inner()) }); local_blinded_route_hints_0 }); };
1610 let mut ret = lightning::routing::router::PaymentParameters::blinded(local_blinded_route_hints);
1611 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1614 /// The recipient of a payment, differing based on whether they've hidden their identity with route
1620 /// The recipient provided blinded paths and payinfo to reach them. The blinded paths themselves
1621 /// will be included in the final [`Route`].
1623 /// Aggregated routing info and blinded paths, for routing to the payee without knowing their
1625 route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ,
1626 /// Features supported by the payee.
1628 /// May be set from the payee's invoice. May be `None` if the invoice does not contain any
1631 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1632 features: crate::lightning::ln::features::Bolt12InvoiceFeatures,
1634 /// The recipient included these route hints in their BOLT11 invoice.
1636 /// The node id of the payee.
1637 node_id: crate::c_types::PublicKey,
1638 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
1639 route_hints: crate::c_types::derived::CVec_RouteHintZ,
1640 /// Features supported by the payee.
1642 /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
1643 /// does not contain any features.
1645 /// [`for_keysend`]: PaymentParameters::for_keysend
1647 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1648 features: crate::lightning::ln::features::Bolt11InvoiceFeatures,
1649 /// The minimum CLTV delta at the end of the route. This value must not be zero.
1650 final_cltv_expiry_delta: u32,
1653 use lightning::routing::router::Payee as PayeeImport;
1654 pub(crate) type nativePayee = PayeeImport;
1658 pub(crate) fn to_native(&self) -> nativePayee {
1660 Payee::Blinded {ref route_hints, ref features, } => {
1661 let mut route_hints_nonref = Clone::clone(route_hints);
1662 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 }); };
1663 let mut features_nonref = Clone::clone(features);
1664 let mut local_features_nonref = if features_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_nonref.take_inner()) } }) };
1665 nativePayee::Blinded {
1666 route_hints: local_route_hints_nonref,
1667 features: local_features_nonref,
1670 Payee::Clear {ref node_id, ref route_hints, ref features, ref final_cltv_expiry_delta, } => {
1671 let mut node_id_nonref = Clone::clone(node_id);
1672 let mut route_hints_nonref = Clone::clone(route_hints);
1673 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()) } }); };
1674 let mut features_nonref = Clone::clone(features);
1675 let mut local_features_nonref = if features_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_nonref.take_inner()) } }) };
1676 let mut final_cltv_expiry_delta_nonref = Clone::clone(final_cltv_expiry_delta);
1677 nativePayee::Clear {
1678 node_id: node_id_nonref.into_rust(),
1679 route_hints: local_route_hints_nonref,
1680 features: local_features_nonref,
1681 final_cltv_expiry_delta: final_cltv_expiry_delta_nonref,
1687 pub(crate) fn into_native(self) -> nativePayee {
1689 Payee::Blinded {mut route_hints, mut features, } => {
1690 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 }); };
1691 let mut local_features = if features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features.take_inner()) } }) };
1692 nativePayee::Blinded {
1693 route_hints: local_route_hints,
1694 features: local_features,
1697 Payee::Clear {mut node_id, mut route_hints, mut features, mut final_cltv_expiry_delta, } => {
1698 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()) } }); };
1699 let mut local_features = if features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features.take_inner()) } }) };
1700 nativePayee::Clear {
1701 node_id: node_id.into_rust(),
1702 route_hints: local_route_hints,
1703 features: local_features,
1704 final_cltv_expiry_delta: final_cltv_expiry_delta,
1710 pub(crate) fn from_native(native: &nativePayee) -> Self {
1712 nativePayee::Blinded {ref route_hints, ref features, } => {
1713 let mut route_hints_nonref = Clone::clone(route_hints);
1714 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 }); };
1715 let mut features_nonref = Clone::clone(features);
1716 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 };
1718 route_hints: local_route_hints_nonref.into(),
1719 features: local_features_nonref,
1722 nativePayee::Clear {ref node_id, ref route_hints, ref features, ref final_cltv_expiry_delta, } => {
1723 let mut node_id_nonref = Clone::clone(node_id);
1724 let mut route_hints_nonref = Clone::clone(route_hints);
1725 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 } }); };
1726 let mut features_nonref = Clone::clone(features);
1727 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 };
1728 let mut final_cltv_expiry_delta_nonref = Clone::clone(final_cltv_expiry_delta);
1730 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1731 route_hints: local_route_hints_nonref.into(),
1732 features: local_features_nonref,
1733 final_cltv_expiry_delta: final_cltv_expiry_delta_nonref,
1739 pub(crate) fn native_into(native: nativePayee) -> Self {
1741 nativePayee::Blinded {mut route_hints, mut features, } => {
1742 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 }); };
1743 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 };
1745 route_hints: local_route_hints.into(),
1746 features: local_features,
1749 nativePayee::Clear {mut node_id, mut route_hints, mut features, mut final_cltv_expiry_delta, } => {
1750 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 } }); };
1751 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 };
1753 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1754 route_hints: local_route_hints.into(),
1755 features: local_features,
1756 final_cltv_expiry_delta: final_cltv_expiry_delta,
1762 /// Frees any resources used by the Payee
1764 pub extern "C" fn Payee_free(this_ptr: Payee) { }
1765 /// Creates a copy of the Payee
1767 pub extern "C" fn Payee_clone(orig: &Payee) -> Payee {
1771 /// Used only if an object of this type is returned as a trait impl by a method
1772 pub(crate) extern "C" fn Payee_clone_void(this_ptr: *const c_void) -> *mut c_void {
1773 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Payee)).clone() })) as *mut c_void
1776 /// Used only if an object of this type is returned as a trait impl by a method
1777 pub(crate) extern "C" fn Payee_free_void(this_ptr: *mut c_void) {
1778 let _ = unsafe { Box::from_raw(this_ptr as *mut Payee) };
1781 /// Utility method to constructs a new Blinded-variant Payee
1782 pub extern "C" fn Payee_blinded(route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ, features: crate::lightning::ln::features::Bolt12InvoiceFeatures) -> Payee {
1789 /// Utility method to constructs a new Clear-variant Payee
1790 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 {
1795 final_cltv_expiry_delta,
1798 /// Generates a non-cryptographic 64-bit hash of the Payee.
1800 pub extern "C" fn Payee_hash(o: &Payee) -> u64 {
1801 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1802 #[allow(deprecated)]
1803 let mut hasher = core::hash::SipHasher::new();
1804 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1805 core::hash::Hasher::finish(&hasher)
1807 /// Checks if two Payees contain equal inner contents.
1808 /// This ignores pointers and is_owned flags and looks at the values in fields.
1810 pub extern "C" fn Payee_eq(a: &Payee, b: &Payee) -> bool {
1811 if &a.to_native() == &b.to_native() { true } else { false }
1814 use lightning::routing::router::RouteHint as nativeRouteHintImport;
1815 pub(crate) type nativeRouteHint = nativeRouteHintImport;
1817 /// A list of hops along a payment path terminating with a channel to the recipient.
1820 pub struct RouteHint {
1821 /// A pointer to the opaque Rust object.
1823 /// Nearly everywhere, inner must be non-null, however in places where
1824 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1825 pub inner: *mut nativeRouteHint,
1826 /// Indicates that this is the only struct which contains the same pointer.
1828 /// Rust functions which take ownership of an object provided via an argument require
1829 /// this to be true and invalidate the object pointed to by inner.
1833 impl Drop for RouteHint {
1834 fn drop(&mut self) {
1835 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
1836 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1840 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
1842 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
1844 /// Used only if an object of this type is returned as a trait impl by a method
1845 pub(crate) extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
1846 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHint) };
1850 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHint {
1851 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1853 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHint {
1854 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1856 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1857 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
1858 assert!(self.is_owned);
1859 let ret = ObjOps::untweak_ptr(self.inner);
1860 self.inner = core::ptr::null_mut();
1865 pub extern "C" fn RouteHint_get_a(this_ptr: &RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ {
1866 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1867 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 } }); };
1868 local_inner_val.into()
1871 pub extern "C" fn RouteHint_set_a(this_ptr: &mut RouteHint, mut val: crate::c_types::derived::CVec_RouteHintHopZ) {
1872 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1873 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = local_val;
1875 /// Constructs a new RouteHint given each field
1878 pub extern "C" fn RouteHint_new(mut a_arg: crate::c_types::derived::CVec_RouteHintHopZ) -> RouteHint {
1879 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()) } }); };
1880 RouteHint { inner: ObjOps::heap_alloc(lightning::routing::router::RouteHint (
1882 )), is_owned: true }
1884 impl Clone for RouteHint {
1885 fn clone(&self) -> Self {
1887 inner: if <*mut nativeRouteHint>::is_null(self.inner) { core::ptr::null_mut() } else {
1888 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1894 /// Used only if an object of this type is returned as a trait impl by a method
1895 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
1896 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRouteHint)).clone() })) as *mut c_void
1899 /// Creates a copy of the RouteHint
1900 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
1903 /// Generates a non-cryptographic 64-bit hash of the RouteHint.
1905 pub extern "C" fn RouteHint_hash(o: &RouteHint) -> u64 {
1906 if o.inner.is_null() { return 0; }
1907 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1908 #[allow(deprecated)]
1909 let mut hasher = core::hash::SipHasher::new();
1910 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1911 core::hash::Hasher::finish(&hasher)
1913 /// Checks if two RouteHints contain equal inner contents.
1914 /// This ignores pointers and is_owned flags and looks at the values in fields.
1915 /// Two objects with NULL inner values will be considered "equal" here.
1917 pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool {
1918 if a.inner == b.inner { return true; }
1919 if a.inner.is_null() || b.inner.is_null() { return false; }
1920 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1923 /// Serialize the RouteHint object into a byte array which can be read by RouteHint_read
1924 pub extern "C" fn RouteHint_write(obj: &crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CVec_u8Z {
1925 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1928 pub(crate) extern "C" fn RouteHint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1929 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHint) })
1932 /// Read a RouteHint from a byte array, created by RouteHint_write
1933 pub extern "C" fn RouteHint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintDecodeErrorZ {
1934 let res: Result<lightning::routing::router::RouteHint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1935 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() };
1939 use lightning::routing::router::RouteHintHop as nativeRouteHintHopImport;
1940 pub(crate) type nativeRouteHintHop = nativeRouteHintHopImport;
1942 /// A channel descriptor for a hop along a payment path.
1945 pub struct RouteHintHop {
1946 /// A pointer to the opaque Rust object.
1948 /// Nearly everywhere, inner must be non-null, however in places where
1949 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1950 pub inner: *mut nativeRouteHintHop,
1951 /// Indicates that this is the only struct which contains the same pointer.
1953 /// Rust functions which take ownership of an object provided via an argument require
1954 /// this to be true and invalidate the object pointed to by inner.
1958 impl Drop for RouteHintHop {
1959 fn drop(&mut self) {
1960 if self.is_owned && !<*mut nativeRouteHintHop>::is_null(self.inner) {
1961 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1965 /// Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL.
1967 pub extern "C" fn RouteHintHop_free(this_obj: RouteHintHop) { }
1969 /// Used only if an object of this type is returned as a trait impl by a method
1970 pub(crate) extern "C" fn RouteHintHop_free_void(this_ptr: *mut c_void) {
1971 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHintHop) };
1975 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHintHop {
1976 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1978 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHintHop {
1979 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1981 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1982 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHintHop {
1983 assert!(self.is_owned);
1984 let ret = ObjOps::untweak_ptr(self.inner);
1985 self.inner = core::ptr::null_mut();
1989 /// The node_id of the non-target end of the route
1991 pub extern "C" fn RouteHintHop_get_src_node_id(this_ptr: &RouteHintHop) -> crate::c_types::PublicKey {
1992 let mut inner_val = &mut this_ptr.get_native_mut_ref().src_node_id;
1993 crate::c_types::PublicKey::from_rust(&inner_val)
1995 /// The node_id of the non-target end of the route
1997 pub extern "C" fn RouteHintHop_set_src_node_id(this_ptr: &mut RouteHintHop, mut val: crate::c_types::PublicKey) {
1998 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.src_node_id = val.into_rust();
2000 /// The short_channel_id of this channel
2002 pub extern "C" fn RouteHintHop_get_short_channel_id(this_ptr: &RouteHintHop) -> u64 {
2003 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
2006 /// The short_channel_id of this channel
2008 pub extern "C" fn RouteHintHop_set_short_channel_id(this_ptr: &mut RouteHintHop, mut val: u64) {
2009 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
2011 /// The fees which must be paid to use this channel
2013 pub extern "C" fn RouteHintHop_get_fees(this_ptr: &RouteHintHop) -> crate::lightning::routing::gossip::RoutingFees {
2014 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
2015 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 }
2017 /// The fees which must be paid to use this channel
2019 pub extern "C" fn RouteHintHop_set_fees(this_ptr: &mut RouteHintHop, mut val: crate::lightning::routing::gossip::RoutingFees) {
2020 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
2022 /// The difference in CLTV values between this node and the next node.
2024 pub extern "C" fn RouteHintHop_get_cltv_expiry_delta(this_ptr: &RouteHintHop) -> u16 {
2025 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
2028 /// The difference in CLTV values between this node and the next node.
2030 pub extern "C" fn RouteHintHop_set_cltv_expiry_delta(this_ptr: &mut RouteHintHop, mut val: u16) {
2031 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
2033 /// The minimum value, in msat, which must be relayed to the next hop.
2035 pub extern "C" fn RouteHintHop_get_htlc_minimum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
2036 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
2037 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() }) };
2040 /// The minimum value, in msat, which must be relayed to the next hop.
2042 pub extern "C" fn RouteHintHop_set_htlc_minimum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
2043 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2044 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = local_val;
2046 /// The maximum value in msat available for routing with a single HTLC.
2048 pub extern "C" fn RouteHintHop_get_htlc_maximum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
2049 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
2050 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() }) };
2053 /// The maximum value in msat available for routing with a single HTLC.
2055 pub extern "C" fn RouteHintHop_set_htlc_maximum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
2056 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2057 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
2059 /// Constructs a new RouteHintHop given each field
2062 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 {
2063 let mut local_htlc_minimum_msat_arg = if htlc_minimum_msat_arg.is_some() { Some( { htlc_minimum_msat_arg.take() }) } else { None };
2064 let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
2065 RouteHintHop { inner: ObjOps::heap_alloc(nativeRouteHintHop {
2066 src_node_id: src_node_id_arg.into_rust(),
2067 short_channel_id: short_channel_id_arg,
2068 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
2069 cltv_expiry_delta: cltv_expiry_delta_arg,
2070 htlc_minimum_msat: local_htlc_minimum_msat_arg,
2071 htlc_maximum_msat: local_htlc_maximum_msat_arg,
2072 }), is_owned: true }
2074 impl Clone for RouteHintHop {
2075 fn clone(&self) -> Self {
2077 inner: if <*mut nativeRouteHintHop>::is_null(self.inner) { core::ptr::null_mut() } else {
2078 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2084 /// Used only if an object of this type is returned as a trait impl by a method
2085 pub(crate) extern "C" fn RouteHintHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
2086 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRouteHintHop)).clone() })) as *mut c_void
2089 /// Creates a copy of the RouteHintHop
2090 pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop {
2093 /// Generates a non-cryptographic 64-bit hash of the RouteHintHop.
2095 pub extern "C" fn RouteHintHop_hash(o: &RouteHintHop) -> u64 {
2096 if o.inner.is_null() { return 0; }
2097 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2098 #[allow(deprecated)]
2099 let mut hasher = core::hash::SipHasher::new();
2100 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2101 core::hash::Hasher::finish(&hasher)
2103 /// Checks if two RouteHintHops contain equal inner contents.
2104 /// This ignores pointers and is_owned flags and looks at the values in fields.
2105 /// Two objects with NULL inner values will be considered "equal" here.
2107 pub extern "C" fn RouteHintHop_eq(a: &RouteHintHop, b: &RouteHintHop) -> bool {
2108 if a.inner == b.inner { return true; }
2109 if a.inner.is_null() || b.inner.is_null() { return false; }
2110 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2113 /// Serialize the RouteHintHop object into a byte array which can be read by RouteHintHop_read
2114 pub extern "C" fn RouteHintHop_write(obj: &crate::lightning::routing::router::RouteHintHop) -> crate::c_types::derived::CVec_u8Z {
2115 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2118 pub(crate) extern "C" fn RouteHintHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2119 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHintHop) })
2122 /// Read a RouteHintHop from a byte array, created by RouteHintHop_write
2123 pub extern "C" fn RouteHintHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintHopDecodeErrorZ {
2124 let res: Result<lightning::routing::router::RouteHintHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2125 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() };
2128 /// Finds a route from us (payer) to the given target node (payee).
2130 /// If the payee provided features in their invoice, they should be provided via the `payee` field
2131 /// in the given [`RouteParameters::payment_params`].
2132 /// Without this, MPP will only be used if the payee's features are available in the network graph.
2134 /// Private routing paths between a public node and the target may be included in the `payee` field
2135 /// of [`RouteParameters::payment_params`].
2137 /// If some channels aren't announced, it may be useful to fill in `first_hops` with the results
2138 /// from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
2139 /// from `network_graph` will be ignored, and only those in `first_hops` will be used.
2141 /// The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
2142 /// However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
2143 /// `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
2147 /// Panics if first_hops contains channels without `short_channel_id`s;
2148 /// [`ChannelManager::list_usable_channels`] will never include such channels.
2150 /// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
2151 /// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
2152 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
2154 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
2156 pub extern "C" fn find_route(mut our_node_pubkey: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, network_graph: &crate::lightning::routing::gossip::NetworkGraph, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut logger: crate::lightning::util::logger::Logger, scorer: &crate::lightning::routing::scoring::ScoreLookUp, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
2157 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[..]);
2158 let mut ret = lightning::routing::router::find_route::<crate::lightning::util::logger::Logger, crate::lightning::util::logger::Logger, crate::lightning::routing::scoring::ScoreLookUp>(&our_node_pubkey.into_rust(), route_params.get_native_ref(), network_graph.get_native_ref(), local_first_hops, logger, scorer, score_params.get_native_ref(), unsafe { &*random_seed_bytes});
2159 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() };
2163 /// Construct a route from us (payer) to the target node (payee) via the given hops (which should
2164 /// exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
2166 /// Re-uses logic from `find_route`, so the restrictions described there also apply here.
2168 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 {
2169 let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { item.into_rust() }); };
2170 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});
2171 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() };