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