Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning / routing / router.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
9 //! The router finds paths within a [`NetworkGraph`] for a payment.
10
11 use alloc::str::FromStr;
12 use alloc::string::String;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
19
20
21 use lightning::routing::router::DefaultRouter as nativeDefaultRouterImport;
22 pub(crate) type nativeDefaultRouter = nativeDefaultRouterImport<&'static lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, crate::lightning::util::logger::Logger, crate::lightning::routing::scoring::LockableScore>;
23
24 /// A [`Router`] implemented using [`find_route`].
25 #[must_use]
26 #[repr(C)]
27 pub struct DefaultRouter {
28         /// A pointer to the opaque Rust object.
29
30         /// Nearly everywhere, inner must be non-null, however in places where
31         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
32         pub inner: *mut nativeDefaultRouter,
33         /// Indicates that this is the only struct which contains the same pointer.
34
35         /// Rust functions which take ownership of an object provided via an argument require
36         /// this to be true and invalidate the object pointed to by inner.
37         pub is_owned: bool,
38 }
39
40 impl Drop for DefaultRouter {
41         fn drop(&mut self) {
42                 if self.is_owned && !<*mut nativeDefaultRouter>::is_null(self.inner) {
43                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
44                 }
45         }
46 }
47 /// Frees any resources used by the DefaultRouter, if is_owned is set and inner is non-NULL.
48 #[no_mangle]
49 pub extern "C" fn DefaultRouter_free(this_obj: DefaultRouter) { }
50 #[allow(unused)]
51 /// Used only if an object of this type is returned as a trait impl by a method
52 pub(crate) extern "C" fn DefaultRouter_free_void(this_ptr: *mut c_void) {
53         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDefaultRouter) };
54 }
55 #[allow(unused)]
56 impl DefaultRouter {
57         pub(crate) fn get_native_ref(&self) -> &'static nativeDefaultRouter {
58                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
59         }
60         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDefaultRouter {
61                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
62         }
63         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
64         pub(crate) fn take_inner(mut self) -> *mut nativeDefaultRouter {
65                 assert!(self.is_owned);
66                 let ret = ObjOps::untweak_ptr(self.inner);
67                 self.inner = core::ptr::null_mut();
68                 ret
69         }
70 }
71 /// Creates a new router.
72 #[must_use]
73 #[no_mangle]
74 pub extern "C" fn DefaultRouter_new(network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut logger: crate::lightning::util::logger::Logger, mut random_seed_bytes: crate::c_types::ThirtyTwoBytes, mut scorer: crate::lightning::routing::scoring::LockableScore, mut score_params: crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> crate::lightning::routing::router::DefaultRouter {
75         let mut ret = lightning::routing::router::DefaultRouter::new(network_graph.get_native_ref(), logger, random_seed_bytes.data, scorer, *unsafe { Box::from_raw(score_params.take_inner()) });
76         crate::lightning::routing::router::DefaultRouter { inner: ObjOps::heap_alloc(ret), is_owned: true }
77 }
78
79 impl From<nativeDefaultRouter> for crate::lightning::routing::router::Router {
80         fn from(obj: nativeDefaultRouter) -> Self {
81                 let mut rust_obj = DefaultRouter { inner: ObjOps::heap_alloc(obj), is_owned: true };
82                 let mut ret = DefaultRouter_as_Router(&rust_obj);
83                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
84                 rust_obj.inner = core::ptr::null_mut();
85                 ret.free = Some(DefaultRouter_free_void);
86                 ret
87         }
88 }
89 /// Constructs a new Router which calls the relevant methods on this_arg.
90 /// This copies the `inner` pointer in this_arg and thus the returned Router must be freed before this_arg is
91 #[no_mangle]
92 pub extern "C" fn DefaultRouter_as_Router(this_arg: &DefaultRouter) -> crate::lightning::routing::router::Router {
93         crate::lightning::routing::router::Router {
94                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
95                 free: None,
96                 find_route: DefaultRouter_Router_find_route,
97                 find_route_with_id: DefaultRouter_Router_find_route_with_id,
98         }
99 }
100
101 #[must_use]
102 extern "C" fn DefaultRouter_Router_find_route(this_arg: *const c_void, mut payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
103         let mut local_first_hops_base = if first_hops == core::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { item.get_native_ref() }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]);
104         let mut ret = <nativeDefaultRouter as lightning::routing::router::Router<>>::find_route(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &payer.into_rust(), route_params.get_native_ref(), local_first_hops, *unsafe { Box::from_raw(inflight_htlcs.take_inner()) });
105         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
106         local_ret
107 }
108 #[must_use]
109 extern "C" fn DefaultRouter_Router_find_route_with_id(this_arg: *const c_void, mut payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs, mut _payment_hash: crate::c_types::ThirtyTwoBytes, mut _payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
110         let mut local_first_hops_base = if first_hops == core::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { item.get_native_ref() }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]);
111         let mut ret = <nativeDefaultRouter as lightning::routing::router::Router<>>::find_route_with_id(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &payer.into_rust(), route_params.get_native_ref(), local_first_hops, *unsafe { Box::from_raw(inflight_htlcs.take_inner()) }, ::lightning::ln::PaymentHash(_payment_hash.data), ::lightning::ln::channelmanager::PaymentId(_payment_id.data));
112         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
113         local_ret
114 }
115
116 /// A trait defining behavior for routing a payment.
117 #[repr(C)]
118 pub struct Router {
119         /// An opaque pointer which is passed to your function implementations as an argument.
120         /// This has no meaning in the LDK, and can be NULL or any other value.
121         pub this_arg: *mut c_void,
122         /// Finds a [`Route`] for a payment between the given `payer` and a payee.
123         ///
124         /// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
125         /// and [`RouteParameters::final_value_msat`], respectively.
126         ///
127         /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
128         pub find_route: extern "C" fn (this_arg: *const c_void, payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CResult_RouteLightningErrorZ,
129         /// Finds a [`Route`] for a payment between the given `payer` and a payee.
130         ///
131         /// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
132         /// and [`RouteParameters::final_value_msat`], respectively.
133         ///
134         /// Includes a [`PaymentHash`] and a [`PaymentId`] to be able to correlate the request with a specific
135         /// payment.
136         ///
137         /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
138         pub find_route_with_id: extern "C" fn (this_arg: *const c_void, payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs, _payment_hash: crate::c_types::ThirtyTwoBytes, _payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_RouteLightningErrorZ,
139         /// Frees any resources associated with this object given its this_arg pointer.
140         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
141         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
142 }
143 unsafe impl Send for Router {}
144 unsafe impl Sync for Router {}
145 pub(crate) fn Router_clone_fields(orig: &Router) -> Router {
146         Router {
147                 this_arg: orig.this_arg,
148                 find_route: Clone::clone(&orig.find_route),
149                 find_route_with_id: Clone::clone(&orig.find_route_with_id),
150                 free: Clone::clone(&orig.free),
151         }
152 }
153
154 use lightning::routing::router::Router as rustRouter;
155 impl rustRouter for Router {
156         fn find_route(&self, mut payer: &bitcoin::secp256k1::PublicKey, mut route_params: &lightning::routing::router::RouteParameters, mut first_hops: Option<&[&lightning::ln::channelmanager::ChannelDetails]>, mut inflight_htlcs: lightning::routing::router::InFlightHtlcs) -> Result<lightning::routing::router::Route, lightning::ln::msgs::LightningError> {
157                 let mut local_first_hops_base = if first_hops.is_none() { SmartPtr::null() } else { SmartPtr::from_obj( { let mut local_first_hops_0 = Vec::new(); for item in (first_hops.unwrap()).iter() { local_first_hops_0.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); }; local_first_hops_0.into() }) }; let mut local_first_hops = *local_first_hops_base;
158                 let mut ret = (self.find_route)(self.this_arg, crate::c_types::PublicKey::from_rust(&payer), &crate::lightning::routing::router::RouteParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((route_params as *const lightning::routing::router::RouteParameters<>) as *mut _) }, is_owned: false }, local_first_hops, crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(inflight_htlcs), is_owned: true });
159                 let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
160                 local_ret
161         }
162         fn find_route_with_id(&self, mut payer: &bitcoin::secp256k1::PublicKey, mut route_params: &lightning::routing::router::RouteParameters, mut first_hops: Option<&[&lightning::ln::channelmanager::ChannelDetails]>, mut inflight_htlcs: lightning::routing::router::InFlightHtlcs, mut _payment_hash: lightning::ln::PaymentHash, mut _payment_id: lightning::ln::channelmanager::PaymentId) -> Result<lightning::routing::router::Route, lightning::ln::msgs::LightningError> {
163                 let mut local_first_hops_base = if first_hops.is_none() { SmartPtr::null() } else { SmartPtr::from_obj( { let mut local_first_hops_0 = Vec::new(); for item in (first_hops.unwrap()).iter() { local_first_hops_0.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); }; local_first_hops_0.into() }) }; let mut local_first_hops = *local_first_hops_base;
164                 let mut ret = (self.find_route_with_id)(self.this_arg, crate::c_types::PublicKey::from_rust(&payer), &crate::lightning::routing::router::RouteParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((route_params as *const lightning::routing::router::RouteParameters<>) as *mut _) }, is_owned: false }, local_first_hops, crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(inflight_htlcs), is_owned: true }, crate::c_types::ThirtyTwoBytes { data: _payment_hash.0 }, crate::c_types::ThirtyTwoBytes { data: _payment_id.0 });
165                 let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
166                 local_ret
167         }
168 }
169
170 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
171 // directly as a Deref trait in higher-level structs:
172 impl core::ops::Deref for Router {
173         type Target = Self;
174         fn deref(&self) -> &Self {
175                 self
176         }
177 }
178 impl core::ops::DerefMut for Router {
179         fn deref_mut(&mut self) -> &mut Self {
180                 self
181         }
182 }
183 /// Calls the free function if one is set
184 #[no_mangle]
185 pub extern "C" fn Router_free(this_ptr: Router) { }
186 impl Drop for Router {
187         fn drop(&mut self) {
188                 if let Some(f) = self.free {
189                         f(self.this_arg);
190                 }
191         }
192 }
193
194 use lightning::routing::router::ScorerAccountingForInFlightHtlcs as nativeScorerAccountingForInFlightHtlcsImport;
195 pub(crate) type nativeScorerAccountingForInFlightHtlcs = nativeScorerAccountingForInFlightHtlcsImport<'static, crate::lightning::routing::scoring::ScoreLookUp>;
196
197 /// [`ScoreLookUp`] implementation that factors in in-flight HTLC liquidity.
198 ///
199 /// Useful for custom [`Router`] implementations to wrap their [`ScoreLookUp`] on-the-fly when calling
200 /// [`find_route`].
201 ///
202 /// [`ScoreLookUp`]: crate::routing::scoring::ScoreLookUp
203 #[must_use]
204 #[repr(C)]
205 pub struct ScorerAccountingForInFlightHtlcs {
206         /// A pointer to the opaque Rust object.
207
208         /// Nearly everywhere, inner must be non-null, however in places where
209         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
210         pub inner: *mut nativeScorerAccountingForInFlightHtlcs,
211         /// Indicates that this is the only struct which contains the same pointer.
212
213         /// Rust functions which take ownership of an object provided via an argument require
214         /// this to be true and invalidate the object pointed to by inner.
215         pub is_owned: bool,
216 }
217
218 impl Drop for ScorerAccountingForInFlightHtlcs {
219         fn drop(&mut self) {
220                 if self.is_owned && !<*mut nativeScorerAccountingForInFlightHtlcs>::is_null(self.inner) {
221                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
222                 }
223         }
224 }
225 /// Frees any resources used by the ScorerAccountingForInFlightHtlcs, if is_owned is set and inner is non-NULL.
226 #[no_mangle]
227 pub extern "C" fn ScorerAccountingForInFlightHtlcs_free(this_obj: ScorerAccountingForInFlightHtlcs) { }
228 #[allow(unused)]
229 /// Used only if an object of this type is returned as a trait impl by a method
230 pub(crate) extern "C" fn ScorerAccountingForInFlightHtlcs_free_void(this_ptr: *mut c_void) {
231         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeScorerAccountingForInFlightHtlcs) };
232 }
233 #[allow(unused)]
234 impl ScorerAccountingForInFlightHtlcs {
235         pub(crate) fn get_native_ref(&self) -> &'static nativeScorerAccountingForInFlightHtlcs {
236                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
237         }
238         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeScorerAccountingForInFlightHtlcs {
239                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
240         }
241         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
242         pub(crate) fn take_inner(mut self) -> *mut nativeScorerAccountingForInFlightHtlcs {
243                 assert!(self.is_owned);
244                 let ret = ObjOps::untweak_ptr(self.inner);
245                 self.inner = core::ptr::null_mut();
246                 ret
247         }
248 }
249 /// Initialize a new `ScorerAccountingForInFlightHtlcs`.
250 #[must_use]
251 #[no_mangle]
252 pub extern "C" fn ScorerAccountingForInFlightHtlcs_new(mut scorer: crate::lightning::routing::scoring::ScoreLookUp, inflight_htlcs: &crate::lightning::routing::router::InFlightHtlcs) -> crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs {
253         let mut ret = lightning::routing::router::ScorerAccountingForInFlightHtlcs::new(scorer, inflight_htlcs.get_native_ref());
254         crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
255 }
256
257 impl From<nativeScorerAccountingForInFlightHtlcs> for crate::lightning::routing::scoring::ScoreLookUp {
258         fn from(obj: nativeScorerAccountingForInFlightHtlcs) -> Self {
259                 let mut rust_obj = ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(obj), is_owned: true };
260                 let mut ret = ScorerAccountingForInFlightHtlcs_as_ScoreLookUp(&rust_obj);
261                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
262                 rust_obj.inner = core::ptr::null_mut();
263                 ret.free = Some(ScorerAccountingForInFlightHtlcs_free_void);
264                 ret
265         }
266 }
267 /// Constructs a new ScoreLookUp which calls the relevant methods on this_arg.
268 /// This copies the `inner` pointer in this_arg and thus the returned ScoreLookUp must be freed before this_arg is
269 #[no_mangle]
270 pub extern "C" fn ScorerAccountingForInFlightHtlcs_as_ScoreLookUp(this_arg: &ScorerAccountingForInFlightHtlcs) -> crate::lightning::routing::scoring::ScoreLookUp {
271         crate::lightning::routing::scoring::ScoreLookUp {
272                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
273                 free: None,
274                 channel_penalty_msat: ScorerAccountingForInFlightHtlcs_ScoreLookUp_channel_penalty_msat,
275         }
276 }
277
278 #[must_use]
279 extern "C" fn ScorerAccountingForInFlightHtlcs_ScoreLookUp_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut usage: crate::lightning::routing::scoring::ChannelUsage, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> u64 {
280         let mut ret = <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::ScoreLookUp<>>::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, short_channel_id, source.get_native_ref(), target.get_native_ref(), *unsafe { Box::from_raw(usage.take_inner()) }, score_params.get_native_ref());
281         ret
282 }
283
284
285 use lightning::routing::router::InFlightHtlcs as nativeInFlightHtlcsImport;
286 pub(crate) type nativeInFlightHtlcs = nativeInFlightHtlcsImport;
287
288 /// A data structure for tracking in-flight HTLCs. May be used during pathfinding to account for
289 /// in-use channel liquidity.
290 #[must_use]
291 #[repr(C)]
292 pub struct InFlightHtlcs {
293         /// A pointer to the opaque Rust object.
294
295         /// Nearly everywhere, inner must be non-null, however in places where
296         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
297         pub inner: *mut nativeInFlightHtlcs,
298         /// Indicates that this is the only struct which contains the same pointer.
299
300         /// Rust functions which take ownership of an object provided via an argument require
301         /// this to be true and invalidate the object pointed to by inner.
302         pub is_owned: bool,
303 }
304
305 impl Drop for InFlightHtlcs {
306         fn drop(&mut self) {
307                 if self.is_owned && !<*mut nativeInFlightHtlcs>::is_null(self.inner) {
308                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
309                 }
310         }
311 }
312 /// Frees any resources used by the InFlightHtlcs, if is_owned is set and inner is non-NULL.
313 #[no_mangle]
314 pub extern "C" fn InFlightHtlcs_free(this_obj: InFlightHtlcs) { }
315 #[allow(unused)]
316 /// Used only if an object of this type is returned as a trait impl by a method
317 pub(crate) extern "C" fn InFlightHtlcs_free_void(this_ptr: *mut c_void) {
318         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInFlightHtlcs) };
319 }
320 #[allow(unused)]
321 impl InFlightHtlcs {
322         pub(crate) fn get_native_ref(&self) -> &'static nativeInFlightHtlcs {
323                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
324         }
325         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInFlightHtlcs {
326                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
327         }
328         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
329         pub(crate) fn take_inner(mut self) -> *mut nativeInFlightHtlcs {
330                 assert!(self.is_owned);
331                 let ret = ObjOps::untweak_ptr(self.inner);
332                 self.inner = core::ptr::null_mut();
333                 ret
334         }
335 }
336 impl Clone for InFlightHtlcs {
337         fn clone(&self) -> Self {
338                 Self {
339                         inner: if <*mut nativeInFlightHtlcs>::is_null(self.inner) { core::ptr::null_mut() } else {
340                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
341                         is_owned: true,
342                 }
343         }
344 }
345 #[allow(unused)]
346 /// Used only if an object of this type is returned as a trait impl by a method
347 pub(crate) extern "C" fn InFlightHtlcs_clone_void(this_ptr: *const c_void) -> *mut c_void {
348         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInFlightHtlcs)).clone() })) as *mut c_void
349 }
350 #[no_mangle]
351 /// Creates a copy of the InFlightHtlcs
352 pub extern "C" fn InFlightHtlcs_clone(orig: &InFlightHtlcs) -> InFlightHtlcs {
353         orig.clone()
354 }
355 /// Constructs an empty `InFlightHtlcs`.
356 #[must_use]
357 #[no_mangle]
358 pub extern "C" fn InFlightHtlcs_new() -> crate::lightning::routing::router::InFlightHtlcs {
359         let mut ret = lightning::routing::router::InFlightHtlcs::new();
360         crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
361 }
362
363 /// Takes in a path with payer's node id and adds the path's details to `InFlightHtlcs`.
364 #[no_mangle]
365 pub extern "C" fn InFlightHtlcs_process_path(this_arg: &mut crate::lightning::routing::router::InFlightHtlcs, path: &crate::lightning::routing::router::Path, mut payer_node_id: crate::c_types::PublicKey) {
366         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::router::nativeInFlightHtlcs)) }.process_path(path.get_native_ref(), payer_node_id.into_rust())
367 }
368
369 /// Adds a known HTLC given the public key of the HTLC source, target, and short channel
370 /// id.
371 #[no_mangle]
372 pub extern "C" fn InFlightHtlcs_add_inflight_htlc(this_arg: &mut crate::lightning::routing::router::InFlightHtlcs, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut channel_scid: u64, mut used_msat: u64) {
373         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::router::nativeInFlightHtlcs)) }.add_inflight_htlc(source.get_native_ref(), target.get_native_ref(), channel_scid, used_msat)
374 }
375
376 /// Returns liquidity in msat given the public key of the HTLC source, target, and short channel
377 /// id.
378 #[must_use]
379 #[no_mangle]
380 pub extern "C" fn InFlightHtlcs_used_liquidity_msat(this_arg: &crate::lightning::routing::router::InFlightHtlcs, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut channel_scid: u64) -> crate::c_types::derived::COption_u64Z {
381         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.used_liquidity_msat(source.get_native_ref(), target.get_native_ref(), channel_scid);
382         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap() }) };
383         local_ret
384 }
385
386 #[no_mangle]
387 /// Serialize the InFlightHtlcs object into a byte array which can be read by InFlightHtlcs_read
388 pub extern "C" fn InFlightHtlcs_write(obj: &crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CVec_u8Z {
389         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
390 }
391 #[no_mangle]
392 pub(crate) extern "C" fn InFlightHtlcs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
393         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInFlightHtlcs) })
394 }
395 #[no_mangle]
396 /// Read a InFlightHtlcs from a byte array, created by InFlightHtlcs_write
397 pub extern "C" fn InFlightHtlcs_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InFlightHtlcsDecodeErrorZ {
398         let res: Result<lightning::routing::router::InFlightHtlcs, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
399         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
400         local_res
401 }
402
403 use lightning::routing::router::RouteHop as nativeRouteHopImport;
404 pub(crate) type nativeRouteHop = nativeRouteHopImport;
405
406 /// A hop in a route, and additional metadata about it. \"Hop\" is defined as a node and the channel
407 /// that leads to it.
408 #[must_use]
409 #[repr(C)]
410 pub struct RouteHop {
411         /// A pointer to the opaque Rust object.
412
413         /// Nearly everywhere, inner must be non-null, however in places where
414         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
415         pub inner: *mut nativeRouteHop,
416         /// Indicates that this is the only struct which contains the same pointer.
417
418         /// Rust functions which take ownership of an object provided via an argument require
419         /// this to be true and invalidate the object pointed to by inner.
420         pub is_owned: bool,
421 }
422
423 impl Drop for RouteHop {
424         fn drop(&mut self) {
425                 if self.is_owned && !<*mut nativeRouteHop>::is_null(self.inner) {
426                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
427                 }
428         }
429 }
430 /// Frees any resources used by the RouteHop, if is_owned is set and inner is non-NULL.
431 #[no_mangle]
432 pub extern "C" fn RouteHop_free(this_obj: RouteHop) { }
433 #[allow(unused)]
434 /// Used only if an object of this type is returned as a trait impl by a method
435 pub(crate) extern "C" fn RouteHop_free_void(this_ptr: *mut c_void) {
436         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHop) };
437 }
438 #[allow(unused)]
439 impl RouteHop {
440         pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHop {
441                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
442         }
443         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHop {
444                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
445         }
446         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
447         pub(crate) fn take_inner(mut self) -> *mut nativeRouteHop {
448                 assert!(self.is_owned);
449                 let ret = ObjOps::untweak_ptr(self.inner);
450                 self.inner = core::ptr::null_mut();
451                 ret
452         }
453 }
454 /// The node_id of the node at this hop.
455 #[no_mangle]
456 pub extern "C" fn RouteHop_get_pubkey(this_ptr: &RouteHop) -> crate::c_types::PublicKey {
457         let mut inner_val = &mut this_ptr.get_native_mut_ref().pubkey;
458         crate::c_types::PublicKey::from_rust(&inner_val)
459 }
460 /// The node_id of the node at this hop.
461 #[no_mangle]
462 pub extern "C" fn RouteHop_set_pubkey(this_ptr: &mut RouteHop, mut val: crate::c_types::PublicKey) {
463         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.pubkey = val.into_rust();
464 }
465 /// The node_announcement features of the node at this hop. For the last hop, these may be
466 /// amended to match the features present in the invoice this node generated.
467 #[no_mangle]
468 pub extern "C" fn RouteHop_get_node_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::NodeFeatures {
469         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_features;
470         crate::lightning::ln::features::NodeFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::NodeFeatures<>) as *mut _) }, is_owned: false }
471 }
472 /// The node_announcement features of the node at this hop. For the last hop, these may be
473 /// amended to match the features present in the invoice this node generated.
474 #[no_mangle]
475 pub extern "C" fn RouteHop_set_node_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::NodeFeatures) {
476         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_features = *unsafe { Box::from_raw(val.take_inner()) };
477 }
478 /// The channel that should be used from the previous hop to reach this node.
479 #[no_mangle]
480 pub extern "C" fn RouteHop_get_short_channel_id(this_ptr: &RouteHop) -> u64 {
481         let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
482         *inner_val
483 }
484 /// The channel that should be used from the previous hop to reach this node.
485 #[no_mangle]
486 pub extern "C" fn RouteHop_set_short_channel_id(this_ptr: &mut RouteHop, mut val: u64) {
487         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
488 }
489 /// The channel_announcement features of the channel that should be used from the previous hop
490 /// to reach this node.
491 #[no_mangle]
492 pub extern "C" fn RouteHop_get_channel_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::ChannelFeatures {
493         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_features;
494         crate::lightning::ln::features::ChannelFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::ChannelFeatures<>) as *mut _) }, is_owned: false }
495 }
496 /// The channel_announcement features of the channel that should be used from the previous hop
497 /// to reach this node.
498 #[no_mangle]
499 pub extern "C" fn RouteHop_set_channel_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::ChannelFeatures) {
500         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_features = *unsafe { Box::from_raw(val.take_inner()) };
501 }
502 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
503 /// If this is the last hop in [`Path::hops`]:
504 /// * if we're sending to a [`BlindedPath`], this is the fee paid for use of the entire blinded path
505 /// * otherwise, this is the full value of this [`Path`]'s part of the payment
506 ///
507 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
508 #[no_mangle]
509 pub extern "C" fn RouteHop_get_fee_msat(this_ptr: &RouteHop) -> u64 {
510         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_msat;
511         *inner_val
512 }
513 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
514 /// If this is the last hop in [`Path::hops`]:
515 /// * if we're sending to a [`BlindedPath`], this is the fee paid for use of the entire blinded path
516 /// * otherwise, this is the full value of this [`Path`]'s part of the payment
517 ///
518 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
519 #[no_mangle]
520 pub extern "C" fn RouteHop_set_fee_msat(this_ptr: &mut RouteHop, mut val: u64) {
521         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_msat = val;
522 }
523 /// The CLTV delta added for this hop.
524 /// If this is the last hop in [`Path::hops`]:
525 /// * if we're sending to a [`BlindedPath`], this is the CLTV delta for the entire blinded path
526 /// * otherwise, this is the CLTV delta expected at the destination
527 ///
528 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
529 #[no_mangle]
530 pub extern "C" fn RouteHop_get_cltv_expiry_delta(this_ptr: &RouteHop) -> u32 {
531         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
532         *inner_val
533 }
534 /// The CLTV delta added for this hop.
535 /// If this is the last hop in [`Path::hops`]:
536 /// * if we're sending to a [`BlindedPath`], this is the CLTV delta for the entire blinded path
537 /// * otherwise, this is the CLTV delta expected at the destination
538 ///
539 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
540 #[no_mangle]
541 pub extern "C" fn RouteHop_set_cltv_expiry_delta(this_ptr: &mut RouteHop, mut val: u32) {
542         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
543 }
544 /// Indicates whether this hop is possibly announced in the public network graph.
545 ///
546 /// Will be `true` if there is a possibility that the channel is publicly known, i.e., if we
547 /// either know for sure it's announced in the public graph, or if any public channels exist
548 /// for which the given `short_channel_id` could be an alias for. Will be `false` if we believe
549 /// the channel to be unannounced.
550 ///
551 /// Will be `true` for objects serialized with LDK version 0.0.116 and before.
552 #[no_mangle]
553 pub extern "C" fn RouteHop_get_maybe_announced_channel(this_ptr: &RouteHop) -> bool {
554         let mut inner_val = &mut this_ptr.get_native_mut_ref().maybe_announced_channel;
555         *inner_val
556 }
557 /// Indicates whether this hop is possibly announced in the public network graph.
558 ///
559 /// Will be `true` if there is a possibility that the channel is publicly known, i.e., if we
560 /// either know for sure it's announced in the public graph, or if any public channels exist
561 /// for which the given `short_channel_id` could be an alias for. Will be `false` if we believe
562 /// the channel to be unannounced.
563 ///
564 /// Will be `true` for objects serialized with LDK version 0.0.116 and before.
565 #[no_mangle]
566 pub extern "C" fn RouteHop_set_maybe_announced_channel(this_ptr: &mut RouteHop, mut val: bool) {
567         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.maybe_announced_channel = val;
568 }
569 /// Constructs a new RouteHop given each field
570 #[must_use]
571 #[no_mangle]
572 pub extern "C" fn RouteHop_new(mut pubkey_arg: crate::c_types::PublicKey, mut node_features_arg: crate::lightning::ln::features::NodeFeatures, mut short_channel_id_arg: u64, mut channel_features_arg: crate::lightning::ln::features::ChannelFeatures, mut fee_msat_arg: u64, mut cltv_expiry_delta_arg: u32, mut maybe_announced_channel_arg: bool) -> RouteHop {
573         RouteHop { inner: ObjOps::heap_alloc(nativeRouteHop {
574                 pubkey: pubkey_arg.into_rust(),
575                 node_features: *unsafe { Box::from_raw(node_features_arg.take_inner()) },
576                 short_channel_id: short_channel_id_arg,
577                 channel_features: *unsafe { Box::from_raw(channel_features_arg.take_inner()) },
578                 fee_msat: fee_msat_arg,
579                 cltv_expiry_delta: cltv_expiry_delta_arg,
580                 maybe_announced_channel: maybe_announced_channel_arg,
581         }), is_owned: true }
582 }
583 impl Clone for RouteHop {
584         fn clone(&self) -> Self {
585                 Self {
586                         inner: if <*mut nativeRouteHop>::is_null(self.inner) { core::ptr::null_mut() } else {
587                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
588                         is_owned: true,
589                 }
590         }
591 }
592 #[allow(unused)]
593 /// Used only if an object of this type is returned as a trait impl by a method
594 pub(crate) extern "C" fn RouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
595         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHop)).clone() })) as *mut c_void
596 }
597 #[no_mangle]
598 /// Creates a copy of the RouteHop
599 pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop {
600         orig.clone()
601 }
602 /// Generates a non-cryptographic 64-bit hash of the RouteHop.
603 #[no_mangle]
604 pub extern "C" fn RouteHop_hash(o: &RouteHop) -> u64 {
605         if o.inner.is_null() { return 0; }
606         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
607         #[allow(deprecated)]
608         let mut hasher = core::hash::SipHasher::new();
609         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
610         core::hash::Hasher::finish(&hasher)
611 }
612 /// Checks if two RouteHops contain equal inner contents.
613 /// This ignores pointers and is_owned flags and looks at the values in fields.
614 /// Two objects with NULL inner values will be considered "equal" here.
615 #[no_mangle]
616 pub extern "C" fn RouteHop_eq(a: &RouteHop, b: &RouteHop) -> bool {
617         if a.inner == b.inner { return true; }
618         if a.inner.is_null() || b.inner.is_null() { return false; }
619         if a.get_native_ref() == b.get_native_ref() { true } else { false }
620 }
621 #[no_mangle]
622 /// Serialize the RouteHop object into a byte array which can be read by RouteHop_read
623 pub extern "C" fn RouteHop_write(obj: &crate::lightning::routing::router::RouteHop) -> crate::c_types::derived::CVec_u8Z {
624         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
625 }
626 #[no_mangle]
627 pub(crate) extern "C" fn RouteHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
628         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHop) })
629 }
630 #[no_mangle]
631 /// Read a RouteHop from a byte array, created by RouteHop_write
632 pub extern "C" fn RouteHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHopDecodeErrorZ {
633         let res: Result<lightning::routing::router::RouteHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
634         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
635         local_res
636 }
637
638 use lightning::routing::router::BlindedTail as nativeBlindedTailImport;
639 pub(crate) type nativeBlindedTail = nativeBlindedTailImport;
640
641 /// The blinded portion of a [`Path`], if we're routing to a recipient who provided blinded paths in
642 /// their [`Bolt12Invoice`].
643 ///
644 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
645 #[must_use]
646 #[repr(C)]
647 pub struct BlindedTail {
648         /// A pointer to the opaque Rust object.
649
650         /// Nearly everywhere, inner must be non-null, however in places where
651         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
652         pub inner: *mut nativeBlindedTail,
653         /// Indicates that this is the only struct which contains the same pointer.
654
655         /// Rust functions which take ownership of an object provided via an argument require
656         /// this to be true and invalidate the object pointed to by inner.
657         pub is_owned: bool,
658 }
659
660 impl Drop for BlindedTail {
661         fn drop(&mut self) {
662                 if self.is_owned && !<*mut nativeBlindedTail>::is_null(self.inner) {
663                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
664                 }
665         }
666 }
667 /// Frees any resources used by the BlindedTail, if is_owned is set and inner is non-NULL.
668 #[no_mangle]
669 pub extern "C" fn BlindedTail_free(this_obj: BlindedTail) { }
670 #[allow(unused)]
671 /// Used only if an object of this type is returned as a trait impl by a method
672 pub(crate) extern "C" fn BlindedTail_free_void(this_ptr: *mut c_void) {
673         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedTail) };
674 }
675 #[allow(unused)]
676 impl BlindedTail {
677         pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedTail {
678                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
679         }
680         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedTail {
681                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
682         }
683         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
684         pub(crate) fn take_inner(mut self) -> *mut nativeBlindedTail {
685                 assert!(self.is_owned);
686                 let ret = ObjOps::untweak_ptr(self.inner);
687                 self.inner = core::ptr::null_mut();
688                 ret
689         }
690 }
691 /// The hops of the [`BlindedPath`] provided by the recipient.
692 ///
693 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
694 #[no_mangle]
695 pub extern "C" fn BlindedTail_get_hops(this_ptr: &BlindedTail) -> crate::c_types::derived::CVec_BlindedHopZ {
696         let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
697         let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::blinded_path::BlindedHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::blinded_path::BlindedHop<>) as *mut _) }, is_owned: false } }); };
698         local_inner_val.into()
699 }
700 /// The hops of the [`BlindedPath`] provided by the recipient.
701 ///
702 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
703 #[no_mangle]
704 pub extern "C" fn BlindedTail_set_hops(this_ptr: &mut BlindedTail, mut val: crate::c_types::derived::CVec_BlindedHopZ) {
705         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
706         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
707 }
708 /// The blinding point of the [`BlindedPath`] provided by the recipient.
709 ///
710 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
711 #[no_mangle]
712 pub extern "C" fn BlindedTail_get_blinding_point(this_ptr: &BlindedTail) -> crate::c_types::PublicKey {
713         let mut inner_val = &mut this_ptr.get_native_mut_ref().blinding_point;
714         crate::c_types::PublicKey::from_rust(&inner_val)
715 }
716 /// The blinding point of the [`BlindedPath`] provided by the recipient.
717 ///
718 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
719 #[no_mangle]
720 pub extern "C" fn BlindedTail_set_blinding_point(this_ptr: &mut BlindedTail, mut val: crate::c_types::PublicKey) {
721         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinding_point = val.into_rust();
722 }
723 /// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
724 /// inferring the destination. May be 0.
725 #[no_mangle]
726 pub extern "C" fn BlindedTail_get_excess_final_cltv_expiry_delta(this_ptr: &BlindedTail) -> u32 {
727         let mut inner_val = &mut this_ptr.get_native_mut_ref().excess_final_cltv_expiry_delta;
728         *inner_val
729 }
730 /// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
731 /// inferring the destination. May be 0.
732 #[no_mangle]
733 pub extern "C" fn BlindedTail_set_excess_final_cltv_expiry_delta(this_ptr: &mut BlindedTail, mut val: u32) {
734         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.excess_final_cltv_expiry_delta = val;
735 }
736 /// The total amount paid on this [`Path`], excluding the fees.
737 #[no_mangle]
738 pub extern "C" fn BlindedTail_get_final_value_msat(this_ptr: &BlindedTail) -> u64 {
739         let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
740         *inner_val
741 }
742 /// The total amount paid on this [`Path`], excluding the fees.
743 #[no_mangle]
744 pub extern "C" fn BlindedTail_set_final_value_msat(this_ptr: &mut BlindedTail, mut val: u64) {
745         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
746 }
747 /// Constructs a new BlindedTail given each field
748 #[must_use]
749 #[no_mangle]
750 pub extern "C" fn BlindedTail_new(mut hops_arg: crate::c_types::derived::CVec_BlindedHopZ, mut blinding_point_arg: crate::c_types::PublicKey, mut excess_final_cltv_expiry_delta_arg: u32, mut final_value_msat_arg: u64) -> BlindedTail {
751         let mut local_hops_arg = Vec::new(); for mut item in hops_arg.into_rust().drain(..) { local_hops_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
752         BlindedTail { inner: ObjOps::heap_alloc(nativeBlindedTail {
753                 hops: local_hops_arg,
754                 blinding_point: blinding_point_arg.into_rust(),
755                 excess_final_cltv_expiry_delta: excess_final_cltv_expiry_delta_arg,
756                 final_value_msat: final_value_msat_arg,
757         }), is_owned: true }
758 }
759 impl Clone for BlindedTail {
760         fn clone(&self) -> Self {
761                 Self {
762                         inner: if <*mut nativeBlindedTail>::is_null(self.inner) { core::ptr::null_mut() } else {
763                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
764                         is_owned: true,
765                 }
766         }
767 }
768 #[allow(unused)]
769 /// Used only if an object of this type is returned as a trait impl by a method
770 pub(crate) extern "C" fn BlindedTail_clone_void(this_ptr: *const c_void) -> *mut c_void {
771         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBlindedTail)).clone() })) as *mut c_void
772 }
773 #[no_mangle]
774 /// Creates a copy of the BlindedTail
775 pub extern "C" fn BlindedTail_clone(orig: &BlindedTail) -> BlindedTail {
776         orig.clone()
777 }
778 /// Generates a non-cryptographic 64-bit hash of the BlindedTail.
779 #[no_mangle]
780 pub extern "C" fn BlindedTail_hash(o: &BlindedTail) -> u64 {
781         if o.inner.is_null() { return 0; }
782         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
783         #[allow(deprecated)]
784         let mut hasher = core::hash::SipHasher::new();
785         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
786         core::hash::Hasher::finish(&hasher)
787 }
788 /// Checks if two BlindedTails contain equal inner contents.
789 /// This ignores pointers and is_owned flags and looks at the values in fields.
790 /// Two objects with NULL inner values will be considered "equal" here.
791 #[no_mangle]
792 pub extern "C" fn BlindedTail_eq(a: &BlindedTail, b: &BlindedTail) -> bool {
793         if a.inner == b.inner { return true; }
794         if a.inner.is_null() || b.inner.is_null() { return false; }
795         if a.get_native_ref() == b.get_native_ref() { true } else { false }
796 }
797 #[no_mangle]
798 /// Serialize the BlindedTail object into a byte array which can be read by BlindedTail_read
799 pub extern "C" fn BlindedTail_write(obj: &crate::lightning::routing::router::BlindedTail) -> crate::c_types::derived::CVec_u8Z {
800         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
801 }
802 #[no_mangle]
803 pub(crate) extern "C" fn BlindedTail_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
804         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedTail) })
805 }
806 #[no_mangle]
807 /// Read a BlindedTail from a byte array, created by BlindedTail_write
808 pub extern "C" fn BlindedTail_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedTailDecodeErrorZ {
809         let res: Result<lightning::routing::router::BlindedTail, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
810         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::BlindedTail { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
811         local_res
812 }
813
814 use lightning::routing::router::Path as nativePathImport;
815 pub(crate) type nativePath = nativePathImport;
816
817 /// A path in a [`Route`] to the payment recipient. Must always be at least length one.
818 /// If no [`Path::blinded_tail`] is present, then [`Path::hops`] length may be up to 19.
819 #[must_use]
820 #[repr(C)]
821 pub struct Path {
822         /// A pointer to the opaque Rust object.
823
824         /// Nearly everywhere, inner must be non-null, however in places where
825         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
826         pub inner: *mut nativePath,
827         /// Indicates that this is the only struct which contains the same pointer.
828
829         /// Rust functions which take ownership of an object provided via an argument require
830         /// this to be true and invalidate the object pointed to by inner.
831         pub is_owned: bool,
832 }
833
834 impl Drop for Path {
835         fn drop(&mut self) {
836                 if self.is_owned && !<*mut nativePath>::is_null(self.inner) {
837                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
838                 }
839         }
840 }
841 /// Frees any resources used by the Path, if is_owned is set and inner is non-NULL.
842 #[no_mangle]
843 pub extern "C" fn Path_free(this_obj: Path) { }
844 #[allow(unused)]
845 /// Used only if an object of this type is returned as a trait impl by a method
846 pub(crate) extern "C" fn Path_free_void(this_ptr: *mut c_void) {
847         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePath) };
848 }
849 #[allow(unused)]
850 impl Path {
851         pub(crate) fn get_native_ref(&self) -> &'static nativePath {
852                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
853         }
854         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePath {
855                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
856         }
857         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
858         pub(crate) fn take_inner(mut self) -> *mut nativePath {
859                 assert!(self.is_owned);
860                 let ret = ObjOps::untweak_ptr(self.inner);
861                 self.inner = core::ptr::null_mut();
862                 ret
863         }
864 }
865 /// The list of unblinded hops in this [`Path`]. Must be at least length one.
866 #[no_mangle]
867 pub extern "C" fn Path_get_hops(this_ptr: &Path) -> crate::c_types::derived::CVec_RouteHopZ {
868         let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
869         let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); };
870         local_inner_val.into()
871 }
872 /// The list of unblinded hops in this [`Path`]. Must be at least length one.
873 #[no_mangle]
874 pub extern "C" fn Path_set_hops(this_ptr: &mut Path, mut val: crate::c_types::derived::CVec_RouteHopZ) {
875         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
876         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
877 }
878 /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
879 ///
880 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
881 #[no_mangle]
882 pub extern "C" fn Path_get_blinded_tail(this_ptr: &Path) -> crate::lightning::routing::router::BlindedTail {
883         let mut inner_val = &mut this_ptr.get_native_mut_ref().blinded_tail;
884         let mut local_inner_val = crate::lightning::routing::router::BlindedTail { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::router::BlindedTail<>) as *mut _ }, is_owned: false };
885         local_inner_val
886 }
887 /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
888 ///
889 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
890 #[no_mangle]
891 pub extern "C" fn Path_set_blinded_tail(this_ptr: &mut Path, mut val: crate::lightning::routing::router::BlindedTail) {
892         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
893         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinded_tail = local_val;
894 }
895 /// Constructs a new Path given each field
896 ///
897 /// Note that blinded_tail_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
898 #[must_use]
899 #[no_mangle]
900 pub extern "C" fn Path_new(mut hops_arg: crate::c_types::derived::CVec_RouteHopZ, mut blinded_tail_arg: crate::lightning::routing::router::BlindedTail) -> Path {
901         let mut local_hops_arg = Vec::new(); for mut item in hops_arg.into_rust().drain(..) { local_hops_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
902         let mut local_blinded_tail_arg = if blinded_tail_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(blinded_tail_arg.take_inner()) } }) };
903         Path { inner: ObjOps::heap_alloc(nativePath {
904                 hops: local_hops_arg,
905                 blinded_tail: local_blinded_tail_arg,
906         }), is_owned: true }
907 }
908 impl Clone for Path {
909         fn clone(&self) -> Self {
910                 Self {
911                         inner: if <*mut nativePath>::is_null(self.inner) { core::ptr::null_mut() } else {
912                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
913                         is_owned: true,
914                 }
915         }
916 }
917 #[allow(unused)]
918 /// Used only if an object of this type is returned as a trait impl by a method
919 pub(crate) extern "C" fn Path_clone_void(this_ptr: *const c_void) -> *mut c_void {
920         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePath)).clone() })) as *mut c_void
921 }
922 #[no_mangle]
923 /// Creates a copy of the Path
924 pub extern "C" fn Path_clone(orig: &Path) -> Path {
925         orig.clone()
926 }
927 /// Generates a non-cryptographic 64-bit hash of the Path.
928 #[no_mangle]
929 pub extern "C" fn Path_hash(o: &Path) -> u64 {
930         if o.inner.is_null() { return 0; }
931         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
932         #[allow(deprecated)]
933         let mut hasher = core::hash::SipHasher::new();
934         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
935         core::hash::Hasher::finish(&hasher)
936 }
937 /// Checks if two Paths contain equal inner contents.
938 /// This ignores pointers and is_owned flags and looks at the values in fields.
939 /// Two objects with NULL inner values will be considered "equal" here.
940 #[no_mangle]
941 pub extern "C" fn Path_eq(a: &Path, b: &Path) -> bool {
942         if a.inner == b.inner { return true; }
943         if a.inner.is_null() || b.inner.is_null() { return false; }
944         if a.get_native_ref() == b.get_native_ref() { true } else { false }
945 }
946 /// Gets the fees for a given path, excluding any excess paid to the recipient.
947 #[must_use]
948 #[no_mangle]
949 pub extern "C" fn Path_fee_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
950         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fee_msat();
951         ret
952 }
953
954 /// Gets the total amount paid on this [`Path`], excluding the fees.
955 #[must_use]
956 #[no_mangle]
957 pub extern "C" fn Path_final_value_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
958         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_value_msat();
959         ret
960 }
961
962 /// Gets the final hop's CLTV expiry delta.
963 #[must_use]
964 #[no_mangle]
965 pub extern "C" fn Path_final_cltv_expiry_delta(this_arg: &crate::lightning::routing::router::Path) -> crate::c_types::derived::COption_u32Z {
966         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_cltv_expiry_delta();
967         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { ret.unwrap() }) };
968         local_ret
969 }
970
971
972 use lightning::routing::router::Route as nativeRouteImport;
973 pub(crate) type nativeRoute = nativeRouteImport;
974
975 /// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
976 /// it can take multiple paths. Each path is composed of one or more hops through the network.
977 #[must_use]
978 #[repr(C)]
979 pub struct Route {
980         /// A pointer to the opaque Rust object.
981
982         /// Nearly everywhere, inner must be non-null, however in places where
983         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
984         pub inner: *mut nativeRoute,
985         /// Indicates that this is the only struct which contains the same pointer.
986
987         /// Rust functions which take ownership of an object provided via an argument require
988         /// this to be true and invalidate the object pointed to by inner.
989         pub is_owned: bool,
990 }
991
992 impl Drop for Route {
993         fn drop(&mut self) {
994                 if self.is_owned && !<*mut nativeRoute>::is_null(self.inner) {
995                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
996                 }
997         }
998 }
999 /// Frees any resources used by the Route, if is_owned is set and inner is non-NULL.
1000 #[no_mangle]
1001 pub extern "C" fn Route_free(this_obj: Route) { }
1002 #[allow(unused)]
1003 /// Used only if an object of this type is returned as a trait impl by a method
1004 pub(crate) extern "C" fn Route_free_void(this_ptr: *mut c_void) {
1005         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoute) };
1006 }
1007 #[allow(unused)]
1008 impl Route {
1009         pub(crate) fn get_native_ref(&self) -> &'static nativeRoute {
1010                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1011         }
1012         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoute {
1013                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1014         }
1015         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1016         pub(crate) fn take_inner(mut self) -> *mut nativeRoute {
1017                 assert!(self.is_owned);
1018                 let ret = ObjOps::untweak_ptr(self.inner);
1019                 self.inner = core::ptr::null_mut();
1020                 ret
1021         }
1022 }
1023 /// The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
1024 /// [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
1025 /// the same.
1026 #[no_mangle]
1027 pub extern "C" fn Route_get_paths(this_ptr: &Route) -> crate::c_types::derived::CVec_PathZ {
1028         let mut inner_val = &mut this_ptr.get_native_mut_ref().paths;
1029         let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::Path { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::Path<>) as *mut _) }, is_owned: false } }); };
1030         local_inner_val.into()
1031 }
1032 /// The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
1033 /// [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
1034 /// the same.
1035 #[no_mangle]
1036 pub extern "C" fn Route_set_paths(this_ptr: &mut Route, mut val: crate::c_types::derived::CVec_PathZ) {
1037         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1038         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.paths = local_val;
1039 }
1040 /// The `route_params` parameter passed to [`find_route`].
1041 ///
1042 /// This is used by `ChannelManager` to track information which may be required for retries.
1043 ///
1044 /// Will be `None` for objects serialized with LDK versions prior to 0.0.117.
1045 ///
1046 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1047 #[no_mangle]
1048 pub extern "C" fn Route_get_route_params(this_ptr: &Route) -> crate::lightning::routing::router::RouteParameters {
1049         let mut inner_val = &mut this_ptr.get_native_mut_ref().route_params;
1050         let mut local_inner_val = crate::lightning::routing::router::RouteParameters { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::router::RouteParameters<>) as *mut _ }, is_owned: false };
1051         local_inner_val
1052 }
1053 /// The `route_params` parameter passed to [`find_route`].
1054 ///
1055 /// This is used by `ChannelManager` to track information which may be required for retries.
1056 ///
1057 /// Will be `None` for objects serialized with LDK versions prior to 0.0.117.
1058 ///
1059 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1060 #[no_mangle]
1061 pub extern "C" fn Route_set_route_params(this_ptr: &mut Route, mut val: crate::lightning::routing::router::RouteParameters) {
1062         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1063         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_params = local_val;
1064 }
1065 /// Constructs a new Route given each field
1066 ///
1067 /// Note that route_params_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
1068 #[must_use]
1069 #[no_mangle]
1070 pub extern "C" fn Route_new(mut paths_arg: crate::c_types::derived::CVec_PathZ, mut route_params_arg: crate::lightning::routing::router::RouteParameters) -> Route {
1071         let mut local_paths_arg = Vec::new(); for mut item in paths_arg.into_rust().drain(..) { local_paths_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1072         let mut local_route_params_arg = if route_params_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(route_params_arg.take_inner()) } }) };
1073         Route { inner: ObjOps::heap_alloc(nativeRoute {
1074                 paths: local_paths_arg,
1075                 route_params: local_route_params_arg,
1076         }), is_owned: true }
1077 }
1078 impl Clone for Route {
1079         fn clone(&self) -> Self {
1080                 Self {
1081                         inner: if <*mut nativeRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
1082                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1083                         is_owned: true,
1084                 }
1085         }
1086 }
1087 #[allow(unused)]
1088 /// Used only if an object of this type is returned as a trait impl by a method
1089 pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_void {
1090         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoute)).clone() })) as *mut c_void
1091 }
1092 #[no_mangle]
1093 /// Creates a copy of the Route
1094 pub extern "C" fn Route_clone(orig: &Route) -> Route {
1095         orig.clone()
1096 }
1097 /// Generates a non-cryptographic 64-bit hash of the Route.
1098 #[no_mangle]
1099 pub extern "C" fn Route_hash(o: &Route) -> u64 {
1100         if o.inner.is_null() { return 0; }
1101         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1102         #[allow(deprecated)]
1103         let mut hasher = core::hash::SipHasher::new();
1104         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1105         core::hash::Hasher::finish(&hasher)
1106 }
1107 /// Checks if two Routes contain equal inner contents.
1108 /// This ignores pointers and is_owned flags and looks at the values in fields.
1109 /// Two objects with NULL inner values will be considered "equal" here.
1110 #[no_mangle]
1111 pub extern "C" fn Route_eq(a: &Route, b: &Route) -> bool {
1112         if a.inner == b.inner { return true; }
1113         if a.inner.is_null() || b.inner.is_null() { return false; }
1114         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1115 }
1116 /// Returns the total amount of fees paid on this [`Route`].
1117 ///
1118 /// For objects serialized with LDK 0.0.117 and after, this includes any extra payment made to
1119 /// the recipient, which can happen in excess of the amount passed to [`find_route`] via
1120 /// [`RouteParameters::final_value_msat`], if we had to reach the [`htlc_minimum_msat`] limits.
1121 ///
1122 /// [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
1123 #[must_use]
1124 #[no_mangle]
1125 pub extern "C" fn Route_get_total_fees(this_arg: &crate::lightning::routing::router::Route) -> u64 {
1126         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_fees();
1127         ret
1128 }
1129
1130 /// Returns the total amount paid on this [`Route`], excluding the fees.
1131 ///
1132 /// Might be more than requested as part of the given [`RouteParameters::final_value_msat`] if
1133 /// we had to reach the [`htlc_minimum_msat`] limits.
1134 ///
1135 /// [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
1136 #[must_use]
1137 #[no_mangle]
1138 pub extern "C" fn Route_get_total_amount(this_arg: &crate::lightning::routing::router::Route) -> u64 {
1139         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_amount();
1140         ret
1141 }
1142
1143 #[no_mangle]
1144 /// Serialize the Route object into a byte array which can be read by Route_read
1145 pub extern "C" fn Route_write(obj: &crate::lightning::routing::router::Route) -> crate::c_types::derived::CVec_u8Z {
1146         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1147 }
1148 #[no_mangle]
1149 pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1150         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) })
1151 }
1152 #[no_mangle]
1153 /// Read a Route from a byte array, created by Route_write
1154 pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ {
1155         let res: Result<lightning::routing::router::Route, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1156         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1157         local_res
1158 }
1159
1160 use lightning::routing::router::RouteParameters as nativeRouteParametersImport;
1161 pub(crate) type nativeRouteParameters = nativeRouteParametersImport;
1162
1163 /// Parameters needed to find a [`Route`].
1164 ///
1165 /// Passed to [`find_route`] and [`build_route_from_hops`].
1166 #[must_use]
1167 #[repr(C)]
1168 pub struct RouteParameters {
1169         /// A pointer to the opaque Rust object.
1170
1171         /// Nearly everywhere, inner must be non-null, however in places where
1172         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1173         pub inner: *mut nativeRouteParameters,
1174         /// Indicates that this is the only struct which contains the same pointer.
1175
1176         /// Rust functions which take ownership of an object provided via an argument require
1177         /// this to be true and invalidate the object pointed to by inner.
1178         pub is_owned: bool,
1179 }
1180
1181 impl Drop for RouteParameters {
1182         fn drop(&mut self) {
1183                 if self.is_owned && !<*mut nativeRouteParameters>::is_null(self.inner) {
1184                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1185                 }
1186         }
1187 }
1188 /// Frees any resources used by the RouteParameters, if is_owned is set and inner is non-NULL.
1189 #[no_mangle]
1190 pub extern "C" fn RouteParameters_free(this_obj: RouteParameters) { }
1191 #[allow(unused)]
1192 /// Used only if an object of this type is returned as a trait impl by a method
1193 pub(crate) extern "C" fn RouteParameters_free_void(this_ptr: *mut c_void) {
1194         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteParameters) };
1195 }
1196 #[allow(unused)]
1197 impl RouteParameters {
1198         pub(crate) fn get_native_ref(&self) -> &'static nativeRouteParameters {
1199                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1200         }
1201         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteParameters {
1202                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1203         }
1204         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1205         pub(crate) fn take_inner(mut self) -> *mut nativeRouteParameters {
1206                 assert!(self.is_owned);
1207                 let ret = ObjOps::untweak_ptr(self.inner);
1208                 self.inner = core::ptr::null_mut();
1209                 ret
1210         }
1211 }
1212 /// The parameters of the failed payment path.
1213 #[no_mangle]
1214 pub extern "C" fn RouteParameters_get_payment_params(this_ptr: &RouteParameters) -> crate::lightning::routing::router::PaymentParameters {
1215         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_params;
1216         crate::lightning::routing::router::PaymentParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::router::PaymentParameters<>) as *mut _) }, is_owned: false }
1217 }
1218 /// The parameters of the failed payment path.
1219 #[no_mangle]
1220 pub extern "C" fn RouteParameters_set_payment_params(this_ptr: &mut RouteParameters, mut val: crate::lightning::routing::router::PaymentParameters) {
1221         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_params = *unsafe { Box::from_raw(val.take_inner()) };
1222 }
1223 /// The amount in msats sent on the failed payment path.
1224 #[no_mangle]
1225 pub extern "C" fn RouteParameters_get_final_value_msat(this_ptr: &RouteParameters) -> u64 {
1226         let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
1227         *inner_val
1228 }
1229 /// The amount in msats sent on the failed payment path.
1230 #[no_mangle]
1231 pub extern "C" fn RouteParameters_set_final_value_msat(this_ptr: &mut RouteParameters, mut val: u64) {
1232         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
1233 }
1234 /// The maximum total fees, in millisatoshi, that may accrue during route finding.
1235 ///
1236 /// This limit also applies to the total fees that may arise while retrying failed payment
1237 /// paths.
1238 ///
1239 /// Note that values below a few sats may result in some paths being spuriously ignored.
1240 #[no_mangle]
1241 pub extern "C" fn RouteParameters_get_max_total_routing_fee_msat(this_ptr: &RouteParameters) -> crate::c_types::derived::COption_u64Z {
1242         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_routing_fee_msat;
1243         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
1244         local_inner_val
1245 }
1246 /// The maximum total fees, in millisatoshi, that may accrue during route finding.
1247 ///
1248 /// This limit also applies to the total fees that may arise while retrying failed payment
1249 /// paths.
1250 ///
1251 /// Note that values below a few sats may result in some paths being spuriously ignored.
1252 #[no_mangle]
1253 pub extern "C" fn RouteParameters_set_max_total_routing_fee_msat(this_ptr: &mut RouteParameters, mut val: crate::c_types::derived::COption_u64Z) {
1254         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1255         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_routing_fee_msat = local_val;
1256 }
1257 /// Constructs a new RouteParameters given each field
1258 #[must_use]
1259 #[no_mangle]
1260 pub extern "C" fn RouteParameters_new(mut payment_params_arg: crate::lightning::routing::router::PaymentParameters, mut final_value_msat_arg: u64, mut max_total_routing_fee_msat_arg: crate::c_types::derived::COption_u64Z) -> RouteParameters {
1261         let mut local_max_total_routing_fee_msat_arg = if max_total_routing_fee_msat_arg.is_some() { Some( { max_total_routing_fee_msat_arg.take() }) } else { None };
1262         RouteParameters { inner: ObjOps::heap_alloc(nativeRouteParameters {
1263                 payment_params: *unsafe { Box::from_raw(payment_params_arg.take_inner()) },
1264                 final_value_msat: final_value_msat_arg,
1265                 max_total_routing_fee_msat: local_max_total_routing_fee_msat_arg,
1266         }), is_owned: true }
1267 }
1268 impl Clone for RouteParameters {
1269         fn clone(&self) -> Self {
1270                 Self {
1271                         inner: if <*mut nativeRouteParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1272                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1273                         is_owned: true,
1274                 }
1275         }
1276 }
1277 #[allow(unused)]
1278 /// Used only if an object of this type is returned as a trait impl by a method
1279 pub(crate) extern "C" fn RouteParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1280         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteParameters)).clone() })) as *mut c_void
1281 }
1282 #[no_mangle]
1283 /// Creates a copy of the RouteParameters
1284 pub extern "C" fn RouteParameters_clone(orig: &RouteParameters) -> RouteParameters {
1285         orig.clone()
1286 }
1287 /// Generates a non-cryptographic 64-bit hash of the RouteParameters.
1288 #[no_mangle]
1289 pub extern "C" fn RouteParameters_hash(o: &RouteParameters) -> u64 {
1290         if o.inner.is_null() { return 0; }
1291         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1292         #[allow(deprecated)]
1293         let mut hasher = core::hash::SipHasher::new();
1294         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1295         core::hash::Hasher::finish(&hasher)
1296 }
1297 /// Checks if two RouteParameterss contain equal inner contents.
1298 /// This ignores pointers and is_owned flags and looks at the values in fields.
1299 /// Two objects with NULL inner values will be considered "equal" here.
1300 #[no_mangle]
1301 pub extern "C" fn RouteParameters_eq(a: &RouteParameters, b: &RouteParameters) -> bool {
1302         if a.inner == b.inner { return true; }
1303         if a.inner.is_null() || b.inner.is_null() { return false; }
1304         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1305 }
1306 /// Constructs [`RouteParameters`] from the given [`PaymentParameters`] and a payment amount.
1307 ///
1308 /// [`Self::max_total_routing_fee_msat`] defaults to 1% of the payment amount + 50 sats
1309 #[must_use]
1310 #[no_mangle]
1311 pub extern "C" fn RouteParameters_from_payment_params_and_value(mut payment_params: crate::lightning::routing::router::PaymentParameters, mut final_value_msat: u64) -> crate::lightning::routing::router::RouteParameters {
1312         let mut ret = lightning::routing::router::RouteParameters::from_payment_params_and_value(*unsafe { Box::from_raw(payment_params.take_inner()) }, final_value_msat);
1313         crate::lightning::routing::router::RouteParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1314 }
1315
1316 #[no_mangle]
1317 /// Serialize the RouteParameters object into a byte array which can be read by RouteParameters_read
1318 pub extern "C" fn RouteParameters_write(obj: &crate::lightning::routing::router::RouteParameters) -> crate::c_types::derived::CVec_u8Z {
1319         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1320 }
1321 #[no_mangle]
1322 pub(crate) extern "C" fn RouteParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1323         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteParameters) })
1324 }
1325 #[no_mangle]
1326 /// Read a RouteParameters from a byte array, created by RouteParameters_write
1327 pub extern "C" fn RouteParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteParametersDecodeErrorZ {
1328         let res: Result<lightning::routing::router::RouteParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1329         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::RouteParameters { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1330         local_res
1331 }
1332 /// Maximum total CTLV difference we allow for a full payment path.
1333
1334 #[no_mangle]
1335 pub static DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = lightning::routing::router::DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
1336 /// Maximum number of paths we allow an (MPP) payment to have.
1337
1338 #[no_mangle]
1339 pub static DEFAULT_MAX_PATH_COUNT: u8 = lightning::routing::router::DEFAULT_MAX_PATH_COUNT;
1340
1341 use lightning::routing::router::PaymentParameters as nativePaymentParametersImport;
1342 pub(crate) type nativePaymentParameters = nativePaymentParametersImport;
1343
1344 /// Information used to route a payment.
1345 #[must_use]
1346 #[repr(C)]
1347 pub struct PaymentParameters {
1348         /// A pointer to the opaque Rust object.
1349
1350         /// Nearly everywhere, inner must be non-null, however in places where
1351         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1352         pub inner: *mut nativePaymentParameters,
1353         /// Indicates that this is the only struct which contains the same pointer.
1354
1355         /// Rust functions which take ownership of an object provided via an argument require
1356         /// this to be true and invalidate the object pointed to by inner.
1357         pub is_owned: bool,
1358 }
1359
1360 impl Drop for PaymentParameters {
1361         fn drop(&mut self) {
1362                 if self.is_owned && !<*mut nativePaymentParameters>::is_null(self.inner) {
1363                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1364                 }
1365         }
1366 }
1367 /// Frees any resources used by the PaymentParameters, if is_owned is set and inner is non-NULL.
1368 #[no_mangle]
1369 pub extern "C" fn PaymentParameters_free(this_obj: PaymentParameters) { }
1370 #[allow(unused)]
1371 /// Used only if an object of this type is returned as a trait impl by a method
1372 pub(crate) extern "C" fn PaymentParameters_free_void(this_ptr: *mut c_void) {
1373         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentParameters) };
1374 }
1375 #[allow(unused)]
1376 impl PaymentParameters {
1377         pub(crate) fn get_native_ref(&self) -> &'static nativePaymentParameters {
1378                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1379         }
1380         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentParameters {
1381                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1382         }
1383         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1384         pub(crate) fn take_inner(mut self) -> *mut nativePaymentParameters {
1385                 assert!(self.is_owned);
1386                 let ret = ObjOps::untweak_ptr(self.inner);
1387                 self.inner = core::ptr::null_mut();
1388                 ret
1389         }
1390 }
1391 /// Information about the payee, such as their features and route hints for their channels.
1392 #[no_mangle]
1393 pub extern "C" fn PaymentParameters_get_payee(this_ptr: &PaymentParameters) -> crate::lightning::routing::router::Payee {
1394         let mut inner_val = &mut this_ptr.get_native_mut_ref().payee;
1395         crate::lightning::routing::router::Payee::from_native(inner_val)
1396 }
1397 /// Information about the payee, such as their features and route hints for their channels.
1398 #[no_mangle]
1399 pub extern "C" fn PaymentParameters_set_payee(this_ptr: &mut PaymentParameters, mut val: crate::lightning::routing::router::Payee) {
1400         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payee = val.into_native();
1401 }
1402 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1403 #[no_mangle]
1404 pub extern "C" fn PaymentParameters_get_expiry_time(this_ptr: &PaymentParameters) -> crate::c_types::derived::COption_u64Z {
1405         let mut inner_val = &mut this_ptr.get_native_mut_ref().expiry_time;
1406         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
1407         local_inner_val
1408 }
1409 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1410 #[no_mangle]
1411 pub extern "C" fn PaymentParameters_set_expiry_time(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::COption_u64Z) {
1412         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1413         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.expiry_time = local_val;
1414 }
1415 /// The maximum total CLTV delta we accept for the route.
1416 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1417 #[no_mangle]
1418 pub extern "C" fn PaymentParameters_get_max_total_cltv_expiry_delta(this_ptr: &PaymentParameters) -> u32 {
1419         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_cltv_expiry_delta;
1420         *inner_val
1421 }
1422 /// The maximum total CLTV delta we accept for the route.
1423 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1424 #[no_mangle]
1425 pub extern "C" fn PaymentParameters_set_max_total_cltv_expiry_delta(this_ptr: &mut PaymentParameters, mut val: u32) {
1426         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_cltv_expiry_delta = val;
1427 }
1428 /// The maximum number of paths that may be used by (MPP) payments.
1429 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1430 #[no_mangle]
1431 pub extern "C" fn PaymentParameters_get_max_path_count(this_ptr: &PaymentParameters) -> u8 {
1432         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_path_count;
1433         *inner_val
1434 }
1435 /// The maximum number of paths that may be used by (MPP) payments.
1436 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1437 #[no_mangle]
1438 pub extern "C" fn PaymentParameters_set_max_path_count(this_ptr: &mut PaymentParameters, mut val: u8) {
1439         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_path_count = val;
1440 }
1441 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1442 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1443 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1444 /// increasing failure probability for those paths.
1445 ///
1446 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1447 /// restriction have been found. While paths which meet this criteria will be searched for, it
1448 /// is ultimately up to the scorer to select them over other paths.
1449 ///
1450 /// A value of 0 will allow payments up to and including a channel's total announced usable
1451 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1452 ///
1453 /// Default value: 2
1454 #[no_mangle]
1455 pub extern "C" fn PaymentParameters_get_max_channel_saturation_power_of_half(this_ptr: &PaymentParameters) -> u8 {
1456         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_saturation_power_of_half;
1457         *inner_val
1458 }
1459 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1460 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1461 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1462 /// increasing failure probability for those paths.
1463 ///
1464 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1465 /// restriction have been found. While paths which meet this criteria will be searched for, it
1466 /// is ultimately up to the scorer to select them over other paths.
1467 ///
1468 /// A value of 0 will allow payments up to and including a channel's total announced usable
1469 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1470 ///
1471 /// Default value: 2
1472 #[no_mangle]
1473 pub extern "C" fn PaymentParameters_set_max_channel_saturation_power_of_half(this_ptr: &mut PaymentParameters, mut val: u8) {
1474         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_saturation_power_of_half = val;
1475 }
1476 /// A list of SCIDs which this payment was previously attempted over and which caused the
1477 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1478 /// these SCIDs.
1479 ///
1480 /// Returns a copy of the field.
1481 #[no_mangle]
1482 pub extern "C" fn PaymentParameters_get_previously_failed_channels(this_ptr: &PaymentParameters) -> crate::c_types::derived::CVec_u64Z {
1483         let mut inner_val = this_ptr.get_native_mut_ref().previously_failed_channels.clone();
1484         let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1485         local_inner_val.into()
1486 }
1487 /// A list of SCIDs which this payment was previously attempted over and which caused the
1488 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1489 /// these SCIDs.
1490 #[no_mangle]
1491 pub extern "C" fn PaymentParameters_set_previously_failed_channels(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_u64Z) {
1492         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1493         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previously_failed_channels = local_val;
1494 }
1495 /// Constructs a new PaymentParameters given each field
1496 #[must_use]
1497 #[no_mangle]
1498 pub extern "C" fn PaymentParameters_new(mut payee_arg: crate::lightning::routing::router::Payee, mut expiry_time_arg: crate::c_types::derived::COption_u64Z, mut max_total_cltv_expiry_delta_arg: u32, mut max_path_count_arg: u8, mut max_channel_saturation_power_of_half_arg: u8, mut previously_failed_channels_arg: crate::c_types::derived::CVec_u64Z) -> PaymentParameters {
1499         let mut local_expiry_time_arg = if expiry_time_arg.is_some() { Some( { expiry_time_arg.take() }) } else { None };
1500         let mut local_previously_failed_channels_arg = Vec::new(); for mut item in previously_failed_channels_arg.into_rust().drain(..) { local_previously_failed_channels_arg.push( { item }); };
1501         PaymentParameters { inner: ObjOps::heap_alloc(nativePaymentParameters {
1502                 payee: payee_arg.into_native(),
1503                 expiry_time: local_expiry_time_arg,
1504                 max_total_cltv_expiry_delta: max_total_cltv_expiry_delta_arg,
1505                 max_path_count: max_path_count_arg,
1506                 max_channel_saturation_power_of_half: max_channel_saturation_power_of_half_arg,
1507                 previously_failed_channels: local_previously_failed_channels_arg,
1508         }), is_owned: true }
1509 }
1510 impl Clone for PaymentParameters {
1511         fn clone(&self) -> Self {
1512                 Self {
1513                         inner: if <*mut nativePaymentParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1514                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1515                         is_owned: true,
1516                 }
1517         }
1518 }
1519 #[allow(unused)]
1520 /// Used only if an object of this type is returned as a trait impl by a method
1521 pub(crate) extern "C" fn PaymentParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1522         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentParameters)).clone() })) as *mut c_void
1523 }
1524 #[no_mangle]
1525 /// Creates a copy of the PaymentParameters
1526 pub extern "C" fn PaymentParameters_clone(orig: &PaymentParameters) -> PaymentParameters {
1527         orig.clone()
1528 }
1529 /// Generates a non-cryptographic 64-bit hash of the PaymentParameters.
1530 #[no_mangle]
1531 pub extern "C" fn PaymentParameters_hash(o: &PaymentParameters) -> u64 {
1532         if o.inner.is_null() { return 0; }
1533         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1534         #[allow(deprecated)]
1535         let mut hasher = core::hash::SipHasher::new();
1536         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1537         core::hash::Hasher::finish(&hasher)
1538 }
1539 /// Checks if two PaymentParameterss contain equal inner contents.
1540 /// This ignores pointers and is_owned flags and looks at the values in fields.
1541 /// Two objects with NULL inner values will be considered "equal" here.
1542 #[no_mangle]
1543 pub extern "C" fn PaymentParameters_eq(a: &PaymentParameters, b: &PaymentParameters) -> bool {
1544         if a.inner == b.inner { return true; }
1545         if a.inner.is_null() || b.inner.is_null() { return false; }
1546         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1547 }
1548 #[no_mangle]
1549 /// Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
1550 pub extern "C" fn PaymentParameters_write(obj: &crate::lightning::routing::router::PaymentParameters) -> crate::c_types::derived::CVec_u8Z {
1551         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1552 }
1553 #[no_mangle]
1554 pub(crate) extern "C" fn PaymentParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1555         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentParameters) })
1556 }
1557 #[no_mangle]
1558 /// Read a PaymentParameters from a byte array, created by PaymentParameters_write
1559 pub extern "C" fn PaymentParameters_read(ser: crate::c_types::u8slice, arg: u32) -> crate::c_types::derived::CResult_PaymentParametersDecodeErrorZ {
1560         let arg_conv = arg;
1561         let res: Result<lightning::routing::router::PaymentParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1562         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1563         local_res
1564 }
1565 /// Creates a payee with the node id of the given `pubkey`.
1566 ///
1567 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1568 /// provided.
1569 #[must_use]
1570 #[no_mangle]
1571 pub extern "C" fn PaymentParameters_from_node_id(mut payee_pubkey: crate::c_types::PublicKey, mut final_cltv_expiry_delta: u32) -> crate::lightning::routing::router::PaymentParameters {
1572         let mut ret = lightning::routing::router::PaymentParameters::from_node_id(payee_pubkey.into_rust(), final_cltv_expiry_delta);
1573         crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1574 }
1575
1576 /// Creates a payee with the node id of the given `pubkey` to use for keysend payments.
1577 ///
1578 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1579 /// provided.
1580 ///
1581 /// Note that MPP keysend is not widely supported yet. The `allow_mpp` lets you choose
1582 /// whether your router will be allowed to find a multi-part route for this payment. If you
1583 /// set `allow_mpp` to true, you should ensure a payment secret is set on send, likely via
1584 /// [`RecipientOnionFields::secret_only`].
1585 ///
1586 /// [`RecipientOnionFields::secret_only`]: crate::ln::channelmanager::RecipientOnionFields::secret_only
1587 #[must_use]
1588 #[no_mangle]
1589 pub extern "C" fn PaymentParameters_for_keysend(mut payee_pubkey: crate::c_types::PublicKey, mut final_cltv_expiry_delta: u32, mut allow_mpp: bool) -> crate::lightning::routing::router::PaymentParameters {
1590         let mut ret = lightning::routing::router::PaymentParameters::for_keysend(payee_pubkey.into_rust(), final_cltv_expiry_delta, allow_mpp);
1591         crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1592 }
1593
1594 /// Creates parameters for paying to a blinded payee from the provided invoice. Sets
1595 /// [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and
1596 /// [`PaymentParameters::expiry_time`].
1597 #[must_use]
1598 #[no_mangle]
1599 pub extern "C" fn PaymentParameters_from_bolt12_invoice(invoice: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::routing::router::PaymentParameters {
1600         let mut ret = lightning::routing::router::PaymentParameters::from_bolt12_invoice(invoice.get_native_ref());
1601         crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1602 }
1603
1604 /// Creates parameters for paying to a blinded payee from the provided blinded route hints.
1605 #[must_use]
1606 #[no_mangle]
1607 pub extern "C" fn PaymentParameters_blinded(mut blinded_route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ) -> crate::lightning::routing::router::PaymentParameters {
1608         let mut local_blinded_route_hints = Vec::new(); for mut item in blinded_route_hints.into_rust().drain(..) { local_blinded_route_hints.push( { let (mut orig_blinded_route_hints_0_0, mut orig_blinded_route_hints_0_1) = item.to_rust(); let mut local_blinded_route_hints_0 = (*unsafe { Box::from_raw(orig_blinded_route_hints_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_blinded_route_hints_0_1.take_inner()) }); local_blinded_route_hints_0 }); };
1609         let mut ret = lightning::routing::router::PaymentParameters::blinded(local_blinded_route_hints);
1610         crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1611 }
1612
1613 /// The recipient of a payment, differing based on whether they've hidden their identity with route
1614 /// blinding.
1615 #[derive(Clone)]
1616 #[must_use]
1617 #[repr(C)]
1618 pub enum Payee {
1619         /// The recipient provided blinded paths and payinfo to reach them. The blinded paths themselves
1620         /// will be included in the final [`Route`].
1621         Blinded {
1622                 /// Aggregated routing info and blinded paths, for routing to the payee without knowing their
1623                 /// node id.
1624                 route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ,
1625                 /// Features supported by the payee.
1626                 ///
1627                 /// May be set from the payee's invoice. May be `None` if the invoice does not contain any
1628                 /// features.
1629                 ///
1630                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1631                 features: crate::lightning::ln::features::Bolt12InvoiceFeatures,
1632         },
1633         /// The recipient included these route hints in their BOLT11 invoice.
1634         Clear {
1635                 /// The node id of the payee.
1636                 node_id: crate::c_types::PublicKey,
1637                 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
1638                 route_hints: crate::c_types::derived::CVec_RouteHintZ,
1639                 /// Features supported by the payee.
1640                 ///
1641                 /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
1642                 /// does not contain any features.
1643                 ///
1644                 /// [`for_keysend`]: PaymentParameters::for_keysend
1645                 ///
1646                 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1647                 features: crate::lightning::ln::features::Bolt11InvoiceFeatures,
1648                 /// The minimum CLTV delta at the end of the route. This value must not be zero.
1649                 final_cltv_expiry_delta: u32,
1650         },
1651 }
1652 use lightning::routing::router::Payee as PayeeImport;
1653 pub(crate) type nativePayee = PayeeImport;
1654
1655 impl Payee {
1656         #[allow(unused)]
1657         pub(crate) fn to_native(&self) -> nativePayee {
1658                 match self {
1659                         Payee::Blinded {ref route_hints, ref features, } => {
1660                                 let mut route_hints_nonref = Clone::clone(route_hints);
1661                                 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.into_rust().drain(..) { local_route_hints_nonref.push( { let (mut orig_route_hints_nonref_0_0, mut orig_route_hints_nonref_0_1) = item.to_rust(); let mut local_route_hints_nonref_0 = (*unsafe { Box::from_raw(orig_route_hints_nonref_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_route_hints_nonref_0_1.take_inner()) }); local_route_hints_nonref_0 }); };
1662                                 let mut features_nonref = Clone::clone(features);
1663                                 let mut local_features_nonref = if features_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_nonref.take_inner()) } }) };
1664                                 nativePayee::Blinded {
1665                                         route_hints: local_route_hints_nonref,
1666                                         features: local_features_nonref,
1667                                 }
1668                         },
1669                         Payee::Clear {ref node_id, ref route_hints, ref features, ref final_cltv_expiry_delta, } => {
1670                                 let mut node_id_nonref = Clone::clone(node_id);
1671                                 let mut route_hints_nonref = Clone::clone(route_hints);
1672                                 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.into_rust().drain(..) { local_route_hints_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1673                                 let mut features_nonref = Clone::clone(features);
1674                                 let mut local_features_nonref = if features_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_nonref.take_inner()) } }) };
1675                                 let mut final_cltv_expiry_delta_nonref = Clone::clone(final_cltv_expiry_delta);
1676                                 nativePayee::Clear {
1677                                         node_id: node_id_nonref.into_rust(),
1678                                         route_hints: local_route_hints_nonref,
1679                                         features: local_features_nonref,
1680                                         final_cltv_expiry_delta: final_cltv_expiry_delta_nonref,
1681                                 }
1682                         },
1683                 }
1684         }
1685         #[allow(unused)]
1686         pub(crate) fn into_native(self) -> nativePayee {
1687                 match self {
1688                         Payee::Blinded {mut route_hints, mut features, } => {
1689                                 let mut local_route_hints = Vec::new(); for mut item in route_hints.into_rust().drain(..) { local_route_hints.push( { let (mut orig_route_hints_0_0, mut orig_route_hints_0_1) = item.to_rust(); let mut local_route_hints_0 = (*unsafe { Box::from_raw(orig_route_hints_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_route_hints_0_1.take_inner()) }); local_route_hints_0 }); };
1690                                 let mut local_features = if features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features.take_inner()) } }) };
1691                                 nativePayee::Blinded {
1692                                         route_hints: local_route_hints,
1693                                         features: local_features,
1694                                 }
1695                         },
1696                         Payee::Clear {mut node_id, mut route_hints, mut features, mut final_cltv_expiry_delta, } => {
1697                                 let mut local_route_hints = Vec::new(); for mut item in route_hints.into_rust().drain(..) { local_route_hints.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1698                                 let mut local_features = if features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features.take_inner()) } }) };
1699                                 nativePayee::Clear {
1700                                         node_id: node_id.into_rust(),
1701                                         route_hints: local_route_hints,
1702                                         features: local_features,
1703                                         final_cltv_expiry_delta: final_cltv_expiry_delta,
1704                                 }
1705                         },
1706                 }
1707         }
1708         #[allow(unused)]
1709         pub(crate) fn from_native(native: &nativePayee) -> Self {
1710                 match native {
1711                         nativePayee::Blinded {ref route_hints, ref features, } => {
1712                                 let mut route_hints_nonref = Clone::clone(route_hints);
1713                                 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.drain(..) { local_route_hints_nonref.push( { let (mut orig_route_hints_nonref_0_0, mut orig_route_hints_nonref_0_1) = item; let mut local_route_hints_nonref_0 = (crate::lightning::offers::invoice::BlindedPayInfo { inner: ObjOps::heap_alloc(orig_route_hints_nonref_0_0), is_owned: true }, crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(orig_route_hints_nonref_0_1), is_owned: true }).into(); local_route_hints_nonref_0 }); };
1714                                 let mut features_nonref = Clone::clone(features);
1715                                 let mut local_features_nonref = crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: if features_nonref.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((features_nonref.unwrap())) } }, is_owned: true };
1716                                 Payee::Blinded {
1717                                         route_hints: local_route_hints_nonref.into(),
1718                                         features: local_features_nonref,
1719                                 }
1720                         },
1721                         nativePayee::Clear {ref node_id, ref route_hints, ref features, ref final_cltv_expiry_delta, } => {
1722                                 let mut node_id_nonref = Clone::clone(node_id);
1723                                 let mut route_hints_nonref = Clone::clone(route_hints);
1724                                 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.drain(..) { local_route_hints_nonref.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1725                                 let mut features_nonref = Clone::clone(features);
1726                                 let mut local_features_nonref = crate::lightning::ln::features::Bolt11InvoiceFeatures { inner: if features_nonref.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((features_nonref.unwrap())) } }, is_owned: true };
1727                                 let mut final_cltv_expiry_delta_nonref = Clone::clone(final_cltv_expiry_delta);
1728                                 Payee::Clear {
1729                                         node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1730                                         route_hints: local_route_hints_nonref.into(),
1731                                         features: local_features_nonref,
1732                                         final_cltv_expiry_delta: final_cltv_expiry_delta_nonref,
1733                                 }
1734                         },
1735                 }
1736         }
1737         #[allow(unused)]
1738         pub(crate) fn native_into(native: nativePayee) -> Self {
1739                 match native {
1740                         nativePayee::Blinded {mut route_hints, mut features, } => {
1741                                 let mut local_route_hints = Vec::new(); for mut item in route_hints.drain(..) { local_route_hints.push( { let (mut orig_route_hints_0_0, mut orig_route_hints_0_1) = item; let mut local_route_hints_0 = (crate::lightning::offers::invoice::BlindedPayInfo { inner: ObjOps::heap_alloc(orig_route_hints_0_0), is_owned: true }, crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(orig_route_hints_0_1), is_owned: true }).into(); local_route_hints_0 }); };
1742                                 let mut local_features = crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: if features.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((features.unwrap())) } }, is_owned: true };
1743                                 Payee::Blinded {
1744                                         route_hints: local_route_hints.into(),
1745                                         features: local_features,
1746                                 }
1747                         },
1748                         nativePayee::Clear {mut node_id, mut route_hints, mut features, mut final_cltv_expiry_delta, } => {
1749                                 let mut local_route_hints = Vec::new(); for mut item in route_hints.drain(..) { local_route_hints.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1750                                 let mut local_features = crate::lightning::ln::features::Bolt11InvoiceFeatures { inner: if features.is_none() { core::ptr::null_mut() } else {  { ObjOps::heap_alloc((features.unwrap())) } }, is_owned: true };
1751                                 Payee::Clear {
1752                                         node_id: crate::c_types::PublicKey::from_rust(&node_id),
1753                                         route_hints: local_route_hints.into(),
1754                                         features: local_features,
1755                                         final_cltv_expiry_delta: final_cltv_expiry_delta,
1756                                 }
1757                         },
1758                 }
1759         }
1760 }
1761 /// Frees any resources used by the Payee
1762 #[no_mangle]
1763 pub extern "C" fn Payee_free(this_ptr: Payee) { }
1764 /// Creates a copy of the Payee
1765 #[no_mangle]
1766 pub extern "C" fn Payee_clone(orig: &Payee) -> Payee {
1767         orig.clone()
1768 }
1769 #[no_mangle]
1770 /// Utility method to constructs a new Blinded-variant Payee
1771 pub extern "C" fn Payee_blinded(route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ, features: crate::lightning::ln::features::Bolt12InvoiceFeatures) -> Payee {
1772         Payee::Blinded {
1773                 route_hints,
1774                 features,
1775         }
1776 }
1777 #[no_mangle]
1778 /// Utility method to constructs a new Clear-variant Payee
1779 pub extern "C" fn Payee_clear(node_id: crate::c_types::PublicKey, route_hints: crate::c_types::derived::CVec_RouteHintZ, features: crate::lightning::ln::features::Bolt11InvoiceFeatures, final_cltv_expiry_delta: u32) -> Payee {
1780         Payee::Clear {
1781                 node_id,
1782                 route_hints,
1783                 features,
1784                 final_cltv_expiry_delta,
1785         }
1786 }
1787 /// Generates a non-cryptographic 64-bit hash of the Payee.
1788 #[no_mangle]
1789 pub extern "C" fn Payee_hash(o: &Payee) -> u64 {
1790         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1791         #[allow(deprecated)]
1792         let mut hasher = core::hash::SipHasher::new();
1793         core::hash::Hash::hash(&o.to_native(), &mut hasher);
1794         core::hash::Hasher::finish(&hasher)
1795 }
1796 /// Checks if two Payees contain equal inner contents.
1797 /// This ignores pointers and is_owned flags and looks at the values in fields.
1798 #[no_mangle]
1799 pub extern "C" fn Payee_eq(a: &Payee, b: &Payee) -> bool {
1800         if &a.to_native() == &b.to_native() { true } else { false }
1801 }
1802
1803 use lightning::routing::router::RouteHint as nativeRouteHintImport;
1804 pub(crate) type nativeRouteHint = nativeRouteHintImport;
1805
1806 /// A list of hops along a payment path terminating with a channel to the recipient.
1807 #[must_use]
1808 #[repr(C)]
1809 pub struct RouteHint {
1810         /// A pointer to the opaque Rust object.
1811
1812         /// Nearly everywhere, inner must be non-null, however in places where
1813         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1814         pub inner: *mut nativeRouteHint,
1815         /// Indicates that this is the only struct which contains the same pointer.
1816
1817         /// Rust functions which take ownership of an object provided via an argument require
1818         /// this to be true and invalidate the object pointed to by inner.
1819         pub is_owned: bool,
1820 }
1821
1822 impl Drop for RouteHint {
1823         fn drop(&mut self) {
1824                 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
1825                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1826                 }
1827         }
1828 }
1829 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
1830 #[no_mangle]
1831 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
1832 #[allow(unused)]
1833 /// Used only if an object of this type is returned as a trait impl by a method
1834 pub(crate) extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
1835         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHint) };
1836 }
1837 #[allow(unused)]
1838 impl RouteHint {
1839         pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHint {
1840                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1841         }
1842         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHint {
1843                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1844         }
1845         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1846         pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
1847                 assert!(self.is_owned);
1848                 let ret = ObjOps::untweak_ptr(self.inner);
1849                 self.inner = core::ptr::null_mut();
1850                 ret
1851         }
1852 }
1853 #[no_mangle]
1854 pub extern "C" fn RouteHint_get_a(this_ptr: &RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ {
1855         let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1856         let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::RouteHintHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::RouteHintHop<>) as *mut _) }, is_owned: false } }); };
1857         local_inner_val.into()
1858 }
1859 #[no_mangle]
1860 pub extern "C" fn RouteHint_set_a(this_ptr: &mut RouteHint, mut val: crate::c_types::derived::CVec_RouteHintHopZ) {
1861         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1862         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = local_val;
1863 }
1864 /// Constructs a new RouteHint given each field
1865 #[must_use]
1866 #[no_mangle]
1867 pub extern "C" fn RouteHint_new(mut a_arg: crate::c_types::derived::CVec_RouteHintHopZ) -> RouteHint {
1868         let mut local_a_arg = Vec::new(); for mut item in a_arg.into_rust().drain(..) { local_a_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1869         RouteHint { inner: ObjOps::heap_alloc(lightning::routing::router::RouteHint (
1870                 local_a_arg,
1871         )), is_owned: true }
1872 }
1873 impl Clone for RouteHint {
1874         fn clone(&self) -> Self {
1875                 Self {
1876                         inner: if <*mut nativeRouteHint>::is_null(self.inner) { core::ptr::null_mut() } else {
1877                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1878                         is_owned: true,
1879                 }
1880         }
1881 }
1882 #[allow(unused)]
1883 /// Used only if an object of this type is returned as a trait impl by a method
1884 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
1885         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void
1886 }
1887 #[no_mangle]
1888 /// Creates a copy of the RouteHint
1889 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
1890         orig.clone()
1891 }
1892 /// Generates a non-cryptographic 64-bit hash of the RouteHint.
1893 #[no_mangle]
1894 pub extern "C" fn RouteHint_hash(o: &RouteHint) -> u64 {
1895         if o.inner.is_null() { return 0; }
1896         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1897         #[allow(deprecated)]
1898         let mut hasher = core::hash::SipHasher::new();
1899         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1900         core::hash::Hasher::finish(&hasher)
1901 }
1902 /// Checks if two RouteHints contain equal inner contents.
1903 /// This ignores pointers and is_owned flags and looks at the values in fields.
1904 /// Two objects with NULL inner values will be considered "equal" here.
1905 #[no_mangle]
1906 pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool {
1907         if a.inner == b.inner { return true; }
1908         if a.inner.is_null() || b.inner.is_null() { return false; }
1909         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1910 }
1911 #[no_mangle]
1912 /// Serialize the RouteHint object into a byte array which can be read by RouteHint_read
1913 pub extern "C" fn RouteHint_write(obj: &crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CVec_u8Z {
1914         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1915 }
1916 #[no_mangle]
1917 pub(crate) extern "C" fn RouteHint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1918         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHint) })
1919 }
1920 #[no_mangle]
1921 /// Read a RouteHint from a byte array, created by RouteHint_write
1922 pub extern "C" fn RouteHint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintDecodeErrorZ {
1923         let res: Result<lightning::routing::router::RouteHint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1924         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1925         local_res
1926 }
1927
1928 use lightning::routing::router::RouteHintHop as nativeRouteHintHopImport;
1929 pub(crate) type nativeRouteHintHop = nativeRouteHintHopImport;
1930
1931 /// A channel descriptor for a hop along a payment path.
1932 #[must_use]
1933 #[repr(C)]
1934 pub struct RouteHintHop {
1935         /// A pointer to the opaque Rust object.
1936
1937         /// Nearly everywhere, inner must be non-null, however in places where
1938         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1939         pub inner: *mut nativeRouteHintHop,
1940         /// Indicates that this is the only struct which contains the same pointer.
1941
1942         /// Rust functions which take ownership of an object provided via an argument require
1943         /// this to be true and invalidate the object pointed to by inner.
1944         pub is_owned: bool,
1945 }
1946
1947 impl Drop for RouteHintHop {
1948         fn drop(&mut self) {
1949                 if self.is_owned && !<*mut nativeRouteHintHop>::is_null(self.inner) {
1950                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1951                 }
1952         }
1953 }
1954 /// Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL.
1955 #[no_mangle]
1956 pub extern "C" fn RouteHintHop_free(this_obj: RouteHintHop) { }
1957 #[allow(unused)]
1958 /// Used only if an object of this type is returned as a trait impl by a method
1959 pub(crate) extern "C" fn RouteHintHop_free_void(this_ptr: *mut c_void) {
1960         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHintHop) };
1961 }
1962 #[allow(unused)]
1963 impl RouteHintHop {
1964         pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHintHop {
1965                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1966         }
1967         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHintHop {
1968                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1969         }
1970         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1971         pub(crate) fn take_inner(mut self) -> *mut nativeRouteHintHop {
1972                 assert!(self.is_owned);
1973                 let ret = ObjOps::untweak_ptr(self.inner);
1974                 self.inner = core::ptr::null_mut();
1975                 ret
1976         }
1977 }
1978 /// The node_id of the non-target end of the route
1979 #[no_mangle]
1980 pub extern "C" fn RouteHintHop_get_src_node_id(this_ptr: &RouteHintHop) -> crate::c_types::PublicKey {
1981         let mut inner_val = &mut this_ptr.get_native_mut_ref().src_node_id;
1982         crate::c_types::PublicKey::from_rust(&inner_val)
1983 }
1984 /// The node_id of the non-target end of the route
1985 #[no_mangle]
1986 pub extern "C" fn RouteHintHop_set_src_node_id(this_ptr: &mut RouteHintHop, mut val: crate::c_types::PublicKey) {
1987         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.src_node_id = val.into_rust();
1988 }
1989 /// The short_channel_id of this channel
1990 #[no_mangle]
1991 pub extern "C" fn RouteHintHop_get_short_channel_id(this_ptr: &RouteHintHop) -> u64 {
1992         let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
1993         *inner_val
1994 }
1995 /// The short_channel_id of this channel
1996 #[no_mangle]
1997 pub extern "C" fn RouteHintHop_set_short_channel_id(this_ptr: &mut RouteHintHop, mut val: u64) {
1998         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
1999 }
2000 /// The fees which must be paid to use this channel
2001 #[no_mangle]
2002 pub extern "C" fn RouteHintHop_get_fees(this_ptr: &RouteHintHop) -> crate::lightning::routing::gossip::RoutingFees {
2003         let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
2004         crate::lightning::routing::gossip::RoutingFees { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::RoutingFees<>) as *mut _) }, is_owned: false }
2005 }
2006 /// The fees which must be paid to use this channel
2007 #[no_mangle]
2008 pub extern "C" fn RouteHintHop_set_fees(this_ptr: &mut RouteHintHop, mut val: crate::lightning::routing::gossip::RoutingFees) {
2009         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
2010 }
2011 /// The difference in CLTV values between this node and the next node.
2012 #[no_mangle]
2013 pub extern "C" fn RouteHintHop_get_cltv_expiry_delta(this_ptr: &RouteHintHop) -> u16 {
2014         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
2015         *inner_val
2016 }
2017 /// The difference in CLTV values between this node and the next node.
2018 #[no_mangle]
2019 pub extern "C" fn RouteHintHop_set_cltv_expiry_delta(this_ptr: &mut RouteHintHop, mut val: u16) {
2020         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
2021 }
2022 /// The minimum value, in msat, which must be relayed to the next hop.
2023 #[no_mangle]
2024 pub extern "C" fn RouteHintHop_get_htlc_minimum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
2025         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
2026         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
2027         local_inner_val
2028 }
2029 /// The minimum value, in msat, which must be relayed to the next hop.
2030 #[no_mangle]
2031 pub extern "C" fn RouteHintHop_set_htlc_minimum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
2032         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2033         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = local_val;
2034 }
2035 /// The maximum value in msat available for routing with a single HTLC.
2036 #[no_mangle]
2037 pub extern "C" fn RouteHintHop_get_htlc_maximum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
2038         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
2039         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
2040         local_inner_val
2041 }
2042 /// The maximum value in msat available for routing with a single HTLC.
2043 #[no_mangle]
2044 pub extern "C" fn RouteHintHop_set_htlc_maximum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
2045         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2046         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
2047 }
2048 /// Constructs a new RouteHintHop given each field
2049 #[must_use]
2050 #[no_mangle]
2051 pub extern "C" fn RouteHintHop_new(mut src_node_id_arg: crate::c_types::PublicKey, mut short_channel_id_arg: u64, mut fees_arg: crate::lightning::routing::gossip::RoutingFees, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: crate::c_types::derived::COption_u64Z, mut htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z) -> RouteHintHop {
2052         let mut local_htlc_minimum_msat_arg = if htlc_minimum_msat_arg.is_some() { Some( { htlc_minimum_msat_arg.take() }) } else { None };
2053         let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
2054         RouteHintHop { inner: ObjOps::heap_alloc(nativeRouteHintHop {
2055                 src_node_id: src_node_id_arg.into_rust(),
2056                 short_channel_id: short_channel_id_arg,
2057                 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
2058                 cltv_expiry_delta: cltv_expiry_delta_arg,
2059                 htlc_minimum_msat: local_htlc_minimum_msat_arg,
2060                 htlc_maximum_msat: local_htlc_maximum_msat_arg,
2061         }), is_owned: true }
2062 }
2063 impl Clone for RouteHintHop {
2064         fn clone(&self) -> Self {
2065                 Self {
2066                         inner: if <*mut nativeRouteHintHop>::is_null(self.inner) { core::ptr::null_mut() } else {
2067                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2068                         is_owned: true,
2069                 }
2070         }
2071 }
2072 #[allow(unused)]
2073 /// Used only if an object of this type is returned as a trait impl by a method
2074 pub(crate) extern "C" fn RouteHintHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
2075         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHintHop)).clone() })) as *mut c_void
2076 }
2077 #[no_mangle]
2078 /// Creates a copy of the RouteHintHop
2079 pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop {
2080         orig.clone()
2081 }
2082 /// Generates a non-cryptographic 64-bit hash of the RouteHintHop.
2083 #[no_mangle]
2084 pub extern "C" fn RouteHintHop_hash(o: &RouteHintHop) -> u64 {
2085         if o.inner.is_null() { return 0; }
2086         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2087         #[allow(deprecated)]
2088         let mut hasher = core::hash::SipHasher::new();
2089         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2090         core::hash::Hasher::finish(&hasher)
2091 }
2092 /// Checks if two RouteHintHops contain equal inner contents.
2093 /// This ignores pointers and is_owned flags and looks at the values in fields.
2094 /// Two objects with NULL inner values will be considered "equal" here.
2095 #[no_mangle]
2096 pub extern "C" fn RouteHintHop_eq(a: &RouteHintHop, b: &RouteHintHop) -> bool {
2097         if a.inner == b.inner { return true; }
2098         if a.inner.is_null() || b.inner.is_null() { return false; }
2099         if a.get_native_ref() == b.get_native_ref() { true } else { false }
2100 }
2101 #[no_mangle]
2102 /// Serialize the RouteHintHop object into a byte array which can be read by RouteHintHop_read
2103 pub extern "C" fn RouteHintHop_write(obj: &crate::lightning::routing::router::RouteHintHop) -> crate::c_types::derived::CVec_u8Z {
2104         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2105 }
2106 #[no_mangle]
2107 pub(crate) extern "C" fn RouteHintHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2108         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHintHop) })
2109 }
2110 #[no_mangle]
2111 /// Read a RouteHintHop from a byte array, created by RouteHintHop_write
2112 pub extern "C" fn RouteHintHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintHopDecodeErrorZ {
2113         let res: Result<lightning::routing::router::RouteHintHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2114         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::RouteHintHop { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
2115         local_res
2116 }
2117 /// Finds a route from us (payer) to the given target node (payee).
2118 ///
2119 /// If the payee provided features in their invoice, they should be provided via the `payee` field
2120 /// in the given [`RouteParameters::payment_params`].
2121 /// Without this, MPP will only be used if the payee's features are available in the network graph.
2122 ///
2123 /// Private routing paths between a public node and the target may be included in the `payee` field
2124 /// of [`RouteParameters::payment_params`].
2125 ///
2126 /// If some channels aren't announced, it may be useful to fill in `first_hops` with the results
2127 /// from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
2128 /// from `network_graph` will be ignored, and only those in `first_hops` will be used.
2129 ///
2130 /// The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
2131 /// However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
2132 /// `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
2133 ///
2134 /// # Panics
2135 ///
2136 /// Panics if first_hops contains channels without `short_channel_id`s;
2137 /// [`ChannelManager::list_usable_channels`] will never include such channels.
2138 ///
2139 /// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
2140 /// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
2141 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
2142 ///
2143 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
2144 #[no_mangle]
2145 pub extern "C" fn find_route(mut our_node_pubkey: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, network_graph: &crate::lightning::routing::gossip::NetworkGraph, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut logger: crate::lightning::util::logger::Logger, scorer: &crate::lightning::routing::scoring::ScoreLookUp, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
2146         let mut local_first_hops_base = if first_hops == core::ptr::null_mut() { None } else { Some( { let mut local_first_hops_0 = Vec::new(); for mut item in unsafe { &mut *first_hops }.as_slice().iter() { local_first_hops_0.push( { item.get_native_ref() }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]);
2147         let mut ret = lightning::routing::router::find_route::<crate::lightning::util::logger::Logger, crate::lightning::util::logger::Logger, crate::lightning::routing::scoring::ScoreLookUp>(&our_node_pubkey.into_rust(), route_params.get_native_ref(), network_graph.get_native_ref(), local_first_hops, logger, scorer, score_params.get_native_ref(), unsafe { &*random_seed_bytes});
2148         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
2149         local_ret
2150 }
2151
2152 /// Construct a route from us (payer) to the target node (payee) via the given hops (which should
2153 /// exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
2154 ///
2155 /// Re-uses logic from `find_route`, so the restrictions described there also apply here.
2156 #[no_mangle]
2157 pub extern "C" fn build_route_from_hops(mut our_node_pubkey: crate::c_types::PublicKey, mut hops: crate::c_types::derived::CVec_PublicKeyZ, route_params: &crate::lightning::routing::router::RouteParameters, network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut logger: crate::lightning::util::logger::Logger, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
2158         let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { item.into_rust() }); };
2159         let mut ret = lightning::routing::router::build_route_from_hops::<crate::lightning::util::logger::Logger, crate::lightning::util::logger::Logger>(&our_node_pubkey.into_rust(), &local_hops[..], route_params.get_native_ref(), network_graph.get_native_ref(), logger, unsafe { &*random_seed_bytes});
2160         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
2161         local_ret
2162 }
2163