Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning / routing / router.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
8
9 //! The router finds paths within a [`NetworkGraph`] for a payment.
10
11 use alloc::str::FromStr;
12 use 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, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) {
287         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
288         <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, &local_path[..], short_channel_id)
289 }
290 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_payment_path_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
291         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
292         <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, &local_path[..])
293 }
294 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_probe_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) {
295         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
296         <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::probe_failed(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, &local_path[..], short_channel_id)
297 }
298 extern "C" fn ScorerAccountingForInFlightHtlcs_Score_probe_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
299         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
300         <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::Score<>>::probe_successful(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, &local_path[..])
301 }
302
303
304 use lightning::routing::router::InFlightHtlcs as nativeInFlightHtlcsImport;
305 pub(crate) type nativeInFlightHtlcs = nativeInFlightHtlcsImport;
306
307 /// A data structure for tracking in-flight HTLCs. May be used during pathfinding to account for
308 /// in-use channel liquidity.
309 #[must_use]
310 #[repr(C)]
311 pub struct InFlightHtlcs {
312         /// A pointer to the opaque Rust object.
313
314         /// Nearly everywhere, inner must be non-null, however in places where
315         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
316         pub inner: *mut nativeInFlightHtlcs,
317         /// Indicates that this is the only struct which contains the same pointer.
318
319         /// Rust functions which take ownership of an object provided via an argument require
320         /// this to be true and invalidate the object pointed to by inner.
321         pub is_owned: bool,
322 }
323
324 impl Drop for InFlightHtlcs {
325         fn drop(&mut self) {
326                 if self.is_owned && !<*mut nativeInFlightHtlcs>::is_null(self.inner) {
327                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
328                 }
329         }
330 }
331 /// Frees any resources used by the InFlightHtlcs, if is_owned is set and inner is non-NULL.
332 #[no_mangle]
333 pub extern "C" fn InFlightHtlcs_free(this_obj: InFlightHtlcs) { }
334 #[allow(unused)]
335 /// Used only if an object of this type is returned as a trait impl by a method
336 pub(crate) extern "C" fn InFlightHtlcs_free_void(this_ptr: *mut c_void) {
337         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInFlightHtlcs) };
338 }
339 #[allow(unused)]
340 impl InFlightHtlcs {
341         pub(crate) fn get_native_ref(&self) -> &'static nativeInFlightHtlcs {
342                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
343         }
344         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInFlightHtlcs {
345                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
346         }
347         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
348         pub(crate) fn take_inner(mut self) -> *mut nativeInFlightHtlcs {
349                 assert!(self.is_owned);
350                 let ret = ObjOps::untweak_ptr(self.inner);
351                 self.inner = core::ptr::null_mut();
352                 ret
353         }
354 }
355 impl Clone for InFlightHtlcs {
356         fn clone(&self) -> Self {
357                 Self {
358                         inner: if <*mut nativeInFlightHtlcs>::is_null(self.inner) { core::ptr::null_mut() } else {
359                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
360                         is_owned: true,
361                 }
362         }
363 }
364 #[allow(unused)]
365 /// Used only if an object of this type is returned as a trait impl by a method
366 pub(crate) extern "C" fn InFlightHtlcs_clone_void(this_ptr: *const c_void) -> *mut c_void {
367         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInFlightHtlcs)).clone() })) as *mut c_void
368 }
369 #[no_mangle]
370 /// Creates a copy of the InFlightHtlcs
371 pub extern "C" fn InFlightHtlcs_clone(orig: &InFlightHtlcs) -> InFlightHtlcs {
372         orig.clone()
373 }
374 /// Constructs an empty `InFlightHtlcs`.
375 #[must_use]
376 #[no_mangle]
377 pub extern "C" fn InFlightHtlcs_new() -> crate::lightning::routing::router::InFlightHtlcs {
378         let mut ret = lightning::routing::router::InFlightHtlcs::new();
379         crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
380 }
381
382 /// Returns liquidity in msat given the public key of the HTLC source, target, and short channel
383 /// id.
384 #[must_use]
385 #[no_mangle]
386 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 {
387         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.used_liquidity_msat(source.get_native_ref(), target.get_native_ref(), channel_scid);
388         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() }) };
389         local_ret
390 }
391
392 #[no_mangle]
393 /// Serialize the InFlightHtlcs object into a byte array which can be read by InFlightHtlcs_read
394 pub extern "C" fn InFlightHtlcs_write(obj: &crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CVec_u8Z {
395         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
396 }
397 #[no_mangle]
398 pub(crate) extern "C" fn InFlightHtlcs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
399         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInFlightHtlcs) })
400 }
401 #[no_mangle]
402 /// Read a InFlightHtlcs from a byte array, created by InFlightHtlcs_write
403 pub extern "C" fn InFlightHtlcs_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InFlightHtlcsDecodeErrorZ {
404         let res: Result<lightning::routing::router::InFlightHtlcs, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
405         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() };
406         local_res
407 }
408
409 use lightning::routing::router::RouteHop as nativeRouteHopImport;
410 pub(crate) type nativeRouteHop = nativeRouteHopImport;
411
412 /// A hop in a route
413 #[must_use]
414 #[repr(C)]
415 pub struct RouteHop {
416         /// A pointer to the opaque Rust object.
417
418         /// Nearly everywhere, inner must be non-null, however in places where
419         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
420         pub inner: *mut nativeRouteHop,
421         /// Indicates that this is the only struct which contains the same pointer.
422
423         /// Rust functions which take ownership of an object provided via an argument require
424         /// this to be true and invalidate the object pointed to by inner.
425         pub is_owned: bool,
426 }
427
428 impl Drop for RouteHop {
429         fn drop(&mut self) {
430                 if self.is_owned && !<*mut nativeRouteHop>::is_null(self.inner) {
431                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
432                 }
433         }
434 }
435 /// Frees any resources used by the RouteHop, if is_owned is set and inner is non-NULL.
436 #[no_mangle]
437 pub extern "C" fn RouteHop_free(this_obj: RouteHop) { }
438 #[allow(unused)]
439 /// Used only if an object of this type is returned as a trait impl by a method
440 pub(crate) extern "C" fn RouteHop_free_void(this_ptr: *mut c_void) {
441         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHop) };
442 }
443 #[allow(unused)]
444 impl RouteHop {
445         pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHop {
446                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
447         }
448         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHop {
449                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
450         }
451         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
452         pub(crate) fn take_inner(mut self) -> *mut nativeRouteHop {
453                 assert!(self.is_owned);
454                 let ret = ObjOps::untweak_ptr(self.inner);
455                 self.inner = core::ptr::null_mut();
456                 ret
457         }
458 }
459 /// The node_id of the node at this hop.
460 #[no_mangle]
461 pub extern "C" fn RouteHop_get_pubkey(this_ptr: &RouteHop) -> crate::c_types::PublicKey {
462         let mut inner_val = &mut this_ptr.get_native_mut_ref().pubkey;
463         crate::c_types::PublicKey::from_rust(&inner_val)
464 }
465 /// The node_id of the node at this hop.
466 #[no_mangle]
467 pub extern "C" fn RouteHop_set_pubkey(this_ptr: &mut RouteHop, mut val: crate::c_types::PublicKey) {
468         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.pubkey = val.into_rust();
469 }
470 /// The node_announcement features of the node at this hop. For the last hop, these may be
471 /// amended to match the features present in the invoice this node generated.
472 #[no_mangle]
473 pub extern "C" fn RouteHop_get_node_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::NodeFeatures {
474         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_features;
475         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 }
476 }
477 /// The node_announcement features of the node at this hop. For the last hop, these may be
478 /// amended to match the features present in the invoice this node generated.
479 #[no_mangle]
480 pub extern "C" fn RouteHop_set_node_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::NodeFeatures) {
481         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_features = *unsafe { Box::from_raw(val.take_inner()) };
482 }
483 /// The channel that should be used from the previous hop to reach this node.
484 #[no_mangle]
485 pub extern "C" fn RouteHop_get_short_channel_id(this_ptr: &RouteHop) -> u64 {
486         let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
487         *inner_val
488 }
489 /// The channel that should be used from the previous hop to reach this node.
490 #[no_mangle]
491 pub extern "C" fn RouteHop_set_short_channel_id(this_ptr: &mut RouteHop, mut val: u64) {
492         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
493 }
494 /// The channel_announcement features of the channel that should be used from the previous hop
495 /// to reach this node.
496 #[no_mangle]
497 pub extern "C" fn RouteHop_get_channel_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::ChannelFeatures {
498         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_features;
499         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 }
500 }
501 /// The channel_announcement features of the channel that should be used from the previous hop
502 /// to reach this node.
503 #[no_mangle]
504 pub extern "C" fn RouteHop_set_channel_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::ChannelFeatures) {
505         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_features = *unsafe { Box::from_raw(val.take_inner()) };
506 }
507 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
508 /// For the last hop, this should be the full value of the payment (might be more than
509 /// requested if we had to match htlc_minimum_msat).
510 #[no_mangle]
511 pub extern "C" fn RouteHop_get_fee_msat(this_ptr: &RouteHop) -> u64 {
512         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_msat;
513         *inner_val
514 }
515 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
516 /// For the last hop, this should be the full value of the payment (might be more than
517 /// requested if we had to match htlc_minimum_msat).
518 #[no_mangle]
519 pub extern "C" fn RouteHop_set_fee_msat(this_ptr: &mut RouteHop, mut val: u64) {
520         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_msat = val;
521 }
522 /// The CLTV delta added for this hop. For the last hop, this should be the full CLTV value
523 /// expected at the destination, in excess of the current block height.
524 #[no_mangle]
525 pub extern "C" fn RouteHop_get_cltv_expiry_delta(this_ptr: &RouteHop) -> u32 {
526         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
527         *inner_val
528 }
529 /// The CLTV delta added for this hop. For the last hop, this should be the full CLTV value
530 /// expected at the destination, in excess of the current block height.
531 #[no_mangle]
532 pub extern "C" fn RouteHop_set_cltv_expiry_delta(this_ptr: &mut RouteHop, mut val: u32) {
533         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
534 }
535 /// Constructs a new RouteHop given each field
536 #[must_use]
537 #[no_mangle]
538 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 {
539         RouteHop { inner: ObjOps::heap_alloc(nativeRouteHop {
540                 pubkey: pubkey_arg.into_rust(),
541                 node_features: *unsafe { Box::from_raw(node_features_arg.take_inner()) },
542                 short_channel_id: short_channel_id_arg,
543                 channel_features: *unsafe { Box::from_raw(channel_features_arg.take_inner()) },
544                 fee_msat: fee_msat_arg,
545                 cltv_expiry_delta: cltv_expiry_delta_arg,
546         }), is_owned: true }
547 }
548 impl Clone for RouteHop {
549         fn clone(&self) -> Self {
550                 Self {
551                         inner: if <*mut nativeRouteHop>::is_null(self.inner) { core::ptr::null_mut() } else {
552                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
553                         is_owned: true,
554                 }
555         }
556 }
557 #[allow(unused)]
558 /// Used only if an object of this type is returned as a trait impl by a method
559 pub(crate) extern "C" fn RouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
560         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHop)).clone() })) as *mut c_void
561 }
562 #[no_mangle]
563 /// Creates a copy of the RouteHop
564 pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop {
565         orig.clone()
566 }
567 /// Checks if two RouteHops contain equal inner contents.
568 #[no_mangle]
569 pub extern "C" fn RouteHop_hash(o: &RouteHop) -> u64 {
570         if o.inner.is_null() { return 0; }
571         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
572         #[allow(deprecated)]
573         let mut hasher = core::hash::SipHasher::new();
574         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
575         core::hash::Hasher::finish(&hasher)
576 }
577 /// Checks if two RouteHops contain equal inner contents.
578 /// This ignores pointers and is_owned flags and looks at the values in fields.
579 /// Two objects with NULL inner values will be considered "equal" here.
580 #[no_mangle]
581 pub extern "C" fn RouteHop_eq(a: &RouteHop, b: &RouteHop) -> bool {
582         if a.inner == b.inner { return true; }
583         if a.inner.is_null() || b.inner.is_null() { return false; }
584         if a.get_native_ref() == b.get_native_ref() { true } else { false }
585 }
586 #[no_mangle]
587 /// Serialize the RouteHop object into a byte array which can be read by RouteHop_read
588 pub extern "C" fn RouteHop_write(obj: &crate::lightning::routing::router::RouteHop) -> crate::c_types::derived::CVec_u8Z {
589         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
590 }
591 #[no_mangle]
592 pub(crate) extern "C" fn RouteHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
593         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHop) })
594 }
595 #[no_mangle]
596 /// Read a RouteHop from a byte array, created by RouteHop_write
597 pub extern "C" fn RouteHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHopDecodeErrorZ {
598         let res: Result<lightning::routing::router::RouteHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
599         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() };
600         local_res
601 }
602
603 use lightning::routing::router::Route as nativeRouteImport;
604 pub(crate) type nativeRoute = nativeRouteImport;
605
606 /// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
607 /// it can take multiple paths. Each path is composed of one or more hops through the network.
608 #[must_use]
609 #[repr(C)]
610 pub struct Route {
611         /// A pointer to the opaque Rust object.
612
613         /// Nearly everywhere, inner must be non-null, however in places where
614         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
615         pub inner: *mut nativeRoute,
616         /// Indicates that this is the only struct which contains the same pointer.
617
618         /// Rust functions which take ownership of an object provided via an argument require
619         /// this to be true and invalidate the object pointed to by inner.
620         pub is_owned: bool,
621 }
622
623 impl Drop for Route {
624         fn drop(&mut self) {
625                 if self.is_owned && !<*mut nativeRoute>::is_null(self.inner) {
626                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
627                 }
628         }
629 }
630 /// Frees any resources used by the Route, if is_owned is set and inner is non-NULL.
631 #[no_mangle]
632 pub extern "C" fn Route_free(this_obj: Route) { }
633 #[allow(unused)]
634 /// Used only if an object of this type is returned as a trait impl by a method
635 pub(crate) extern "C" fn Route_free_void(this_ptr: *mut c_void) {
636         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoute) };
637 }
638 #[allow(unused)]
639 impl Route {
640         pub(crate) fn get_native_ref(&self) -> &'static nativeRoute {
641                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
642         }
643         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoute {
644                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
645         }
646         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
647         pub(crate) fn take_inner(mut self) -> *mut nativeRoute {
648                 assert!(self.is_owned);
649                 let ret = ObjOps::untweak_ptr(self.inner);
650                 self.inner = core::ptr::null_mut();
651                 ret
652         }
653 }
654 /// The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
655 /// last RouteHop in each path must be the same. Each entry represents a list of hops, NOT
656 /// INCLUDING our own, where the last hop is the destination. Thus, this must always be at
657 /// least length one. While the maximum length of any given path is variable, keeping the length
658 /// of any path less or equal to 19 should currently ensure it is viable.
659 #[no_mangle]
660 pub extern "C" fn Route_get_paths(this_ptr: &Route) -> crate::c_types::derived::CVec_CVec_RouteHopZZ {
661         let mut inner_val = &mut this_ptr.get_native_mut_ref().paths;
662         let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { let mut local_inner_val_0 = Vec::new(); for item in item.iter() { local_inner_val_0.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 } }); }; local_inner_val_0.into() }); };
663         local_inner_val.into()
664 }
665 /// The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
666 /// last RouteHop in each path must be the same. Each entry represents a list of hops, NOT
667 /// INCLUDING our own, where the last hop is the destination. Thus, this must always be at
668 /// least length one. While the maximum length of any given path is variable, keeping the length
669 /// of any path less or equal to 19 should currently ensure it is viable.
670 #[no_mangle]
671 pub extern "C" fn Route_set_paths(this_ptr: &mut Route, mut val: crate::c_types::derived::CVec_CVec_RouteHopZZ) {
672         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { let mut local_val_0 = Vec::new(); for mut item in item.into_rust().drain(..) { local_val_0.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; local_val_0 }); };
673         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.paths = local_val;
674 }
675 /// The `payment_params` parameter passed to [`find_route`].
676 /// This is used by `ChannelManager` to track information which may be required for retries,
677 /// provided back to you via [`Event::PaymentPathFailed`].
678 ///
679 /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
680 ///
681 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
682 #[no_mangle]
683 pub extern "C" fn Route_get_payment_params(this_ptr: &Route) -> crate::lightning::routing::router::PaymentParameters {
684         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_params;
685         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 };
686         local_inner_val
687 }
688 /// The `payment_params` parameter passed to [`find_route`].
689 /// This is used by `ChannelManager` to track information which may be required for retries,
690 /// provided back to you via [`Event::PaymentPathFailed`].
691 ///
692 /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
693 ///
694 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
695 #[no_mangle]
696 pub extern "C" fn Route_set_payment_params(this_ptr: &mut Route, mut val: crate::lightning::routing::router::PaymentParameters) {
697         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
698         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_params = local_val;
699 }
700 /// Constructs a new Route given each field
701 #[must_use]
702 #[no_mangle]
703 pub extern "C" fn Route_new(mut paths_arg: crate::c_types::derived::CVec_CVec_RouteHopZZ, mut payment_params_arg: crate::lightning::routing::router::PaymentParameters) -> Route {
704         let mut local_paths_arg = Vec::new(); for mut item in paths_arg.into_rust().drain(..) { local_paths_arg.push( { let mut local_paths_arg_0 = Vec::new(); for mut item in item.into_rust().drain(..) { local_paths_arg_0.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; local_paths_arg_0 }); };
705         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()) } }) };
706         Route { inner: ObjOps::heap_alloc(nativeRoute {
707                 paths: local_paths_arg,
708                 payment_params: local_payment_params_arg,
709         }), is_owned: true }
710 }
711 impl Clone for Route {
712         fn clone(&self) -> Self {
713                 Self {
714                         inner: if <*mut nativeRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
715                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
716                         is_owned: true,
717                 }
718         }
719 }
720 #[allow(unused)]
721 /// Used only if an object of this type is returned as a trait impl by a method
722 pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_void {
723         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoute)).clone() })) as *mut c_void
724 }
725 #[no_mangle]
726 /// Creates a copy of the Route
727 pub extern "C" fn Route_clone(orig: &Route) -> Route {
728         orig.clone()
729 }
730 /// Checks if two Routes contain equal inner contents.
731 #[no_mangle]
732 pub extern "C" fn Route_hash(o: &Route) -> u64 {
733         if o.inner.is_null() { return 0; }
734         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
735         #[allow(deprecated)]
736         let mut hasher = core::hash::SipHasher::new();
737         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
738         core::hash::Hasher::finish(&hasher)
739 }
740 /// Checks if two Routes contain equal inner contents.
741 /// This ignores pointers and is_owned flags and looks at the values in fields.
742 /// Two objects with NULL inner values will be considered "equal" here.
743 #[no_mangle]
744 pub extern "C" fn Route_eq(a: &Route, b: &Route) -> bool {
745         if a.inner == b.inner { return true; }
746         if a.inner.is_null() || b.inner.is_null() { return false; }
747         if a.get_native_ref() == b.get_native_ref() { true } else { false }
748 }
749 /// Returns the total amount of fees paid on this [`Route`].
750 ///
751 /// This doesn't include any extra payment made to the recipient, which can happen in excess of
752 /// the amount passed to [`find_route`]'s `params.final_value_msat`.
753 #[must_use]
754 #[no_mangle]
755 pub extern "C" fn Route_get_total_fees(this_arg: &crate::lightning::routing::router::Route) -> u64 {
756         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_fees();
757         ret
758 }
759
760 /// Returns the total amount paid on this [`Route`], excluding the fees.
761 #[must_use]
762 #[no_mangle]
763 pub extern "C" fn Route_get_total_amount(this_arg: &crate::lightning::routing::router::Route) -> u64 {
764         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_amount();
765         ret
766 }
767
768 #[no_mangle]
769 /// Serialize the Route object into a byte array which can be read by Route_read
770 pub extern "C" fn Route_write(obj: &crate::lightning::routing::router::Route) -> crate::c_types::derived::CVec_u8Z {
771         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
772 }
773 #[no_mangle]
774 pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
775         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) })
776 }
777 #[no_mangle]
778 /// Read a Route from a byte array, created by Route_write
779 pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ {
780         let res: Result<lightning::routing::router::Route, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
781         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() };
782         local_res
783 }
784
785 use lightning::routing::router::RouteParameters as nativeRouteParametersImport;
786 pub(crate) type nativeRouteParameters = nativeRouteParametersImport;
787
788 /// Parameters needed to find a [`Route`].
789 ///
790 /// Passed to [`find_route`] and [`build_route_from_hops`], but also provided in
791 /// [`Event::PaymentPathFailed`].
792 ///
793 /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
794 #[must_use]
795 #[repr(C)]
796 pub struct RouteParameters {
797         /// A pointer to the opaque Rust object.
798
799         /// Nearly everywhere, inner must be non-null, however in places where
800         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
801         pub inner: *mut nativeRouteParameters,
802         /// Indicates that this is the only struct which contains the same pointer.
803
804         /// Rust functions which take ownership of an object provided via an argument require
805         /// this to be true and invalidate the object pointed to by inner.
806         pub is_owned: bool,
807 }
808
809 impl Drop for RouteParameters {
810         fn drop(&mut self) {
811                 if self.is_owned && !<*mut nativeRouteParameters>::is_null(self.inner) {
812                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
813                 }
814         }
815 }
816 /// Frees any resources used by the RouteParameters, if is_owned is set and inner is non-NULL.
817 #[no_mangle]
818 pub extern "C" fn RouteParameters_free(this_obj: RouteParameters) { }
819 #[allow(unused)]
820 /// Used only if an object of this type is returned as a trait impl by a method
821 pub(crate) extern "C" fn RouteParameters_free_void(this_ptr: *mut c_void) {
822         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteParameters) };
823 }
824 #[allow(unused)]
825 impl RouteParameters {
826         pub(crate) fn get_native_ref(&self) -> &'static nativeRouteParameters {
827                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
828         }
829         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteParameters {
830                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
831         }
832         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
833         pub(crate) fn take_inner(mut self) -> *mut nativeRouteParameters {
834                 assert!(self.is_owned);
835                 let ret = ObjOps::untweak_ptr(self.inner);
836                 self.inner = core::ptr::null_mut();
837                 ret
838         }
839 }
840 /// The parameters of the failed payment path.
841 #[no_mangle]
842 pub extern "C" fn RouteParameters_get_payment_params(this_ptr: &RouteParameters) -> crate::lightning::routing::router::PaymentParameters {
843         let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_params;
844         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 }
845 }
846 /// The parameters of the failed payment path.
847 #[no_mangle]
848 pub extern "C" fn RouteParameters_set_payment_params(this_ptr: &mut RouteParameters, mut val: crate::lightning::routing::router::PaymentParameters) {
849         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_params = *unsafe { Box::from_raw(val.take_inner()) };
850 }
851 /// The amount in msats sent on the failed payment path.
852 #[no_mangle]
853 pub extern "C" fn RouteParameters_get_final_value_msat(this_ptr: &RouteParameters) -> u64 {
854         let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
855         *inner_val
856 }
857 /// The amount in msats sent on the failed payment path.
858 #[no_mangle]
859 pub extern "C" fn RouteParameters_set_final_value_msat(this_ptr: &mut RouteParameters, mut val: u64) {
860         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
861 }
862 /// Constructs a new RouteParameters given each field
863 #[must_use]
864 #[no_mangle]
865 pub extern "C" fn RouteParameters_new(mut payment_params_arg: crate::lightning::routing::router::PaymentParameters, mut final_value_msat_arg: u64) -> RouteParameters {
866         RouteParameters { inner: ObjOps::heap_alloc(nativeRouteParameters {
867                 payment_params: *unsafe { Box::from_raw(payment_params_arg.take_inner()) },
868                 final_value_msat: final_value_msat_arg,
869         }), is_owned: true }
870 }
871 impl Clone for RouteParameters {
872         fn clone(&self) -> Self {
873                 Self {
874                         inner: if <*mut nativeRouteParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
875                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
876                         is_owned: true,
877                 }
878         }
879 }
880 #[allow(unused)]
881 /// Used only if an object of this type is returned as a trait impl by a method
882 pub(crate) extern "C" fn RouteParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
883         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteParameters)).clone() })) as *mut c_void
884 }
885 #[no_mangle]
886 /// Creates a copy of the RouteParameters
887 pub extern "C" fn RouteParameters_clone(orig: &RouteParameters) -> RouteParameters {
888         orig.clone()
889 }
890 /// Checks if two RouteParameterss contain equal inner contents.
891 /// This ignores pointers and is_owned flags and looks at the values in fields.
892 /// Two objects with NULL inner values will be considered "equal" here.
893 #[no_mangle]
894 pub extern "C" fn RouteParameters_eq(a: &RouteParameters, b: &RouteParameters) -> bool {
895         if a.inner == b.inner { return true; }
896         if a.inner.is_null() || b.inner.is_null() { return false; }
897         if a.get_native_ref() == b.get_native_ref() { true } else { false }
898 }
899 #[no_mangle]
900 /// Serialize the RouteParameters object into a byte array which can be read by RouteParameters_read
901 pub extern "C" fn RouteParameters_write(obj: &crate::lightning::routing::router::RouteParameters) -> crate::c_types::derived::CVec_u8Z {
902         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
903 }
904 #[no_mangle]
905 pub(crate) extern "C" fn RouteParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
906         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteParameters) })
907 }
908 #[no_mangle]
909 /// Read a RouteParameters from a byte array, created by RouteParameters_write
910 pub extern "C" fn RouteParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteParametersDecodeErrorZ {
911         let res: Result<lightning::routing::router::RouteParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
912         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() };
913         local_res
914 }
915 /// Maximum total CTLV difference we allow for a full payment path.
916
917 #[no_mangle]
918 pub static DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = lightning::routing::router::DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
919 /// Maximum number of paths we allow an (MPP) payment to have.
920
921 #[no_mangle]
922 pub static DEFAULT_MAX_PATH_COUNT: u8 = lightning::routing::router::DEFAULT_MAX_PATH_COUNT;
923
924 use lightning::routing::router::PaymentParameters as nativePaymentParametersImport;
925 pub(crate) type nativePaymentParameters = nativePaymentParametersImport;
926
927 /// The recipient of a payment.
928 #[must_use]
929 #[repr(C)]
930 pub struct PaymentParameters {
931         /// A pointer to the opaque Rust object.
932
933         /// Nearly everywhere, inner must be non-null, however in places where
934         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
935         pub inner: *mut nativePaymentParameters,
936         /// Indicates that this is the only struct which contains the same pointer.
937
938         /// Rust functions which take ownership of an object provided via an argument require
939         /// this to be true and invalidate the object pointed to by inner.
940         pub is_owned: bool,
941 }
942
943 impl Drop for PaymentParameters {
944         fn drop(&mut self) {
945                 if self.is_owned && !<*mut nativePaymentParameters>::is_null(self.inner) {
946                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
947                 }
948         }
949 }
950 /// Frees any resources used by the PaymentParameters, if is_owned is set and inner is non-NULL.
951 #[no_mangle]
952 pub extern "C" fn PaymentParameters_free(this_obj: PaymentParameters) { }
953 #[allow(unused)]
954 /// Used only if an object of this type is returned as a trait impl by a method
955 pub(crate) extern "C" fn PaymentParameters_free_void(this_ptr: *mut c_void) {
956         let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentParameters) };
957 }
958 #[allow(unused)]
959 impl PaymentParameters {
960         pub(crate) fn get_native_ref(&self) -> &'static nativePaymentParameters {
961                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
962         }
963         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentParameters {
964                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
965         }
966         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
967         pub(crate) fn take_inner(mut self) -> *mut nativePaymentParameters {
968                 assert!(self.is_owned);
969                 let ret = ObjOps::untweak_ptr(self.inner);
970                 self.inner = core::ptr::null_mut();
971                 ret
972         }
973 }
974 /// The node id of the payee.
975 #[no_mangle]
976 pub extern "C" fn PaymentParameters_get_payee_pubkey(this_ptr: &PaymentParameters) -> crate::c_types::PublicKey {
977         let mut inner_val = &mut this_ptr.get_native_mut_ref().payee_pubkey;
978         crate::c_types::PublicKey::from_rust(&inner_val)
979 }
980 /// The node id of the payee.
981 #[no_mangle]
982 pub extern "C" fn PaymentParameters_set_payee_pubkey(this_ptr: &mut PaymentParameters, mut val: crate::c_types::PublicKey) {
983         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payee_pubkey = val.into_rust();
984 }
985 /// Features supported by the payee.
986 ///
987 /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
988 /// does not contain any features.
989 ///
990 /// [`for_keysend`]: Self::for_keysend
991 ///
992 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
993 #[no_mangle]
994 pub extern "C" fn PaymentParameters_get_features(this_ptr: &PaymentParameters) -> crate::lightning::ln::features::InvoiceFeatures {
995         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
996         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 };
997         local_inner_val
998 }
999 /// Features supported by the payee.
1000 ///
1001 /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
1002 /// does not contain any features.
1003 ///
1004 /// [`for_keysend`]: Self::for_keysend
1005 ///
1006 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1007 #[no_mangle]
1008 pub extern "C" fn PaymentParameters_set_features(this_ptr: &mut PaymentParameters, mut val: crate::lightning::ln::features::InvoiceFeatures) {
1009         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1010         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = local_val;
1011 }
1012 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
1013 #[no_mangle]
1014 pub extern "C" fn PaymentParameters_get_route_hints(this_ptr: &PaymentParameters) -> crate::c_types::derived::CVec_RouteHintZ {
1015         let mut inner_val = &mut this_ptr.get_native_mut_ref().route_hints;
1016         let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::RouteHint { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::RouteHint<>) as *mut _) }, is_owned: false } }); };
1017         local_inner_val.into()
1018 }
1019 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
1020 #[no_mangle]
1021 pub extern "C" fn PaymentParameters_set_route_hints(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_RouteHintZ) {
1022         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1023         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_hints = local_val;
1024 }
1025 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1026 #[no_mangle]
1027 pub extern "C" fn PaymentParameters_get_expiry_time(this_ptr: &PaymentParameters) -> crate::c_types::derived::COption_u64Z {
1028         let mut inner_val = &mut this_ptr.get_native_mut_ref().expiry_time;
1029         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() }) };
1030         local_inner_val
1031 }
1032 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1033 #[no_mangle]
1034 pub extern "C" fn PaymentParameters_set_expiry_time(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::COption_u64Z) {
1035         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1036         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.expiry_time = local_val;
1037 }
1038 /// The maximum total CLTV delta we accept for the route.
1039 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1040 #[no_mangle]
1041 pub extern "C" fn PaymentParameters_get_max_total_cltv_expiry_delta(this_ptr: &PaymentParameters) -> u32 {
1042         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_cltv_expiry_delta;
1043         *inner_val
1044 }
1045 /// The maximum total CLTV delta we accept for the route.
1046 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1047 #[no_mangle]
1048 pub extern "C" fn PaymentParameters_set_max_total_cltv_expiry_delta(this_ptr: &mut PaymentParameters, mut val: u32) {
1049         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_cltv_expiry_delta = val;
1050 }
1051 /// The maximum number of paths that may be used by (MPP) payments.
1052 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1053 #[no_mangle]
1054 pub extern "C" fn PaymentParameters_get_max_path_count(this_ptr: &PaymentParameters) -> u8 {
1055         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_path_count;
1056         *inner_val
1057 }
1058 /// The maximum number of paths that may be used by (MPP) payments.
1059 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1060 #[no_mangle]
1061 pub extern "C" fn PaymentParameters_set_max_path_count(this_ptr: &mut PaymentParameters, mut val: u8) {
1062         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_path_count = val;
1063 }
1064 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1065 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1066 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1067 /// increasing failure probability for those paths.
1068 ///
1069 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1070 /// restriction have been found. While paths which meet this criteria will be searched for, it
1071 /// is ultimately up to the scorer to select them over other paths.
1072 ///
1073 /// A value of 0 will allow payments up to and including a channel's total announced usable
1074 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1075 ///
1076 /// Default value: 2
1077 #[no_mangle]
1078 pub extern "C" fn PaymentParameters_get_max_channel_saturation_power_of_half(this_ptr: &PaymentParameters) -> u8 {
1079         let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_saturation_power_of_half;
1080         *inner_val
1081 }
1082 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1083 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1084 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1085 /// increasing failure probability for those paths.
1086 ///
1087 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1088 /// restriction have been found. While paths which meet this criteria will be searched for, it
1089 /// is ultimately up to the scorer to select them over other paths.
1090 ///
1091 /// A value of 0 will allow payments up to and including a channel's total announced usable
1092 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1093 ///
1094 /// Default value: 2
1095 #[no_mangle]
1096 pub extern "C" fn PaymentParameters_set_max_channel_saturation_power_of_half(this_ptr: &mut PaymentParameters, mut val: u8) {
1097         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_saturation_power_of_half = val;
1098 }
1099 /// A list of SCIDs which this payment was previously attempted over and which caused the
1100 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1101 /// these SCIDs.
1102 ///
1103 /// Returns a copy of the field.
1104 #[no_mangle]
1105 pub extern "C" fn PaymentParameters_get_previously_failed_channels(this_ptr: &PaymentParameters) -> crate::c_types::derived::CVec_u64Z {
1106         let mut inner_val = this_ptr.get_native_mut_ref().previously_failed_channels.clone();
1107         let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1108         local_inner_val.into()
1109 }
1110 /// A list of SCIDs which this payment was previously attempted over and which caused the
1111 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1112 /// these SCIDs.
1113 #[no_mangle]
1114 pub extern "C" fn PaymentParameters_set_previously_failed_channels(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_u64Z) {
1115         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1116         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previously_failed_channels = local_val;
1117 }
1118 /// The minimum CLTV delta at the end of the route. This value must not be zero.
1119 #[no_mangle]
1120 pub extern "C" fn PaymentParameters_get_final_cltv_expiry_delta(this_ptr: &PaymentParameters) -> u32 {
1121         let mut inner_val = &mut this_ptr.get_native_mut_ref().final_cltv_expiry_delta;
1122         *inner_val
1123 }
1124 /// The minimum CLTV delta at the end of the route. This value must not be zero.
1125 #[no_mangle]
1126 pub extern "C" fn PaymentParameters_set_final_cltv_expiry_delta(this_ptr: &mut PaymentParameters, mut val: u32) {
1127         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_cltv_expiry_delta = val;
1128 }
1129 /// Constructs a new PaymentParameters given each field
1130 #[must_use]
1131 #[no_mangle]
1132 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::c_types::derived::CVec_RouteHintZ, 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 {
1133         let mut local_features_arg = if features_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_arg.take_inner()) } }) };
1134         let mut local_route_hints_arg = Vec::new(); for mut item in route_hints_arg.into_rust().drain(..) { local_route_hints_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1135         let mut local_expiry_time_arg = if expiry_time_arg.is_some() { Some( { expiry_time_arg.take() }) } else { None };
1136         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 }); };
1137         PaymentParameters { inner: ObjOps::heap_alloc(nativePaymentParameters {
1138                 payee_pubkey: payee_pubkey_arg.into_rust(),
1139                 features: local_features_arg,
1140                 route_hints: local_route_hints_arg,
1141                 expiry_time: local_expiry_time_arg,
1142                 max_total_cltv_expiry_delta: max_total_cltv_expiry_delta_arg,
1143                 max_path_count: max_path_count_arg,
1144                 max_channel_saturation_power_of_half: max_channel_saturation_power_of_half_arg,
1145                 previously_failed_channels: local_previously_failed_channels_arg,
1146                 final_cltv_expiry_delta: final_cltv_expiry_delta_arg,
1147         }), is_owned: true }
1148 }
1149 impl Clone for PaymentParameters {
1150         fn clone(&self) -> Self {
1151                 Self {
1152                         inner: if <*mut nativePaymentParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1153                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1154                         is_owned: true,
1155                 }
1156         }
1157 }
1158 #[allow(unused)]
1159 /// Used only if an object of this type is returned as a trait impl by a method
1160 pub(crate) extern "C" fn PaymentParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1161         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePaymentParameters)).clone() })) as *mut c_void
1162 }
1163 #[no_mangle]
1164 /// Creates a copy of the PaymentParameters
1165 pub extern "C" fn PaymentParameters_clone(orig: &PaymentParameters) -> PaymentParameters {
1166         orig.clone()
1167 }
1168 /// Checks if two PaymentParameterss contain equal inner contents.
1169 #[no_mangle]
1170 pub extern "C" fn PaymentParameters_hash(o: &PaymentParameters) -> u64 {
1171         if o.inner.is_null() { return 0; }
1172         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1173         #[allow(deprecated)]
1174         let mut hasher = core::hash::SipHasher::new();
1175         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1176         core::hash::Hasher::finish(&hasher)
1177 }
1178 /// Checks if two PaymentParameterss contain equal inner contents.
1179 /// This ignores pointers and is_owned flags and looks at the values in fields.
1180 /// Two objects with NULL inner values will be considered "equal" here.
1181 #[no_mangle]
1182 pub extern "C" fn PaymentParameters_eq(a: &PaymentParameters, b: &PaymentParameters) -> bool {
1183         if a.inner == b.inner { return true; }
1184         if a.inner.is_null() || b.inner.is_null() { return false; }
1185         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1186 }
1187 #[no_mangle]
1188 /// Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
1189 pub extern "C" fn PaymentParameters_write(obj: &crate::lightning::routing::router::PaymentParameters) -> crate::c_types::derived::CVec_u8Z {
1190         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1191 }
1192 #[no_mangle]
1193 pub(crate) extern "C" fn PaymentParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1194         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentParameters) })
1195 }
1196 #[no_mangle]
1197 /// Read a PaymentParameters from a byte array, created by PaymentParameters_write
1198 pub extern "C" fn PaymentParameters_read(ser: crate::c_types::u8slice, arg: u32) -> crate::c_types::derived::CResult_PaymentParametersDecodeErrorZ {
1199         let arg_conv = arg;
1200         let res: Result<lightning::routing::router::PaymentParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1201         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() };
1202         local_res
1203 }
1204 /// Creates a payee with the node id of the given `pubkey`.
1205 ///
1206 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1207 /// provided.
1208 #[must_use]
1209 #[no_mangle]
1210 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 {
1211         let mut ret = lightning::routing::router::PaymentParameters::from_node_id(payee_pubkey.into_rust(), final_cltv_expiry_delta);
1212         crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1213 }
1214
1215 /// Creates a payee with the node id of the given `pubkey` to use for keysend payments.
1216 ///
1217 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1218 /// provided.
1219 #[must_use]
1220 #[no_mangle]
1221 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 {
1222         let mut ret = lightning::routing::router::PaymentParameters::for_keysend(payee_pubkey.into_rust(), final_cltv_expiry_delta);
1223         crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1224 }
1225
1226
1227 use lightning::routing::router::RouteHint as nativeRouteHintImport;
1228 pub(crate) type nativeRouteHint = nativeRouteHintImport;
1229
1230 /// A list of hops along a payment path terminating with a channel to the recipient.
1231 #[must_use]
1232 #[repr(C)]
1233 pub struct RouteHint {
1234         /// A pointer to the opaque Rust object.
1235
1236         /// Nearly everywhere, inner must be non-null, however in places where
1237         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1238         pub inner: *mut nativeRouteHint,
1239         /// Indicates that this is the only struct which contains the same pointer.
1240
1241         /// Rust functions which take ownership of an object provided via an argument require
1242         /// this to be true and invalidate the object pointed to by inner.
1243         pub is_owned: bool,
1244 }
1245
1246 impl Drop for RouteHint {
1247         fn drop(&mut self) {
1248                 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
1249                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1250                 }
1251         }
1252 }
1253 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
1254 #[no_mangle]
1255 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
1256 #[allow(unused)]
1257 /// Used only if an object of this type is returned as a trait impl by a method
1258 pub(crate) extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
1259         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHint) };
1260 }
1261 #[allow(unused)]
1262 impl RouteHint {
1263         pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHint {
1264                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1265         }
1266         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHint {
1267                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1268         }
1269         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1270         pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
1271                 assert!(self.is_owned);
1272                 let ret = ObjOps::untweak_ptr(self.inner);
1273                 self.inner = core::ptr::null_mut();
1274                 ret
1275         }
1276 }
1277 #[no_mangle]
1278 pub extern "C" fn RouteHint_get_a(this_ptr: &RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ {
1279         let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1280         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 } }); };
1281         local_inner_val.into()
1282 }
1283 #[no_mangle]
1284 pub extern "C" fn RouteHint_set_a(this_ptr: &mut RouteHint, mut val: crate::c_types::derived::CVec_RouteHintHopZ) {
1285         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1286         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = local_val;
1287 }
1288 /// Constructs a new RouteHint given each field
1289 #[must_use]
1290 #[no_mangle]
1291 pub extern "C" fn RouteHint_new(mut a_arg: crate::c_types::derived::CVec_RouteHintHopZ) -> RouteHint {
1292         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()) } }); };
1293         RouteHint { inner: ObjOps::heap_alloc(lightning::routing::router::RouteHint (
1294                 local_a_arg,
1295         )), is_owned: true }
1296 }
1297 impl Clone for RouteHint {
1298         fn clone(&self) -> Self {
1299                 Self {
1300                         inner: if <*mut nativeRouteHint>::is_null(self.inner) { core::ptr::null_mut() } else {
1301                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1302                         is_owned: true,
1303                 }
1304         }
1305 }
1306 #[allow(unused)]
1307 /// Used only if an object of this type is returned as a trait impl by a method
1308 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
1309         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void
1310 }
1311 #[no_mangle]
1312 /// Creates a copy of the RouteHint
1313 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
1314         orig.clone()
1315 }
1316 /// Checks if two RouteHints contain equal inner contents.
1317 #[no_mangle]
1318 pub extern "C" fn RouteHint_hash(o: &RouteHint) -> u64 {
1319         if o.inner.is_null() { return 0; }
1320         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1321         #[allow(deprecated)]
1322         let mut hasher = core::hash::SipHasher::new();
1323         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1324         core::hash::Hasher::finish(&hasher)
1325 }
1326 /// Checks if two RouteHints contain equal inner contents.
1327 /// This ignores pointers and is_owned flags and looks at the values in fields.
1328 /// Two objects with NULL inner values will be considered "equal" here.
1329 #[no_mangle]
1330 pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool {
1331         if a.inner == b.inner { return true; }
1332         if a.inner.is_null() || b.inner.is_null() { return false; }
1333         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1334 }
1335 #[no_mangle]
1336 /// Serialize the RouteHint object into a byte array which can be read by RouteHint_read
1337 pub extern "C" fn RouteHint_write(obj: &crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CVec_u8Z {
1338         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1339 }
1340 #[no_mangle]
1341 pub(crate) extern "C" fn RouteHint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1342         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHint) })
1343 }
1344 #[no_mangle]
1345 /// Read a RouteHint from a byte array, created by RouteHint_write
1346 pub extern "C" fn RouteHint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintDecodeErrorZ {
1347         let res: Result<lightning::routing::router::RouteHint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1348         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() };
1349         local_res
1350 }
1351
1352 use lightning::routing::router::RouteHintHop as nativeRouteHintHopImport;
1353 pub(crate) type nativeRouteHintHop = nativeRouteHintHopImport;
1354
1355 /// A channel descriptor for a hop along a payment path.
1356 #[must_use]
1357 #[repr(C)]
1358 pub struct RouteHintHop {
1359         /// A pointer to the opaque Rust object.
1360
1361         /// Nearly everywhere, inner must be non-null, however in places where
1362         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1363         pub inner: *mut nativeRouteHintHop,
1364         /// Indicates that this is the only struct which contains the same pointer.
1365
1366         /// Rust functions which take ownership of an object provided via an argument require
1367         /// this to be true and invalidate the object pointed to by inner.
1368         pub is_owned: bool,
1369 }
1370
1371 impl Drop for RouteHintHop {
1372         fn drop(&mut self) {
1373                 if self.is_owned && !<*mut nativeRouteHintHop>::is_null(self.inner) {
1374                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1375                 }
1376         }
1377 }
1378 /// Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL.
1379 #[no_mangle]
1380 pub extern "C" fn RouteHintHop_free(this_obj: RouteHintHop) { }
1381 #[allow(unused)]
1382 /// Used only if an object of this type is returned as a trait impl by a method
1383 pub(crate) extern "C" fn RouteHintHop_free_void(this_ptr: *mut c_void) {
1384         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHintHop) };
1385 }
1386 #[allow(unused)]
1387 impl RouteHintHop {
1388         pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHintHop {
1389                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1390         }
1391         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHintHop {
1392                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1393         }
1394         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1395         pub(crate) fn take_inner(mut self) -> *mut nativeRouteHintHop {
1396                 assert!(self.is_owned);
1397                 let ret = ObjOps::untweak_ptr(self.inner);
1398                 self.inner = core::ptr::null_mut();
1399                 ret
1400         }
1401 }
1402 /// The node_id of the non-target end of the route
1403 #[no_mangle]
1404 pub extern "C" fn RouteHintHop_get_src_node_id(this_ptr: &RouteHintHop) -> crate::c_types::PublicKey {
1405         let mut inner_val = &mut this_ptr.get_native_mut_ref().src_node_id;
1406         crate::c_types::PublicKey::from_rust(&inner_val)
1407 }
1408 /// The node_id of the non-target end of the route
1409 #[no_mangle]
1410 pub extern "C" fn RouteHintHop_set_src_node_id(this_ptr: &mut RouteHintHop, mut val: crate::c_types::PublicKey) {
1411         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.src_node_id = val.into_rust();
1412 }
1413 /// The short_channel_id of this channel
1414 #[no_mangle]
1415 pub extern "C" fn RouteHintHop_get_short_channel_id(this_ptr: &RouteHintHop) -> u64 {
1416         let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
1417         *inner_val
1418 }
1419 /// The short_channel_id of this channel
1420 #[no_mangle]
1421 pub extern "C" fn RouteHintHop_set_short_channel_id(this_ptr: &mut RouteHintHop, mut val: u64) {
1422         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
1423 }
1424 /// The fees which must be paid to use this channel
1425 #[no_mangle]
1426 pub extern "C" fn RouteHintHop_get_fees(this_ptr: &RouteHintHop) -> crate::lightning::routing::gossip::RoutingFees {
1427         let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
1428         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 }
1429 }
1430 /// The fees which must be paid to use this channel
1431 #[no_mangle]
1432 pub extern "C" fn RouteHintHop_set_fees(this_ptr: &mut RouteHintHop, mut val: crate::lightning::routing::gossip::RoutingFees) {
1433         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
1434 }
1435 /// The difference in CLTV values between this node and the next node.
1436 #[no_mangle]
1437 pub extern "C" fn RouteHintHop_get_cltv_expiry_delta(this_ptr: &RouteHintHop) -> u16 {
1438         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
1439         *inner_val
1440 }
1441 /// The difference in CLTV values between this node and the next node.
1442 #[no_mangle]
1443 pub extern "C" fn RouteHintHop_set_cltv_expiry_delta(this_ptr: &mut RouteHintHop, mut val: u16) {
1444         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
1445 }
1446 /// The minimum value, in msat, which must be relayed to the next hop.
1447 #[no_mangle]
1448 pub extern "C" fn RouteHintHop_get_htlc_minimum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
1449         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
1450         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() }) };
1451         local_inner_val
1452 }
1453 /// The minimum value, in msat, which must be relayed to the next hop.
1454 #[no_mangle]
1455 pub extern "C" fn RouteHintHop_set_htlc_minimum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
1456         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1457         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = local_val;
1458 }
1459 /// The maximum value in msat available for routing with a single HTLC.
1460 #[no_mangle]
1461 pub extern "C" fn RouteHintHop_get_htlc_maximum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
1462         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
1463         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() }) };
1464         local_inner_val
1465 }
1466 /// The maximum value in msat available for routing with a single HTLC.
1467 #[no_mangle]
1468 pub extern "C" fn RouteHintHop_set_htlc_maximum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
1469         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1470         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
1471 }
1472 /// Constructs a new RouteHintHop given each field
1473 #[must_use]
1474 #[no_mangle]
1475 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 {
1476         let mut local_htlc_minimum_msat_arg = if htlc_minimum_msat_arg.is_some() { Some( { htlc_minimum_msat_arg.take() }) } else { None };
1477         let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
1478         RouteHintHop { inner: ObjOps::heap_alloc(nativeRouteHintHop {
1479                 src_node_id: src_node_id_arg.into_rust(),
1480                 short_channel_id: short_channel_id_arg,
1481                 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
1482                 cltv_expiry_delta: cltv_expiry_delta_arg,
1483                 htlc_minimum_msat: local_htlc_minimum_msat_arg,
1484                 htlc_maximum_msat: local_htlc_maximum_msat_arg,
1485         }), is_owned: true }
1486 }
1487 impl Clone for RouteHintHop {
1488         fn clone(&self) -> Self {
1489                 Self {
1490                         inner: if <*mut nativeRouteHintHop>::is_null(self.inner) { core::ptr::null_mut() } else {
1491                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1492                         is_owned: true,
1493                 }
1494         }
1495 }
1496 #[allow(unused)]
1497 /// Used only if an object of this type is returned as a trait impl by a method
1498 pub(crate) extern "C" fn RouteHintHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
1499         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHintHop)).clone() })) as *mut c_void
1500 }
1501 #[no_mangle]
1502 /// Creates a copy of the RouteHintHop
1503 pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop {
1504         orig.clone()
1505 }
1506 /// Checks if two RouteHintHops contain equal inner contents.
1507 #[no_mangle]
1508 pub extern "C" fn RouteHintHop_hash(o: &RouteHintHop) -> u64 {
1509         if o.inner.is_null() { return 0; }
1510         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1511         #[allow(deprecated)]
1512         let mut hasher = core::hash::SipHasher::new();
1513         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1514         core::hash::Hasher::finish(&hasher)
1515 }
1516 /// Checks if two RouteHintHops contain equal inner contents.
1517 /// This ignores pointers and is_owned flags and looks at the values in fields.
1518 /// Two objects with NULL inner values will be considered "equal" here.
1519 #[no_mangle]
1520 pub extern "C" fn RouteHintHop_eq(a: &RouteHintHop, b: &RouteHintHop) -> bool {
1521         if a.inner == b.inner { return true; }
1522         if a.inner.is_null() || b.inner.is_null() { return false; }
1523         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1524 }
1525 #[no_mangle]
1526 /// Serialize the RouteHintHop object into a byte array which can be read by RouteHintHop_read
1527 pub extern "C" fn RouteHintHop_write(obj: &crate::lightning::routing::router::RouteHintHop) -> crate::c_types::derived::CVec_u8Z {
1528         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1529 }
1530 #[no_mangle]
1531 pub(crate) extern "C" fn RouteHintHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1532         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHintHop) })
1533 }
1534 #[no_mangle]
1535 /// Read a RouteHintHop from a byte array, created by RouteHintHop_write
1536 pub extern "C" fn RouteHintHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintHopDecodeErrorZ {
1537         let res: Result<lightning::routing::router::RouteHintHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1538         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() };
1539         local_res
1540 }
1541 /// Finds a route from us (payer) to the given target node (payee).
1542 ///
1543 /// If the payee provided features in their invoice, they should be provided via `params.payee`.
1544 /// Without this, MPP will only be used if the payee's features are available in the network graph.
1545 ///
1546 /// Private routing paths between a public node and the target may be included in `params.payee`.
1547 ///
1548 /// If some channels aren't announced, it may be useful to fill in `first_hops` with the results
1549 /// from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
1550 /// from `network_graph` will be ignored, and only those in `first_hops` will be used.
1551 ///
1552 /// The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
1553 /// However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
1554 /// `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
1555 ///
1556 /// # Note
1557 ///
1558 /// May be used to re-compute a [`Route`] when handling a [`Event::PaymentPathFailed`]. Any
1559 /// adjustments to the [`NetworkGraph`] and channel scores should be made prior to calling this
1560 /// function.
1561 ///
1562 /// # Panics
1563 ///
1564 /// Panics if first_hops contains channels without short_channel_ids;
1565 /// [`ChannelManager::list_usable_channels`] will never include such channels.
1566 ///
1567 /// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
1568 /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
1569 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
1570 ///
1571 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
1572 #[no_mangle]
1573 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 {
1574         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[..]);
1575         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});
1576         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() };
1577         local_ret
1578 }
1579
1580 /// Construct a route from us (payer) to the target node (payee) via the given hops (which should
1581 /// exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
1582 ///
1583 /// Re-uses logic from `find_route`, so the restrictions described there also apply here.
1584 #[no_mangle]
1585 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 {
1586         let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { item.into_rust() }); };
1587         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});
1588         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() };
1589         local_ret
1590 }
1591