1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! The router finds paths within a [`NetworkGraph`] for a payment.
11 use alloc::str::FromStr;
12 use alloc::string::String;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
21 use lightning::routing::router::DefaultRouter as nativeDefaultRouterImport;
22 pub(crate) type nativeDefaultRouter = nativeDefaultRouterImport<&'static lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, crate::lightning::util::logger::Logger, crate::lightning::routing::scoring::LockableScore>;
24 /// A [`Router`] implemented using [`find_route`].
27 pub struct DefaultRouter {
28 /// A pointer to the opaque Rust object.
30 /// Nearly everywhere, inner must be non-null, however in places where
31 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
32 pub inner: *mut nativeDefaultRouter,
33 /// Indicates that this is the only struct which contains the same pointer.
35 /// Rust functions which take ownership of an object provided via an argument require
36 /// this to be true and invalidate the object pointed to by inner.
40 impl Drop for DefaultRouter {
42 if self.is_owned && !<*mut nativeDefaultRouter>::is_null(self.inner) {
43 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
47 /// Frees any resources used by the DefaultRouter, if is_owned is set and inner is non-NULL.
49 pub extern "C" fn DefaultRouter_free(this_obj: DefaultRouter) { }
51 /// Used only if an object of this type is returned as a trait impl by a method
52 pub(crate) extern "C" fn DefaultRouter_free_void(this_ptr: *mut c_void) {
53 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDefaultRouter) };
57 pub(crate) fn get_native_ref(&self) -> &'static nativeDefaultRouter {
58 unsafe { &*ObjOps::untweak_ptr(self.inner) }
60 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDefaultRouter {
61 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
63 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
64 pub(crate) fn take_inner(mut self) -> *mut nativeDefaultRouter {
65 assert!(self.is_owned);
66 let ret = ObjOps::untweak_ptr(self.inner);
67 self.inner = core::ptr::null_mut();
71 /// Creates a new router.
74 pub extern "C" fn DefaultRouter_new(network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut logger: crate::lightning::util::logger::Logger, mut random_seed_bytes: crate::c_types::ThirtyTwoBytes, mut scorer: crate::lightning::routing::scoring::LockableScore, mut score_params: crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> crate::lightning::routing::router::DefaultRouter {
75 let mut ret = lightning::routing::router::DefaultRouter::new(network_graph.get_native_ref(), logger, random_seed_bytes.data, scorer, *unsafe { Box::from_raw(score_params.take_inner()) });
76 crate::lightning::routing::router::DefaultRouter { inner: ObjOps::heap_alloc(ret), is_owned: true }
79 impl From<nativeDefaultRouter> for crate::lightning::routing::router::Router {
80 fn from(obj: nativeDefaultRouter) -> Self {
81 let mut rust_obj = DefaultRouter { inner: ObjOps::heap_alloc(obj), is_owned: true };
82 let mut ret = DefaultRouter_as_Router(&rust_obj);
83 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
84 rust_obj.inner = core::ptr::null_mut();
85 ret.free = Some(DefaultRouter_free_void);
89 /// Constructs a new Router which calls the relevant methods on this_arg.
90 /// This copies the `inner` pointer in this_arg and thus the returned Router must be freed before this_arg is
92 pub extern "C" fn DefaultRouter_as_Router(this_arg: &DefaultRouter) -> crate::lightning::routing::router::Router {
93 crate::lightning::routing::router::Router {
94 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
96 find_route: DefaultRouter_Router_find_route,
97 find_route_with_id: DefaultRouter_Router_find_route_with_id,
102 extern "C" fn DefaultRouter_Router_find_route(this_arg: *const c_void, mut payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
103 let mut local_first_hops_base = if first_hops == core::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { item.get_native_ref() }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]);
104 let mut ret = <nativeDefaultRouter as lightning::routing::router::Router<>>::find_route(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &payer.into_rust(), route_params.get_native_ref(), local_first_hops, *unsafe { Box::from_raw(inflight_htlcs.take_inner()) });
105 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
109 extern "C" fn DefaultRouter_Router_find_route_with_id(this_arg: *const c_void, mut payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs, mut _payment_hash: crate::c_types::ThirtyTwoBytes, mut _payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
110 let mut local_first_hops_base = if first_hops == core::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { item.get_native_ref() }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]);
111 let mut ret = <nativeDefaultRouter as lightning::routing::router::Router<>>::find_route_with_id(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &payer.into_rust(), route_params.get_native_ref(), local_first_hops, *unsafe { Box::from_raw(inflight_htlcs.take_inner()) }, ::lightning::ln::PaymentHash(_payment_hash.data), ::lightning::ln::channelmanager::PaymentId(_payment_id.data));
112 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
116 /// A trait defining behavior for routing a payment.
119 /// An opaque pointer which is passed to your function implementations as an argument.
120 /// This has no meaning in the LDK, and can be NULL or any other value.
121 pub this_arg: *mut c_void,
122 /// Finds a [`Route`] for a payment between the given `payer` and a payee.
124 /// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
125 /// and [`RouteParameters::final_value_msat`], respectively.
127 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
128 pub find_route: extern "C" fn (this_arg: *const c_void, payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CResult_RouteLightningErrorZ,
129 /// Finds a [`Route`] for a payment between the given `payer` and a payee.
131 /// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
132 /// and [`RouteParameters::final_value_msat`], respectively.
134 /// Includes a [`PaymentHash`] and a [`PaymentId`] to be able to correlate the request with a specific
137 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
138 pub find_route_with_id: extern "C" fn (this_arg: *const c_void, payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs, _payment_hash: crate::c_types::ThirtyTwoBytes, _payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_RouteLightningErrorZ,
139 /// Frees any resources associated with this object given its this_arg pointer.
140 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
141 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
143 unsafe impl Send for Router {}
144 unsafe impl Sync for Router {}
145 pub(crate) fn Router_clone_fields(orig: &Router) -> Router {
147 this_arg: orig.this_arg,
148 find_route: Clone::clone(&orig.find_route),
149 find_route_with_id: Clone::clone(&orig.find_route_with_id),
150 free: Clone::clone(&orig.free),
154 use lightning::routing::router::Router as rustRouter;
155 impl rustRouter for Router {
156 fn find_route(&self, mut payer: &bitcoin::secp256k1::PublicKey, mut route_params: &lightning::routing::router::RouteParameters, mut first_hops: Option<&[&lightning::ln::channelmanager::ChannelDetails]>, mut inflight_htlcs: lightning::routing::router::InFlightHtlcs) -> Result<lightning::routing::router::Route, lightning::ln::msgs::LightningError> {
157 let mut local_first_hops_base = if first_hops.is_none() { SmartPtr::null() } else { SmartPtr::from_obj( { let mut local_first_hops_0 = Vec::new(); for item in (first_hops.unwrap()).iter() { local_first_hops_0.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); }; local_first_hops_0.into() }) }; let mut local_first_hops = *local_first_hops_base;
158 let mut ret = (self.find_route)(self.this_arg, crate::c_types::PublicKey::from_rust(&payer), &crate::lightning::routing::router::RouteParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((route_params as *const lightning::routing::router::RouteParameters<>) as *mut _) }, is_owned: false }, local_first_hops, crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(inflight_htlcs), is_owned: true });
159 let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
162 fn find_route_with_id(&self, mut payer: &bitcoin::secp256k1::PublicKey, mut route_params: &lightning::routing::router::RouteParameters, mut first_hops: Option<&[&lightning::ln::channelmanager::ChannelDetails]>, mut inflight_htlcs: lightning::routing::router::InFlightHtlcs, mut _payment_hash: lightning::ln::PaymentHash, mut _payment_id: lightning::ln::channelmanager::PaymentId) -> Result<lightning::routing::router::Route, lightning::ln::msgs::LightningError> {
163 let mut local_first_hops_base = if first_hops.is_none() { SmartPtr::null() } else { SmartPtr::from_obj( { let mut local_first_hops_0 = Vec::new(); for item in (first_hops.unwrap()).iter() { local_first_hops_0.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); }; local_first_hops_0.into() }) }; let mut local_first_hops = *local_first_hops_base;
164 let mut ret = (self.find_route_with_id)(self.this_arg, crate::c_types::PublicKey::from_rust(&payer), &crate::lightning::routing::router::RouteParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((route_params as *const lightning::routing::router::RouteParameters<>) as *mut _) }, is_owned: false }, local_first_hops, crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(inflight_htlcs), is_owned: true }, crate::c_types::ThirtyTwoBytes { data: _payment_hash.0 }, crate::c_types::ThirtyTwoBytes { data: _payment_id.0 });
165 let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
170 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
171 // directly as a Deref trait in higher-level structs:
172 impl core::ops::Deref for Router {
174 fn deref(&self) -> &Self {
178 impl core::ops::DerefMut for Router {
179 fn deref_mut(&mut self) -> &mut Self {
183 /// Calls the free function if one is set
185 pub extern "C" fn Router_free(this_ptr: Router) { }
186 impl Drop for Router {
188 if let Some(f) = self.free {
194 use lightning::routing::router::ScorerAccountingForInFlightHtlcs as nativeScorerAccountingForInFlightHtlcsImport;
195 pub(crate) type nativeScorerAccountingForInFlightHtlcs = nativeScorerAccountingForInFlightHtlcsImport<'static, crate::lightning::routing::scoring::ScoreLookUp>;
197 /// [`ScoreLookUp`] implementation that factors in in-flight HTLC liquidity.
199 /// Useful for custom [`Router`] implementations to wrap their [`ScoreLookUp`] on-the-fly when calling
202 /// [`ScoreLookUp`]: crate::routing::scoring::ScoreLookUp
205 pub struct ScorerAccountingForInFlightHtlcs {
206 /// A pointer to the opaque Rust object.
208 /// Nearly everywhere, inner must be non-null, however in places where
209 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
210 pub inner: *mut nativeScorerAccountingForInFlightHtlcs,
211 /// Indicates that this is the only struct which contains the same pointer.
213 /// Rust functions which take ownership of an object provided via an argument require
214 /// this to be true and invalidate the object pointed to by inner.
218 impl Drop for ScorerAccountingForInFlightHtlcs {
220 if self.is_owned && !<*mut nativeScorerAccountingForInFlightHtlcs>::is_null(self.inner) {
221 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
225 /// Frees any resources used by the ScorerAccountingForInFlightHtlcs, if is_owned is set and inner is non-NULL.
227 pub extern "C" fn ScorerAccountingForInFlightHtlcs_free(this_obj: ScorerAccountingForInFlightHtlcs) { }
229 /// Used only if an object of this type is returned as a trait impl by a method
230 pub(crate) extern "C" fn ScorerAccountingForInFlightHtlcs_free_void(this_ptr: *mut c_void) {
231 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeScorerAccountingForInFlightHtlcs) };
234 impl ScorerAccountingForInFlightHtlcs {
235 pub(crate) fn get_native_ref(&self) -> &'static nativeScorerAccountingForInFlightHtlcs {
236 unsafe { &*ObjOps::untweak_ptr(self.inner) }
238 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeScorerAccountingForInFlightHtlcs {
239 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
241 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
242 pub(crate) fn take_inner(mut self) -> *mut nativeScorerAccountingForInFlightHtlcs {
243 assert!(self.is_owned);
244 let ret = ObjOps::untweak_ptr(self.inner);
245 self.inner = core::ptr::null_mut();
249 /// Initialize a new `ScorerAccountingForInFlightHtlcs`.
252 pub extern "C" fn ScorerAccountingForInFlightHtlcs_new(mut scorer: crate::lightning::routing::scoring::ScoreLookUp, inflight_htlcs: &crate::lightning::routing::router::InFlightHtlcs) -> crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs {
253 let mut ret = lightning::routing::router::ScorerAccountingForInFlightHtlcs::new(scorer, inflight_htlcs.get_native_ref());
254 crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
257 impl From<nativeScorerAccountingForInFlightHtlcs> for crate::lightning::routing::scoring::ScoreLookUp {
258 fn from(obj: nativeScorerAccountingForInFlightHtlcs) -> Self {
259 let mut rust_obj = ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(obj), is_owned: true };
260 let mut ret = ScorerAccountingForInFlightHtlcs_as_ScoreLookUp(&rust_obj);
261 // 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
262 rust_obj.inner = core::ptr::null_mut();
263 ret.free = Some(ScorerAccountingForInFlightHtlcs_free_void);
267 /// Constructs a new ScoreLookUp which calls the relevant methods on this_arg.
268 /// This copies the `inner` pointer in this_arg and thus the returned ScoreLookUp must be freed before this_arg is
270 pub extern "C" fn ScorerAccountingForInFlightHtlcs_as_ScoreLookUp(this_arg: &ScorerAccountingForInFlightHtlcs) -> crate::lightning::routing::scoring::ScoreLookUp {
271 crate::lightning::routing::scoring::ScoreLookUp {
272 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
274 channel_penalty_msat: ScorerAccountingForInFlightHtlcs_ScoreLookUp_channel_penalty_msat,
279 extern "C" fn ScorerAccountingForInFlightHtlcs_ScoreLookUp_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut usage: crate::lightning::routing::scoring::ChannelUsage, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> u64 {
280 let mut ret = <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::ScoreLookUp<>>::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, short_channel_id, source.get_native_ref(), target.get_native_ref(), *unsafe { Box::from_raw(usage.take_inner()) }, score_params.get_native_ref());
285 use lightning::routing::router::InFlightHtlcs as nativeInFlightHtlcsImport;
286 pub(crate) type nativeInFlightHtlcs = nativeInFlightHtlcsImport;
288 /// A data structure for tracking in-flight HTLCs. May be used during pathfinding to account for
289 /// in-use channel liquidity.
292 pub struct InFlightHtlcs {
293 /// A pointer to the opaque Rust object.
295 /// Nearly everywhere, inner must be non-null, however in places where
296 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
297 pub inner: *mut nativeInFlightHtlcs,
298 /// Indicates that this is the only struct which contains the same pointer.
300 /// Rust functions which take ownership of an object provided via an argument require
301 /// this to be true and invalidate the object pointed to by inner.
305 impl Drop for InFlightHtlcs {
307 if self.is_owned && !<*mut nativeInFlightHtlcs>::is_null(self.inner) {
308 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
312 /// Frees any resources used by the InFlightHtlcs, if is_owned is set and inner is non-NULL.
314 pub extern "C" fn InFlightHtlcs_free(this_obj: InFlightHtlcs) { }
316 /// Used only if an object of this type is returned as a trait impl by a method
317 pub(crate) extern "C" fn InFlightHtlcs_free_void(this_ptr: *mut c_void) {
318 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInFlightHtlcs) };
322 pub(crate) fn get_native_ref(&self) -> &'static nativeInFlightHtlcs {
323 unsafe { &*ObjOps::untweak_ptr(self.inner) }
325 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInFlightHtlcs {
326 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
328 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
329 pub(crate) fn take_inner(mut self) -> *mut nativeInFlightHtlcs {
330 assert!(self.is_owned);
331 let ret = ObjOps::untweak_ptr(self.inner);
332 self.inner = core::ptr::null_mut();
336 impl Clone for InFlightHtlcs {
337 fn clone(&self) -> Self {
339 inner: if <*mut nativeInFlightHtlcs>::is_null(self.inner) { core::ptr::null_mut() } else {
340 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
346 /// Used only if an object of this type is returned as a trait impl by a method
347 pub(crate) extern "C" fn InFlightHtlcs_clone_void(this_ptr: *const c_void) -> *mut c_void {
348 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInFlightHtlcs)).clone() })) as *mut c_void
351 /// Creates a copy of the InFlightHtlcs
352 pub extern "C" fn InFlightHtlcs_clone(orig: &InFlightHtlcs) -> InFlightHtlcs {
355 /// Constructs an empty `InFlightHtlcs`.
358 pub extern "C" fn InFlightHtlcs_new() -> crate::lightning::routing::router::InFlightHtlcs {
359 let mut ret = lightning::routing::router::InFlightHtlcs::new();
360 crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
363 /// Takes in a path with payer's node id and adds the path's details to `InFlightHtlcs`.
365 pub extern "C" fn InFlightHtlcs_process_path(this_arg: &mut crate::lightning::routing::router::InFlightHtlcs, path: &crate::lightning::routing::router::Path, mut payer_node_id: crate::c_types::PublicKey) {
366 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::router::nativeInFlightHtlcs)) }.process_path(path.get_native_ref(), payer_node_id.into_rust())
369 /// Adds a known HTLC given the public key of the HTLC source, target, and short channel
372 pub extern "C" fn InFlightHtlcs_add_inflight_htlc(this_arg: &mut crate::lightning::routing::router::InFlightHtlcs, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut channel_scid: u64, mut used_msat: u64) {
373 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::router::nativeInFlightHtlcs)) }.add_inflight_htlc(source.get_native_ref(), target.get_native_ref(), channel_scid, used_msat)
376 /// Returns liquidity in msat given the public key of the HTLC source, target, and short channel
380 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 {
381 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.used_liquidity_msat(source.get_native_ref(), target.get_native_ref(), channel_scid);
382 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() }) };
387 /// Serialize the InFlightHtlcs object into a byte array which can be read by InFlightHtlcs_read
388 pub extern "C" fn InFlightHtlcs_write(obj: &crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CVec_u8Z {
389 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
392 pub(crate) extern "C" fn InFlightHtlcs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
393 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInFlightHtlcs) })
396 /// Read a InFlightHtlcs from a byte array, created by InFlightHtlcs_write
397 pub extern "C" fn InFlightHtlcs_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InFlightHtlcsDecodeErrorZ {
398 let res: Result<lightning::routing::router::InFlightHtlcs, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
399 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() };
403 use lightning::routing::router::RouteHop as nativeRouteHopImport;
404 pub(crate) type nativeRouteHop = nativeRouteHopImport;
406 /// A hop in a route, and additional metadata about it. \"Hop\" is defined as a node and the channel
407 /// that leads to it.
410 pub struct RouteHop {
411 /// A pointer to the opaque Rust object.
413 /// Nearly everywhere, inner must be non-null, however in places where
414 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
415 pub inner: *mut nativeRouteHop,
416 /// Indicates that this is the only struct which contains the same pointer.
418 /// Rust functions which take ownership of an object provided via an argument require
419 /// this to be true and invalidate the object pointed to by inner.
423 impl Drop for RouteHop {
425 if self.is_owned && !<*mut nativeRouteHop>::is_null(self.inner) {
426 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
430 /// Frees any resources used by the RouteHop, if is_owned is set and inner is non-NULL.
432 pub extern "C" fn RouteHop_free(this_obj: RouteHop) { }
434 /// Used only if an object of this type is returned as a trait impl by a method
435 pub(crate) extern "C" fn RouteHop_free_void(this_ptr: *mut c_void) {
436 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHop) };
440 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHop {
441 unsafe { &*ObjOps::untweak_ptr(self.inner) }
443 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHop {
444 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
446 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
447 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHop {
448 assert!(self.is_owned);
449 let ret = ObjOps::untweak_ptr(self.inner);
450 self.inner = core::ptr::null_mut();
454 /// The node_id of the node at this hop.
456 pub extern "C" fn RouteHop_get_pubkey(this_ptr: &RouteHop) -> crate::c_types::PublicKey {
457 let mut inner_val = &mut this_ptr.get_native_mut_ref().pubkey;
458 crate::c_types::PublicKey::from_rust(&inner_val)
460 /// The node_id of the node at this hop.
462 pub extern "C" fn RouteHop_set_pubkey(this_ptr: &mut RouteHop, mut val: crate::c_types::PublicKey) {
463 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.pubkey = val.into_rust();
465 /// The node_announcement features of the node at this hop. For the last hop, these may be
466 /// amended to match the features present in the invoice this node generated.
468 pub extern "C" fn RouteHop_get_node_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::NodeFeatures {
469 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_features;
470 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 }
472 /// The node_announcement features of the node at this hop. For the last hop, these may be
473 /// amended to match the features present in the invoice this node generated.
475 pub extern "C" fn RouteHop_set_node_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::NodeFeatures) {
476 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_features = *unsafe { Box::from_raw(val.take_inner()) };
478 /// The channel that should be used from the previous hop to reach this node.
480 pub extern "C" fn RouteHop_get_short_channel_id(this_ptr: &RouteHop) -> u64 {
481 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
484 /// The channel that should be used from the previous hop to reach this node.
486 pub extern "C" fn RouteHop_set_short_channel_id(this_ptr: &mut RouteHop, mut val: u64) {
487 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
489 /// The channel_announcement features of the channel that should be used from the previous hop
490 /// to reach this node.
492 pub extern "C" fn RouteHop_get_channel_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::ChannelFeatures {
493 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_features;
494 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 }
496 /// The channel_announcement features of the channel that should be used from the previous hop
497 /// to reach this node.
499 pub extern "C" fn RouteHop_set_channel_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::ChannelFeatures) {
500 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_features = *unsafe { Box::from_raw(val.take_inner()) };
502 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
503 /// If this is the last hop in [`Path::hops`]:
504 /// * if we're sending to a [`BlindedPath`], this is the fee paid for use of the entire blinded path
505 /// * otherwise, this is the full value of this [`Path`]'s part of the payment
507 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
509 pub extern "C" fn RouteHop_get_fee_msat(this_ptr: &RouteHop) -> u64 {
510 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_msat;
513 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
514 /// If this is the last hop in [`Path::hops`]:
515 /// * if we're sending to a [`BlindedPath`], this is the fee paid for use of the entire blinded path
516 /// * otherwise, this is the full value of this [`Path`]'s part of the payment
518 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
520 pub extern "C" fn RouteHop_set_fee_msat(this_ptr: &mut RouteHop, mut val: u64) {
521 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_msat = val;
523 /// The CLTV delta added for this hop.
524 /// If this is the last hop in [`Path::hops`]:
525 /// * if we're sending to a [`BlindedPath`], this is the CLTV delta for the entire blinded path
526 /// * otherwise, this is the CLTV delta expected at the destination
528 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
530 pub extern "C" fn RouteHop_get_cltv_expiry_delta(this_ptr: &RouteHop) -> u32 {
531 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
534 /// The CLTV delta added for this hop.
535 /// If this is the last hop in [`Path::hops`]:
536 /// * if we're sending to a [`BlindedPath`], this is the CLTV delta for the entire blinded path
537 /// * otherwise, this is the CLTV delta expected at the destination
539 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
541 pub extern "C" fn RouteHop_set_cltv_expiry_delta(this_ptr: &mut RouteHop, mut val: u32) {
542 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
544 /// Indicates whether this hop is possibly announced in the public network graph.
546 /// Will be `true` if there is a possibility that the channel is publicly known, i.e., if we
547 /// either know for sure it's announced in the public graph, or if any public channels exist
548 /// for which the given `short_channel_id` could be an alias for. Will be `false` if we believe
549 /// the channel to be unannounced.
551 /// Will be `true` for objects serialized with LDK version 0.0.116 and before.
553 pub extern "C" fn RouteHop_get_maybe_announced_channel(this_ptr: &RouteHop) -> bool {
554 let mut inner_val = &mut this_ptr.get_native_mut_ref().maybe_announced_channel;
557 /// Indicates whether this hop is possibly announced in the public network graph.
559 /// Will be `true` if there is a possibility that the channel is publicly known, i.e., if we
560 /// either know for sure it's announced in the public graph, or if any public channels exist
561 /// for which the given `short_channel_id` could be an alias for. Will be `false` if we believe
562 /// the channel to be unannounced.
564 /// Will be `true` for objects serialized with LDK version 0.0.116 and before.
566 pub extern "C" fn RouteHop_set_maybe_announced_channel(this_ptr: &mut RouteHop, mut val: bool) {
567 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.maybe_announced_channel = val;
569 /// Constructs a new RouteHop given each field
572 pub extern "C" fn RouteHop_new(mut pubkey_arg: crate::c_types::PublicKey, mut node_features_arg: crate::lightning::ln::features::NodeFeatures, mut short_channel_id_arg: u64, mut channel_features_arg: crate::lightning::ln::features::ChannelFeatures, mut fee_msat_arg: u64, mut cltv_expiry_delta_arg: u32, mut maybe_announced_channel_arg: bool) -> RouteHop {
573 RouteHop { inner: ObjOps::heap_alloc(nativeRouteHop {
574 pubkey: pubkey_arg.into_rust(),
575 node_features: *unsafe { Box::from_raw(node_features_arg.take_inner()) },
576 short_channel_id: short_channel_id_arg,
577 channel_features: *unsafe { Box::from_raw(channel_features_arg.take_inner()) },
578 fee_msat: fee_msat_arg,
579 cltv_expiry_delta: cltv_expiry_delta_arg,
580 maybe_announced_channel: maybe_announced_channel_arg,
583 impl Clone for RouteHop {
584 fn clone(&self) -> Self {
586 inner: if <*mut nativeRouteHop>::is_null(self.inner) { core::ptr::null_mut() } else {
587 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
593 /// Used only if an object of this type is returned as a trait impl by a method
594 pub(crate) extern "C" fn RouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
595 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHop)).clone() })) as *mut c_void
598 /// Creates a copy of the RouteHop
599 pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop {
602 /// Generates a non-cryptographic 64-bit hash of the RouteHop.
604 pub extern "C" fn RouteHop_hash(o: &RouteHop) -> u64 {
605 if o.inner.is_null() { return 0; }
606 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
608 let mut hasher = core::hash::SipHasher::new();
609 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
610 core::hash::Hasher::finish(&hasher)
612 /// Checks if two RouteHops contain equal inner contents.
613 /// This ignores pointers and is_owned flags and looks at the values in fields.
614 /// Two objects with NULL inner values will be considered "equal" here.
616 pub extern "C" fn RouteHop_eq(a: &RouteHop, b: &RouteHop) -> bool {
617 if a.inner == b.inner { return true; }
618 if a.inner.is_null() || b.inner.is_null() { return false; }
619 if a.get_native_ref() == b.get_native_ref() { true } else { false }
622 /// Serialize the RouteHop object into a byte array which can be read by RouteHop_read
623 pub extern "C" fn RouteHop_write(obj: &crate::lightning::routing::router::RouteHop) -> crate::c_types::derived::CVec_u8Z {
624 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
627 pub(crate) extern "C" fn RouteHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
628 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHop) })
631 /// Read a RouteHop from a byte array, created by RouteHop_write
632 pub extern "C" fn RouteHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHopDecodeErrorZ {
633 let res: Result<lightning::routing::router::RouteHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
634 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() };
638 use lightning::routing::router::BlindedTail as nativeBlindedTailImport;
639 pub(crate) type nativeBlindedTail = nativeBlindedTailImport;
641 /// The blinded portion of a [`Path`], if we're routing to a recipient who provided blinded paths in
642 /// their [`Bolt12Invoice`].
644 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
647 pub struct BlindedTail {
648 /// A pointer to the opaque Rust object.
650 /// Nearly everywhere, inner must be non-null, however in places where
651 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
652 pub inner: *mut nativeBlindedTail,
653 /// Indicates that this is the only struct which contains the same pointer.
655 /// Rust functions which take ownership of an object provided via an argument require
656 /// this to be true and invalidate the object pointed to by inner.
660 impl Drop for BlindedTail {
662 if self.is_owned && !<*mut nativeBlindedTail>::is_null(self.inner) {
663 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
667 /// Frees any resources used by the BlindedTail, if is_owned is set and inner is non-NULL.
669 pub extern "C" fn BlindedTail_free(this_obj: BlindedTail) { }
671 /// Used only if an object of this type is returned as a trait impl by a method
672 pub(crate) extern "C" fn BlindedTail_free_void(this_ptr: *mut c_void) {
673 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedTail) };
677 pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedTail {
678 unsafe { &*ObjOps::untweak_ptr(self.inner) }
680 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedTail {
681 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
683 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
684 pub(crate) fn take_inner(mut self) -> *mut nativeBlindedTail {
685 assert!(self.is_owned);
686 let ret = ObjOps::untweak_ptr(self.inner);
687 self.inner = core::ptr::null_mut();
691 /// The hops of the [`BlindedPath`] provided by the recipient.
693 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
695 pub extern "C" fn BlindedTail_get_hops(this_ptr: &BlindedTail) -> crate::c_types::derived::CVec_BlindedHopZ {
696 let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
697 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::blinded_path::BlindedHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::blinded_path::BlindedHop<>) as *mut _) }, is_owned: false } }); };
698 local_inner_val.into()
700 /// The hops of the [`BlindedPath`] provided by the recipient.
702 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
704 pub extern "C" fn BlindedTail_set_hops(this_ptr: &mut BlindedTail, mut val: crate::c_types::derived::CVec_BlindedHopZ) {
705 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
706 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
708 /// The blinding point of the [`BlindedPath`] provided by the recipient.
710 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
712 pub extern "C" fn BlindedTail_get_blinding_point(this_ptr: &BlindedTail) -> crate::c_types::PublicKey {
713 let mut inner_val = &mut this_ptr.get_native_mut_ref().blinding_point;
714 crate::c_types::PublicKey::from_rust(&inner_val)
716 /// The blinding point of the [`BlindedPath`] provided by the recipient.
718 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
720 pub extern "C" fn BlindedTail_set_blinding_point(this_ptr: &mut BlindedTail, mut val: crate::c_types::PublicKey) {
721 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinding_point = val.into_rust();
723 /// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
724 /// inferring the destination. May be 0.
726 pub extern "C" fn BlindedTail_get_excess_final_cltv_expiry_delta(this_ptr: &BlindedTail) -> u32 {
727 let mut inner_val = &mut this_ptr.get_native_mut_ref().excess_final_cltv_expiry_delta;
730 /// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
731 /// inferring the destination. May be 0.
733 pub extern "C" fn BlindedTail_set_excess_final_cltv_expiry_delta(this_ptr: &mut BlindedTail, mut val: u32) {
734 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.excess_final_cltv_expiry_delta = val;
736 /// The total amount paid on this [`Path`], excluding the fees.
738 pub extern "C" fn BlindedTail_get_final_value_msat(this_ptr: &BlindedTail) -> u64 {
739 let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
742 /// The total amount paid on this [`Path`], excluding the fees.
744 pub extern "C" fn BlindedTail_set_final_value_msat(this_ptr: &mut BlindedTail, mut val: u64) {
745 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
747 /// Constructs a new BlindedTail given each field
750 pub extern "C" fn BlindedTail_new(mut hops_arg: crate::c_types::derived::CVec_BlindedHopZ, mut blinding_point_arg: crate::c_types::PublicKey, mut excess_final_cltv_expiry_delta_arg: u32, mut final_value_msat_arg: u64) -> BlindedTail {
751 let mut local_hops_arg = Vec::new(); for mut item in hops_arg.into_rust().drain(..) { local_hops_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
752 BlindedTail { inner: ObjOps::heap_alloc(nativeBlindedTail {
753 hops: local_hops_arg,
754 blinding_point: blinding_point_arg.into_rust(),
755 excess_final_cltv_expiry_delta: excess_final_cltv_expiry_delta_arg,
756 final_value_msat: final_value_msat_arg,
759 impl Clone for BlindedTail {
760 fn clone(&self) -> Self {
762 inner: if <*mut nativeBlindedTail>::is_null(self.inner) { core::ptr::null_mut() } else {
763 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
769 /// Used only if an object of this type is returned as a trait impl by a method
770 pub(crate) extern "C" fn BlindedTail_clone_void(this_ptr: *const c_void) -> *mut c_void {
771 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBlindedTail)).clone() })) as *mut c_void
774 /// Creates a copy of the BlindedTail
775 pub extern "C" fn BlindedTail_clone(orig: &BlindedTail) -> BlindedTail {
778 /// Generates a non-cryptographic 64-bit hash of the BlindedTail.
780 pub extern "C" fn BlindedTail_hash(o: &BlindedTail) -> u64 {
781 if o.inner.is_null() { return 0; }
782 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
784 let mut hasher = core::hash::SipHasher::new();
785 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
786 core::hash::Hasher::finish(&hasher)
788 /// Checks if two BlindedTails contain equal inner contents.
789 /// This ignores pointers and is_owned flags and looks at the values in fields.
790 /// Two objects with NULL inner values will be considered "equal" here.
792 pub extern "C" fn BlindedTail_eq(a: &BlindedTail, b: &BlindedTail) -> bool {
793 if a.inner == b.inner { return true; }
794 if a.inner.is_null() || b.inner.is_null() { return false; }
795 if a.get_native_ref() == b.get_native_ref() { true } else { false }
798 /// Serialize the BlindedTail object into a byte array which can be read by BlindedTail_read
799 pub extern "C" fn BlindedTail_write(obj: &crate::lightning::routing::router::BlindedTail) -> crate::c_types::derived::CVec_u8Z {
800 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
803 pub(crate) extern "C" fn BlindedTail_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
804 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedTail) })
807 /// Read a BlindedTail from a byte array, created by BlindedTail_write
808 pub extern "C" fn BlindedTail_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedTailDecodeErrorZ {
809 let res: Result<lightning::routing::router::BlindedTail, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
810 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::BlindedTail { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
814 use lightning::routing::router::Path as nativePathImport;
815 pub(crate) type nativePath = nativePathImport;
817 /// A path in a [`Route`] to the payment recipient. Must always be at least length one.
818 /// If no [`Path::blinded_tail`] is present, then [`Path::hops`] length may be up to 19.
822 /// A pointer to the opaque Rust object.
824 /// Nearly everywhere, inner must be non-null, however in places where
825 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
826 pub inner: *mut nativePath,
827 /// Indicates that this is the only struct which contains the same pointer.
829 /// Rust functions which take ownership of an object provided via an argument require
830 /// this to be true and invalidate the object pointed to by inner.
836 if self.is_owned && !<*mut nativePath>::is_null(self.inner) {
837 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
841 /// Frees any resources used by the Path, if is_owned is set and inner is non-NULL.
843 pub extern "C" fn Path_free(this_obj: Path) { }
845 /// Used only if an object of this type is returned as a trait impl by a method
846 pub(crate) extern "C" fn Path_free_void(this_ptr: *mut c_void) {
847 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePath) };
851 pub(crate) fn get_native_ref(&self) -> &'static nativePath {
852 unsafe { &*ObjOps::untweak_ptr(self.inner) }
854 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePath {
855 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
857 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
858 pub(crate) fn take_inner(mut self) -> *mut nativePath {
859 assert!(self.is_owned);
860 let ret = ObjOps::untweak_ptr(self.inner);
861 self.inner = core::ptr::null_mut();
865 /// The list of unblinded hops in this [`Path`]. Must be at least length one.
867 pub extern "C" fn Path_get_hops(this_ptr: &Path) -> crate::c_types::derived::CVec_RouteHopZ {
868 let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
869 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); };
870 local_inner_val.into()
872 /// The list of unblinded hops in this [`Path`]. Must be at least length one.
874 pub extern "C" fn Path_set_hops(this_ptr: &mut Path, mut val: crate::c_types::derived::CVec_RouteHopZ) {
875 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
876 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
878 /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
880 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
882 pub extern "C" fn Path_get_blinded_tail(this_ptr: &Path) -> crate::lightning::routing::router::BlindedTail {
883 let mut inner_val = &mut this_ptr.get_native_mut_ref().blinded_tail;
884 let mut local_inner_val = crate::lightning::routing::router::BlindedTail { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::router::BlindedTail<>) as *mut _ }, is_owned: false };
887 /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
889 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
891 pub extern "C" fn Path_set_blinded_tail(this_ptr: &mut Path, mut val: crate::lightning::routing::router::BlindedTail) {
892 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
893 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinded_tail = local_val;
895 /// Constructs a new Path given each field
897 /// Note that blinded_tail_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
900 pub extern "C" fn Path_new(mut hops_arg: crate::c_types::derived::CVec_RouteHopZ, mut blinded_tail_arg: crate::lightning::routing::router::BlindedTail) -> Path {
901 let mut local_hops_arg = Vec::new(); for mut item in hops_arg.into_rust().drain(..) { local_hops_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
902 let mut local_blinded_tail_arg = if blinded_tail_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(blinded_tail_arg.take_inner()) } }) };
903 Path { inner: ObjOps::heap_alloc(nativePath {
904 hops: local_hops_arg,
905 blinded_tail: local_blinded_tail_arg,
908 impl Clone for Path {
909 fn clone(&self) -> Self {
911 inner: if <*mut nativePath>::is_null(self.inner) { core::ptr::null_mut() } else {
912 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
918 /// Used only if an object of this type is returned as a trait impl by a method
919 pub(crate) extern "C" fn Path_clone_void(this_ptr: *const c_void) -> *mut c_void {
920 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePath)).clone() })) as *mut c_void
923 /// Creates a copy of the Path
924 pub extern "C" fn Path_clone(orig: &Path) -> Path {
927 /// Generates a non-cryptographic 64-bit hash of the Path.
929 pub extern "C" fn Path_hash(o: &Path) -> u64 {
930 if o.inner.is_null() { return 0; }
931 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
933 let mut hasher = core::hash::SipHasher::new();
934 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
935 core::hash::Hasher::finish(&hasher)
937 /// Checks if two Paths contain equal inner contents.
938 /// This ignores pointers and is_owned flags and looks at the values in fields.
939 /// Two objects with NULL inner values will be considered "equal" here.
941 pub extern "C" fn Path_eq(a: &Path, b: &Path) -> bool {
942 if a.inner == b.inner { return true; }
943 if a.inner.is_null() || b.inner.is_null() { return false; }
944 if a.get_native_ref() == b.get_native_ref() { true } else { false }
946 /// Gets the fees for a given path, excluding any excess paid to the recipient.
949 pub extern "C" fn Path_fee_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
950 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fee_msat();
954 /// Gets the total amount paid on this [`Path`], excluding the fees.
957 pub extern "C" fn Path_final_value_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
958 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_value_msat();
962 /// Gets the final hop's CLTV expiry delta.
965 pub extern "C" fn Path_final_cltv_expiry_delta(this_arg: &crate::lightning::routing::router::Path) -> crate::c_types::derived::COption_u32Z {
966 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_cltv_expiry_delta();
967 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { ret.unwrap() }) };
972 use lightning::routing::router::Route as nativeRouteImport;
973 pub(crate) type nativeRoute = nativeRouteImport;
975 /// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
976 /// it can take multiple paths. Each path is composed of one or more hops through the network.
980 /// A pointer to the opaque Rust object.
982 /// Nearly everywhere, inner must be non-null, however in places where
983 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
984 pub inner: *mut nativeRoute,
985 /// Indicates that this is the only struct which contains the same pointer.
987 /// Rust functions which take ownership of an object provided via an argument require
988 /// this to be true and invalidate the object pointed to by inner.
992 impl Drop for Route {
994 if self.is_owned && !<*mut nativeRoute>::is_null(self.inner) {
995 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
999 /// Frees any resources used by the Route, if is_owned is set and inner is non-NULL.
1001 pub extern "C" fn Route_free(this_obj: Route) { }
1003 /// Used only if an object of this type is returned as a trait impl by a method
1004 pub(crate) extern "C" fn Route_free_void(this_ptr: *mut c_void) {
1005 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoute) };
1009 pub(crate) fn get_native_ref(&self) -> &'static nativeRoute {
1010 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1012 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoute {
1013 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1015 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1016 pub(crate) fn take_inner(mut self) -> *mut nativeRoute {
1017 assert!(self.is_owned);
1018 let ret = ObjOps::untweak_ptr(self.inner);
1019 self.inner = core::ptr::null_mut();
1023 /// The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
1024 /// [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
1027 pub extern "C" fn Route_get_paths(this_ptr: &Route) -> crate::c_types::derived::CVec_PathZ {
1028 let mut inner_val = &mut this_ptr.get_native_mut_ref().paths;
1029 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::Path { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::Path<>) as *mut _) }, is_owned: false } }); };
1030 local_inner_val.into()
1032 /// The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
1033 /// [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
1036 pub extern "C" fn Route_set_paths(this_ptr: &mut Route, mut val: crate::c_types::derived::CVec_PathZ) {
1037 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1038 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.paths = local_val;
1040 /// The `route_params` parameter passed to [`find_route`].
1042 /// This is used by `ChannelManager` to track information which may be required for retries.
1044 /// Will be `None` for objects serialized with LDK versions prior to 0.0.117.
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 Route_get_route_params(this_ptr: &Route) -> crate::lightning::routing::router::RouteParameters {
1049 let mut inner_val = &mut this_ptr.get_native_mut_ref().route_params;
1050 let mut local_inner_val = crate::lightning::routing::router::RouteParameters { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::router::RouteParameters<>) as *mut _ }, is_owned: false };
1053 /// The `route_params` parameter passed to [`find_route`].
1055 /// This is used by `ChannelManager` to track information which may be required for retries.
1057 /// Will be `None` for objects serialized with LDK versions prior to 0.0.117.
1059 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1061 pub extern "C" fn Route_set_route_params(this_ptr: &mut Route, mut val: crate::lightning::routing::router::RouteParameters) {
1062 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1063 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_params = local_val;
1065 /// Constructs a new Route given each field
1067 /// Note that route_params_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
1070 pub extern "C" fn Route_new(mut paths_arg: crate::c_types::derived::CVec_PathZ, mut route_params_arg: crate::lightning::routing::router::RouteParameters) -> Route {
1071 let mut local_paths_arg = Vec::new(); for mut item in paths_arg.into_rust().drain(..) { local_paths_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1072 let mut local_route_params_arg = if route_params_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(route_params_arg.take_inner()) } }) };
1073 Route { inner: ObjOps::heap_alloc(nativeRoute {
1074 paths: local_paths_arg,
1075 route_params: local_route_params_arg,
1076 }), is_owned: true }
1078 impl Clone for Route {
1079 fn clone(&self) -> Self {
1081 inner: if <*mut nativeRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
1082 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1088 /// Used only if an object of this type is returned as a trait impl by a method
1089 pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_void {
1090 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoute)).clone() })) as *mut c_void
1093 /// Creates a copy of the Route
1094 pub extern "C" fn Route_clone(orig: &Route) -> Route {
1097 /// Generates a non-cryptographic 64-bit hash of the Route.
1099 pub extern "C" fn Route_hash(o: &Route) -> u64 {
1100 if o.inner.is_null() { return 0; }
1101 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1102 #[allow(deprecated)]
1103 let mut hasher = core::hash::SipHasher::new();
1104 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1105 core::hash::Hasher::finish(&hasher)
1107 /// Checks if two Routes contain equal inner contents.
1108 /// This ignores pointers and is_owned flags and looks at the values in fields.
1109 /// Two objects with NULL inner values will be considered "equal" here.
1111 pub extern "C" fn Route_eq(a: &Route, b: &Route) -> bool {
1112 if a.inner == b.inner { return true; }
1113 if a.inner.is_null() || b.inner.is_null() { return false; }
1114 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1116 /// Returns the total amount of fees paid on this [`Route`].
1118 /// For objects serialized with LDK 0.0.117 and after, this includes any extra payment made to
1119 /// the recipient, which can happen in excess of the amount passed to [`find_route`] via
1120 /// [`RouteParameters::final_value_msat`], if we had to reach the [`htlc_minimum_msat`] limits.
1122 /// [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
1125 pub extern "C" fn Route_get_total_fees(this_arg: &crate::lightning::routing::router::Route) -> u64 {
1126 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_fees();
1130 /// Returns the total amount paid on this [`Route`], excluding the fees.
1132 /// Might be more than requested as part of the given [`RouteParameters::final_value_msat`] if
1133 /// we had to reach the [`htlc_minimum_msat`] limits.
1135 /// [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
1138 pub extern "C" fn Route_get_total_amount(this_arg: &crate::lightning::routing::router::Route) -> u64 {
1139 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_amount();
1144 /// Serialize the Route object into a byte array which can be read by Route_read
1145 pub extern "C" fn Route_write(obj: &crate::lightning::routing::router::Route) -> crate::c_types::derived::CVec_u8Z {
1146 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1149 pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1150 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) })
1153 /// Read a Route from a byte array, created by Route_write
1154 pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ {
1155 let res: Result<lightning::routing::router::Route, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1156 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() };
1160 use lightning::routing::router::RouteParameters as nativeRouteParametersImport;
1161 pub(crate) type nativeRouteParameters = nativeRouteParametersImport;
1163 /// Parameters needed to find a [`Route`].
1165 /// Passed to [`find_route`] and [`build_route_from_hops`].
1168 pub struct RouteParameters {
1169 /// A pointer to the opaque Rust object.
1171 /// Nearly everywhere, inner must be non-null, however in places where
1172 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1173 pub inner: *mut nativeRouteParameters,
1174 /// Indicates that this is the only struct which contains the same pointer.
1176 /// Rust functions which take ownership of an object provided via an argument require
1177 /// this to be true and invalidate the object pointed to by inner.
1181 impl Drop for RouteParameters {
1182 fn drop(&mut self) {
1183 if self.is_owned && !<*mut nativeRouteParameters>::is_null(self.inner) {
1184 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1188 /// Frees any resources used by the RouteParameters, if is_owned is set and inner is non-NULL.
1190 pub extern "C" fn RouteParameters_free(this_obj: RouteParameters) { }
1192 /// Used only if an object of this type is returned as a trait impl by a method
1193 pub(crate) extern "C" fn RouteParameters_free_void(this_ptr: *mut c_void) {
1194 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteParameters) };
1197 impl RouteParameters {
1198 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteParameters {
1199 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1201 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteParameters {
1202 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1204 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1205 pub(crate) fn take_inner(mut self) -> *mut nativeRouteParameters {
1206 assert!(self.is_owned);
1207 let ret = ObjOps::untweak_ptr(self.inner);
1208 self.inner = core::ptr::null_mut();
1212 /// The parameters of the failed payment path.
1214 pub extern "C" fn RouteParameters_get_payment_params(this_ptr: &RouteParameters) -> crate::lightning::routing::router::PaymentParameters {
1215 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_params;
1216 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 }
1218 /// The parameters of the failed payment path.
1220 pub extern "C" fn RouteParameters_set_payment_params(this_ptr: &mut RouteParameters, mut val: crate::lightning::routing::router::PaymentParameters) {
1221 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_params = *unsafe { Box::from_raw(val.take_inner()) };
1223 /// The amount in msats sent on the failed payment path.
1225 pub extern "C" fn RouteParameters_get_final_value_msat(this_ptr: &RouteParameters) -> u64 {
1226 let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
1229 /// The amount in msats sent on the failed payment path.
1231 pub extern "C" fn RouteParameters_set_final_value_msat(this_ptr: &mut RouteParameters, mut val: u64) {
1232 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
1234 /// The maximum total fees, in millisatoshi, that may accrue during route finding.
1236 /// This limit also applies to the total fees that may arise while retrying failed payment
1239 /// Note that values below a few sats may result in some paths being spuriously ignored.
1241 pub extern "C" fn RouteParameters_get_max_total_routing_fee_msat(this_ptr: &RouteParameters) -> crate::c_types::derived::COption_u64Z {
1242 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_routing_fee_msat;
1243 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() }) };
1246 /// The maximum total fees, in millisatoshi, that may accrue during route finding.
1248 /// This limit also applies to the total fees that may arise while retrying failed payment
1251 /// Note that values below a few sats may result in some paths being spuriously ignored.
1253 pub extern "C" fn RouteParameters_set_max_total_routing_fee_msat(this_ptr: &mut RouteParameters, mut val: crate::c_types::derived::COption_u64Z) {
1254 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1255 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_routing_fee_msat = local_val;
1257 /// Constructs a new RouteParameters given each field
1260 pub extern "C" fn RouteParameters_new(mut payment_params_arg: crate::lightning::routing::router::PaymentParameters, mut final_value_msat_arg: u64, mut max_total_routing_fee_msat_arg: crate::c_types::derived::COption_u64Z) -> RouteParameters {
1261 let mut local_max_total_routing_fee_msat_arg = if max_total_routing_fee_msat_arg.is_some() { Some( { max_total_routing_fee_msat_arg.take() }) } else { None };
1262 RouteParameters { inner: ObjOps::heap_alloc(nativeRouteParameters {
1263 payment_params: *unsafe { Box::from_raw(payment_params_arg.take_inner()) },
1264 final_value_msat: final_value_msat_arg,
1265 max_total_routing_fee_msat: local_max_total_routing_fee_msat_arg,
1266 }), is_owned: true }
1268 impl Clone for RouteParameters {
1269 fn clone(&self) -> Self {
1271 inner: if <*mut nativeRouteParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1272 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1278 /// Used only if an object of this type is returned as a trait impl by a method
1279 pub(crate) extern "C" fn RouteParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1280 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteParameters)).clone() })) as *mut c_void
1283 /// Creates a copy of the RouteParameters
1284 pub extern "C" fn RouteParameters_clone(orig: &RouteParameters) -> RouteParameters {
1287 /// Generates a non-cryptographic 64-bit hash of the RouteParameters.
1289 pub extern "C" fn RouteParameters_hash(o: &RouteParameters) -> u64 {
1290 if o.inner.is_null() { return 0; }
1291 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1292 #[allow(deprecated)]
1293 let mut hasher = core::hash::SipHasher::new();
1294 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1295 core::hash::Hasher::finish(&hasher)
1297 /// Checks if two RouteParameterss contain equal inner contents.
1298 /// This ignores pointers and is_owned flags and looks at the values in fields.
1299 /// Two objects with NULL inner values will be considered "equal" here.
1301 pub extern "C" fn RouteParameters_eq(a: &RouteParameters, b: &RouteParameters) -> bool {
1302 if a.inner == b.inner { return true; }
1303 if a.inner.is_null() || b.inner.is_null() { return false; }
1304 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1306 /// Constructs [`RouteParameters`] from the given [`PaymentParameters`] and a payment amount.
1308 /// [`Self::max_total_routing_fee_msat`] defaults to 1% of the payment amount + 50 sats
1311 pub extern "C" fn RouteParameters_from_payment_params_and_value(mut payment_params: crate::lightning::routing::router::PaymentParameters, mut final_value_msat: u64) -> crate::lightning::routing::router::RouteParameters {
1312 let mut ret = lightning::routing::router::RouteParameters::from_payment_params_and_value(*unsafe { Box::from_raw(payment_params.take_inner()) }, final_value_msat);
1313 crate::lightning::routing::router::RouteParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1317 /// Serialize the RouteParameters object into a byte array which can be read by RouteParameters_read
1318 pub extern "C" fn RouteParameters_write(obj: &crate::lightning::routing::router::RouteParameters) -> crate::c_types::derived::CVec_u8Z {
1319 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1322 pub(crate) extern "C" fn RouteParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1323 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteParameters) })
1326 /// Read a RouteParameters from a byte array, created by RouteParameters_write
1327 pub extern "C" fn RouteParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteParametersDecodeErrorZ {
1328 let res: Result<lightning::routing::router::RouteParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1329 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() };
1332 /// Maximum total CTLV difference we allow for a full payment path.
1335 pub static DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = lightning::routing::router::DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
1336 /// Maximum number of paths we allow an (MPP) payment to have.
1339 pub static DEFAULT_MAX_PATH_COUNT: u8 = lightning::routing::router::DEFAULT_MAX_PATH_COUNT;
1341 use lightning::routing::router::PaymentParameters as nativePaymentParametersImport;
1342 pub(crate) type nativePaymentParameters = nativePaymentParametersImport;
1344 /// Information used to route a payment.
1347 pub struct PaymentParameters {
1348 /// A pointer to the opaque Rust object.
1350 /// Nearly everywhere, inner must be non-null, however in places where
1351 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1352 pub inner: *mut nativePaymentParameters,
1353 /// Indicates that this is the only struct which contains the same pointer.
1355 /// Rust functions which take ownership of an object provided via an argument require
1356 /// this to be true and invalidate the object pointed to by inner.
1360 impl Drop for PaymentParameters {
1361 fn drop(&mut self) {
1362 if self.is_owned && !<*mut nativePaymentParameters>::is_null(self.inner) {
1363 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1367 /// Frees any resources used by the PaymentParameters, if is_owned is set and inner is non-NULL.
1369 pub extern "C" fn PaymentParameters_free(this_obj: PaymentParameters) { }
1371 /// Used only if an object of this type is returned as a trait impl by a method
1372 pub(crate) extern "C" fn PaymentParameters_free_void(this_ptr: *mut c_void) {
1373 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentParameters) };
1376 impl PaymentParameters {
1377 pub(crate) fn get_native_ref(&self) -> &'static nativePaymentParameters {
1378 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1380 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentParameters {
1381 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1383 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1384 pub(crate) fn take_inner(mut self) -> *mut nativePaymentParameters {
1385 assert!(self.is_owned);
1386 let ret = ObjOps::untweak_ptr(self.inner);
1387 self.inner = core::ptr::null_mut();
1391 /// Information about the payee, such as their features and route hints for their channels.
1393 pub extern "C" fn PaymentParameters_get_payee(this_ptr: &PaymentParameters) -> crate::lightning::routing::router::Payee {
1394 let mut inner_val = &mut this_ptr.get_native_mut_ref().payee;
1395 crate::lightning::routing::router::Payee::from_native(inner_val)
1397 /// Information about the payee, such as their features and route hints for their channels.
1399 pub extern "C" fn PaymentParameters_set_payee(this_ptr: &mut PaymentParameters, mut val: crate::lightning::routing::router::Payee) {
1400 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payee = val.into_native();
1402 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1404 pub extern "C" fn PaymentParameters_get_expiry_time(this_ptr: &PaymentParameters) -> crate::c_types::derived::COption_u64Z {
1405 let mut inner_val = &mut this_ptr.get_native_mut_ref().expiry_time;
1406 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() }) };
1409 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1411 pub extern "C" fn PaymentParameters_set_expiry_time(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::COption_u64Z) {
1412 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1413 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.expiry_time = local_val;
1415 /// The maximum total CLTV delta we accept for the route.
1416 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1418 pub extern "C" fn PaymentParameters_get_max_total_cltv_expiry_delta(this_ptr: &PaymentParameters) -> u32 {
1419 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_cltv_expiry_delta;
1422 /// The maximum total CLTV delta we accept for the route.
1423 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1425 pub extern "C" fn PaymentParameters_set_max_total_cltv_expiry_delta(this_ptr: &mut PaymentParameters, mut val: u32) {
1426 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_cltv_expiry_delta = val;
1428 /// The maximum number of paths that may be used by (MPP) payments.
1429 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1431 pub extern "C" fn PaymentParameters_get_max_path_count(this_ptr: &PaymentParameters) -> u8 {
1432 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_path_count;
1435 /// The maximum number of paths that may be used by (MPP) payments.
1436 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1438 pub extern "C" fn PaymentParameters_set_max_path_count(this_ptr: &mut PaymentParameters, mut val: u8) {
1439 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_path_count = val;
1441 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1442 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1443 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1444 /// increasing failure probability for those paths.
1446 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1447 /// restriction have been found. While paths which meet this criteria will be searched for, it
1448 /// is ultimately up to the scorer to select them over other paths.
1450 /// A value of 0 will allow payments up to and including a channel's total announced usable
1451 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1453 /// Default value: 2
1455 pub extern "C" fn PaymentParameters_get_max_channel_saturation_power_of_half(this_ptr: &PaymentParameters) -> u8 {
1456 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_saturation_power_of_half;
1459 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1460 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1461 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1462 /// increasing failure probability for those paths.
1464 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1465 /// restriction have been found. While paths which meet this criteria will be searched for, it
1466 /// is ultimately up to the scorer to select them over other paths.
1468 /// A value of 0 will allow payments up to and including a channel's total announced usable
1469 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1471 /// Default value: 2
1473 pub extern "C" fn PaymentParameters_set_max_channel_saturation_power_of_half(this_ptr: &mut PaymentParameters, mut val: u8) {
1474 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_saturation_power_of_half = val;
1476 /// A list of SCIDs which this payment was previously attempted over and which caused the
1477 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1480 /// Returns a copy of the field.
1482 pub extern "C" fn PaymentParameters_get_previously_failed_channels(this_ptr: &PaymentParameters) -> crate::c_types::derived::CVec_u64Z {
1483 let mut inner_val = this_ptr.get_native_mut_ref().previously_failed_channels.clone();
1484 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1485 local_inner_val.into()
1487 /// A list of SCIDs which this payment was previously attempted over and which caused the
1488 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1491 pub extern "C" fn PaymentParameters_set_previously_failed_channels(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_u64Z) {
1492 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1493 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previously_failed_channels = local_val;
1495 /// Constructs a new PaymentParameters given each field
1498 pub extern "C" fn PaymentParameters_new(mut payee_arg: crate::lightning::routing::router::Payee, mut expiry_time_arg: crate::c_types::derived::COption_u64Z, mut max_total_cltv_expiry_delta_arg: u32, mut max_path_count_arg: u8, mut max_channel_saturation_power_of_half_arg: u8, mut previously_failed_channels_arg: crate::c_types::derived::CVec_u64Z) -> PaymentParameters {
1499 let mut local_expiry_time_arg = if expiry_time_arg.is_some() { Some( { expiry_time_arg.take() }) } else { None };
1500 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 }); };
1501 PaymentParameters { inner: ObjOps::heap_alloc(nativePaymentParameters {
1502 payee: payee_arg.into_native(),
1503 expiry_time: local_expiry_time_arg,
1504 max_total_cltv_expiry_delta: max_total_cltv_expiry_delta_arg,
1505 max_path_count: max_path_count_arg,
1506 max_channel_saturation_power_of_half: max_channel_saturation_power_of_half_arg,
1507 previously_failed_channels: local_previously_failed_channels_arg,
1508 }), is_owned: true }
1510 impl Clone for PaymentParameters {
1511 fn clone(&self) -> Self {
1513 inner: if <*mut nativePaymentParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1514 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1520 /// Used only if an object of this type is returned as a trait impl by a method
1521 pub(crate) extern "C" fn PaymentParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1522 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentParameters)).clone() })) as *mut c_void
1525 /// Creates a copy of the PaymentParameters
1526 pub extern "C" fn PaymentParameters_clone(orig: &PaymentParameters) -> PaymentParameters {
1529 /// Generates a non-cryptographic 64-bit hash of the PaymentParameters.
1531 pub extern "C" fn PaymentParameters_hash(o: &PaymentParameters) -> u64 {
1532 if o.inner.is_null() { return 0; }
1533 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1534 #[allow(deprecated)]
1535 let mut hasher = core::hash::SipHasher::new();
1536 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1537 core::hash::Hasher::finish(&hasher)
1539 /// Checks if two PaymentParameterss contain equal inner contents.
1540 /// This ignores pointers and is_owned flags and looks at the values in fields.
1541 /// Two objects with NULL inner values will be considered "equal" here.
1543 pub extern "C" fn PaymentParameters_eq(a: &PaymentParameters, b: &PaymentParameters) -> bool {
1544 if a.inner == b.inner { return true; }
1545 if a.inner.is_null() || b.inner.is_null() { return false; }
1546 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1549 /// Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
1550 pub extern "C" fn PaymentParameters_write(obj: &crate::lightning::routing::router::PaymentParameters) -> crate::c_types::derived::CVec_u8Z {
1551 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1554 pub(crate) extern "C" fn PaymentParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1555 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentParameters) })
1558 /// Read a PaymentParameters from a byte array, created by PaymentParameters_write
1559 pub extern "C" fn PaymentParameters_read(ser: crate::c_types::u8slice, arg: u32) -> crate::c_types::derived::CResult_PaymentParametersDecodeErrorZ {
1561 let res: Result<lightning::routing::router::PaymentParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1562 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() };
1565 /// Creates a payee with the node id of the given `pubkey`.
1567 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1571 pub extern "C" fn PaymentParameters_from_node_id(mut payee_pubkey: crate::c_types::PublicKey, mut final_cltv_expiry_delta: u32) -> crate::lightning::routing::router::PaymentParameters {
1572 let mut ret = lightning::routing::router::PaymentParameters::from_node_id(payee_pubkey.into_rust(), final_cltv_expiry_delta);
1573 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1576 /// Creates a payee with the node id of the given `pubkey` to use for keysend payments.
1578 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1581 /// Note that MPP keysend is not widely supported yet. The `allow_mpp` lets you choose
1582 /// whether your router will be allowed to find a multi-part route for this payment. If you
1583 /// set `allow_mpp` to true, you should ensure a payment secret is set on send, likely via
1584 /// [`RecipientOnionFields::secret_only`].
1586 /// [`RecipientOnionFields::secret_only`]: crate::ln::channelmanager::RecipientOnionFields::secret_only
1589 pub extern "C" fn PaymentParameters_for_keysend(mut payee_pubkey: crate::c_types::PublicKey, mut final_cltv_expiry_delta: u32, mut allow_mpp: bool) -> crate::lightning::routing::router::PaymentParameters {
1590 let mut ret = lightning::routing::router::PaymentParameters::for_keysend(payee_pubkey.into_rust(), final_cltv_expiry_delta, allow_mpp);
1591 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1594 /// Creates parameters for paying to a blinded payee from the provided invoice. Sets
1595 /// [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and
1596 /// [`PaymentParameters::expiry_time`].
1599 pub extern "C" fn PaymentParameters_from_bolt12_invoice(invoice: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::routing::router::PaymentParameters {
1600 let mut ret = lightning::routing::router::PaymentParameters::from_bolt12_invoice(invoice.get_native_ref());
1601 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1604 /// Creates parameters for paying to a blinded payee from the provided blinded route hints.
1607 pub extern "C" fn PaymentParameters_blinded(mut blinded_route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ) -> crate::lightning::routing::router::PaymentParameters {
1608 let mut local_blinded_route_hints = Vec::new(); for mut item in blinded_route_hints.into_rust().drain(..) { local_blinded_route_hints.push( { let (mut orig_blinded_route_hints_0_0, mut orig_blinded_route_hints_0_1) = item.to_rust(); let mut local_blinded_route_hints_0 = (*unsafe { Box::from_raw(orig_blinded_route_hints_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_blinded_route_hints_0_1.take_inner()) }); local_blinded_route_hints_0 }); };
1609 let mut ret = lightning::routing::router::PaymentParameters::blinded(local_blinded_route_hints);
1610 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1613 /// The recipient of a payment, differing based on whether they've hidden their identity with route
1619 /// The recipient provided blinded paths and payinfo to reach them. The blinded paths themselves
1620 /// will be included in the final [`Route`].
1622 /// Aggregated routing info and blinded paths, for routing to the payee without knowing their
1624 route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ,
1625 /// Features supported by the payee.
1627 /// May be set from the payee's invoice. May be `None` if the invoice does not contain any
1630 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1631 features: crate::lightning::ln::features::Bolt12InvoiceFeatures,
1633 /// The recipient included these route hints in their BOLT11 invoice.
1635 /// The node id of the payee.
1636 node_id: crate::c_types::PublicKey,
1637 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
1638 route_hints: crate::c_types::derived::CVec_RouteHintZ,
1639 /// Features supported by the payee.
1641 /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
1642 /// does not contain any features.
1644 /// [`for_keysend`]: PaymentParameters::for_keysend
1646 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1647 features: crate::lightning::ln::features::Bolt11InvoiceFeatures,
1648 /// The minimum CLTV delta at the end of the route. This value must not be zero.
1649 final_cltv_expiry_delta: u32,
1652 use lightning::routing::router::Payee as PayeeImport;
1653 pub(crate) type nativePayee = PayeeImport;
1657 pub(crate) fn to_native(&self) -> nativePayee {
1659 Payee::Blinded {ref route_hints, ref features, } => {
1660 let mut route_hints_nonref = Clone::clone(route_hints);
1661 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.into_rust().drain(..) { local_route_hints_nonref.push( { let (mut orig_route_hints_nonref_0_0, mut orig_route_hints_nonref_0_1) = item.to_rust(); let mut local_route_hints_nonref_0 = (*unsafe { Box::from_raw(orig_route_hints_nonref_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_route_hints_nonref_0_1.take_inner()) }); local_route_hints_nonref_0 }); };
1662 let mut features_nonref = Clone::clone(features);
1663 let mut local_features_nonref = if features_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_nonref.take_inner()) } }) };
1664 nativePayee::Blinded {
1665 route_hints: local_route_hints_nonref,
1666 features: local_features_nonref,
1669 Payee::Clear {ref node_id, ref route_hints, ref features, ref final_cltv_expiry_delta, } => {
1670 let mut node_id_nonref = Clone::clone(node_id);
1671 let mut route_hints_nonref = Clone::clone(route_hints);
1672 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.into_rust().drain(..) { local_route_hints_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1673 let mut features_nonref = Clone::clone(features);
1674 let mut local_features_nonref = if features_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_nonref.take_inner()) } }) };
1675 let mut final_cltv_expiry_delta_nonref = Clone::clone(final_cltv_expiry_delta);
1676 nativePayee::Clear {
1677 node_id: node_id_nonref.into_rust(),
1678 route_hints: local_route_hints_nonref,
1679 features: local_features_nonref,
1680 final_cltv_expiry_delta: final_cltv_expiry_delta_nonref,
1686 pub(crate) fn into_native(self) -> nativePayee {
1688 Payee::Blinded {mut route_hints, mut features, } => {
1689 let mut local_route_hints = Vec::new(); for mut item in route_hints.into_rust().drain(..) { local_route_hints.push( { let (mut orig_route_hints_0_0, mut orig_route_hints_0_1) = item.to_rust(); let mut local_route_hints_0 = (*unsafe { Box::from_raw(orig_route_hints_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_route_hints_0_1.take_inner()) }); local_route_hints_0 }); };
1690 let mut local_features = if features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features.take_inner()) } }) };
1691 nativePayee::Blinded {
1692 route_hints: local_route_hints,
1693 features: local_features,
1696 Payee::Clear {mut node_id, mut route_hints, mut features, mut final_cltv_expiry_delta, } => {
1697 let mut local_route_hints = Vec::new(); for mut item in route_hints.into_rust().drain(..) { local_route_hints.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1698 let mut local_features = if features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features.take_inner()) } }) };
1699 nativePayee::Clear {
1700 node_id: node_id.into_rust(),
1701 route_hints: local_route_hints,
1702 features: local_features,
1703 final_cltv_expiry_delta: final_cltv_expiry_delta,
1709 pub(crate) fn from_native(native: &nativePayee) -> Self {
1711 nativePayee::Blinded {ref route_hints, ref features, } => {
1712 let mut route_hints_nonref = Clone::clone(route_hints);
1713 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.drain(..) { local_route_hints_nonref.push( { let (mut orig_route_hints_nonref_0_0, mut orig_route_hints_nonref_0_1) = item; let mut local_route_hints_nonref_0 = (crate::lightning::offers::invoice::BlindedPayInfo { inner: ObjOps::heap_alloc(orig_route_hints_nonref_0_0), is_owned: true }, crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(orig_route_hints_nonref_0_1), is_owned: true }).into(); local_route_hints_nonref_0 }); };
1714 let mut features_nonref = Clone::clone(features);
1715 let mut local_features_nonref = crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: if features_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features_nonref.unwrap())) } }, is_owned: true };
1717 route_hints: local_route_hints_nonref.into(),
1718 features: local_features_nonref,
1721 nativePayee::Clear {ref node_id, ref route_hints, ref features, ref final_cltv_expiry_delta, } => {
1722 let mut node_id_nonref = Clone::clone(node_id);
1723 let mut route_hints_nonref = Clone::clone(route_hints);
1724 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.drain(..) { local_route_hints_nonref.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1725 let mut features_nonref = Clone::clone(features);
1726 let mut local_features_nonref = crate::lightning::ln::features::Bolt11InvoiceFeatures { inner: if features_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features_nonref.unwrap())) } }, is_owned: true };
1727 let mut final_cltv_expiry_delta_nonref = Clone::clone(final_cltv_expiry_delta);
1729 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1730 route_hints: local_route_hints_nonref.into(),
1731 features: local_features_nonref,
1732 final_cltv_expiry_delta: final_cltv_expiry_delta_nonref,
1738 pub(crate) fn native_into(native: nativePayee) -> Self {
1740 nativePayee::Blinded {mut route_hints, mut features, } => {
1741 let mut local_route_hints = Vec::new(); for mut item in route_hints.drain(..) { local_route_hints.push( { let (mut orig_route_hints_0_0, mut orig_route_hints_0_1) = item; let mut local_route_hints_0 = (crate::lightning::offers::invoice::BlindedPayInfo { inner: ObjOps::heap_alloc(orig_route_hints_0_0), is_owned: true }, crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(orig_route_hints_0_1), is_owned: true }).into(); local_route_hints_0 }); };
1742 let mut local_features = crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: if features.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features.unwrap())) } }, is_owned: true };
1744 route_hints: local_route_hints.into(),
1745 features: local_features,
1748 nativePayee::Clear {mut node_id, mut route_hints, mut features, mut final_cltv_expiry_delta, } => {
1749 let mut local_route_hints = Vec::new(); for mut item in route_hints.drain(..) { local_route_hints.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1750 let mut local_features = crate::lightning::ln::features::Bolt11InvoiceFeatures { inner: if features.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features.unwrap())) } }, is_owned: true };
1752 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1753 route_hints: local_route_hints.into(),
1754 features: local_features,
1755 final_cltv_expiry_delta: final_cltv_expiry_delta,
1761 /// Frees any resources used by the Payee
1763 pub extern "C" fn Payee_free(this_ptr: Payee) { }
1764 /// Creates a copy of the Payee
1766 pub extern "C" fn Payee_clone(orig: &Payee) -> Payee {
1770 /// Utility method to constructs a new Blinded-variant Payee
1771 pub extern "C" fn Payee_blinded(route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ, features: crate::lightning::ln::features::Bolt12InvoiceFeatures) -> Payee {
1778 /// Utility method to constructs a new Clear-variant Payee
1779 pub extern "C" fn Payee_clear(node_id: crate::c_types::PublicKey, route_hints: crate::c_types::derived::CVec_RouteHintZ, features: crate::lightning::ln::features::Bolt11InvoiceFeatures, final_cltv_expiry_delta: u32) -> Payee {
1784 final_cltv_expiry_delta,
1787 /// Generates a non-cryptographic 64-bit hash of the Payee.
1789 pub extern "C" fn Payee_hash(o: &Payee) -> u64 {
1790 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1791 #[allow(deprecated)]
1792 let mut hasher = core::hash::SipHasher::new();
1793 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1794 core::hash::Hasher::finish(&hasher)
1796 /// Checks if two Payees contain equal inner contents.
1797 /// This ignores pointers and is_owned flags and looks at the values in fields.
1799 pub extern "C" fn Payee_eq(a: &Payee, b: &Payee) -> bool {
1800 if &a.to_native() == &b.to_native() { true } else { false }
1803 use lightning::routing::router::RouteHint as nativeRouteHintImport;
1804 pub(crate) type nativeRouteHint = nativeRouteHintImport;
1806 /// A list of hops along a payment path terminating with a channel to the recipient.
1809 pub struct RouteHint {
1810 /// A pointer to the opaque Rust object.
1812 /// Nearly everywhere, inner must be non-null, however in places where
1813 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1814 pub inner: *mut nativeRouteHint,
1815 /// Indicates that this is the only struct which contains the same pointer.
1817 /// Rust functions which take ownership of an object provided via an argument require
1818 /// this to be true and invalidate the object pointed to by inner.
1822 impl Drop for RouteHint {
1823 fn drop(&mut self) {
1824 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
1825 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1829 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
1831 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
1833 /// Used only if an object of this type is returned as a trait impl by a method
1834 pub(crate) extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
1835 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHint) };
1839 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHint {
1840 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1842 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHint {
1843 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1845 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1846 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
1847 assert!(self.is_owned);
1848 let ret = ObjOps::untweak_ptr(self.inner);
1849 self.inner = core::ptr::null_mut();
1854 pub extern "C" fn RouteHint_get_a(this_ptr: &RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ {
1855 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1856 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 } }); };
1857 local_inner_val.into()
1860 pub extern "C" fn RouteHint_set_a(this_ptr: &mut RouteHint, mut val: crate::c_types::derived::CVec_RouteHintHopZ) {
1861 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1862 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = local_val;
1864 /// Constructs a new RouteHint given each field
1867 pub extern "C" fn RouteHint_new(mut a_arg: crate::c_types::derived::CVec_RouteHintHopZ) -> RouteHint {
1868 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()) } }); };
1869 RouteHint { inner: ObjOps::heap_alloc(lightning::routing::router::RouteHint (
1871 )), is_owned: true }
1873 impl Clone for RouteHint {
1874 fn clone(&self) -> Self {
1876 inner: if <*mut nativeRouteHint>::is_null(self.inner) { core::ptr::null_mut() } else {
1877 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1883 /// Used only if an object of this type is returned as a trait impl by a method
1884 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
1885 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void
1888 /// Creates a copy of the RouteHint
1889 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
1892 /// Generates a non-cryptographic 64-bit hash of the RouteHint.
1894 pub extern "C" fn RouteHint_hash(o: &RouteHint) -> u64 {
1895 if o.inner.is_null() { return 0; }
1896 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1897 #[allow(deprecated)]
1898 let mut hasher = core::hash::SipHasher::new();
1899 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1900 core::hash::Hasher::finish(&hasher)
1902 /// Checks if two RouteHints contain equal inner contents.
1903 /// This ignores pointers and is_owned flags and looks at the values in fields.
1904 /// Two objects with NULL inner values will be considered "equal" here.
1906 pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool {
1907 if a.inner == b.inner { return true; }
1908 if a.inner.is_null() || b.inner.is_null() { return false; }
1909 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1912 /// Serialize the RouteHint object into a byte array which can be read by RouteHint_read
1913 pub extern "C" fn RouteHint_write(obj: &crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CVec_u8Z {
1914 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1917 pub(crate) extern "C" fn RouteHint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1918 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHint) })
1921 /// Read a RouteHint from a byte array, created by RouteHint_write
1922 pub extern "C" fn RouteHint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintDecodeErrorZ {
1923 let res: Result<lightning::routing::router::RouteHint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1924 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() };
1928 use lightning::routing::router::RouteHintHop as nativeRouteHintHopImport;
1929 pub(crate) type nativeRouteHintHop = nativeRouteHintHopImport;
1931 /// A channel descriptor for a hop along a payment path.
1934 pub struct RouteHintHop {
1935 /// A pointer to the opaque Rust object.
1937 /// Nearly everywhere, inner must be non-null, however in places where
1938 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1939 pub inner: *mut nativeRouteHintHop,
1940 /// Indicates that this is the only struct which contains the same pointer.
1942 /// Rust functions which take ownership of an object provided via an argument require
1943 /// this to be true and invalidate the object pointed to by inner.
1947 impl Drop for RouteHintHop {
1948 fn drop(&mut self) {
1949 if self.is_owned && !<*mut nativeRouteHintHop>::is_null(self.inner) {
1950 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1954 /// Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL.
1956 pub extern "C" fn RouteHintHop_free(this_obj: RouteHintHop) { }
1958 /// Used only if an object of this type is returned as a trait impl by a method
1959 pub(crate) extern "C" fn RouteHintHop_free_void(this_ptr: *mut c_void) {
1960 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHintHop) };
1964 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHintHop {
1965 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1967 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHintHop {
1968 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1970 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1971 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHintHop {
1972 assert!(self.is_owned);
1973 let ret = ObjOps::untweak_ptr(self.inner);
1974 self.inner = core::ptr::null_mut();
1978 /// The node_id of the non-target end of the route
1980 pub extern "C" fn RouteHintHop_get_src_node_id(this_ptr: &RouteHintHop) -> crate::c_types::PublicKey {
1981 let mut inner_val = &mut this_ptr.get_native_mut_ref().src_node_id;
1982 crate::c_types::PublicKey::from_rust(&inner_val)
1984 /// The node_id of the non-target end of the route
1986 pub extern "C" fn RouteHintHop_set_src_node_id(this_ptr: &mut RouteHintHop, mut val: crate::c_types::PublicKey) {
1987 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.src_node_id = val.into_rust();
1989 /// The short_channel_id of this channel
1991 pub extern "C" fn RouteHintHop_get_short_channel_id(this_ptr: &RouteHintHop) -> u64 {
1992 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
1995 /// The short_channel_id of this channel
1997 pub extern "C" fn RouteHintHop_set_short_channel_id(this_ptr: &mut RouteHintHop, mut val: u64) {
1998 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
2000 /// The fees which must be paid to use this channel
2002 pub extern "C" fn RouteHintHop_get_fees(this_ptr: &RouteHintHop) -> crate::lightning::routing::gossip::RoutingFees {
2003 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
2004 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 }
2006 /// The fees which must be paid to use this channel
2008 pub extern "C" fn RouteHintHop_set_fees(this_ptr: &mut RouteHintHop, mut val: crate::lightning::routing::gossip::RoutingFees) {
2009 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
2011 /// The difference in CLTV values between this node and the next node.
2013 pub extern "C" fn RouteHintHop_get_cltv_expiry_delta(this_ptr: &RouteHintHop) -> u16 {
2014 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
2017 /// The difference in CLTV values between this node and the next node.
2019 pub extern "C" fn RouteHintHop_set_cltv_expiry_delta(this_ptr: &mut RouteHintHop, mut val: u16) {
2020 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
2022 /// The minimum value, in msat, which must be relayed to the next hop.
2024 pub extern "C" fn RouteHintHop_get_htlc_minimum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
2025 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
2026 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() }) };
2029 /// The minimum value, in msat, which must be relayed to the next hop.
2031 pub extern "C" fn RouteHintHop_set_htlc_minimum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
2032 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2033 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = local_val;
2035 /// The maximum value in msat available for routing with a single HTLC.
2037 pub extern "C" fn RouteHintHop_get_htlc_maximum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
2038 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
2039 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() }) };
2042 /// The maximum value in msat available for routing with a single HTLC.
2044 pub extern "C" fn RouteHintHop_set_htlc_maximum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
2045 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2046 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
2048 /// Constructs a new RouteHintHop given each field
2051 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 {
2052 let mut local_htlc_minimum_msat_arg = if htlc_minimum_msat_arg.is_some() { Some( { htlc_minimum_msat_arg.take() }) } else { None };
2053 let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
2054 RouteHintHop { inner: ObjOps::heap_alloc(nativeRouteHintHop {
2055 src_node_id: src_node_id_arg.into_rust(),
2056 short_channel_id: short_channel_id_arg,
2057 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
2058 cltv_expiry_delta: cltv_expiry_delta_arg,
2059 htlc_minimum_msat: local_htlc_minimum_msat_arg,
2060 htlc_maximum_msat: local_htlc_maximum_msat_arg,
2061 }), is_owned: true }
2063 impl Clone for RouteHintHop {
2064 fn clone(&self) -> Self {
2066 inner: if <*mut nativeRouteHintHop>::is_null(self.inner) { core::ptr::null_mut() } else {
2067 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2073 /// Used only if an object of this type is returned as a trait impl by a method
2074 pub(crate) extern "C" fn RouteHintHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
2075 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHintHop)).clone() })) as *mut c_void
2078 /// Creates a copy of the RouteHintHop
2079 pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop {
2082 /// Generates a non-cryptographic 64-bit hash of the RouteHintHop.
2084 pub extern "C" fn RouteHintHop_hash(o: &RouteHintHop) -> u64 {
2085 if o.inner.is_null() { return 0; }
2086 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2087 #[allow(deprecated)]
2088 let mut hasher = core::hash::SipHasher::new();
2089 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2090 core::hash::Hasher::finish(&hasher)
2092 /// Checks if two RouteHintHops contain equal inner contents.
2093 /// This ignores pointers and is_owned flags and looks at the values in fields.
2094 /// Two objects with NULL inner values will be considered "equal" here.
2096 pub extern "C" fn RouteHintHop_eq(a: &RouteHintHop, b: &RouteHintHop) -> bool {
2097 if a.inner == b.inner { return true; }
2098 if a.inner.is_null() || b.inner.is_null() { return false; }
2099 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2102 /// Serialize the RouteHintHop object into a byte array which can be read by RouteHintHop_read
2103 pub extern "C" fn RouteHintHop_write(obj: &crate::lightning::routing::router::RouteHintHop) -> crate::c_types::derived::CVec_u8Z {
2104 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2107 pub(crate) extern "C" fn RouteHintHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2108 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHintHop) })
2111 /// Read a RouteHintHop from a byte array, created by RouteHintHop_write
2112 pub extern "C" fn RouteHintHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintHopDecodeErrorZ {
2113 let res: Result<lightning::routing::router::RouteHintHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2114 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() };
2117 /// Finds a route from us (payer) to the given target node (payee).
2119 /// If the payee provided features in their invoice, they should be provided via the `payee` field
2120 /// in the given [`RouteParameters::payment_params`].
2121 /// Without this, MPP will only be used if the payee's features are available in the network graph.
2123 /// Private routing paths between a public node and the target may be included in the `payee` field
2124 /// of [`RouteParameters::payment_params`].
2126 /// If some channels aren't announced, it may be useful to fill in `first_hops` with the results
2127 /// from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
2128 /// from `network_graph` will be ignored, and only those in `first_hops` will be used.
2130 /// The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
2131 /// However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
2132 /// `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
2136 /// Panics if first_hops contains channels without `short_channel_id`s;
2137 /// [`ChannelManager::list_usable_channels`] will never include such channels.
2139 /// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
2140 /// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
2141 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
2143 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
2145 pub extern "C" fn find_route(mut our_node_pubkey: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, network_graph: &crate::lightning::routing::gossip::NetworkGraph, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut logger: crate::lightning::util::logger::Logger, scorer: &crate::lightning::routing::scoring::ScoreLookUp, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
2146 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[..]);
2147 let mut ret = lightning::routing::router::find_route::<crate::lightning::util::logger::Logger, crate::lightning::util::logger::Logger, crate::lightning::routing::scoring::ScoreLookUp>(&our_node_pubkey.into_rust(), route_params.get_native_ref(), network_graph.get_native_ref(), local_first_hops, logger, scorer, score_params.get_native_ref(), unsafe { &*random_seed_bytes});
2148 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() };
2152 /// Construct a route from us (payer) to the target node (payee) via the given hops (which should
2153 /// exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
2155 /// Re-uses logic from `find_route`, so the restrictions described there also apply here.
2157 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 {
2158 let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { item.into_rust() }); };
2159 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});
2160 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() };