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