1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! The router finds paths within a [`NetworkGraph`] for a payment.
11 use alloc::str::FromStr;
12 use core::ffi::c_void;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
16 #[cfg(feature="no-std")]
17 use alloc::{vec::Vec, boxed::Box};
20 use lightning::routing::router::DefaultRouter as nativeDefaultRouterImport;
21 pub(crate) type nativeDefaultRouter = nativeDefaultRouterImport<&'static lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, crate::lightning::util::logger::Logger, crate::lightning::routing::scoring::LockableScore>;
23 /// A [`Router`] implemented using [`find_route`].
26 pub struct DefaultRouter {
27 /// A pointer to the opaque Rust object.
29 /// Nearly everywhere, inner must be non-null, however in places where
30 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
31 pub inner: *mut nativeDefaultRouter,
32 /// Indicates that this is the only struct which contains the same pointer.
34 /// Rust functions which take ownership of an object provided via an argument require
35 /// this to be true and invalidate the object pointed to by inner.
39 impl Drop for DefaultRouter {
41 if self.is_owned && !<*mut nativeDefaultRouter>::is_null(self.inner) {
42 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
46 /// Frees any resources used by the DefaultRouter, if is_owned is set and inner is non-NULL.
48 pub extern "C" fn DefaultRouter_free(this_obj: DefaultRouter) { }
50 /// Used only if an object of this type is returned as a trait impl by a method
51 pub(crate) extern "C" fn DefaultRouter_free_void(this_ptr: *mut c_void) {
52 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDefaultRouter) };
56 pub(crate) fn get_native_ref(&self) -> &'static nativeDefaultRouter {
57 unsafe { &*ObjOps::untweak_ptr(self.inner) }
59 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDefaultRouter {
60 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
62 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
63 pub(crate) fn take_inner(mut self) -> *mut nativeDefaultRouter {
64 assert!(self.is_owned);
65 let ret = ObjOps::untweak_ptr(self.inner);
66 self.inner = core::ptr::null_mut();
70 /// Creates a new router.
73 pub extern "C" fn DefaultRouter_new(network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut logger: crate::lightning::util::logger::Logger, mut random_seed_bytes: crate::c_types::ThirtyTwoBytes, mut scorer: crate::lightning::routing::scoring::LockableScore) -> crate::lightning::routing::router::DefaultRouter {
74 let mut ret = lightning::routing::router::DefaultRouter::new(network_graph.get_native_ref(), logger, random_seed_bytes.data, scorer);
75 crate::lightning::routing::router::DefaultRouter { inner: ObjOps::heap_alloc(ret), is_owned: true }
78 impl From<nativeDefaultRouter> for crate::lightning::routing::router::Router {
79 fn from(obj: nativeDefaultRouter) -> Self {
80 let mut rust_obj = DefaultRouter { inner: ObjOps::heap_alloc(obj), is_owned: true };
81 let mut ret = DefaultRouter_as_Router(&rust_obj);
82 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
83 rust_obj.inner = core::ptr::null_mut();
84 ret.free = Some(DefaultRouter_free_void);
88 /// Constructs a new Router which calls the relevant methods on this_arg.
89 /// This copies the `inner` pointer in this_arg and thus the returned Router must be freed before this_arg is
91 pub extern "C" fn DefaultRouter_as_Router(this_arg: &DefaultRouter) -> crate::lightning::routing::router::Router {
92 crate::lightning::routing::router::Router {
93 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
95 find_route: DefaultRouter_Router_find_route,
96 find_route_with_id: DefaultRouter_Router_find_route_with_id,
101 extern "C" fn DefaultRouter_Router_find_route(this_arg: *const c_void, mut payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, inflight_htlcs: &crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
102 let mut local_first_hops_base = if first_hops == core::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { item.get_native_ref() }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]);
103 let mut ret = <nativeDefaultRouter as lightning::routing::router::Router<>>::find_route(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &payer.into_rust(), route_params.get_native_ref(), local_first_hops, inflight_htlcs.get_native_ref());
104 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
108 extern "C" fn DefaultRouter_Router_find_route_with_id(this_arg: *const c_void, mut payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, inflight_htlcs: &crate::lightning::routing::router::InFlightHtlcs, mut _payment_hash: crate::c_types::ThirtyTwoBytes, mut _payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
109 let mut local_first_hops_base = if first_hops == core::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { item.get_native_ref() }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]);
110 let mut ret = <nativeDefaultRouter as lightning::routing::router::Router<>>::find_route_with_id(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &payer.into_rust(), route_params.get_native_ref(), local_first_hops, inflight_htlcs.get_native_ref(), ::lightning::ln::PaymentHash(_payment_hash.data), ::lightning::ln::channelmanager::PaymentId(_payment_id.data));
111 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
115 /// A trait defining behavior for routing a payment.
118 /// An opaque pointer which is passed to your function implementations as an argument.
119 /// This has no meaning in the LDK, and can be NULL or any other value.
120 pub this_arg: *mut c_void,
121 /// Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
123 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
125 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,
126 /// Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
127 /// `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
129 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
131 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,
132 /// Frees any resources associated with this object given its this_arg pointer.
133 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
134 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
136 unsafe impl Send for Router {}
137 unsafe impl Sync for Router {}
139 pub(crate) extern "C" fn Router_clone_fields(orig: &Router) -> Router {
141 this_arg: orig.this_arg,
142 find_route: Clone::clone(&orig.find_route),
143 find_route_with_id: Clone::clone(&orig.find_route_with_id),
144 free: Clone::clone(&orig.free),
148 use lightning::routing::router::Router as rustRouter;
149 impl rustRouter for Router {
150 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> {
151 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;
152 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: unsafe { ObjOps::nonnull_ptr_to_inner((inflight_htlcs as *const lightning::routing::router::InFlightHtlcs<>) as *mut _) }, is_owned: false });
153 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()) } })};
156 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> {
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_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: unsafe { ObjOps::nonnull_ptr_to_inner((inflight_htlcs as *const lightning::routing::router::InFlightHtlcs<>) as *mut _) }, is_owned: false }, crate::c_types::ThirtyTwoBytes { data: _payment_hash.0 }, crate::c_types::ThirtyTwoBytes { data: _payment_id.0 });
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()) } })};
164 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
165 // directly as a Deref trait in higher-level structs:
166 impl core::ops::Deref for Router {
168 fn deref(&self) -> &Self {
172 /// Calls the free function if one is set
174 pub extern "C" fn Router_free(this_ptr: Router) { }
175 impl Drop for Router {
177 if let Some(f) = self.free {
183 use lightning::routing::router::ScorerAccountingForInFlightHtlcs as nativeScorerAccountingForInFlightHtlcsImport;
184 pub(crate) type nativeScorerAccountingForInFlightHtlcs = nativeScorerAccountingForInFlightHtlcsImport<'static, crate::lightning::routing::scoring::Score>;
186 /// [`Score`] implementation that factors in in-flight HTLC liquidity.
188 /// Useful for custom [`Router`] implementations to wrap their [`Score`] on-the-fly when calling
191 /// [`Score`]: crate::routing::scoring::Score
194 pub struct ScorerAccountingForInFlightHtlcs {
195 /// A pointer to the opaque Rust object.
197 /// Nearly everywhere, inner must be non-null, however in places where
198 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
199 pub inner: *mut nativeScorerAccountingForInFlightHtlcs,
200 /// Indicates that this is the only struct which contains the same pointer.
202 /// Rust functions which take ownership of an object provided via an argument require
203 /// this to be true and invalidate the object pointed to by inner.
207 impl Drop for ScorerAccountingForInFlightHtlcs {
209 if self.is_owned && !<*mut nativeScorerAccountingForInFlightHtlcs>::is_null(self.inner) {
210 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
214 /// Frees any resources used by the ScorerAccountingForInFlightHtlcs, if is_owned is set and inner is non-NULL.
216 pub extern "C" fn ScorerAccountingForInFlightHtlcs_free(this_obj: ScorerAccountingForInFlightHtlcs) { }
218 /// Used only if an object of this type is returned as a trait impl by a method
219 pub(crate) extern "C" fn ScorerAccountingForInFlightHtlcs_free_void(this_ptr: *mut c_void) {
220 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeScorerAccountingForInFlightHtlcs) };
223 impl ScorerAccountingForInFlightHtlcs {
224 pub(crate) fn get_native_ref(&self) -> &'static nativeScorerAccountingForInFlightHtlcs {
225 unsafe { &*ObjOps::untweak_ptr(self.inner) }
227 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeScorerAccountingForInFlightHtlcs {
228 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
230 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
231 pub(crate) fn take_inner(mut self) -> *mut nativeScorerAccountingForInFlightHtlcs {
232 assert!(self.is_owned);
233 let ret = ObjOps::untweak_ptr(self.inner);
234 self.inner = core::ptr::null_mut();
238 /// Initialize a new `ScorerAccountingForInFlightHtlcs`.
241 pub extern "C" fn ScorerAccountingForInFlightHtlcs_new(mut scorer: crate::lightning::routing::scoring::Score, inflight_htlcs: &crate::lightning::routing::router::InFlightHtlcs) -> crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs {
242 let mut ret = lightning::routing::router::ScorerAccountingForInFlightHtlcs::new(scorer, inflight_htlcs.get_native_ref());
243 crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
247 /// Serialize the ScorerAccountingForInFlightHtlcs object into a byte array which can be read by ScorerAccountingForInFlightHtlcs_read
248 pub extern "C" fn ScorerAccountingForInFlightHtlcs_write(obj: &crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs) -> crate::c_types::derived::CVec_u8Z {
249 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
252 pub(crate) extern "C" fn ScorerAccountingForInFlightHtlcs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
253 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeScorerAccountingForInFlightHtlcs) })
255 impl From<nativeScorerAccountingForInFlightHtlcs> for crate::lightning::routing::scoring::Score {
256 fn from(obj: nativeScorerAccountingForInFlightHtlcs) -> Self {
257 let mut rust_obj = ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(obj), is_owned: true };
258 let mut ret = ScorerAccountingForInFlightHtlcs_as_Score(&rust_obj);
259 // 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
260 rust_obj.inner = core::ptr::null_mut();
261 ret.free = Some(ScorerAccountingForInFlightHtlcs_free_void);
265 /// Constructs a new Score which calls the relevant methods on this_arg.
266 /// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
268 pub extern "C" fn ScorerAccountingForInFlightHtlcs_as_Score(this_arg: &ScorerAccountingForInFlightHtlcs) -> crate::lightning::routing::scoring::Score {
269 crate::lightning::routing::scoring::Score {
270 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
272 channel_penalty_msat: ScorerAccountingForInFlightHtlcs_Score_channel_penalty_msat,
273 payment_path_failed: ScorerAccountingForInFlightHtlcs_Score_payment_path_failed,
274 payment_path_successful: ScorerAccountingForInFlightHtlcs_Score_payment_path_successful,
275 probe_failed: ScorerAccountingForInFlightHtlcs_Score_probe_failed,
276 probe_successful: ScorerAccountingForInFlightHtlcs_Score_probe_successful,
277 write: ScorerAccountingForInFlightHtlcs_write_void,
282 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut usage: crate::lightning::routing::scoring::ChannelUsage) -> u64 {
283 let mut ret = <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, short_channel_id, source.get_native_ref(), target.get_native_ref(), *unsafe { Box::from_raw(usage.take_inner()) });
286 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_payment_path_failed(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path, mut short_channel_id: u64) {
287 <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, path.get_native_ref(), short_channel_id)
289 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_payment_path_successful(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path) {
290 <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, path.get_native_ref())
292 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_probe_failed(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path, mut short_channel_id: u64) {
293 <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::probe_failed(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, path.get_native_ref(), short_channel_id)
295 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_probe_successful(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path) {
296 <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::probe_successful(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, path.get_native_ref())
300 use lightning::routing::router::InFlightHtlcs as nativeInFlightHtlcsImport;
301 pub(crate) type nativeInFlightHtlcs = nativeInFlightHtlcsImport;
303 /// A data structure for tracking in-flight HTLCs. May be used during pathfinding to account for
304 /// in-use channel liquidity.
307 pub struct InFlightHtlcs {
308 /// A pointer to the opaque Rust object.
310 /// Nearly everywhere, inner must be non-null, however in places where
311 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
312 pub inner: *mut nativeInFlightHtlcs,
313 /// Indicates that this is the only struct which contains the same pointer.
315 /// Rust functions which take ownership of an object provided via an argument require
316 /// this to be true and invalidate the object pointed to by inner.
320 impl Drop for InFlightHtlcs {
322 if self.is_owned && !<*mut nativeInFlightHtlcs>::is_null(self.inner) {
323 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
327 /// Frees any resources used by the InFlightHtlcs, if is_owned is set and inner is non-NULL.
329 pub extern "C" fn InFlightHtlcs_free(this_obj: InFlightHtlcs) { }
331 /// Used only if an object of this type is returned as a trait impl by a method
332 pub(crate) extern "C" fn InFlightHtlcs_free_void(this_ptr: *mut c_void) {
333 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInFlightHtlcs) };
337 pub(crate) fn get_native_ref(&self) -> &'static nativeInFlightHtlcs {
338 unsafe { &*ObjOps::untweak_ptr(self.inner) }
340 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInFlightHtlcs {
341 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
343 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
344 pub(crate) fn take_inner(mut self) -> *mut nativeInFlightHtlcs {
345 assert!(self.is_owned);
346 let ret = ObjOps::untweak_ptr(self.inner);
347 self.inner = core::ptr::null_mut();
351 impl Clone for InFlightHtlcs {
352 fn clone(&self) -> Self {
354 inner: if <*mut nativeInFlightHtlcs>::is_null(self.inner) { core::ptr::null_mut() } else {
355 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
361 /// Used only if an object of this type is returned as a trait impl by a method
362 pub(crate) extern "C" fn InFlightHtlcs_clone_void(this_ptr: *const c_void) -> *mut c_void {
363 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInFlightHtlcs)).clone() })) as *mut c_void
366 /// Creates a copy of the InFlightHtlcs
367 pub extern "C" fn InFlightHtlcs_clone(orig: &InFlightHtlcs) -> InFlightHtlcs {
370 /// Constructs an empty `InFlightHtlcs`.
373 pub extern "C" fn InFlightHtlcs_new() -> crate::lightning::routing::router::InFlightHtlcs {
374 let mut ret = lightning::routing::router::InFlightHtlcs::new();
375 crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
378 /// Takes in a path with payer's node id and adds the path's details to `InFlightHtlcs`.
380 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) {
381 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())
384 /// Returns liquidity in msat given the public key of the HTLC source, target, and short channel
388 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 {
389 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.used_liquidity_msat(source.get_native_ref(), target.get_native_ref(), channel_scid);
390 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() }) };
395 /// Serialize the InFlightHtlcs object into a byte array which can be read by InFlightHtlcs_read
396 pub extern "C" fn InFlightHtlcs_write(obj: &crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CVec_u8Z {
397 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
400 pub(crate) extern "C" fn InFlightHtlcs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
401 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInFlightHtlcs) })
404 /// Read a InFlightHtlcs from a byte array, created by InFlightHtlcs_write
405 pub extern "C" fn InFlightHtlcs_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InFlightHtlcsDecodeErrorZ {
406 let res: Result<lightning::routing::router::InFlightHtlcs, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
407 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() };
411 use lightning::routing::router::RouteHop as nativeRouteHopImport;
412 pub(crate) type nativeRouteHop = nativeRouteHopImport;
414 /// A hop in a route, and additional metadata about it. \"Hop\" is defined as a node and the channel
415 /// that leads to it.
418 pub struct RouteHop {
419 /// A pointer to the opaque Rust object.
421 /// Nearly everywhere, inner must be non-null, however in places where
422 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
423 pub inner: *mut nativeRouteHop,
424 /// Indicates that this is the only struct which contains the same pointer.
426 /// Rust functions which take ownership of an object provided via an argument require
427 /// this to be true and invalidate the object pointed to by inner.
431 impl Drop for RouteHop {
433 if self.is_owned && !<*mut nativeRouteHop>::is_null(self.inner) {
434 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
438 /// Frees any resources used by the RouteHop, if is_owned is set and inner is non-NULL.
440 pub extern "C" fn RouteHop_free(this_obj: RouteHop) { }
442 /// Used only if an object of this type is returned as a trait impl by a method
443 pub(crate) extern "C" fn RouteHop_free_void(this_ptr: *mut c_void) {
444 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHop) };
448 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHop {
449 unsafe { &*ObjOps::untweak_ptr(self.inner) }
451 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHop {
452 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
454 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
455 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHop {
456 assert!(self.is_owned);
457 let ret = ObjOps::untweak_ptr(self.inner);
458 self.inner = core::ptr::null_mut();
462 /// The node_id of the node at this hop.
464 pub extern "C" fn RouteHop_get_pubkey(this_ptr: &RouteHop) -> crate::c_types::PublicKey {
465 let mut inner_val = &mut this_ptr.get_native_mut_ref().pubkey;
466 crate::c_types::PublicKey::from_rust(&inner_val)
468 /// The node_id of the node at this hop.
470 pub extern "C" fn RouteHop_set_pubkey(this_ptr: &mut RouteHop, mut val: crate::c_types::PublicKey) {
471 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.pubkey = val.into_rust();
473 /// The node_announcement features of the node at this hop. For the last hop, these may be
474 /// amended to match the features present in the invoice this node generated.
476 pub extern "C" fn RouteHop_get_node_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::NodeFeatures {
477 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_features;
478 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 }
480 /// The node_announcement features of the node at this hop. For the last hop, these may be
481 /// amended to match the features present in the invoice this node generated.
483 pub extern "C" fn RouteHop_set_node_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::NodeFeatures) {
484 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_features = *unsafe { Box::from_raw(val.take_inner()) };
486 /// The channel that should be used from the previous hop to reach this node.
488 pub extern "C" fn RouteHop_get_short_channel_id(this_ptr: &RouteHop) -> u64 {
489 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
492 /// The channel that should be used from the previous hop to reach this node.
494 pub extern "C" fn RouteHop_set_short_channel_id(this_ptr: &mut RouteHop, mut val: u64) {
495 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
497 /// The channel_announcement features of the channel that should be used from the previous hop
498 /// to reach this node.
500 pub extern "C" fn RouteHop_get_channel_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::ChannelFeatures {
501 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_features;
502 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 }
504 /// The channel_announcement features of the channel that should be used from the previous hop
505 /// to reach this node.
507 pub extern "C" fn RouteHop_set_channel_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::ChannelFeatures) {
508 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_features = *unsafe { Box::from_raw(val.take_inner()) };
510 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
511 /// If this is the last hop in [`Path::hops`]:
512 /// * if we're sending to a [`BlindedPath`], this is the fee paid for use of the entire blinded path
513 /// * otherwise, this is the full value of this [`Path`]'s part of the payment
515 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
517 pub extern "C" fn RouteHop_get_fee_msat(this_ptr: &RouteHop) -> u64 {
518 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_msat;
521 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
522 /// If this is the last hop in [`Path::hops`]:
523 /// * if we're sending to a [`BlindedPath`], this is the fee paid for use of the entire blinded path
524 /// * otherwise, this is the full value of this [`Path`]'s part of the payment
526 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
528 pub extern "C" fn RouteHop_set_fee_msat(this_ptr: &mut RouteHop, mut val: u64) {
529 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_msat = val;
531 /// The CLTV delta added for this hop.
532 /// If this is the last hop in [`Path::hops`]:
533 /// * if we're sending to a [`BlindedPath`], this is the CLTV delta for the entire blinded path
534 /// * otherwise, this is the CLTV delta expected at the destination
536 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
538 pub extern "C" fn RouteHop_get_cltv_expiry_delta(this_ptr: &RouteHop) -> u32 {
539 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
542 /// The CLTV delta added for this hop.
543 /// If this is the last hop in [`Path::hops`]:
544 /// * if we're sending to a [`BlindedPath`], this is the CLTV delta for the entire blinded path
545 /// * otherwise, this is the CLTV delta expected at the destination
547 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
549 pub extern "C" fn RouteHop_set_cltv_expiry_delta(this_ptr: &mut RouteHop, mut val: u32) {
550 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
552 /// Constructs a new RouteHop given each field
555 pub extern "C" fn RouteHop_new(mut pubkey_arg: crate::c_types::PublicKey, mut node_features_arg: crate::lightning::ln::features::NodeFeatures, mut short_channel_id_arg: u64, mut channel_features_arg: crate::lightning::ln::features::ChannelFeatures, mut fee_msat_arg: u64, mut cltv_expiry_delta_arg: u32) -> RouteHop {
556 RouteHop { inner: ObjOps::heap_alloc(nativeRouteHop {
557 pubkey: pubkey_arg.into_rust(),
558 node_features: *unsafe { Box::from_raw(node_features_arg.take_inner()) },
559 short_channel_id: short_channel_id_arg,
560 channel_features: *unsafe { Box::from_raw(channel_features_arg.take_inner()) },
561 fee_msat: fee_msat_arg,
562 cltv_expiry_delta: cltv_expiry_delta_arg,
565 impl Clone for RouteHop {
566 fn clone(&self) -> Self {
568 inner: if <*mut nativeRouteHop>::is_null(self.inner) { core::ptr::null_mut() } else {
569 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
575 /// Used only if an object of this type is returned as a trait impl by a method
576 pub(crate) extern "C" fn RouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
577 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHop)).clone() })) as *mut c_void
580 /// Creates a copy of the RouteHop
581 pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop {
584 /// Generates a non-cryptographic 64-bit hash of the RouteHop.
586 pub extern "C" fn RouteHop_hash(o: &RouteHop) -> u64 {
587 if o.inner.is_null() { return 0; }
588 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
590 let mut hasher = core::hash::SipHasher::new();
591 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
592 core::hash::Hasher::finish(&hasher)
594 /// Checks if two RouteHops contain equal inner contents.
595 /// This ignores pointers and is_owned flags and looks at the values in fields.
596 /// Two objects with NULL inner values will be considered "equal" here.
598 pub extern "C" fn RouteHop_eq(a: &RouteHop, b: &RouteHop) -> bool {
599 if a.inner == b.inner { return true; }
600 if a.inner.is_null() || b.inner.is_null() { return false; }
601 if a.get_native_ref() == b.get_native_ref() { true } else { false }
604 /// Serialize the RouteHop object into a byte array which can be read by RouteHop_read
605 pub extern "C" fn RouteHop_write(obj: &crate::lightning::routing::router::RouteHop) -> crate::c_types::derived::CVec_u8Z {
606 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
609 pub(crate) extern "C" fn RouteHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
610 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHop) })
613 /// Read a RouteHop from a byte array, created by RouteHop_write
614 pub extern "C" fn RouteHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHopDecodeErrorZ {
615 let res: Result<lightning::routing::router::RouteHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
616 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() };
620 use lightning::routing::router::BlindedTail as nativeBlindedTailImport;
621 pub(crate) type nativeBlindedTail = nativeBlindedTailImport;
623 /// The blinded portion of a [`Path`], if we're routing to a recipient who provided blinded paths in
624 /// their BOLT12 [`Invoice`].
626 /// [`Invoice`]: crate::offers::invoice::Invoice
629 pub struct BlindedTail {
630 /// A pointer to the opaque Rust object.
632 /// Nearly everywhere, inner must be non-null, however in places where
633 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
634 pub inner: *mut nativeBlindedTail,
635 /// Indicates that this is the only struct which contains the same pointer.
637 /// Rust functions which take ownership of an object provided via an argument require
638 /// this to be true and invalidate the object pointed to by inner.
642 impl Drop for BlindedTail {
644 if self.is_owned && !<*mut nativeBlindedTail>::is_null(self.inner) {
645 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
649 /// Frees any resources used by the BlindedTail, if is_owned is set and inner is non-NULL.
651 pub extern "C" fn BlindedTail_free(this_obj: BlindedTail) { }
653 /// Used only if an object of this type is returned as a trait impl by a method
654 pub(crate) extern "C" fn BlindedTail_free_void(this_ptr: *mut c_void) {
655 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedTail) };
659 pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedTail {
660 unsafe { &*ObjOps::untweak_ptr(self.inner) }
662 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedTail {
663 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
665 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
666 pub(crate) fn take_inner(mut self) -> *mut nativeBlindedTail {
667 assert!(self.is_owned);
668 let ret = ObjOps::untweak_ptr(self.inner);
669 self.inner = core::ptr::null_mut();
673 /// The hops of the [`BlindedPath`] provided by the recipient.
675 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
677 pub extern "C" fn BlindedTail_get_hops(this_ptr: &BlindedTail) -> crate::c_types::derived::CVec_BlindedHopZ {
678 let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
679 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 } }); };
680 local_inner_val.into()
682 /// The hops of the [`BlindedPath`] provided by the recipient.
684 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
686 pub extern "C" fn BlindedTail_set_hops(this_ptr: &mut BlindedTail, mut val: crate::c_types::derived::CVec_BlindedHopZ) {
687 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
688 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
690 /// The blinding point of the [`BlindedPath`] provided by the recipient.
692 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
694 pub extern "C" fn BlindedTail_get_blinding_point(this_ptr: &BlindedTail) -> crate::c_types::PublicKey {
695 let mut inner_val = &mut this_ptr.get_native_mut_ref().blinding_point;
696 crate::c_types::PublicKey::from_rust(&inner_val)
698 /// The blinding point of the [`BlindedPath`] provided by the recipient.
700 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
702 pub extern "C" fn BlindedTail_set_blinding_point(this_ptr: &mut BlindedTail, mut val: crate::c_types::PublicKey) {
703 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinding_point = val.into_rust();
705 /// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
706 /// inferring the destination. May be 0.
708 pub extern "C" fn BlindedTail_get_excess_final_cltv_expiry_delta(this_ptr: &BlindedTail) -> u32 {
709 let mut inner_val = &mut this_ptr.get_native_mut_ref().excess_final_cltv_expiry_delta;
712 /// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
713 /// inferring the destination. May be 0.
715 pub extern "C" fn BlindedTail_set_excess_final_cltv_expiry_delta(this_ptr: &mut BlindedTail, mut val: u32) {
716 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.excess_final_cltv_expiry_delta = val;
718 /// The total amount paid on this [`Path`], excluding the fees.
720 pub extern "C" fn BlindedTail_get_final_value_msat(this_ptr: &BlindedTail) -> u64 {
721 let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
724 /// The total amount paid on this [`Path`], excluding the fees.
726 pub extern "C" fn BlindedTail_set_final_value_msat(this_ptr: &mut BlindedTail, mut val: u64) {
727 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
729 /// Constructs a new BlindedTail given each field
732 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 {
733 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()) } }); };
734 BlindedTail { inner: ObjOps::heap_alloc(nativeBlindedTail {
735 hops: local_hops_arg,
736 blinding_point: blinding_point_arg.into_rust(),
737 excess_final_cltv_expiry_delta: excess_final_cltv_expiry_delta_arg,
738 final_value_msat: final_value_msat_arg,
741 impl Clone for BlindedTail {
742 fn clone(&self) -> Self {
744 inner: if <*mut nativeBlindedTail>::is_null(self.inner) { core::ptr::null_mut() } else {
745 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
751 /// Used only if an object of this type is returned as a trait impl by a method
752 pub(crate) extern "C" fn BlindedTail_clone_void(this_ptr: *const c_void) -> *mut c_void {
753 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBlindedTail)).clone() })) as *mut c_void
756 /// Creates a copy of the BlindedTail
757 pub extern "C" fn BlindedTail_clone(orig: &BlindedTail) -> BlindedTail {
760 /// Generates a non-cryptographic 64-bit hash of the BlindedTail.
762 pub extern "C" fn BlindedTail_hash(o: &BlindedTail) -> u64 {
763 if o.inner.is_null() { return 0; }
764 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
766 let mut hasher = core::hash::SipHasher::new();
767 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
768 core::hash::Hasher::finish(&hasher)
770 /// Checks if two BlindedTails contain equal inner contents.
771 /// This ignores pointers and is_owned flags and looks at the values in fields.
772 /// Two objects with NULL inner values will be considered "equal" here.
774 pub extern "C" fn BlindedTail_eq(a: &BlindedTail, b: &BlindedTail) -> bool {
775 if a.inner == b.inner { return true; }
776 if a.inner.is_null() || b.inner.is_null() { return false; }
777 if a.get_native_ref() == b.get_native_ref() { true } else { false }
780 /// Serialize the BlindedTail object into a byte array which can be read by BlindedTail_read
781 pub extern "C" fn BlindedTail_write(obj: &crate::lightning::routing::router::BlindedTail) -> crate::c_types::derived::CVec_u8Z {
782 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
785 pub(crate) extern "C" fn BlindedTail_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
786 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedTail) })
789 /// Read a BlindedTail from a byte array, created by BlindedTail_write
790 pub extern "C" fn BlindedTail_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedTailDecodeErrorZ {
791 let res: Result<lightning::routing::router::BlindedTail, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
792 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() };
796 use lightning::routing::router::Path as nativePathImport;
797 pub(crate) type nativePath = nativePathImport;
799 /// A path in a [`Route`] to the payment recipient. Must always be at least length one.
800 /// If no [`Path::blinded_tail`] is present, then [`Path::hops`] length may be up to 19.
804 /// A pointer to the opaque Rust object.
806 /// Nearly everywhere, inner must be non-null, however in places where
807 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
808 pub inner: *mut nativePath,
809 /// Indicates that this is the only struct which contains the same pointer.
811 /// Rust functions which take ownership of an object provided via an argument require
812 /// this to be true and invalidate the object pointed to by inner.
818 if self.is_owned && !<*mut nativePath>::is_null(self.inner) {
819 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
823 /// Frees any resources used by the Path, if is_owned is set and inner is non-NULL.
825 pub extern "C" fn Path_free(this_obj: Path) { }
827 /// Used only if an object of this type is returned as a trait impl by a method
828 pub(crate) extern "C" fn Path_free_void(this_ptr: *mut c_void) {
829 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePath) };
833 pub(crate) fn get_native_ref(&self) -> &'static nativePath {
834 unsafe { &*ObjOps::untweak_ptr(self.inner) }
836 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePath {
837 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
839 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
840 pub(crate) fn take_inner(mut self) -> *mut nativePath {
841 assert!(self.is_owned);
842 let ret = ObjOps::untweak_ptr(self.inner);
843 self.inner = core::ptr::null_mut();
847 /// The list of unblinded hops in this [`Path`]. Must be at least length one.
849 pub extern "C" fn Path_get_hops(this_ptr: &Path) -> crate::c_types::derived::CVec_RouteHopZ {
850 let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
851 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 } }); };
852 local_inner_val.into()
854 /// The list of unblinded hops in this [`Path`]. Must be at least length one.
856 pub extern "C" fn Path_set_hops(this_ptr: &mut Path, mut val: crate::c_types::derived::CVec_RouteHopZ) {
857 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
858 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
860 /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
862 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
864 pub extern "C" fn Path_get_blinded_tail(this_ptr: &Path) -> crate::lightning::routing::router::BlindedTail {
865 let mut inner_val = &mut this_ptr.get_native_mut_ref().blinded_tail;
866 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 };
869 /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
871 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
873 pub extern "C" fn Path_set_blinded_tail(this_ptr: &mut Path, mut val: crate::lightning::routing::router::BlindedTail) {
874 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
875 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinded_tail = local_val;
877 /// Constructs a new Path given each field
880 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 {
881 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()) } }); };
882 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()) } }) };
883 Path { inner: ObjOps::heap_alloc(nativePath {
884 hops: local_hops_arg,
885 blinded_tail: local_blinded_tail_arg,
888 impl Clone for Path {
889 fn clone(&self) -> Self {
891 inner: if <*mut nativePath>::is_null(self.inner) { core::ptr::null_mut() } else {
892 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
898 /// Used only if an object of this type is returned as a trait impl by a method
899 pub(crate) extern "C" fn Path_clone_void(this_ptr: *const c_void) -> *mut c_void {
900 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePath)).clone() })) as *mut c_void
903 /// Creates a copy of the Path
904 pub extern "C" fn Path_clone(orig: &Path) -> Path {
907 /// Generates a non-cryptographic 64-bit hash of the Path.
909 pub extern "C" fn Path_hash(o: &Path) -> u64 {
910 if o.inner.is_null() { return 0; }
911 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
913 let mut hasher = core::hash::SipHasher::new();
914 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
915 core::hash::Hasher::finish(&hasher)
917 /// Checks if two Paths contain equal inner contents.
918 /// This ignores pointers and is_owned flags and looks at the values in fields.
919 /// Two objects with NULL inner values will be considered "equal" here.
921 pub extern "C" fn Path_eq(a: &Path, b: &Path) -> bool {
922 if a.inner == b.inner { return true; }
923 if a.inner.is_null() || b.inner.is_null() { return false; }
924 if a.get_native_ref() == b.get_native_ref() { true } else { false }
926 /// Gets the fees for a given path, excluding any excess paid to the recipient.
929 pub extern "C" fn Path_fee_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
930 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fee_msat();
934 /// Gets the total amount paid on this [`Path`], excluding the fees.
937 pub extern "C" fn Path_final_value_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
938 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_value_msat();
942 /// Gets the final hop's CLTV expiry delta.
945 pub extern "C" fn Path_final_cltv_expiry_delta(this_arg: &crate::lightning::routing::router::Path) -> crate::c_types::derived::COption_u32Z {
946 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_cltv_expiry_delta();
947 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() }) };
952 use lightning::routing::router::Route as nativeRouteImport;
953 pub(crate) type nativeRoute = nativeRouteImport;
955 /// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
956 /// it can take multiple paths. Each path is composed of one or more hops through the network.
960 /// A pointer to the opaque Rust object.
962 /// Nearly everywhere, inner must be non-null, however in places where
963 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
964 pub inner: *mut nativeRoute,
965 /// Indicates that this is the only struct which contains the same pointer.
967 /// Rust functions which take ownership of an object provided via an argument require
968 /// this to be true and invalidate the object pointed to by inner.
972 impl Drop for Route {
974 if self.is_owned && !<*mut nativeRoute>::is_null(self.inner) {
975 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
979 /// Frees any resources used by the Route, if is_owned is set and inner is non-NULL.
981 pub extern "C" fn Route_free(this_obj: Route) { }
983 /// Used only if an object of this type is returned as a trait impl by a method
984 pub(crate) extern "C" fn Route_free_void(this_ptr: *mut c_void) {
985 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoute) };
989 pub(crate) fn get_native_ref(&self) -> &'static nativeRoute {
990 unsafe { &*ObjOps::untweak_ptr(self.inner) }
992 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoute {
993 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
995 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
996 pub(crate) fn take_inner(mut self) -> *mut nativeRoute {
997 assert!(self.is_owned);
998 let ret = ObjOps::untweak_ptr(self.inner);
999 self.inner = core::ptr::null_mut();
1003 /// The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
1004 /// [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
1007 pub extern "C" fn Route_get_paths(this_ptr: &Route) -> crate::c_types::derived::CVec_PathZ {
1008 let mut inner_val = &mut this_ptr.get_native_mut_ref().paths;
1009 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 } }); };
1010 local_inner_val.into()
1012 /// The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
1013 /// [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
1016 pub extern "C" fn Route_set_paths(this_ptr: &mut Route, mut val: crate::c_types::derived::CVec_PathZ) {
1017 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1018 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.paths = local_val;
1020 /// The `payment_params` parameter passed to [`find_route`].
1021 /// This is used by `ChannelManager` to track information which may be required for retries,
1022 /// provided back to you via [`Event::PaymentPathFailed`].
1024 /// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
1026 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1028 pub extern "C" fn Route_get_payment_params(this_ptr: &Route) -> crate::lightning::routing::router::PaymentParameters {
1029 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_params;
1030 let mut local_inner_val = crate::lightning::routing::router::PaymentParameters { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::router::PaymentParameters<>) as *mut _ }, is_owned: false };
1033 /// The `payment_params` parameter passed to [`find_route`].
1034 /// This is used by `ChannelManager` to track information which may be required for retries,
1035 /// provided back to you via [`Event::PaymentPathFailed`].
1037 /// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
1039 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1041 pub extern "C" fn Route_set_payment_params(this_ptr: &mut Route, mut val: crate::lightning::routing::router::PaymentParameters) {
1042 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1043 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_params = local_val;
1045 /// Constructs a new Route given each field
1048 pub extern "C" fn Route_new(mut paths_arg: crate::c_types::derived::CVec_PathZ, mut payment_params_arg: crate::lightning::routing::router::PaymentParameters) -> Route {
1049 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()) } }); };
1050 let mut local_payment_params_arg = if payment_params_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(payment_params_arg.take_inner()) } }) };
1051 Route { inner: ObjOps::heap_alloc(nativeRoute {
1052 paths: local_paths_arg,
1053 payment_params: local_payment_params_arg,
1054 }), is_owned: true }
1056 impl Clone for Route {
1057 fn clone(&self) -> Self {
1059 inner: if <*mut nativeRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
1060 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1066 /// Used only if an object of this type is returned as a trait impl by a method
1067 pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_void {
1068 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoute)).clone() })) as *mut c_void
1071 /// Creates a copy of the Route
1072 pub extern "C" fn Route_clone(orig: &Route) -> Route {
1075 /// Generates a non-cryptographic 64-bit hash of the Route.
1077 pub extern "C" fn Route_hash(o: &Route) -> u64 {
1078 if o.inner.is_null() { return 0; }
1079 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1080 #[allow(deprecated)]
1081 let mut hasher = core::hash::SipHasher::new();
1082 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1083 core::hash::Hasher::finish(&hasher)
1085 /// Checks if two Routes contain equal inner contents.
1086 /// This ignores pointers and is_owned flags and looks at the values in fields.
1087 /// Two objects with NULL inner values will be considered "equal" here.
1089 pub extern "C" fn Route_eq(a: &Route, b: &Route) -> bool {
1090 if a.inner == b.inner { return true; }
1091 if a.inner.is_null() || b.inner.is_null() { return false; }
1092 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1094 /// Returns the total amount of fees paid on this [`Route`].
1096 /// This doesn't include any extra payment made to the recipient, which can happen in excess of
1097 /// the amount passed to [`find_route`]'s `params.final_value_msat`.
1100 pub extern "C" fn Route_get_total_fees(this_arg: &crate::lightning::routing::router::Route) -> u64 {
1101 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_fees();
1105 /// Returns the total amount paid on this [`Route`], excluding the fees. Might be more than
1106 /// requested if we had to reach htlc_minimum_msat.
1109 pub extern "C" fn Route_get_total_amount(this_arg: &crate::lightning::routing::router::Route) -> u64 {
1110 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_amount();
1115 /// Serialize the Route object into a byte array which can be read by Route_read
1116 pub extern "C" fn Route_write(obj: &crate::lightning::routing::router::Route) -> crate::c_types::derived::CVec_u8Z {
1117 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1120 pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1121 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) })
1124 /// Read a Route from a byte array, created by Route_write
1125 pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ {
1126 let res: Result<lightning::routing::router::Route, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1127 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() };
1131 use lightning::routing::router::RouteParameters as nativeRouteParametersImport;
1132 pub(crate) type nativeRouteParameters = nativeRouteParametersImport;
1134 /// Parameters needed to find a [`Route`].
1136 /// Passed to [`find_route`] and [`build_route_from_hops`], but also provided in
1137 /// [`Event::PaymentPathFailed`].
1139 /// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
1142 pub struct RouteParameters {
1143 /// A pointer to the opaque Rust object.
1145 /// Nearly everywhere, inner must be non-null, however in places where
1146 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1147 pub inner: *mut nativeRouteParameters,
1148 /// Indicates that this is the only struct which contains the same pointer.
1150 /// Rust functions which take ownership of an object provided via an argument require
1151 /// this to be true and invalidate the object pointed to by inner.
1155 impl Drop for RouteParameters {
1156 fn drop(&mut self) {
1157 if self.is_owned && !<*mut nativeRouteParameters>::is_null(self.inner) {
1158 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1162 /// Frees any resources used by the RouteParameters, if is_owned is set and inner is non-NULL.
1164 pub extern "C" fn RouteParameters_free(this_obj: RouteParameters) { }
1166 /// Used only if an object of this type is returned as a trait impl by a method
1167 pub(crate) extern "C" fn RouteParameters_free_void(this_ptr: *mut c_void) {
1168 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteParameters) };
1171 impl RouteParameters {
1172 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteParameters {
1173 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1175 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteParameters {
1176 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1178 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1179 pub(crate) fn take_inner(mut self) -> *mut nativeRouteParameters {
1180 assert!(self.is_owned);
1181 let ret = ObjOps::untweak_ptr(self.inner);
1182 self.inner = core::ptr::null_mut();
1186 /// The parameters of the failed payment path.
1188 pub extern "C" fn RouteParameters_get_payment_params(this_ptr: &RouteParameters) -> crate::lightning::routing::router::PaymentParameters {
1189 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_params;
1190 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 }
1192 /// The parameters of the failed payment path.
1194 pub extern "C" fn RouteParameters_set_payment_params(this_ptr: &mut RouteParameters, mut val: crate::lightning::routing::router::PaymentParameters) {
1195 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_params = *unsafe { Box::from_raw(val.take_inner()) };
1197 /// The amount in msats sent on the failed payment path.
1199 pub extern "C" fn RouteParameters_get_final_value_msat(this_ptr: &RouteParameters) -> u64 {
1200 let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
1203 /// The amount in msats sent on the failed payment path.
1205 pub extern "C" fn RouteParameters_set_final_value_msat(this_ptr: &mut RouteParameters, mut val: u64) {
1206 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
1208 /// Constructs a new RouteParameters given each field
1211 pub extern "C" fn RouteParameters_new(mut payment_params_arg: crate::lightning::routing::router::PaymentParameters, mut final_value_msat_arg: u64) -> RouteParameters {
1212 RouteParameters { inner: ObjOps::heap_alloc(nativeRouteParameters {
1213 payment_params: *unsafe { Box::from_raw(payment_params_arg.take_inner()) },
1214 final_value_msat: final_value_msat_arg,
1215 }), is_owned: true }
1217 impl Clone for RouteParameters {
1218 fn clone(&self) -> Self {
1220 inner: if <*mut nativeRouteParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1221 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1227 /// Used only if an object of this type is returned as a trait impl by a method
1228 pub(crate) extern "C" fn RouteParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1229 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteParameters)).clone() })) as *mut c_void
1232 /// Creates a copy of the RouteParameters
1233 pub extern "C" fn RouteParameters_clone(orig: &RouteParameters) -> RouteParameters {
1236 /// Checks if two RouteParameterss contain equal inner contents.
1237 /// This ignores pointers and is_owned flags and looks at the values in fields.
1238 /// Two objects with NULL inner values will be considered "equal" here.
1240 pub extern "C" fn RouteParameters_eq(a: &RouteParameters, b: &RouteParameters) -> bool {
1241 if a.inner == b.inner { return true; }
1242 if a.inner.is_null() || b.inner.is_null() { return false; }
1243 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1246 /// Serialize the RouteParameters object into a byte array which can be read by RouteParameters_read
1247 pub extern "C" fn RouteParameters_write(obj: &crate::lightning::routing::router::RouteParameters) -> crate::c_types::derived::CVec_u8Z {
1248 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1251 pub(crate) extern "C" fn RouteParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1252 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteParameters) })
1255 /// Read a RouteParameters from a byte array, created by RouteParameters_write
1256 pub extern "C" fn RouteParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteParametersDecodeErrorZ {
1257 let res: Result<lightning::routing::router::RouteParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1258 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() };
1261 /// Maximum total CTLV difference we allow for a full payment path.
1264 pub static DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = lightning::routing::router::DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
1265 /// Maximum number of paths we allow an (MPP) payment to have.
1268 pub static DEFAULT_MAX_PATH_COUNT: u8 = lightning::routing::router::DEFAULT_MAX_PATH_COUNT;
1270 use lightning::routing::router::PaymentParameters as nativePaymentParametersImport;
1271 pub(crate) type nativePaymentParameters = nativePaymentParametersImport;
1273 /// The recipient of a payment.
1276 pub struct PaymentParameters {
1277 /// A pointer to the opaque Rust object.
1279 /// Nearly everywhere, inner must be non-null, however in places where
1280 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1281 pub inner: *mut nativePaymentParameters,
1282 /// Indicates that this is the only struct which contains the same pointer.
1284 /// Rust functions which take ownership of an object provided via an argument require
1285 /// this to be true and invalidate the object pointed to by inner.
1289 impl Drop for PaymentParameters {
1290 fn drop(&mut self) {
1291 if self.is_owned && !<*mut nativePaymentParameters>::is_null(self.inner) {
1292 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1296 /// Frees any resources used by the PaymentParameters, if is_owned is set and inner is non-NULL.
1298 pub extern "C" fn PaymentParameters_free(this_obj: PaymentParameters) { }
1300 /// Used only if an object of this type is returned as a trait impl by a method
1301 pub(crate) extern "C" fn PaymentParameters_free_void(this_ptr: *mut c_void) {
1302 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentParameters) };
1305 impl PaymentParameters {
1306 pub(crate) fn get_native_ref(&self) -> &'static nativePaymentParameters {
1307 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1309 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentParameters {
1310 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1312 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1313 pub(crate) fn take_inner(mut self) -> *mut nativePaymentParameters {
1314 assert!(self.is_owned);
1315 let ret = ObjOps::untweak_ptr(self.inner);
1316 self.inner = core::ptr::null_mut();
1320 /// The node id of the payee.
1322 pub extern "C" fn PaymentParameters_get_payee_pubkey(this_ptr: &PaymentParameters) -> crate::c_types::PublicKey {
1323 let mut inner_val = &mut this_ptr.get_native_mut_ref().payee_pubkey;
1324 crate::c_types::PublicKey::from_rust(&inner_val)
1326 /// The node id of the payee.
1328 pub extern "C" fn PaymentParameters_set_payee_pubkey(this_ptr: &mut PaymentParameters, mut val: crate::c_types::PublicKey) {
1329 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payee_pubkey = val.into_rust();
1331 /// Features supported by the payee.
1333 /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
1334 /// does not contain any features.
1336 /// [`for_keysend`]: Self::for_keysend
1338 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1340 pub extern "C" fn PaymentParameters_get_features(this_ptr: &PaymentParameters) -> crate::lightning::ln::features::InvoiceFeatures {
1341 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1342 let mut local_inner_val = crate::lightning::ln::features::InvoiceFeatures { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::features::InvoiceFeatures<>) as *mut _ }, is_owned: false };
1345 /// Features supported by the payee.
1347 /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
1348 /// does not contain any features.
1350 /// [`for_keysend`]: Self::for_keysend
1352 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1354 pub extern "C" fn PaymentParameters_set_features(this_ptr: &mut PaymentParameters, mut val: crate::lightning::ln::features::InvoiceFeatures) {
1355 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1356 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = local_val;
1358 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
1360 pub extern "C" fn PaymentParameters_get_route_hints(this_ptr: &PaymentParameters) -> crate::lightning::routing::router::Hints {
1361 let mut inner_val = &mut this_ptr.get_native_mut_ref().route_hints;
1362 crate::lightning::routing::router::Hints::from_native(inner_val)
1364 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
1366 pub extern "C" fn PaymentParameters_set_route_hints(this_ptr: &mut PaymentParameters, mut val: crate::lightning::routing::router::Hints) {
1367 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_hints = val.into_native();
1369 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1371 pub extern "C" fn PaymentParameters_get_expiry_time(this_ptr: &PaymentParameters) -> crate::c_types::derived::COption_u64Z {
1372 let mut inner_val = &mut this_ptr.get_native_mut_ref().expiry_time;
1373 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() }) };
1376 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1378 pub extern "C" fn PaymentParameters_set_expiry_time(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::COption_u64Z) {
1379 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1380 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.expiry_time = local_val;
1382 /// The maximum total CLTV delta we accept for the route.
1383 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1385 pub extern "C" fn PaymentParameters_get_max_total_cltv_expiry_delta(this_ptr: &PaymentParameters) -> u32 {
1386 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_cltv_expiry_delta;
1389 /// The maximum total CLTV delta we accept for the route.
1390 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1392 pub extern "C" fn PaymentParameters_set_max_total_cltv_expiry_delta(this_ptr: &mut PaymentParameters, mut val: u32) {
1393 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_cltv_expiry_delta = val;
1395 /// The maximum number of paths that may be used by (MPP) payments.
1396 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1398 pub extern "C" fn PaymentParameters_get_max_path_count(this_ptr: &PaymentParameters) -> u8 {
1399 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_path_count;
1402 /// The maximum number of paths that may be used by (MPP) payments.
1403 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1405 pub extern "C" fn PaymentParameters_set_max_path_count(this_ptr: &mut PaymentParameters, mut val: u8) {
1406 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_path_count = val;
1408 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1409 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1410 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1411 /// increasing failure probability for those paths.
1413 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1414 /// restriction have been found. While paths which meet this criteria will be searched for, it
1415 /// is ultimately up to the scorer to select them over other paths.
1417 /// A value of 0 will allow payments up to and including a channel's total announced usable
1418 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1420 /// Default value: 2
1422 pub extern "C" fn PaymentParameters_get_max_channel_saturation_power_of_half(this_ptr: &PaymentParameters) -> u8 {
1423 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_saturation_power_of_half;
1426 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1427 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1428 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1429 /// increasing failure probability for those paths.
1431 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1432 /// restriction have been found. While paths which meet this criteria will be searched for, it
1433 /// is ultimately up to the scorer to select them over other paths.
1435 /// A value of 0 will allow payments up to and including a channel's total announced usable
1436 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1438 /// Default value: 2
1440 pub extern "C" fn PaymentParameters_set_max_channel_saturation_power_of_half(this_ptr: &mut PaymentParameters, mut val: u8) {
1441 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_saturation_power_of_half = val;
1443 /// A list of SCIDs which this payment was previously attempted over and which caused the
1444 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1447 /// Returns a copy of the field.
1449 pub extern "C" fn PaymentParameters_get_previously_failed_channels(this_ptr: &PaymentParameters) -> crate::c_types::derived::CVec_u64Z {
1450 let mut inner_val = this_ptr.get_native_mut_ref().previously_failed_channels.clone();
1451 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1452 local_inner_val.into()
1454 /// A list of SCIDs which this payment was previously attempted over and which caused the
1455 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1458 pub extern "C" fn PaymentParameters_set_previously_failed_channels(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_u64Z) {
1459 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1460 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previously_failed_channels = local_val;
1462 /// The minimum CLTV delta at the end of the route. This value must not be zero.
1464 pub extern "C" fn PaymentParameters_get_final_cltv_expiry_delta(this_ptr: &PaymentParameters) -> u32 {
1465 let mut inner_val = &mut this_ptr.get_native_mut_ref().final_cltv_expiry_delta;
1468 /// The minimum CLTV delta at the end of the route. This value must not be zero.
1470 pub extern "C" fn PaymentParameters_set_final_cltv_expiry_delta(this_ptr: &mut PaymentParameters, mut val: u32) {
1471 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_cltv_expiry_delta = val;
1473 /// Constructs a new PaymentParameters given each field
1476 pub extern "C" fn PaymentParameters_new(mut payee_pubkey_arg: crate::c_types::PublicKey, mut features_arg: crate::lightning::ln::features::InvoiceFeatures, mut route_hints_arg: crate::lightning::routing::router::Hints, 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, mut final_cltv_expiry_delta_arg: u32) -> PaymentParameters {
1477 let mut local_features_arg = if features_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_arg.take_inner()) } }) };
1478 let mut local_expiry_time_arg = if expiry_time_arg.is_some() { Some( { expiry_time_arg.take() }) } else { None };
1479 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 }); };
1480 PaymentParameters { inner: ObjOps::heap_alloc(nativePaymentParameters {
1481 payee_pubkey: payee_pubkey_arg.into_rust(),
1482 features: local_features_arg,
1483 route_hints: route_hints_arg.into_native(),
1484 expiry_time: local_expiry_time_arg,
1485 max_total_cltv_expiry_delta: max_total_cltv_expiry_delta_arg,
1486 max_path_count: max_path_count_arg,
1487 max_channel_saturation_power_of_half: max_channel_saturation_power_of_half_arg,
1488 previously_failed_channels: local_previously_failed_channels_arg,
1489 final_cltv_expiry_delta: final_cltv_expiry_delta_arg,
1490 }), is_owned: true }
1492 impl Clone for PaymentParameters {
1493 fn clone(&self) -> Self {
1495 inner: if <*mut nativePaymentParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1496 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1502 /// Used only if an object of this type is returned as a trait impl by a method
1503 pub(crate) extern "C" fn PaymentParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1504 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentParameters)).clone() })) as *mut c_void
1507 /// Creates a copy of the PaymentParameters
1508 pub extern "C" fn PaymentParameters_clone(orig: &PaymentParameters) -> PaymentParameters {
1511 /// Generates a non-cryptographic 64-bit hash of the PaymentParameters.
1513 pub extern "C" fn PaymentParameters_hash(o: &PaymentParameters) -> u64 {
1514 if o.inner.is_null() { return 0; }
1515 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1516 #[allow(deprecated)]
1517 let mut hasher = core::hash::SipHasher::new();
1518 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1519 core::hash::Hasher::finish(&hasher)
1521 /// Checks if two PaymentParameterss contain equal inner contents.
1522 /// This ignores pointers and is_owned flags and looks at the values in fields.
1523 /// Two objects with NULL inner values will be considered "equal" here.
1525 pub extern "C" fn PaymentParameters_eq(a: &PaymentParameters, b: &PaymentParameters) -> bool {
1526 if a.inner == b.inner { return true; }
1527 if a.inner.is_null() || b.inner.is_null() { return false; }
1528 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1531 /// Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
1532 pub extern "C" fn PaymentParameters_write(obj: &crate::lightning::routing::router::PaymentParameters) -> crate::c_types::derived::CVec_u8Z {
1533 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1536 pub(crate) extern "C" fn PaymentParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1537 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentParameters) })
1540 /// Read a PaymentParameters from a byte array, created by PaymentParameters_write
1541 pub extern "C" fn PaymentParameters_read(ser: crate::c_types::u8slice, arg: u32) -> crate::c_types::derived::CResult_PaymentParametersDecodeErrorZ {
1543 let res: Result<lightning::routing::router::PaymentParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1544 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() };
1547 /// Creates a payee with the node id of the given `pubkey`.
1549 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1553 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 {
1554 let mut ret = lightning::routing::router::PaymentParameters::from_node_id(payee_pubkey.into_rust(), final_cltv_expiry_delta);
1555 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1558 /// Creates a payee with the node id of the given `pubkey` to use for keysend payments.
1560 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1564 pub extern "C" fn PaymentParameters_for_keysend(mut payee_pubkey: crate::c_types::PublicKey, mut final_cltv_expiry_delta: u32) -> crate::lightning::routing::router::PaymentParameters {
1565 let mut ret = lightning::routing::router::PaymentParameters::for_keysend(payee_pubkey.into_rust(), final_cltv_expiry_delta);
1566 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1569 /// Routing hints for the tail of the route.
1574 /// The recipient provided blinded paths and payinfo to reach them. The blinded paths themselves
1575 /// will be included in the final [`Route`].
1577 crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ),
1578 /// The recipient included these route hints in their BOLT11 invoice.
1580 crate::c_types::derived::CVec_RouteHintZ),
1582 use lightning::routing::router::Hints as HintsImport;
1583 pub(crate) type nativeHints = HintsImport;
1587 pub(crate) fn to_native(&self) -> nativeHints {
1589 Hints::Blinded (ref a, ) => {
1590 let mut a_nonref = Clone::clone(a);
1591 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { let (mut orig_a_nonref_0_0, mut orig_a_nonref_0_1) = item.to_rust(); let mut local_a_nonref_0 = (*unsafe { Box::from_raw(orig_a_nonref_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_a_nonref_0_1.take_inner()) }); local_a_nonref_0 }); };
1592 nativeHints::Blinded (
1596 Hints::Clear (ref a, ) => {
1597 let mut a_nonref = Clone::clone(a);
1598 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.into_rust().drain(..) { local_a_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1599 nativeHints::Clear (
1606 pub(crate) fn into_native(self) -> nativeHints {
1608 Hints::Blinded (mut a, ) => {
1609 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { let (mut orig_a_0_0, mut orig_a_0_1) = item.to_rust(); let mut local_a_0 = (*unsafe { Box::from_raw(orig_a_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_a_0_1.take_inner()) }); local_a_0 }); };
1610 nativeHints::Blinded (
1614 Hints::Clear (mut a, ) => {
1615 let mut local_a = Vec::new(); for mut item in a.into_rust().drain(..) { local_a.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1616 nativeHints::Clear (
1623 pub(crate) fn from_native(native: &nativeHints) -> Self {
1625 nativeHints::Blinded (ref a, ) => {
1626 let mut a_nonref = Clone::clone(a);
1627 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { let (mut orig_a_nonref_0_0, mut orig_a_nonref_0_1) = item; let mut local_a_nonref_0 = (crate::lightning::offers::invoice::BlindedPayInfo { inner: ObjOps::heap_alloc(orig_a_nonref_0_0), is_owned: true }, crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(orig_a_nonref_0_1), is_owned: true }).into(); local_a_nonref_0 }); };
1629 local_a_nonref.into(),
1632 nativeHints::Clear (ref a, ) => {
1633 let mut a_nonref = Clone::clone(a);
1634 let mut local_a_nonref = Vec::new(); for mut item in a_nonref.drain(..) { local_a_nonref.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1636 local_a_nonref.into(),
1642 pub(crate) fn native_into(native: nativeHints) -> Self {
1644 nativeHints::Blinded (mut a, ) => {
1645 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { let (mut orig_a_0_0, mut orig_a_0_1) = item; let mut local_a_0 = (crate::lightning::offers::invoice::BlindedPayInfo { inner: ObjOps::heap_alloc(orig_a_0_0), is_owned: true }, crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(orig_a_0_1), is_owned: true }).into(); local_a_0 }); };
1650 nativeHints::Clear (mut a, ) => {
1651 let mut local_a = Vec::new(); for mut item in a.drain(..) { local_a.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1659 /// Frees any resources used by the Hints
1661 pub extern "C" fn Hints_free(this_ptr: Hints) { }
1662 /// Creates a copy of the Hints
1664 pub extern "C" fn Hints_clone(orig: &Hints) -> Hints {
1668 /// Utility method to constructs a new Blinded-variant Hints
1669 pub extern "C" fn Hints_blinded(a: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ) -> Hints {
1673 /// Utility method to constructs a new Clear-variant Hints
1674 pub extern "C" fn Hints_clear(a: crate::c_types::derived::CVec_RouteHintZ) -> Hints {
1677 /// Generates a non-cryptographic 64-bit hash of the Hints.
1679 pub extern "C" fn Hints_hash(o: &Hints) -> u64 {
1680 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1681 #[allow(deprecated)]
1682 let mut hasher = core::hash::SipHasher::new();
1683 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1684 core::hash::Hasher::finish(&hasher)
1686 /// Checks if two Hintss contain equal inner contents.
1687 /// This ignores pointers and is_owned flags and looks at the values in fields.
1689 pub extern "C" fn Hints_eq(a: &Hints, b: &Hints) -> bool {
1690 if &a.to_native() == &b.to_native() { true } else { false }
1693 use lightning::routing::router::RouteHint as nativeRouteHintImport;
1694 pub(crate) type nativeRouteHint = nativeRouteHintImport;
1696 /// A list of hops along a payment path terminating with a channel to the recipient.
1699 pub struct RouteHint {
1700 /// A pointer to the opaque Rust object.
1702 /// Nearly everywhere, inner must be non-null, however in places where
1703 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1704 pub inner: *mut nativeRouteHint,
1705 /// Indicates that this is the only struct which contains the same pointer.
1707 /// Rust functions which take ownership of an object provided via an argument require
1708 /// this to be true and invalidate the object pointed to by inner.
1712 impl Drop for RouteHint {
1713 fn drop(&mut self) {
1714 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
1715 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1719 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
1721 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
1723 /// Used only if an object of this type is returned as a trait impl by a method
1724 pub(crate) extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
1725 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHint) };
1729 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHint {
1730 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1732 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHint {
1733 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1735 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1736 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
1737 assert!(self.is_owned);
1738 let ret = ObjOps::untweak_ptr(self.inner);
1739 self.inner = core::ptr::null_mut();
1744 pub extern "C" fn RouteHint_get_a(this_ptr: &RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ {
1745 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1746 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 } }); };
1747 local_inner_val.into()
1750 pub extern "C" fn RouteHint_set_a(this_ptr: &mut RouteHint, mut val: crate::c_types::derived::CVec_RouteHintHopZ) {
1751 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1752 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = local_val;
1754 /// Constructs a new RouteHint given each field
1757 pub extern "C" fn RouteHint_new(mut a_arg: crate::c_types::derived::CVec_RouteHintHopZ) -> RouteHint {
1758 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()) } }); };
1759 RouteHint { inner: ObjOps::heap_alloc(lightning::routing::router::RouteHint (
1761 )), is_owned: true }
1763 impl Clone for RouteHint {
1764 fn clone(&self) -> Self {
1766 inner: if <*mut nativeRouteHint>::is_null(self.inner) { core::ptr::null_mut() } else {
1767 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1773 /// Used only if an object of this type is returned as a trait impl by a method
1774 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
1775 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void
1778 /// Creates a copy of the RouteHint
1779 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
1782 /// Generates a non-cryptographic 64-bit hash of the RouteHint.
1784 pub extern "C" fn RouteHint_hash(o: &RouteHint) -> u64 {
1785 if o.inner.is_null() { return 0; }
1786 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1787 #[allow(deprecated)]
1788 let mut hasher = core::hash::SipHasher::new();
1789 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1790 core::hash::Hasher::finish(&hasher)
1792 /// Checks if two RouteHints contain equal inner contents.
1793 /// This ignores pointers and is_owned flags and looks at the values in fields.
1794 /// Two objects with NULL inner values will be considered "equal" here.
1796 pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool {
1797 if a.inner == b.inner { return true; }
1798 if a.inner.is_null() || b.inner.is_null() { return false; }
1799 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1802 /// Serialize the RouteHint object into a byte array which can be read by RouteHint_read
1803 pub extern "C" fn RouteHint_write(obj: &crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CVec_u8Z {
1804 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1807 pub(crate) extern "C" fn RouteHint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1808 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHint) })
1811 /// Read a RouteHint from a byte array, created by RouteHint_write
1812 pub extern "C" fn RouteHint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintDecodeErrorZ {
1813 let res: Result<lightning::routing::router::RouteHint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1814 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() };
1818 use lightning::routing::router::RouteHintHop as nativeRouteHintHopImport;
1819 pub(crate) type nativeRouteHintHop = nativeRouteHintHopImport;
1821 /// A channel descriptor for a hop along a payment path.
1824 pub struct RouteHintHop {
1825 /// A pointer to the opaque Rust object.
1827 /// Nearly everywhere, inner must be non-null, however in places where
1828 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1829 pub inner: *mut nativeRouteHintHop,
1830 /// Indicates that this is the only struct which contains the same pointer.
1832 /// Rust functions which take ownership of an object provided via an argument require
1833 /// this to be true and invalidate the object pointed to by inner.
1837 impl Drop for RouteHintHop {
1838 fn drop(&mut self) {
1839 if self.is_owned && !<*mut nativeRouteHintHop>::is_null(self.inner) {
1840 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1844 /// Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL.
1846 pub extern "C" fn RouteHintHop_free(this_obj: RouteHintHop) { }
1848 /// Used only if an object of this type is returned as a trait impl by a method
1849 pub(crate) extern "C" fn RouteHintHop_free_void(this_ptr: *mut c_void) {
1850 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHintHop) };
1854 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHintHop {
1855 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1857 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHintHop {
1858 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1860 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1861 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHintHop {
1862 assert!(self.is_owned);
1863 let ret = ObjOps::untweak_ptr(self.inner);
1864 self.inner = core::ptr::null_mut();
1868 /// The node_id of the non-target end of the route
1870 pub extern "C" fn RouteHintHop_get_src_node_id(this_ptr: &RouteHintHop) -> crate::c_types::PublicKey {
1871 let mut inner_val = &mut this_ptr.get_native_mut_ref().src_node_id;
1872 crate::c_types::PublicKey::from_rust(&inner_val)
1874 /// The node_id of the non-target end of the route
1876 pub extern "C" fn RouteHintHop_set_src_node_id(this_ptr: &mut RouteHintHop, mut val: crate::c_types::PublicKey) {
1877 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.src_node_id = val.into_rust();
1879 /// The short_channel_id of this channel
1881 pub extern "C" fn RouteHintHop_get_short_channel_id(this_ptr: &RouteHintHop) -> u64 {
1882 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
1885 /// The short_channel_id of this channel
1887 pub extern "C" fn RouteHintHop_set_short_channel_id(this_ptr: &mut RouteHintHop, mut val: u64) {
1888 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
1890 /// The fees which must be paid to use this channel
1892 pub extern "C" fn RouteHintHop_get_fees(this_ptr: &RouteHintHop) -> crate::lightning::routing::gossip::RoutingFees {
1893 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
1894 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 }
1896 /// The fees which must be paid to use this channel
1898 pub extern "C" fn RouteHintHop_set_fees(this_ptr: &mut RouteHintHop, mut val: crate::lightning::routing::gossip::RoutingFees) {
1899 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
1901 /// The difference in CLTV values between this node and the next node.
1903 pub extern "C" fn RouteHintHop_get_cltv_expiry_delta(this_ptr: &RouteHintHop) -> u16 {
1904 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
1907 /// The difference in CLTV values between this node and the next node.
1909 pub extern "C" fn RouteHintHop_set_cltv_expiry_delta(this_ptr: &mut RouteHintHop, mut val: u16) {
1910 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
1912 /// The minimum value, in msat, which must be relayed to the next hop.
1914 pub extern "C" fn RouteHintHop_get_htlc_minimum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
1915 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
1916 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() }) };
1919 /// The minimum value, in msat, which must be relayed to the next hop.
1921 pub extern "C" fn RouteHintHop_set_htlc_minimum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
1922 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1923 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = local_val;
1925 /// The maximum value in msat available for routing with a single HTLC.
1927 pub extern "C" fn RouteHintHop_get_htlc_maximum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
1928 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
1929 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() }) };
1932 /// The maximum value in msat available for routing with a single HTLC.
1934 pub extern "C" fn RouteHintHop_set_htlc_maximum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
1935 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1936 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
1938 /// Constructs a new RouteHintHop given each field
1941 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 {
1942 let mut local_htlc_minimum_msat_arg = if htlc_minimum_msat_arg.is_some() { Some( { htlc_minimum_msat_arg.take() }) } else { None };
1943 let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
1944 RouteHintHop { inner: ObjOps::heap_alloc(nativeRouteHintHop {
1945 src_node_id: src_node_id_arg.into_rust(),
1946 short_channel_id: short_channel_id_arg,
1947 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
1948 cltv_expiry_delta: cltv_expiry_delta_arg,
1949 htlc_minimum_msat: local_htlc_minimum_msat_arg,
1950 htlc_maximum_msat: local_htlc_maximum_msat_arg,
1951 }), is_owned: true }
1953 impl Clone for RouteHintHop {
1954 fn clone(&self) -> Self {
1956 inner: if <*mut nativeRouteHintHop>::is_null(self.inner) { core::ptr::null_mut() } else {
1957 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1963 /// Used only if an object of this type is returned as a trait impl by a method
1964 pub(crate) extern "C" fn RouteHintHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
1965 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHintHop)).clone() })) as *mut c_void
1968 /// Creates a copy of the RouteHintHop
1969 pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop {
1972 /// Generates a non-cryptographic 64-bit hash of the RouteHintHop.
1974 pub extern "C" fn RouteHintHop_hash(o: &RouteHintHop) -> u64 {
1975 if o.inner.is_null() { return 0; }
1976 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1977 #[allow(deprecated)]
1978 let mut hasher = core::hash::SipHasher::new();
1979 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1980 core::hash::Hasher::finish(&hasher)
1982 /// Checks if two RouteHintHops contain equal inner contents.
1983 /// This ignores pointers and is_owned flags and looks at the values in fields.
1984 /// Two objects with NULL inner values will be considered "equal" here.
1986 pub extern "C" fn RouteHintHop_eq(a: &RouteHintHop, b: &RouteHintHop) -> bool {
1987 if a.inner == b.inner { return true; }
1988 if a.inner.is_null() || b.inner.is_null() { return false; }
1989 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1992 /// Serialize the RouteHintHop object into a byte array which can be read by RouteHintHop_read
1993 pub extern "C" fn RouteHintHop_write(obj: &crate::lightning::routing::router::RouteHintHop) -> crate::c_types::derived::CVec_u8Z {
1994 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1997 pub(crate) extern "C" fn RouteHintHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1998 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHintHop) })
2001 /// Read a RouteHintHop from a byte array, created by RouteHintHop_write
2002 pub extern "C" fn RouteHintHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintHopDecodeErrorZ {
2003 let res: Result<lightning::routing::router::RouteHintHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2004 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() };
2007 /// Finds a route from us (payer) to the given target node (payee).
2009 /// If the payee provided features in their invoice, they should be provided via `params.payee`.
2010 /// Without this, MPP will only be used if the payee's features are available in the network graph.
2012 /// Private routing paths between a public node and the target may be included in `params.payee`.
2014 /// If some channels aren't announced, it may be useful to fill in `first_hops` with the results
2015 /// from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
2016 /// from `network_graph` will be ignored, and only those in `first_hops` will be used.
2018 /// The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
2019 /// However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
2020 /// `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
2024 /// May be used to re-compute a [`Route`] when handling a [`Event::PaymentPathFailed`]. Any
2025 /// adjustments to the [`NetworkGraph`] and channel scores should be made prior to calling this
2030 /// Panics if first_hops contains channels without short_channel_ids;
2031 /// [`ChannelManager::list_usable_channels`] will never include such channels.
2033 /// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
2034 /// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
2035 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
2037 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
2039 pub extern "C" fn find_route(mut our_node_pubkey: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, network_graph: &crate::lightning::routing::gossip::NetworkGraph, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut logger: crate::lightning::util::logger::Logger, scorer: &crate::lightning::routing::scoring::Score, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
2040 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[..]);
2041 let mut ret = lightning::routing::router::find_route::<crate::lightning::util::logger::Logger, crate::lightning::util::logger::Logger, crate::lightning::routing::scoring::Score>(&our_node_pubkey.into_rust(), route_params.get_native_ref(), network_graph.get_native_ref(), local_first_hops, logger, scorer, unsafe { &*random_seed_bytes});
2042 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() };
2046 /// Construct a route from us (payer) to the target node (payee) via the given hops (which should
2047 /// exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
2049 /// Re-uses logic from `find_route`, so the restrictions described there also apply here.
2051 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 {
2052 let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { item.into_rust() }); };
2053 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});
2054 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() };