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 top-level routing/network map tracking logic lives here.
11 //! You probably want to create a P2PGossipSync and use that as your RoutingMessageHandler and then
12 //! interrogate it to get routes for your own payments.
14 use alloc::str::FromStr;
15 use core::ffi::c_void;
16 use core::convert::Infallible;
17 use bitcoin::hashes::Hash;
18 use crate::c_types::*;
19 #[cfg(feature="no-std")]
20 use alloc::{vec::Vec, boxed::Box};
23 use lightning::routing::router::DefaultRouter as nativeDefaultRouterImport;
24 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>;
26 /// A [`Router`] implemented using [`find_route`].
29 pub struct DefaultRouter {
30 /// A pointer to the opaque Rust object.
32 /// Nearly everywhere, inner must be non-null, however in places where
33 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
34 pub inner: *mut nativeDefaultRouter,
35 /// Indicates that this is the only struct which contains the same pointer.
37 /// Rust functions which take ownership of an object provided via an argument require
38 /// this to be true and invalidate the object pointed to by inner.
42 impl Drop for DefaultRouter {
44 if self.is_owned && !<*mut nativeDefaultRouter>::is_null(self.inner) {
45 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
49 /// Frees any resources used by the DefaultRouter, if is_owned is set and inner is non-NULL.
51 pub extern "C" fn DefaultRouter_free(this_obj: DefaultRouter) { }
53 /// Used only if an object of this type is returned as a trait impl by a method
54 pub(crate) extern "C" fn DefaultRouter_free_void(this_ptr: *mut c_void) {
55 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDefaultRouter) };
59 pub(crate) fn get_native_ref(&self) -> &'static nativeDefaultRouter {
60 unsafe { &*ObjOps::untweak_ptr(self.inner) }
62 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDefaultRouter {
63 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
65 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
66 pub(crate) fn take_inner(mut self) -> *mut nativeDefaultRouter {
67 assert!(self.is_owned);
68 let ret = ObjOps::untweak_ptr(self.inner);
69 self.inner = core::ptr::null_mut();
73 /// Creates a new router.
76 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) -> crate::lightning::routing::router::DefaultRouter {
77 let mut ret = lightning::routing::router::DefaultRouter::new(network_graph.get_native_ref(), logger, random_seed_bytes.data, scorer);
78 crate::lightning::routing::router::DefaultRouter { inner: ObjOps::heap_alloc(ret), is_owned: true }
81 impl From<nativeDefaultRouter> for crate::lightning::routing::router::Router {
82 fn from(obj: nativeDefaultRouter) -> Self {
83 let mut rust_obj = DefaultRouter { inner: ObjOps::heap_alloc(obj), is_owned: true };
84 let mut ret = DefaultRouter_as_Router(&rust_obj);
85 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
86 rust_obj.inner = core::ptr::null_mut();
87 ret.free = Some(DefaultRouter_free_void);
91 /// Constructs a new Router which calls the relevant methods on this_arg.
92 /// This copies the `inner` pointer in this_arg and thus the returned Router must be freed before this_arg is
94 pub extern "C" fn DefaultRouter_as_Router(this_arg: &DefaultRouter) -> crate::lightning::routing::router::Router {
95 crate::lightning::routing::router::Router {
96 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
98 find_route: DefaultRouter_Router_find_route,
99 find_route_with_id: DefaultRouter_Router_find_route_with_id,
100 notify_payment_path_failed: DefaultRouter_Router_notify_payment_path_failed,
101 notify_payment_path_successful: DefaultRouter_Router_notify_payment_path_successful,
102 notify_payment_probe_successful: DefaultRouter_Router_notify_payment_probe_successful,
103 notify_payment_probe_failed: DefaultRouter_Router_notify_payment_probe_failed,
108 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 {
109 let mut local_first_hops_base = if first_hops == core::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { item.get_native_ref() }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]);
110 let mut ret = <nativeDefaultRouter as lightning::routing::router::Router<>>::find_route(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()) });
111 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
115 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 {
116 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[..]);
117 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));
118 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() };
121 extern "C" fn DefaultRouter_Router_notify_payment_path_failed(this_arg: *const c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) {
122 let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
123 <nativeDefaultRouter as lightning::routing::router::Router<>>::notify_payment_path_failed(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &local_path[..], short_channel_id)
125 extern "C" fn DefaultRouter_Router_notify_payment_path_successful(this_arg: *const c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
126 let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
127 <nativeDefaultRouter as lightning::routing::router::Router<>>::notify_payment_path_successful(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &local_path[..])
129 extern "C" fn DefaultRouter_Router_notify_payment_probe_successful(this_arg: *const c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
130 let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
131 <nativeDefaultRouter as lightning::routing::router::Router<>>::notify_payment_probe_successful(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &local_path[..])
133 extern "C" fn DefaultRouter_Router_notify_payment_probe_failed(this_arg: *const c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) {
134 let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
135 <nativeDefaultRouter as lightning::routing::router::Router<>>::notify_payment_probe_failed(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &local_path[..], short_channel_id)
138 /// A trait defining behavior for routing a payment.
141 /// An opaque pointer which is passed to your function implementations as an argument.
142 /// This has no meaning in the LDK, and can be NULL or any other value.
143 pub this_arg: *mut c_void,
144 /// Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
146 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
148 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,
149 /// Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
150 /// `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
152 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
154 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,
155 /// Lets the router know that payment through a specific path has failed.
156 pub notify_payment_path_failed: extern "C" fn (this_arg: *const c_void, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: u64),
157 /// Lets the router know that payment through a specific path was successful.
158 pub notify_payment_path_successful: extern "C" fn (this_arg: *const c_void, path: crate::c_types::derived::CVec_RouteHopZ),
159 /// Lets the router know that a payment probe was successful.
160 pub notify_payment_probe_successful: extern "C" fn (this_arg: *const c_void, path: crate::c_types::derived::CVec_RouteHopZ),
161 /// Lets the router know that a payment probe failed.
162 pub notify_payment_probe_failed: extern "C" fn (this_arg: *const c_void, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: u64),
163 /// Frees any resources associated with this object given its this_arg pointer.
164 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
165 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
167 unsafe impl Send for Router {}
168 unsafe impl Sync for Router {}
170 pub(crate) extern "C" fn Router_clone_fields(orig: &Router) -> Router {
172 this_arg: orig.this_arg,
173 find_route: Clone::clone(&orig.find_route),
174 find_route_with_id: Clone::clone(&orig.find_route_with_id),
175 notify_payment_path_failed: Clone::clone(&orig.notify_payment_path_failed),
176 notify_payment_path_successful: Clone::clone(&orig.notify_payment_path_successful),
177 notify_payment_probe_successful: Clone::clone(&orig.notify_payment_probe_successful),
178 notify_payment_probe_failed: Clone::clone(&orig.notify_payment_probe_failed),
179 free: Clone::clone(&orig.free),
183 use lightning::routing::router::Router as rustRouter;
184 impl rustRouter for Router {
185 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> {
186 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;
187 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 });
188 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()) } })};
191 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> {
192 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;
193 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 });
194 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()) } })};
197 fn notify_payment_path_failed(&self, mut path: &[&lightning::routing::router::RouteHop], mut short_channel_id: u64) {
198 let mut local_path = Vec::new(); for item in path.iter() { local_path.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 } }); };
199 (self.notify_payment_path_failed)(self.this_arg, local_path.into(), short_channel_id)
201 fn notify_payment_path_successful(&self, mut path: &[&lightning::routing::router::RouteHop]) {
202 let mut local_path = Vec::new(); for item in path.iter() { local_path.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 } }); };
203 (self.notify_payment_path_successful)(self.this_arg, local_path.into())
205 fn notify_payment_probe_successful(&self, mut path: &[&lightning::routing::router::RouteHop]) {
206 let mut local_path = Vec::new(); for item in path.iter() { local_path.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 } }); };
207 (self.notify_payment_probe_successful)(self.this_arg, local_path.into())
209 fn notify_payment_probe_failed(&self, mut path: &[&lightning::routing::router::RouteHop], mut short_channel_id: u64) {
210 let mut local_path = Vec::new(); for item in path.iter() { local_path.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 } }); };
211 (self.notify_payment_probe_failed)(self.this_arg, local_path.into(), short_channel_id)
215 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
216 // directly as a Deref trait in higher-level structs:
217 impl core::ops::Deref for Router {
219 fn deref(&self) -> &Self {
223 /// Calls the free function if one is set
225 pub extern "C" fn Router_free(this_ptr: Router) { }
226 impl Drop for Router {
228 if let Some(f) = self.free {
234 use lightning::routing::router::ScorerAccountingForInFlightHtlcs as nativeScorerAccountingForInFlightHtlcsImport;
235 pub(crate) type nativeScorerAccountingForInFlightHtlcs = nativeScorerAccountingForInFlightHtlcsImport<crate::lightning::routing::scoring::Score>;
237 /// [`Score`] implementation that factors in in-flight HTLC liquidity.
239 /// Useful for custom [`Router`] implementations to wrap their [`Score`] on-the-fly when calling
242 /// [`Score`]: crate::routing::scoring::Score
245 pub struct ScorerAccountingForInFlightHtlcs {
246 /// A pointer to the opaque Rust object.
248 /// Nearly everywhere, inner must be non-null, however in places where
249 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
250 pub inner: *mut nativeScorerAccountingForInFlightHtlcs,
251 /// Indicates that this is the only struct which contains the same pointer.
253 /// Rust functions which take ownership of an object provided via an argument require
254 /// this to be true and invalidate the object pointed to by inner.
258 impl Drop for ScorerAccountingForInFlightHtlcs {
260 if self.is_owned && !<*mut nativeScorerAccountingForInFlightHtlcs>::is_null(self.inner) {
261 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
265 /// Frees any resources used by the ScorerAccountingForInFlightHtlcs, if is_owned is set and inner is non-NULL.
267 pub extern "C" fn ScorerAccountingForInFlightHtlcs_free(this_obj: ScorerAccountingForInFlightHtlcs) { }
269 /// Used only if an object of this type is returned as a trait impl by a method
270 pub(crate) extern "C" fn ScorerAccountingForInFlightHtlcs_free_void(this_ptr: *mut c_void) {
271 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeScorerAccountingForInFlightHtlcs) };
274 impl ScorerAccountingForInFlightHtlcs {
275 pub(crate) fn get_native_ref(&self) -> &'static nativeScorerAccountingForInFlightHtlcs {
276 unsafe { &*ObjOps::untweak_ptr(self.inner) }
278 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeScorerAccountingForInFlightHtlcs {
279 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
281 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
282 pub(crate) fn take_inner(mut self) -> *mut nativeScorerAccountingForInFlightHtlcs {
283 assert!(self.is_owned);
284 let ret = ObjOps::untweak_ptr(self.inner);
285 self.inner = core::ptr::null_mut();
289 /// Initialize a new `ScorerAccountingForInFlightHtlcs`.
292 pub extern "C" fn ScorerAccountingForInFlightHtlcs_new(mut scorer: crate::lightning::routing::scoring::Score, mut inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs) -> crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs {
293 let mut ret = lightning::routing::router::ScorerAccountingForInFlightHtlcs::new(scorer, *unsafe { Box::from_raw(inflight_htlcs.take_inner()) });
294 crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
298 /// Serialize the ScorerAccountingForInFlightHtlcs object into a byte array which can be read by ScorerAccountingForInFlightHtlcs_read
299 pub extern "C" fn ScorerAccountingForInFlightHtlcs_write(obj: &crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs) -> crate::c_types::derived::CVec_u8Z {
300 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
303 pub(crate) extern "C" fn ScorerAccountingForInFlightHtlcs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
304 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeScorerAccountingForInFlightHtlcs) })
306 impl From<nativeScorerAccountingForInFlightHtlcs> for crate::lightning::routing::scoring::Score {
307 fn from(obj: nativeScorerAccountingForInFlightHtlcs) -> Self {
308 let mut rust_obj = ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(obj), is_owned: true };
309 let mut ret = ScorerAccountingForInFlightHtlcs_as_Score(&rust_obj);
310 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
311 rust_obj.inner = core::ptr::null_mut();
312 ret.free = Some(ScorerAccountingForInFlightHtlcs_free_void);
316 /// Constructs a new Score which calls the relevant methods on this_arg.
317 /// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
319 pub extern "C" fn ScorerAccountingForInFlightHtlcs_as_Score(this_arg: &ScorerAccountingForInFlightHtlcs) -> crate::lightning::routing::scoring::Score {
320 crate::lightning::routing::scoring::Score {
321 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
323 channel_penalty_msat: ScorerAccountingForInFlightHtlcs_Score_channel_penalty_msat,
324 payment_path_failed: ScorerAccountingForInFlightHtlcs_Score_payment_path_failed,
325 payment_path_successful: ScorerAccountingForInFlightHtlcs_Score_payment_path_successful,
326 probe_failed: ScorerAccountingForInFlightHtlcs_Score_probe_failed,
327 probe_successful: ScorerAccountingForInFlightHtlcs_Score_probe_successful,
328 write: ScorerAccountingForInFlightHtlcs_write_void,
333 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut usage: crate::lightning::routing::scoring::ChannelUsage) -> u64 {
334 let mut ret = <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, short_channel_id, source.get_native_ref(), target.get_native_ref(), *unsafe { Box::from_raw(usage.take_inner()) });
337 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_payment_path_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) {
338 let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
339 <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, &local_path[..], short_channel_id)
341 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_payment_path_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
342 let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
343 <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, &local_path[..])
345 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_probe_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) {
346 let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
347 <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::probe_failed(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, &local_path[..], short_channel_id)
349 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_probe_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
350 let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
351 <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::probe_successful(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, &local_path[..])
355 use lightning::routing::router::InFlightHtlcs as nativeInFlightHtlcsImport;
356 pub(crate) type nativeInFlightHtlcs = nativeInFlightHtlcsImport;
358 /// A data structure for tracking in-flight HTLCs. May be used during pathfinding to account for
359 /// in-use channel liquidity.
362 pub struct InFlightHtlcs {
363 /// A pointer to the opaque Rust object.
365 /// Nearly everywhere, inner must be non-null, however in places where
366 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
367 pub inner: *mut nativeInFlightHtlcs,
368 /// Indicates that this is the only struct which contains the same pointer.
370 /// Rust functions which take ownership of an object provided via an argument require
371 /// this to be true and invalidate the object pointed to by inner.
375 impl Drop for InFlightHtlcs {
377 if self.is_owned && !<*mut nativeInFlightHtlcs>::is_null(self.inner) {
378 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
382 /// Frees any resources used by the InFlightHtlcs, if is_owned is set and inner is non-NULL.
384 pub extern "C" fn InFlightHtlcs_free(this_obj: InFlightHtlcs) { }
386 /// Used only if an object of this type is returned as a trait impl by a method
387 pub(crate) extern "C" fn InFlightHtlcs_free_void(this_ptr: *mut c_void) {
388 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInFlightHtlcs) };
392 pub(crate) fn get_native_ref(&self) -> &'static nativeInFlightHtlcs {
393 unsafe { &*ObjOps::untweak_ptr(self.inner) }
395 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInFlightHtlcs {
396 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
398 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
399 pub(crate) fn take_inner(mut self) -> *mut nativeInFlightHtlcs {
400 assert!(self.is_owned);
401 let ret = ObjOps::untweak_ptr(self.inner);
402 self.inner = core::ptr::null_mut();
406 impl Clone for InFlightHtlcs {
407 fn clone(&self) -> Self {
409 inner: if <*mut nativeInFlightHtlcs>::is_null(self.inner) { core::ptr::null_mut() } else {
410 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
416 /// Used only if an object of this type is returned as a trait impl by a method
417 pub(crate) extern "C" fn InFlightHtlcs_clone_void(this_ptr: *const c_void) -> *mut c_void {
418 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInFlightHtlcs)).clone() })) as *mut c_void
421 /// Creates a copy of the InFlightHtlcs
422 pub extern "C" fn InFlightHtlcs_clone(orig: &InFlightHtlcs) -> InFlightHtlcs {
425 /// Constructs an empty `InFlightHtlcs`.
428 pub extern "C" fn InFlightHtlcs_new() -> crate::lightning::routing::router::InFlightHtlcs {
429 let mut ret = lightning::routing::router::InFlightHtlcs::new();
430 crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
433 /// Returns liquidity in msat given the public key of the HTLC source, target, and short channel
437 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 {
438 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.used_liquidity_msat(source.get_native_ref(), target.get_native_ref(), channel_scid);
439 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() }) };
444 /// Serialize the InFlightHtlcs object into a byte array which can be read by InFlightHtlcs_read
445 pub extern "C" fn InFlightHtlcs_write(obj: &crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CVec_u8Z {
446 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
449 pub(crate) extern "C" fn InFlightHtlcs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
450 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInFlightHtlcs) })
453 /// Read a InFlightHtlcs from a byte array, created by InFlightHtlcs_write
454 pub extern "C" fn InFlightHtlcs_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InFlightHtlcsDecodeErrorZ {
455 let res: Result<lightning::routing::router::InFlightHtlcs, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
456 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() };
460 use lightning::routing::router::RouteHop as nativeRouteHopImport;
461 pub(crate) type nativeRouteHop = nativeRouteHopImport;
466 pub struct RouteHop {
467 /// A pointer to the opaque Rust object.
469 /// Nearly everywhere, inner must be non-null, however in places where
470 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
471 pub inner: *mut nativeRouteHop,
472 /// Indicates that this is the only struct which contains the same pointer.
474 /// Rust functions which take ownership of an object provided via an argument require
475 /// this to be true and invalidate the object pointed to by inner.
479 impl Drop for RouteHop {
481 if self.is_owned && !<*mut nativeRouteHop>::is_null(self.inner) {
482 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
486 /// Frees any resources used by the RouteHop, if is_owned is set and inner is non-NULL.
488 pub extern "C" fn RouteHop_free(this_obj: RouteHop) { }
490 /// Used only if an object of this type is returned as a trait impl by a method
491 pub(crate) extern "C" fn RouteHop_free_void(this_ptr: *mut c_void) {
492 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHop) };
496 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHop {
497 unsafe { &*ObjOps::untweak_ptr(self.inner) }
499 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHop {
500 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
502 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
503 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHop {
504 assert!(self.is_owned);
505 let ret = ObjOps::untweak_ptr(self.inner);
506 self.inner = core::ptr::null_mut();
510 /// The node_id of the node at this hop.
512 pub extern "C" fn RouteHop_get_pubkey(this_ptr: &RouteHop) -> crate::c_types::PublicKey {
513 let mut inner_val = &mut this_ptr.get_native_mut_ref().pubkey;
514 crate::c_types::PublicKey::from_rust(&inner_val)
516 /// The node_id of the node at this hop.
518 pub extern "C" fn RouteHop_set_pubkey(this_ptr: &mut RouteHop, mut val: crate::c_types::PublicKey) {
519 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.pubkey = val.into_rust();
521 /// The node_announcement features of the node at this hop. For the last hop, these may be
522 /// amended to match the features present in the invoice this node generated.
524 pub extern "C" fn RouteHop_get_node_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::NodeFeatures {
525 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_features;
526 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 }
528 /// The node_announcement features of the node at this hop. For the last hop, these may be
529 /// amended to match the features present in the invoice this node generated.
531 pub extern "C" fn RouteHop_set_node_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::NodeFeatures) {
532 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_features = *unsafe { Box::from_raw(val.take_inner()) };
534 /// The channel that should be used from the previous hop to reach this node.
536 pub extern "C" fn RouteHop_get_short_channel_id(this_ptr: &RouteHop) -> u64 {
537 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
540 /// The channel that should be used from the previous hop to reach this node.
542 pub extern "C" fn RouteHop_set_short_channel_id(this_ptr: &mut RouteHop, mut val: u64) {
543 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
545 /// The channel_announcement features of the channel that should be used from the previous hop
546 /// to reach this node.
548 pub extern "C" fn RouteHop_get_channel_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::ChannelFeatures {
549 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_features;
550 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 }
552 /// The channel_announcement features of the channel that should be used from the previous hop
553 /// to reach this node.
555 pub extern "C" fn RouteHop_set_channel_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::ChannelFeatures) {
556 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_features = *unsafe { Box::from_raw(val.take_inner()) };
558 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
559 /// For the last hop, this should be the full value of the payment (might be more than
560 /// requested if we had to match htlc_minimum_msat).
562 pub extern "C" fn RouteHop_get_fee_msat(this_ptr: &RouteHop) -> u64 {
563 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_msat;
566 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
567 /// For the last hop, this should be the full value of the payment (might be more than
568 /// requested if we had to match htlc_minimum_msat).
570 pub extern "C" fn RouteHop_set_fee_msat(this_ptr: &mut RouteHop, mut val: u64) {
571 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_msat = val;
573 /// The CLTV delta added for this hop. For the last hop, this should be the full CLTV value
574 /// expected at the destination, in excess of the current block height.
576 pub extern "C" fn RouteHop_get_cltv_expiry_delta(this_ptr: &RouteHop) -> u32 {
577 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
580 /// The CLTV delta added for this hop. For the last hop, this should be the full CLTV value
581 /// expected at the destination, in excess of the current block height.
583 pub extern "C" fn RouteHop_set_cltv_expiry_delta(this_ptr: &mut RouteHop, mut val: u32) {
584 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
586 /// Constructs a new RouteHop given each field
589 pub extern "C" fn RouteHop_new(mut pubkey_arg: crate::c_types::PublicKey, mut node_features_arg: crate::lightning::ln::features::NodeFeatures, mut short_channel_id_arg: u64, mut channel_features_arg: crate::lightning::ln::features::ChannelFeatures, mut fee_msat_arg: u64, mut cltv_expiry_delta_arg: u32) -> RouteHop {
590 RouteHop { inner: ObjOps::heap_alloc(nativeRouteHop {
591 pubkey: pubkey_arg.into_rust(),
592 node_features: *unsafe { Box::from_raw(node_features_arg.take_inner()) },
593 short_channel_id: short_channel_id_arg,
594 channel_features: *unsafe { Box::from_raw(channel_features_arg.take_inner()) },
595 fee_msat: fee_msat_arg,
596 cltv_expiry_delta: cltv_expiry_delta_arg,
599 impl Clone for RouteHop {
600 fn clone(&self) -> Self {
602 inner: if <*mut nativeRouteHop>::is_null(self.inner) { core::ptr::null_mut() } else {
603 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
609 /// Used only if an object of this type is returned as a trait impl by a method
610 pub(crate) extern "C" fn RouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
611 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHop)).clone() })) as *mut c_void
614 /// Creates a copy of the RouteHop
615 pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop {
618 /// Checks if two RouteHops contain equal inner contents.
620 pub extern "C" fn RouteHop_hash(o: &RouteHop) -> u64 {
621 if o.inner.is_null() { return 0; }
622 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
624 let mut hasher = core::hash::SipHasher::new();
625 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
626 core::hash::Hasher::finish(&hasher)
628 /// Checks if two RouteHops contain equal inner contents.
629 /// This ignores pointers and is_owned flags and looks at the values in fields.
630 /// Two objects with NULL inner values will be considered "equal" here.
632 pub extern "C" fn RouteHop_eq(a: &RouteHop, b: &RouteHop) -> bool {
633 if a.inner == b.inner { return true; }
634 if a.inner.is_null() || b.inner.is_null() { return false; }
635 if a.get_native_ref() == b.get_native_ref() { true } else { false }
638 /// Serialize the RouteHop object into a byte array which can be read by RouteHop_read
639 pub extern "C" fn RouteHop_write(obj: &crate::lightning::routing::router::RouteHop) -> crate::c_types::derived::CVec_u8Z {
640 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
643 pub(crate) extern "C" fn RouteHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
644 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHop) })
647 /// Read a RouteHop from a byte array, created by RouteHop_write
648 pub extern "C" fn RouteHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHopDecodeErrorZ {
649 let res: Result<lightning::routing::router::RouteHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
650 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() };
654 use lightning::routing::router::Route as nativeRouteImport;
655 pub(crate) type nativeRoute = nativeRouteImport;
657 /// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
658 /// it can take multiple paths. Each path is composed of one or more hops through the network.
662 /// A pointer to the opaque Rust object.
664 /// Nearly everywhere, inner must be non-null, however in places where
665 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
666 pub inner: *mut nativeRoute,
667 /// Indicates that this is the only struct which contains the same pointer.
669 /// Rust functions which take ownership of an object provided via an argument require
670 /// this to be true and invalidate the object pointed to by inner.
674 impl Drop for Route {
676 if self.is_owned && !<*mut nativeRoute>::is_null(self.inner) {
677 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
681 /// Frees any resources used by the Route, if is_owned is set and inner is non-NULL.
683 pub extern "C" fn Route_free(this_obj: Route) { }
685 /// Used only if an object of this type is returned as a trait impl by a method
686 pub(crate) extern "C" fn Route_free_void(this_ptr: *mut c_void) {
687 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoute) };
691 pub(crate) fn get_native_ref(&self) -> &'static nativeRoute {
692 unsafe { &*ObjOps::untweak_ptr(self.inner) }
694 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoute {
695 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
697 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
698 pub(crate) fn take_inner(mut self) -> *mut nativeRoute {
699 assert!(self.is_owned);
700 let ret = ObjOps::untweak_ptr(self.inner);
701 self.inner = core::ptr::null_mut();
705 /// The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
706 /// last RouteHop in each path must be the same. Each entry represents a list of hops, NOT
707 /// INCLUDING our own, where the last hop is the destination. Thus, this must always be at
708 /// least length one. While the maximum length of any given path is variable, keeping the length
709 /// of any path less or equal to 19 should currently ensure it is viable.
711 pub extern "C" fn Route_get_paths(this_ptr: &Route) -> crate::c_types::derived::CVec_CVec_RouteHopZZ {
712 let mut inner_val = &mut this_ptr.get_native_mut_ref().paths;
713 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { let mut local_inner_val_0 = Vec::new(); for item in item.iter() { local_inner_val_0.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 } }); }; local_inner_val_0.into() }); };
714 local_inner_val.into()
716 /// The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
717 /// last RouteHop in each path must be the same. Each entry represents a list of hops, NOT
718 /// INCLUDING our own, where the last hop is the destination. Thus, this must always be at
719 /// least length one. While the maximum length of any given path is variable, keeping the length
720 /// of any path less or equal to 19 should currently ensure it is viable.
722 pub extern "C" fn Route_set_paths(this_ptr: &mut Route, mut val: crate::c_types::derived::CVec_CVec_RouteHopZZ) {
723 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { let mut local_val_0 = Vec::new(); for mut item in item.into_rust().drain(..) { local_val_0.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; local_val_0 }); };
724 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.paths = local_val;
726 /// The `payment_params` parameter passed to [`find_route`].
727 /// This is used by `ChannelManager` to track information which may be required for retries,
728 /// provided back to you via [`Event::PaymentPathFailed`].
730 /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
732 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
734 pub extern "C" fn Route_get_payment_params(this_ptr: &Route) -> crate::lightning::routing::router::PaymentParameters {
735 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_params;
736 let mut local_inner_val = crate::lightning::routing::router::PaymentParameters { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::router::PaymentParameters<>) as *mut _ }, is_owned: false };
739 /// The `payment_params` parameter passed to [`find_route`].
740 /// This is used by `ChannelManager` to track information which may be required for retries,
741 /// provided back to you via [`Event::PaymentPathFailed`].
743 /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
745 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
747 pub extern "C" fn Route_set_payment_params(this_ptr: &mut Route, mut val: crate::lightning::routing::router::PaymentParameters) {
748 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
749 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_params = local_val;
751 /// Constructs a new Route given each field
754 pub extern "C" fn Route_new(mut paths_arg: crate::c_types::derived::CVec_CVec_RouteHopZZ, mut payment_params_arg: crate::lightning::routing::router::PaymentParameters) -> Route {
755 let mut local_paths_arg = Vec::new(); for mut item in paths_arg.into_rust().drain(..) { local_paths_arg.push( { let mut local_paths_arg_0 = Vec::new(); for mut item in item.into_rust().drain(..) { local_paths_arg_0.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; local_paths_arg_0 }); };
756 let mut local_payment_params_arg = if payment_params_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(payment_params_arg.take_inner()) } }) };
757 Route { inner: ObjOps::heap_alloc(nativeRoute {
758 paths: local_paths_arg,
759 payment_params: local_payment_params_arg,
762 impl Clone for Route {
763 fn clone(&self) -> Self {
765 inner: if <*mut nativeRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
766 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
772 /// Used only if an object of this type is returned as a trait impl by a method
773 pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_void {
774 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoute)).clone() })) as *mut c_void
777 /// Creates a copy of the Route
778 pub extern "C" fn Route_clone(orig: &Route) -> Route {
781 /// Checks if two Routes contain equal inner contents.
783 pub extern "C" fn Route_hash(o: &Route) -> u64 {
784 if o.inner.is_null() { return 0; }
785 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
787 let mut hasher = core::hash::SipHasher::new();
788 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
789 core::hash::Hasher::finish(&hasher)
791 /// Checks if two Routes contain equal inner contents.
792 /// This ignores pointers and is_owned flags and looks at the values in fields.
793 /// Two objects with NULL inner values will be considered "equal" here.
795 pub extern "C" fn Route_eq(a: &Route, b: &Route) -> bool {
796 if a.inner == b.inner { return true; }
797 if a.inner.is_null() || b.inner.is_null() { return false; }
798 if a.get_native_ref() == b.get_native_ref() { true } else { false }
800 /// Returns the total amount of fees paid on this [`Route`].
802 /// This doesn't include any extra payment made to the recipient, which can happen in excess of
803 /// the amount passed to [`find_route`]'s `params.final_value_msat`.
806 pub extern "C" fn Route_get_total_fees(this_arg: &crate::lightning::routing::router::Route) -> u64 {
807 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_fees();
811 /// Returns the total amount paid on this [`Route`], excluding the fees.
814 pub extern "C" fn Route_get_total_amount(this_arg: &crate::lightning::routing::router::Route) -> u64 {
815 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_amount();
820 /// Serialize the Route object into a byte array which can be read by Route_read
821 pub extern "C" fn Route_write(obj: &crate::lightning::routing::router::Route) -> crate::c_types::derived::CVec_u8Z {
822 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
825 pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
826 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) })
829 /// Read a Route from a byte array, created by Route_write
830 pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ {
831 let res: Result<lightning::routing::router::Route, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
832 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() };
836 use lightning::routing::router::RouteParameters as nativeRouteParametersImport;
837 pub(crate) type nativeRouteParameters = nativeRouteParametersImport;
839 /// Parameters needed to find a [`Route`].
841 /// Passed to [`find_route`] and [`build_route_from_hops`], but also provided in
842 /// [`Event::PaymentPathFailed`] for retrying a failed payment path.
844 /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
847 pub struct RouteParameters {
848 /// A pointer to the opaque Rust object.
850 /// Nearly everywhere, inner must be non-null, however in places where
851 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
852 pub inner: *mut nativeRouteParameters,
853 /// Indicates that this is the only struct which contains the same pointer.
855 /// Rust functions which take ownership of an object provided via an argument require
856 /// this to be true and invalidate the object pointed to by inner.
860 impl Drop for RouteParameters {
862 if self.is_owned && !<*mut nativeRouteParameters>::is_null(self.inner) {
863 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
867 /// Frees any resources used by the RouteParameters, if is_owned is set and inner is non-NULL.
869 pub extern "C" fn RouteParameters_free(this_obj: RouteParameters) { }
871 /// Used only if an object of this type is returned as a trait impl by a method
872 pub(crate) extern "C" fn RouteParameters_free_void(this_ptr: *mut c_void) {
873 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteParameters) };
876 impl RouteParameters {
877 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteParameters {
878 unsafe { &*ObjOps::untweak_ptr(self.inner) }
880 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteParameters {
881 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
883 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
884 pub(crate) fn take_inner(mut self) -> *mut nativeRouteParameters {
885 assert!(self.is_owned);
886 let ret = ObjOps::untweak_ptr(self.inner);
887 self.inner = core::ptr::null_mut();
891 /// The parameters of the failed payment path.
893 pub extern "C" fn RouteParameters_get_payment_params(this_ptr: &RouteParameters) -> crate::lightning::routing::router::PaymentParameters {
894 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_params;
895 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 }
897 /// The parameters of the failed payment path.
899 pub extern "C" fn RouteParameters_set_payment_params(this_ptr: &mut RouteParameters, mut val: crate::lightning::routing::router::PaymentParameters) {
900 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_params = *unsafe { Box::from_raw(val.take_inner()) };
902 /// The amount in msats sent on the failed payment path.
904 pub extern "C" fn RouteParameters_get_final_value_msat(this_ptr: &RouteParameters) -> u64 {
905 let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
908 /// The amount in msats sent on the failed payment path.
910 pub extern "C" fn RouteParameters_set_final_value_msat(this_ptr: &mut RouteParameters, mut val: u64) {
911 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
913 /// The CLTV on the final hop of the failed payment path.
915 pub extern "C" fn RouteParameters_get_final_cltv_expiry_delta(this_ptr: &RouteParameters) -> u32 {
916 let mut inner_val = &mut this_ptr.get_native_mut_ref().final_cltv_expiry_delta;
919 /// The CLTV on the final hop of the failed payment path.
921 pub extern "C" fn RouteParameters_set_final_cltv_expiry_delta(this_ptr: &mut RouteParameters, mut val: u32) {
922 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_cltv_expiry_delta = val;
924 /// Constructs a new RouteParameters given each field
927 pub extern "C" fn RouteParameters_new(mut payment_params_arg: crate::lightning::routing::router::PaymentParameters, mut final_value_msat_arg: u64, mut final_cltv_expiry_delta_arg: u32) -> RouteParameters {
928 RouteParameters { inner: ObjOps::heap_alloc(nativeRouteParameters {
929 payment_params: *unsafe { Box::from_raw(payment_params_arg.take_inner()) },
930 final_value_msat: final_value_msat_arg,
931 final_cltv_expiry_delta: final_cltv_expiry_delta_arg,
934 impl Clone for RouteParameters {
935 fn clone(&self) -> Self {
937 inner: if <*mut nativeRouteParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
938 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
944 /// Used only if an object of this type is returned as a trait impl by a method
945 pub(crate) extern "C" fn RouteParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
946 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteParameters)).clone() })) as *mut c_void
949 /// Creates a copy of the RouteParameters
950 pub extern "C" fn RouteParameters_clone(orig: &RouteParameters) -> RouteParameters {
954 /// Serialize the RouteParameters object into a byte array which can be read by RouteParameters_read
955 pub extern "C" fn RouteParameters_write(obj: &crate::lightning::routing::router::RouteParameters) -> crate::c_types::derived::CVec_u8Z {
956 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
959 pub(crate) extern "C" fn RouteParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
960 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteParameters) })
963 /// Read a RouteParameters from a byte array, created by RouteParameters_write
964 pub extern "C" fn RouteParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteParametersDecodeErrorZ {
965 let res: Result<lightning::routing::router::RouteParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
966 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() };
969 /// Maximum total CTLV difference we allow for a full payment path.
972 pub static DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = lightning::routing::router::DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
973 /// Maximum number of paths we allow an (MPP) payment to have.
976 pub static DEFAULT_MAX_PATH_COUNT: u8 = lightning::routing::router::DEFAULT_MAX_PATH_COUNT;
978 use lightning::routing::router::PaymentParameters as nativePaymentParametersImport;
979 pub(crate) type nativePaymentParameters = nativePaymentParametersImport;
981 /// The recipient of a payment.
984 pub struct PaymentParameters {
985 /// A pointer to the opaque Rust object.
987 /// Nearly everywhere, inner must be non-null, however in places where
988 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
989 pub inner: *mut nativePaymentParameters,
990 /// Indicates that this is the only struct which contains the same pointer.
992 /// Rust functions which take ownership of an object provided via an argument require
993 /// this to be true and invalidate the object pointed to by inner.
997 impl Drop for PaymentParameters {
999 if self.is_owned && !<*mut nativePaymentParameters>::is_null(self.inner) {
1000 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1004 /// Frees any resources used by the PaymentParameters, if is_owned is set and inner is non-NULL.
1006 pub extern "C" fn PaymentParameters_free(this_obj: PaymentParameters) { }
1008 /// Used only if an object of this type is returned as a trait impl by a method
1009 pub(crate) extern "C" fn PaymentParameters_free_void(this_ptr: *mut c_void) {
1010 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentParameters) };
1013 impl PaymentParameters {
1014 pub(crate) fn get_native_ref(&self) -> &'static nativePaymentParameters {
1015 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1017 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentParameters {
1018 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1020 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1021 pub(crate) fn take_inner(mut self) -> *mut nativePaymentParameters {
1022 assert!(self.is_owned);
1023 let ret = ObjOps::untweak_ptr(self.inner);
1024 self.inner = core::ptr::null_mut();
1028 /// The node id of the payee.
1030 pub extern "C" fn PaymentParameters_get_payee_pubkey(this_ptr: &PaymentParameters) -> crate::c_types::PublicKey {
1031 let mut inner_val = &mut this_ptr.get_native_mut_ref().payee_pubkey;
1032 crate::c_types::PublicKey::from_rust(&inner_val)
1034 /// The node id of the payee.
1036 pub extern "C" fn PaymentParameters_set_payee_pubkey(this_ptr: &mut PaymentParameters, mut val: crate::c_types::PublicKey) {
1037 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payee_pubkey = val.into_rust();
1039 /// Features supported by the payee.
1041 /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
1042 /// does not contain any features.
1044 /// [`for_keysend`]: Self::for_keysend
1046 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1048 pub extern "C" fn PaymentParameters_get_features(this_ptr: &PaymentParameters) -> crate::lightning::ln::features::InvoiceFeatures {
1049 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1050 let mut local_inner_val = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false };
1053 /// Features supported by the payee.
1055 /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
1056 /// does not contain any features.
1058 /// [`for_keysend`]: Self::for_keysend
1060 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1062 pub extern "C" fn PaymentParameters_set_features(this_ptr: &mut PaymentParameters, mut val: crate::lightning::ln::features::InvoiceFeatures) {
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) }.features = local_val;
1066 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
1068 pub extern "C" fn PaymentParameters_get_route_hints(this_ptr: &PaymentParameters) -> crate::c_types::derived::CVec_RouteHintZ {
1069 let mut inner_val = &mut this_ptr.get_native_mut_ref().route_hints;
1070 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::RouteHint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::RouteHint<>) as *mut _) }, is_owned: false } }); };
1071 local_inner_val.into()
1073 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
1075 pub extern "C" fn PaymentParameters_set_route_hints(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_RouteHintZ) {
1076 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1077 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_hints = local_val;
1079 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1081 pub extern "C" fn PaymentParameters_get_expiry_time(this_ptr: &PaymentParameters) -> crate::c_types::derived::COption_u64Z {
1082 let mut inner_val = &mut this_ptr.get_native_mut_ref().expiry_time;
1083 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() }) };
1086 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1088 pub extern "C" fn PaymentParameters_set_expiry_time(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::COption_u64Z) {
1089 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1090 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.expiry_time = local_val;
1092 /// The maximum total CLTV delta we accept for the route.
1093 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1095 pub extern "C" fn PaymentParameters_get_max_total_cltv_expiry_delta(this_ptr: &PaymentParameters) -> u32 {
1096 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_cltv_expiry_delta;
1099 /// The maximum total CLTV delta we accept for the route.
1100 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1102 pub extern "C" fn PaymentParameters_set_max_total_cltv_expiry_delta(this_ptr: &mut PaymentParameters, mut val: u32) {
1103 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_cltv_expiry_delta = val;
1105 /// The maximum number of paths that may be used by (MPP) payments.
1106 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1108 pub extern "C" fn PaymentParameters_get_max_path_count(this_ptr: &PaymentParameters) -> u8 {
1109 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_path_count;
1112 /// The maximum number of paths that may be used by (MPP) payments.
1113 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1115 pub extern "C" fn PaymentParameters_set_max_path_count(this_ptr: &mut PaymentParameters, mut val: u8) {
1116 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_path_count = val;
1118 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1119 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1120 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1121 /// increasing failure probability for those paths.
1123 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1124 /// restriction have been found. While paths which meet this criteria will be searched for, it
1125 /// is ultimately up to the scorer to select them over other paths.
1127 /// A value of 0 will allow payments up to and including a channel's total announced usable
1128 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1130 /// Default value: 2
1132 pub extern "C" fn PaymentParameters_get_max_channel_saturation_power_of_half(this_ptr: &PaymentParameters) -> u8 {
1133 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_saturation_power_of_half;
1136 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1137 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1138 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1139 /// increasing failure probability for those paths.
1141 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1142 /// restriction have been found. While paths which meet this criteria will be searched for, it
1143 /// is ultimately up to the scorer to select them over other paths.
1145 /// A value of 0 will allow payments up to and including a channel's total announced usable
1146 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1148 /// Default value: 2
1150 pub extern "C" fn PaymentParameters_set_max_channel_saturation_power_of_half(this_ptr: &mut PaymentParameters, mut val: u8) {
1151 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_saturation_power_of_half = val;
1153 /// A list of SCIDs which this payment was previously attempted over and which caused the
1154 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1157 /// Returns a copy of the field.
1159 pub extern "C" fn PaymentParameters_get_previously_failed_channels(this_ptr: &PaymentParameters) -> crate::c_types::derived::CVec_u64Z {
1160 let mut inner_val = this_ptr.get_native_mut_ref().previously_failed_channels.clone();
1161 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1162 local_inner_val.into()
1164 /// A list of SCIDs which this payment was previously attempted over and which caused the
1165 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1168 pub extern "C" fn PaymentParameters_set_previously_failed_channels(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_u64Z) {
1169 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1170 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previously_failed_channels = local_val;
1172 /// Constructs a new PaymentParameters given each field
1175 pub extern "C" fn PaymentParameters_new(mut payee_pubkey_arg: crate::c_types::PublicKey, mut features_arg: crate::lightning::ln::features::InvoiceFeatures, mut route_hints_arg: crate::c_types::derived::CVec_RouteHintZ, 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 {
1176 let mut local_features_arg = if features_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_arg.take_inner()) } }) };
1177 let mut local_route_hints_arg = Vec::new(); for mut item in route_hints_arg.into_rust().drain(..) { local_route_hints_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1178 let mut local_expiry_time_arg = if expiry_time_arg.is_some() { Some( { expiry_time_arg.take() }) } else { None };
1179 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 }); };
1180 PaymentParameters { inner: ObjOps::heap_alloc(nativePaymentParameters {
1181 payee_pubkey: payee_pubkey_arg.into_rust(),
1182 features: local_features_arg,
1183 route_hints: local_route_hints_arg,
1184 expiry_time: local_expiry_time_arg,
1185 max_total_cltv_expiry_delta: max_total_cltv_expiry_delta_arg,
1186 max_path_count: max_path_count_arg,
1187 max_channel_saturation_power_of_half: max_channel_saturation_power_of_half_arg,
1188 previously_failed_channels: local_previously_failed_channels_arg,
1189 }), is_owned: true }
1191 impl Clone for PaymentParameters {
1192 fn clone(&self) -> Self {
1194 inner: if <*mut nativePaymentParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1195 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1201 /// Used only if an object of this type is returned as a trait impl by a method
1202 pub(crate) extern "C" fn PaymentParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1203 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentParameters)).clone() })) as *mut c_void
1206 /// Creates a copy of the PaymentParameters
1207 pub extern "C" fn PaymentParameters_clone(orig: &PaymentParameters) -> PaymentParameters {
1210 /// Checks if two PaymentParameterss contain equal inner contents.
1212 pub extern "C" fn PaymentParameters_hash(o: &PaymentParameters) -> u64 {
1213 if o.inner.is_null() { return 0; }
1214 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1215 #[allow(deprecated)]
1216 let mut hasher = core::hash::SipHasher::new();
1217 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1218 core::hash::Hasher::finish(&hasher)
1220 /// Checks if two PaymentParameterss contain equal inner contents.
1221 /// This ignores pointers and is_owned flags and looks at the values in fields.
1222 /// Two objects with NULL inner values will be considered "equal" here.
1224 pub extern "C" fn PaymentParameters_eq(a: &PaymentParameters, b: &PaymentParameters) -> bool {
1225 if a.inner == b.inner { return true; }
1226 if a.inner.is_null() || b.inner.is_null() { return false; }
1227 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1230 /// Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
1231 pub extern "C" fn PaymentParameters_write(obj: &crate::lightning::routing::router::PaymentParameters) -> crate::c_types::derived::CVec_u8Z {
1232 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1235 pub(crate) extern "C" fn PaymentParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1236 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentParameters) })
1239 /// Read a PaymentParameters from a byte array, created by PaymentParameters_write
1240 pub extern "C" fn PaymentParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PaymentParametersDecodeErrorZ {
1241 let res: Result<lightning::routing::router::PaymentParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1242 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() };
1245 /// Creates a payee with the node id of the given `pubkey`.
1248 pub extern "C" fn PaymentParameters_from_node_id(mut payee_pubkey: crate::c_types::PublicKey) -> crate::lightning::routing::router::PaymentParameters {
1249 let mut ret = lightning::routing::router::PaymentParameters::from_node_id(payee_pubkey.into_rust());
1250 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1253 /// Creates a payee with the node id of the given `pubkey` to use for keysend payments.
1256 pub extern "C" fn PaymentParameters_for_keysend(mut payee_pubkey: crate::c_types::PublicKey) -> crate::lightning::routing::router::PaymentParameters {
1257 let mut ret = lightning::routing::router::PaymentParameters::for_keysend(payee_pubkey.into_rust());
1258 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1262 use lightning::routing::router::RouteHint as nativeRouteHintImport;
1263 pub(crate) type nativeRouteHint = nativeRouteHintImport;
1265 /// A list of hops along a payment path terminating with a channel to the recipient.
1268 pub struct RouteHint {
1269 /// A pointer to the opaque Rust object.
1271 /// Nearly everywhere, inner must be non-null, however in places where
1272 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1273 pub inner: *mut nativeRouteHint,
1274 /// Indicates that this is the only struct which contains the same pointer.
1276 /// Rust functions which take ownership of an object provided via an argument require
1277 /// this to be true and invalidate the object pointed to by inner.
1281 impl Drop for RouteHint {
1282 fn drop(&mut self) {
1283 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
1284 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1288 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
1290 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
1292 /// Used only if an object of this type is returned as a trait impl by a method
1293 pub(crate) extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
1294 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHint) };
1298 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHint {
1299 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1301 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHint {
1302 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1304 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1305 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
1306 assert!(self.is_owned);
1307 let ret = ObjOps::untweak_ptr(self.inner);
1308 self.inner = core::ptr::null_mut();
1313 pub extern "C" fn RouteHint_get_a(this_ptr: &RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ {
1314 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1315 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 } }); };
1316 local_inner_val.into()
1319 pub extern "C" fn RouteHint_set_a(this_ptr: &mut RouteHint, mut val: crate::c_types::derived::CVec_RouteHintHopZ) {
1320 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1321 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = local_val;
1323 /// Constructs a new RouteHint given each field
1326 pub extern "C" fn RouteHint_new(mut a_arg: crate::c_types::derived::CVec_RouteHintHopZ) -> RouteHint {
1327 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()) } }); };
1328 RouteHint { inner: ObjOps::heap_alloc(lightning::routing::router::RouteHint (
1330 )), is_owned: true }
1332 impl Clone for RouteHint {
1333 fn clone(&self) -> Self {
1335 inner: if <*mut nativeRouteHint>::is_null(self.inner) { core::ptr::null_mut() } else {
1336 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1342 /// Used only if an object of this type is returned as a trait impl by a method
1343 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
1344 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void
1347 /// Creates a copy of the RouteHint
1348 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
1351 /// Checks if two RouteHints contain equal inner contents.
1353 pub extern "C" fn RouteHint_hash(o: &RouteHint) -> u64 {
1354 if o.inner.is_null() { return 0; }
1355 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1356 #[allow(deprecated)]
1357 let mut hasher = core::hash::SipHasher::new();
1358 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1359 core::hash::Hasher::finish(&hasher)
1361 /// Checks if two RouteHints contain equal inner contents.
1362 /// This ignores pointers and is_owned flags and looks at the values in fields.
1363 /// Two objects with NULL inner values will be considered "equal" here.
1365 pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool {
1366 if a.inner == b.inner { return true; }
1367 if a.inner.is_null() || b.inner.is_null() { return false; }
1368 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1371 /// Serialize the RouteHint object into a byte array which can be read by RouteHint_read
1372 pub extern "C" fn RouteHint_write(obj: &crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CVec_u8Z {
1373 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1376 pub(crate) extern "C" fn RouteHint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1377 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHint) })
1380 /// Read a RouteHint from a byte array, created by RouteHint_write
1381 pub extern "C" fn RouteHint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintDecodeErrorZ {
1382 let res: Result<lightning::routing::router::RouteHint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1383 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() };
1387 use lightning::routing::router::RouteHintHop as nativeRouteHintHopImport;
1388 pub(crate) type nativeRouteHintHop = nativeRouteHintHopImport;
1390 /// A channel descriptor for a hop along a payment path.
1393 pub struct RouteHintHop {
1394 /// A pointer to the opaque Rust object.
1396 /// Nearly everywhere, inner must be non-null, however in places where
1397 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1398 pub inner: *mut nativeRouteHintHop,
1399 /// Indicates that this is the only struct which contains the same pointer.
1401 /// Rust functions which take ownership of an object provided via an argument require
1402 /// this to be true and invalidate the object pointed to by inner.
1406 impl Drop for RouteHintHop {
1407 fn drop(&mut self) {
1408 if self.is_owned && !<*mut nativeRouteHintHop>::is_null(self.inner) {
1409 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1413 /// Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL.
1415 pub extern "C" fn RouteHintHop_free(this_obj: RouteHintHop) { }
1417 /// Used only if an object of this type is returned as a trait impl by a method
1418 pub(crate) extern "C" fn RouteHintHop_free_void(this_ptr: *mut c_void) {
1419 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHintHop) };
1423 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHintHop {
1424 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1426 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHintHop {
1427 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1429 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1430 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHintHop {
1431 assert!(self.is_owned);
1432 let ret = ObjOps::untweak_ptr(self.inner);
1433 self.inner = core::ptr::null_mut();
1437 /// The node_id of the non-target end of the route
1439 pub extern "C" fn RouteHintHop_get_src_node_id(this_ptr: &RouteHintHop) -> crate::c_types::PublicKey {
1440 let mut inner_val = &mut this_ptr.get_native_mut_ref().src_node_id;
1441 crate::c_types::PublicKey::from_rust(&inner_val)
1443 /// The node_id of the non-target end of the route
1445 pub extern "C" fn RouteHintHop_set_src_node_id(this_ptr: &mut RouteHintHop, mut val: crate::c_types::PublicKey) {
1446 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.src_node_id = val.into_rust();
1448 /// The short_channel_id of this channel
1450 pub extern "C" fn RouteHintHop_get_short_channel_id(this_ptr: &RouteHintHop) -> u64 {
1451 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
1454 /// The short_channel_id of this channel
1456 pub extern "C" fn RouteHintHop_set_short_channel_id(this_ptr: &mut RouteHintHop, mut val: u64) {
1457 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
1459 /// The fees which must be paid to use this channel
1461 pub extern "C" fn RouteHintHop_get_fees(this_ptr: &RouteHintHop) -> crate::lightning::routing::gossip::RoutingFees {
1462 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
1463 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 }
1465 /// The fees which must be paid to use this channel
1467 pub extern "C" fn RouteHintHop_set_fees(this_ptr: &mut RouteHintHop, mut val: crate::lightning::routing::gossip::RoutingFees) {
1468 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
1470 /// The difference in CLTV values between this node and the next node.
1472 pub extern "C" fn RouteHintHop_get_cltv_expiry_delta(this_ptr: &RouteHintHop) -> u16 {
1473 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
1476 /// The difference in CLTV values between this node and the next node.
1478 pub extern "C" fn RouteHintHop_set_cltv_expiry_delta(this_ptr: &mut RouteHintHop, mut val: u16) {
1479 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
1481 /// The minimum value, in msat, which must be relayed to the next hop.
1483 pub extern "C" fn RouteHintHop_get_htlc_minimum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
1484 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
1485 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() }) };
1488 /// The minimum value, in msat, which must be relayed to the next hop.
1490 pub extern "C" fn RouteHintHop_set_htlc_minimum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
1491 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1492 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = local_val;
1494 /// The maximum value in msat available for routing with a single HTLC.
1496 pub extern "C" fn RouteHintHop_get_htlc_maximum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
1497 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
1498 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() }) };
1501 /// The maximum value in msat available for routing with a single HTLC.
1503 pub extern "C" fn RouteHintHop_set_htlc_maximum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
1504 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1505 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
1507 /// Constructs a new RouteHintHop given each field
1510 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 {
1511 let mut local_htlc_minimum_msat_arg = if htlc_minimum_msat_arg.is_some() { Some( { htlc_minimum_msat_arg.take() }) } else { None };
1512 let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
1513 RouteHintHop { inner: ObjOps::heap_alloc(nativeRouteHintHop {
1514 src_node_id: src_node_id_arg.into_rust(),
1515 short_channel_id: short_channel_id_arg,
1516 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
1517 cltv_expiry_delta: cltv_expiry_delta_arg,
1518 htlc_minimum_msat: local_htlc_minimum_msat_arg,
1519 htlc_maximum_msat: local_htlc_maximum_msat_arg,
1520 }), is_owned: true }
1522 impl Clone for RouteHintHop {
1523 fn clone(&self) -> Self {
1525 inner: if <*mut nativeRouteHintHop>::is_null(self.inner) { core::ptr::null_mut() } else {
1526 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1532 /// Used only if an object of this type is returned as a trait impl by a method
1533 pub(crate) extern "C" fn RouteHintHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
1534 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHintHop)).clone() })) as *mut c_void
1537 /// Creates a copy of the RouteHintHop
1538 pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop {
1541 /// Checks if two RouteHintHops contain equal inner contents.
1543 pub extern "C" fn RouteHintHop_hash(o: &RouteHintHop) -> u64 {
1544 if o.inner.is_null() { return 0; }
1545 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1546 #[allow(deprecated)]
1547 let mut hasher = core::hash::SipHasher::new();
1548 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1549 core::hash::Hasher::finish(&hasher)
1551 /// Checks if two RouteHintHops contain equal inner contents.
1552 /// This ignores pointers and is_owned flags and looks at the values in fields.
1553 /// Two objects with NULL inner values will be considered "equal" here.
1555 pub extern "C" fn RouteHintHop_eq(a: &RouteHintHop, b: &RouteHintHop) -> bool {
1556 if a.inner == b.inner { return true; }
1557 if a.inner.is_null() || b.inner.is_null() { return false; }
1558 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1561 /// Serialize the RouteHintHop object into a byte array which can be read by RouteHintHop_read
1562 pub extern "C" fn RouteHintHop_write(obj: &crate::lightning::routing::router::RouteHintHop) -> crate::c_types::derived::CVec_u8Z {
1563 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1566 pub(crate) extern "C" fn RouteHintHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1567 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHintHop) })
1570 /// Read a RouteHintHop from a byte array, created by RouteHintHop_write
1571 pub extern "C" fn RouteHintHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintHopDecodeErrorZ {
1572 let res: Result<lightning::routing::router::RouteHintHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1573 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() };
1576 /// Finds a route from us (payer) to the given target node (payee).
1578 /// If the payee provided features in their invoice, they should be provided via `params.payee`.
1579 /// Without this, MPP will only be used if the payee's features are available in the network graph.
1581 /// Private routing paths between a public node and the target may be included in `params.payee`.
1583 /// If some channels aren't announced, it may be useful to fill in `first_hops` with the results
1584 /// from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
1585 /// from `network_graph` will be ignored, and only those in `first_hops` will be used.
1587 /// The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
1588 /// However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
1589 /// `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
1593 /// May be used to re-compute a [`Route`] when handling a [`Event::PaymentPathFailed`]. Any
1594 /// adjustments to the [`NetworkGraph`] and channel scores should be made prior to calling this
1599 /// Panics if first_hops contains channels without short_channel_ids;
1600 /// [`ChannelManager::list_usable_channels`] will never include such channels.
1602 /// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
1603 /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
1604 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
1606 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
1608 pub extern "C" fn find_route(mut our_node_pubkey: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, network_graph: &crate::lightning::routing::gossip::NetworkGraph, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut logger: crate::lightning::util::logger::Logger, scorer: &crate::lightning::routing::scoring::Score, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
1609 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[..]);
1610 let mut ret = lightning::routing::router::find_route::<crate::lightning::util::logger::Logger, crate::lightning::util::logger::Logger, crate::lightning::routing::scoring::Score>(&our_node_pubkey.into_rust(), route_params.get_native_ref(), network_graph.get_native_ref(), local_first_hops, logger, scorer, unsafe { &*random_seed_bytes});
1611 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() };
1615 /// Construct a route from us (payer) to the target node (payee) via the given hops (which should
1616 /// exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
1618 /// Re-uses logic from `find_route`, so the restrictions described there also apply here.
1620 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 {
1621 let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { item.into_rust() }); };
1622 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});
1623 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() };