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