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