Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning / routing / router.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
8
9 //! The top-level routing/network map tracking logic lives here.
10 //!
11 //! You probably want to create a NetGraphMsgHandler 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::RouteHop as nativeRouteHopImport;
24 pub(crate) type nativeRouteHop = nativeRouteHopImport;
25
26 /// A hop in a route
27 #[must_use]
28 #[repr(C)]
29 pub struct RouteHop {
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 nativeRouteHop,
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 RouteHop {
43         fn drop(&mut self) {
44                 if self.is_owned && !<*mut nativeRouteHop>::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 RouteHop, if is_owned is set and inner is non-NULL.
50 #[no_mangle]
51 pub extern "C" fn RouteHop_free(this_obj: RouteHop) { }
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 RouteHop_free_void(this_ptr: *mut c_void) {
55         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHop); }
56 }
57 #[allow(unused)]
58 impl RouteHop {
59         pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHop {
60                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
61         }
62         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHop {
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 nativeRouteHop {
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 /// The node_id of the node at this hop.
74 #[no_mangle]
75 pub extern "C" fn RouteHop_get_pubkey(this_ptr: &RouteHop) -> crate::c_types::PublicKey {
76         let mut inner_val = &mut this_ptr.get_native_mut_ref().pubkey;
77         crate::c_types::PublicKey::from_rust(&inner_val)
78 }
79 /// The node_id of the node at this hop.
80 #[no_mangle]
81 pub extern "C" fn RouteHop_set_pubkey(this_ptr: &mut RouteHop, mut val: crate::c_types::PublicKey) {
82         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.pubkey = val.into_rust();
83 }
84 /// The node_announcement features of the node at this hop. For the last hop, these may be
85 /// amended to match the features present in the invoice this node generated.
86 #[no_mangle]
87 pub extern "C" fn RouteHop_get_node_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::NodeFeatures {
88         let mut inner_val = &mut this_ptr.get_native_mut_ref().node_features;
89         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 }
90 }
91 /// The node_announcement features of the node at this hop. For the last hop, these may be
92 /// amended to match the features present in the invoice this node generated.
93 #[no_mangle]
94 pub extern "C" fn RouteHop_set_node_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::NodeFeatures) {
95         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_features = *unsafe { Box::from_raw(val.take_inner()) };
96 }
97 /// The channel that should be used from the previous hop to reach this node.
98 #[no_mangle]
99 pub extern "C" fn RouteHop_get_short_channel_id(this_ptr: &RouteHop) -> u64 {
100         let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
101         *inner_val
102 }
103 /// The channel that should be used from the previous hop to reach this node.
104 #[no_mangle]
105 pub extern "C" fn RouteHop_set_short_channel_id(this_ptr: &mut RouteHop, mut val: u64) {
106         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
107 }
108 /// The channel_announcement features of the channel that should be used from the previous hop
109 /// to reach this node.
110 #[no_mangle]
111 pub extern "C" fn RouteHop_get_channel_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::ChannelFeatures {
112         let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_features;
113         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 }
114 }
115 /// The channel_announcement features of the channel that should be used from the previous hop
116 /// to reach this node.
117 #[no_mangle]
118 pub extern "C" fn RouteHop_set_channel_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::ChannelFeatures) {
119         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_features = *unsafe { Box::from_raw(val.take_inner()) };
120 }
121 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
122 /// For the last hop, this should be the full value of the payment (might be more than
123 /// requested if we had to match htlc_minimum_msat).
124 #[no_mangle]
125 pub extern "C" fn RouteHop_get_fee_msat(this_ptr: &RouteHop) -> u64 {
126         let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_msat;
127         *inner_val
128 }
129 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
130 /// For the last hop, this should be the full value of the payment (might be more than
131 /// requested if we had to match htlc_minimum_msat).
132 #[no_mangle]
133 pub extern "C" fn RouteHop_set_fee_msat(this_ptr: &mut RouteHop, mut val: u64) {
134         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_msat = val;
135 }
136 /// The CLTV delta added for this hop. For the last hop, this should be the full CLTV value
137 /// expected at the destination, in excess of the current block height.
138 #[no_mangle]
139 pub extern "C" fn RouteHop_get_cltv_expiry_delta(this_ptr: &RouteHop) -> u32 {
140         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
141         *inner_val
142 }
143 /// The CLTV delta added for this hop. For the last hop, this should be the full CLTV value
144 /// expected at the destination, in excess of the current block height.
145 #[no_mangle]
146 pub extern "C" fn RouteHop_set_cltv_expiry_delta(this_ptr: &mut RouteHop, mut val: u32) {
147         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
148 }
149 /// Constructs a new RouteHop given each field
150 #[must_use]
151 #[no_mangle]
152 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 {
153         RouteHop { inner: ObjOps::heap_alloc(nativeRouteHop {
154                 pubkey: pubkey_arg.into_rust(),
155                 node_features: *unsafe { Box::from_raw(node_features_arg.take_inner()) },
156                 short_channel_id: short_channel_id_arg,
157                 channel_features: *unsafe { Box::from_raw(channel_features_arg.take_inner()) },
158                 fee_msat: fee_msat_arg,
159                 cltv_expiry_delta: cltv_expiry_delta_arg,
160         }), is_owned: true }
161 }
162 impl Clone for RouteHop {
163         fn clone(&self) -> Self {
164                 Self {
165                         inner: if <*mut nativeRouteHop>::is_null(self.inner) { core::ptr::null_mut() } else {
166                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
167                         is_owned: true,
168                 }
169         }
170 }
171 #[allow(unused)]
172 /// Used only if an object of this type is returned as a trait impl by a method
173 pub(crate) extern "C" fn RouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
174         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHop)).clone() })) as *mut c_void
175 }
176 #[no_mangle]
177 /// Creates a copy of the RouteHop
178 pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop {
179         orig.clone()
180 }
181 /// Checks if two RouteHops contain equal inner contents.
182 #[no_mangle]
183 pub extern "C" fn RouteHop_hash(o: &RouteHop) -> u64 {
184         if o.inner.is_null() { return 0; }
185         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
186         #[allow(deprecated)]
187         let mut hasher = core::hash::SipHasher::new();
188         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
189         core::hash::Hasher::finish(&hasher)
190 }
191 /// Checks if two RouteHops contain equal inner contents.
192 /// This ignores pointers and is_owned flags and looks at the values in fields.
193 /// Two objects with NULL inner values will be considered "equal" here.
194 #[no_mangle]
195 pub extern "C" fn RouteHop_eq(a: &RouteHop, b: &RouteHop) -> bool {
196         if a.inner == b.inner { return true; }
197         if a.inner.is_null() || b.inner.is_null() { return false; }
198         if a.get_native_ref() == b.get_native_ref() { true } else { false }
199 }
200 #[no_mangle]
201 /// Serialize the RouteHop object into a byte array which can be read by RouteHop_read
202 pub extern "C" fn RouteHop_write(obj: &RouteHop) -> crate::c_types::derived::CVec_u8Z {
203         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
204 }
205 #[no_mangle]
206 pub(crate) extern "C" fn RouteHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
207         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHop) })
208 }
209 #[no_mangle]
210 /// Read a RouteHop from a byte array, created by RouteHop_write
211 pub extern "C" fn RouteHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHopDecodeErrorZ {
212         let res: Result<lightning::routing::router::RouteHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
213         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
214         local_res
215 }
216
217 use lightning::routing::router::Route as nativeRouteImport;
218 pub(crate) type nativeRoute = nativeRouteImport;
219
220 /// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
221 /// it can take multiple paths. Each path is composed of one or more hops through the network.
222 #[must_use]
223 #[repr(C)]
224 pub struct Route {
225         /// A pointer to the opaque Rust object.
226
227         /// Nearly everywhere, inner must be non-null, however in places where
228         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
229         pub inner: *mut nativeRoute,
230         /// Indicates that this is the only struct which contains the same pointer.
231
232         /// Rust functions which take ownership of an object provided via an argument require
233         /// this to be true and invalidate the object pointed to by inner.
234         pub is_owned: bool,
235 }
236
237 impl Drop for Route {
238         fn drop(&mut self) {
239                 if self.is_owned && !<*mut nativeRoute>::is_null(self.inner) {
240                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
241                 }
242         }
243 }
244 /// Frees any resources used by the Route, if is_owned is set and inner is non-NULL.
245 #[no_mangle]
246 pub extern "C" fn Route_free(this_obj: Route) { }
247 #[allow(unused)]
248 /// Used only if an object of this type is returned as a trait impl by a method
249 pub(crate) extern "C" fn Route_free_void(this_ptr: *mut c_void) {
250         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoute); }
251 }
252 #[allow(unused)]
253 impl Route {
254         pub(crate) fn get_native_ref(&self) -> &'static nativeRoute {
255                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
256         }
257         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoute {
258                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
259         }
260         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
261         pub(crate) fn take_inner(mut self) -> *mut nativeRoute {
262                 assert!(self.is_owned);
263                 let ret = ObjOps::untweak_ptr(self.inner);
264                 self.inner = core::ptr::null_mut();
265                 ret
266         }
267 }
268 /// The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
269 /// last RouteHop in each path must be the same.
270 /// Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the
271 /// destination. Thus, this must always be at least length one. While the maximum length of any
272 /// given path is variable, keeping the length of any path to less than 20 should currently
273 /// ensure it is viable.
274 #[no_mangle]
275 pub extern "C" fn Route_get_paths(this_ptr: &Route) -> crate::c_types::derived::CVec_CVec_RouteHopZZ {
276         let mut inner_val = &mut this_ptr.get_native_mut_ref().paths;
277         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() }); };
278         local_inner_val.into()
279 }
280 /// The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
281 /// last RouteHop in each path must be the same.
282 /// Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the
283 /// destination. Thus, this must always be at least length one. While the maximum length of any
284 /// given path is variable, keeping the length of any path to less than 20 should currently
285 /// ensure it is viable.
286 #[no_mangle]
287 pub extern "C" fn Route_set_paths(this_ptr: &mut Route, mut val: crate::c_types::derived::CVec_CVec_RouteHopZZ) {
288         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 }); };
289         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.paths = local_val;
290 }
291 /// The `payee` parameter passed to [`find_route`].
292 /// This is used by `ChannelManager` to track information which may be required for retries,
293 /// provided back to you via [`Event::PaymentPathFailed`].
294 ///
295 /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
296 ///
297 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
298 #[no_mangle]
299 pub extern "C" fn Route_get_payee(this_ptr: &Route) -> crate::lightning::routing::router::Payee {
300         let mut inner_val = &mut this_ptr.get_native_mut_ref().payee;
301         let mut local_inner_val = crate::lightning::routing::router::Payee { 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::Payee<>) as *mut _ }, is_owned: false };
302         local_inner_val
303 }
304 /// The `payee` parameter passed to [`find_route`].
305 /// This is used by `ChannelManager` to track information which may be required for retries,
306 /// provided back to you via [`Event::PaymentPathFailed`].
307 ///
308 /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
309 ///
310 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
311 #[no_mangle]
312 pub extern "C" fn Route_set_payee(this_ptr: &mut Route, mut val: crate::lightning::routing::router::Payee) {
313         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
314         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payee = local_val;
315 }
316 /// Constructs a new Route given each field
317 #[must_use]
318 #[no_mangle]
319 pub extern "C" fn Route_new(mut paths_arg: crate::c_types::derived::CVec_CVec_RouteHopZZ, mut payee_arg: crate::lightning::routing::router::Payee) -> Route {
320         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 }); };
321         let mut local_payee_arg = if payee_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(payee_arg.take_inner()) } }) };
322         Route { inner: ObjOps::heap_alloc(nativeRoute {
323                 paths: local_paths_arg,
324                 payee: local_payee_arg,
325         }), is_owned: true }
326 }
327 impl Clone for Route {
328         fn clone(&self) -> Self {
329                 Self {
330                         inner: if <*mut nativeRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
331                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
332                         is_owned: true,
333                 }
334         }
335 }
336 #[allow(unused)]
337 /// Used only if an object of this type is returned as a trait impl by a method
338 pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_void {
339         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoute)).clone() })) as *mut c_void
340 }
341 #[no_mangle]
342 /// Creates a copy of the Route
343 pub extern "C" fn Route_clone(orig: &Route) -> Route {
344         orig.clone()
345 }
346 /// Checks if two Routes contain equal inner contents.
347 #[no_mangle]
348 pub extern "C" fn Route_hash(o: &Route) -> u64 {
349         if o.inner.is_null() { return 0; }
350         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
351         #[allow(deprecated)]
352         let mut hasher = core::hash::SipHasher::new();
353         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
354         core::hash::Hasher::finish(&hasher)
355 }
356 /// Checks if two Routes contain equal inner contents.
357 /// This ignores pointers and is_owned flags and looks at the values in fields.
358 /// Two objects with NULL inner values will be considered "equal" here.
359 #[no_mangle]
360 pub extern "C" fn Route_eq(a: &Route, b: &Route) -> bool {
361         if a.inner == b.inner { return true; }
362         if a.inner.is_null() || b.inner.is_null() { return false; }
363         if a.get_native_ref() == b.get_native_ref() { true } else { false }
364 }
365 /// Returns the total amount of fees paid on this [`Route`].
366 ///
367 /// This doesn't include any extra payment made to the recipient, which can happen in excess of
368 /// the amount passed to [`find_route`]'s `params.final_value_msat`.
369 #[must_use]
370 #[no_mangle]
371 pub extern "C" fn Route_get_total_fees(this_arg: &Route) -> u64 {
372         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_fees();
373         ret
374 }
375
376 /// Returns the total amount paid on this [`Route`], excluding the fees.
377 #[must_use]
378 #[no_mangle]
379 pub extern "C" fn Route_get_total_amount(this_arg: &Route) -> u64 {
380         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_amount();
381         ret
382 }
383
384 #[no_mangle]
385 /// Serialize the Route object into a byte array which can be read by Route_read
386 pub extern "C" fn Route_write(obj: &Route) -> crate::c_types::derived::CVec_u8Z {
387         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
388 }
389 #[no_mangle]
390 pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
391         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) })
392 }
393 #[no_mangle]
394 /// Read a Route from a byte array, created by Route_write
395 pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ {
396         let res: Result<lightning::routing::router::Route, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
397         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
398         local_res
399 }
400
401 use lightning::routing::router::RouteParameters as nativeRouteParametersImport;
402 pub(crate) type nativeRouteParameters = nativeRouteParametersImport;
403
404 /// Parameters needed to find a [`Route`] for paying a [`Payee`].
405 ///
406 /// Passed to [`find_route`] and also provided in [`Event::PaymentPathFailed`] for retrying a failed
407 /// payment path.
408 ///
409 /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
410 #[must_use]
411 #[repr(C)]
412 pub struct RouteParameters {
413         /// A pointer to the opaque Rust object.
414
415         /// Nearly everywhere, inner must be non-null, however in places where
416         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
417         pub inner: *mut nativeRouteParameters,
418         /// Indicates that this is the only struct which contains the same pointer.
419
420         /// Rust functions which take ownership of an object provided via an argument require
421         /// this to be true and invalidate the object pointed to by inner.
422         pub is_owned: bool,
423 }
424
425 impl Drop for RouteParameters {
426         fn drop(&mut self) {
427                 if self.is_owned && !<*mut nativeRouteParameters>::is_null(self.inner) {
428                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
429                 }
430         }
431 }
432 /// Frees any resources used by the RouteParameters, if is_owned is set and inner is non-NULL.
433 #[no_mangle]
434 pub extern "C" fn RouteParameters_free(this_obj: RouteParameters) { }
435 #[allow(unused)]
436 /// Used only if an object of this type is returned as a trait impl by a method
437 pub(crate) extern "C" fn RouteParameters_free_void(this_ptr: *mut c_void) {
438         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteParameters); }
439 }
440 #[allow(unused)]
441 impl RouteParameters {
442         pub(crate) fn get_native_ref(&self) -> &'static nativeRouteParameters {
443                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
444         }
445         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteParameters {
446                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
447         }
448         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
449         pub(crate) fn take_inner(mut self) -> *mut nativeRouteParameters {
450                 assert!(self.is_owned);
451                 let ret = ObjOps::untweak_ptr(self.inner);
452                 self.inner = core::ptr::null_mut();
453                 ret
454         }
455 }
456 /// The recipient of the failed payment path.
457 #[no_mangle]
458 pub extern "C" fn RouteParameters_get_payee(this_ptr: &RouteParameters) -> crate::lightning::routing::router::Payee {
459         let mut inner_val = &mut this_ptr.get_native_mut_ref().payee;
460         crate::lightning::routing::router::Payee { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::router::Payee<>) as *mut _) }, is_owned: false }
461 }
462 /// The recipient of the failed payment path.
463 #[no_mangle]
464 pub extern "C" fn RouteParameters_set_payee(this_ptr: &mut RouteParameters, mut val: crate::lightning::routing::router::Payee) {
465         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payee = *unsafe { Box::from_raw(val.take_inner()) };
466 }
467 /// The amount in msats sent on the failed payment path.
468 #[no_mangle]
469 pub extern "C" fn RouteParameters_get_final_value_msat(this_ptr: &RouteParameters) -> u64 {
470         let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
471         *inner_val
472 }
473 /// The amount in msats sent on the failed payment path.
474 #[no_mangle]
475 pub extern "C" fn RouteParameters_set_final_value_msat(this_ptr: &mut RouteParameters, mut val: u64) {
476         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
477 }
478 /// The CLTV on the final hop of the failed payment path.
479 #[no_mangle]
480 pub extern "C" fn RouteParameters_get_final_cltv_expiry_delta(this_ptr: &RouteParameters) -> u32 {
481         let mut inner_val = &mut this_ptr.get_native_mut_ref().final_cltv_expiry_delta;
482         *inner_val
483 }
484 /// The CLTV on the final hop of the failed payment path.
485 #[no_mangle]
486 pub extern "C" fn RouteParameters_set_final_cltv_expiry_delta(this_ptr: &mut RouteParameters, mut val: u32) {
487         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_cltv_expiry_delta = val;
488 }
489 /// Constructs a new RouteParameters given each field
490 #[must_use]
491 #[no_mangle]
492 pub extern "C" fn RouteParameters_new(mut payee_arg: crate::lightning::routing::router::Payee, mut final_value_msat_arg: u64, mut final_cltv_expiry_delta_arg: u32) -> RouteParameters {
493         RouteParameters { inner: ObjOps::heap_alloc(nativeRouteParameters {
494                 payee: *unsafe { Box::from_raw(payee_arg.take_inner()) },
495                 final_value_msat: final_value_msat_arg,
496                 final_cltv_expiry_delta: final_cltv_expiry_delta_arg,
497         }), is_owned: true }
498 }
499 impl Clone for RouteParameters {
500         fn clone(&self) -> Self {
501                 Self {
502                         inner: if <*mut nativeRouteParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
503                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
504                         is_owned: true,
505                 }
506         }
507 }
508 #[allow(unused)]
509 /// Used only if an object of this type is returned as a trait impl by a method
510 pub(crate) extern "C" fn RouteParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
511         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteParameters)).clone() })) as *mut c_void
512 }
513 #[no_mangle]
514 /// Creates a copy of the RouteParameters
515 pub extern "C" fn RouteParameters_clone(orig: &RouteParameters) -> RouteParameters {
516         orig.clone()
517 }
518 #[no_mangle]
519 /// Serialize the RouteParameters object into a byte array which can be read by RouteParameters_read
520 pub extern "C" fn RouteParameters_write(obj: &RouteParameters) -> crate::c_types::derived::CVec_u8Z {
521         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
522 }
523 #[no_mangle]
524 pub(crate) extern "C" fn RouteParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
525         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteParameters) })
526 }
527 #[no_mangle]
528 /// Read a RouteParameters from a byte array, created by RouteParameters_write
529 pub extern "C" fn RouteParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteParametersDecodeErrorZ {
530         let res: Result<lightning::routing::router::RouteParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
531         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
532         local_res
533 }
534
535 use lightning::routing::router::Payee as nativePayeeImport;
536 pub(crate) type nativePayee = nativePayeeImport;
537
538 /// The recipient of a payment.
539 #[must_use]
540 #[repr(C)]
541 pub struct Payee {
542         /// A pointer to the opaque Rust object.
543
544         /// Nearly everywhere, inner must be non-null, however in places where
545         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
546         pub inner: *mut nativePayee,
547         /// Indicates that this is the only struct which contains the same pointer.
548
549         /// Rust functions which take ownership of an object provided via an argument require
550         /// this to be true and invalidate the object pointed to by inner.
551         pub is_owned: bool,
552 }
553
554 impl Drop for Payee {
555         fn drop(&mut self) {
556                 if self.is_owned && !<*mut nativePayee>::is_null(self.inner) {
557                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
558                 }
559         }
560 }
561 /// Frees any resources used by the Payee, if is_owned is set and inner is non-NULL.
562 #[no_mangle]
563 pub extern "C" fn Payee_free(this_obj: Payee) { }
564 #[allow(unused)]
565 /// Used only if an object of this type is returned as a trait impl by a method
566 pub(crate) extern "C" fn Payee_free_void(this_ptr: *mut c_void) {
567         unsafe { let _ = Box::from_raw(this_ptr as *mut nativePayee); }
568 }
569 #[allow(unused)]
570 impl Payee {
571         pub(crate) fn get_native_ref(&self) -> &'static nativePayee {
572                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
573         }
574         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayee {
575                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
576         }
577         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
578         pub(crate) fn take_inner(mut self) -> *mut nativePayee {
579                 assert!(self.is_owned);
580                 let ret = ObjOps::untweak_ptr(self.inner);
581                 self.inner = core::ptr::null_mut();
582                 ret
583         }
584 }
585 /// The node id of the payee.
586 #[no_mangle]
587 pub extern "C" fn Payee_get_pubkey(this_ptr: &Payee) -> crate::c_types::PublicKey {
588         let mut inner_val = &mut this_ptr.get_native_mut_ref().pubkey;
589         crate::c_types::PublicKey::from_rust(&inner_val)
590 }
591 /// The node id of the payee.
592 #[no_mangle]
593 pub extern "C" fn Payee_set_pubkey(this_ptr: &mut Payee, mut val: crate::c_types::PublicKey) {
594         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.pubkey = val.into_rust();
595 }
596 /// Features supported by the payee.
597 ///
598 /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
599 /// does not contain any features.
600 ///
601 /// [`for_keysend`]: Self::for_keysend
602 ///
603 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
604 #[no_mangle]
605 pub extern "C" fn Payee_get_features(this_ptr: &Payee) -> crate::lightning::ln::features::InvoiceFeatures {
606         let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
607         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 };
608         local_inner_val
609 }
610 /// Features supported by the payee.
611 ///
612 /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
613 /// does not contain any features.
614 ///
615 /// [`for_keysend`]: Self::for_keysend
616 ///
617 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
618 #[no_mangle]
619 pub extern "C" fn Payee_set_features(this_ptr: &mut Payee, mut val: crate::lightning::ln::features::InvoiceFeatures) {
620         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
621         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = local_val;
622 }
623 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
624 #[no_mangle]
625 pub extern "C" fn Payee_get_route_hints(this_ptr: &Payee) -> crate::c_types::derived::CVec_RouteHintZ {
626         let mut inner_val = &mut this_ptr.get_native_mut_ref().route_hints;
627         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 } }); };
628         local_inner_val.into()
629 }
630 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
631 #[no_mangle]
632 pub extern "C" fn Payee_set_route_hints(this_ptr: &mut Payee, mut val: crate::c_types::derived::CVec_RouteHintZ) {
633         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
634         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_hints = local_val;
635 }
636 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
637 #[no_mangle]
638 pub extern "C" fn Payee_get_expiry_time(this_ptr: &Payee) -> crate::c_types::derived::COption_u64Z {
639         let mut inner_val = &mut this_ptr.get_native_mut_ref().expiry_time;
640         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() }) };
641         local_inner_val
642 }
643 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
644 #[no_mangle]
645 pub extern "C" fn Payee_set_expiry_time(this_ptr: &mut Payee, mut val: crate::c_types::derived::COption_u64Z) {
646         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
647         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.expiry_time = local_val;
648 }
649 /// Constructs a new Payee given each field
650 #[must_use]
651 #[no_mangle]
652 pub extern "C" fn Payee_new(mut 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) -> Payee {
653         let mut local_features_arg = if features_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_arg.take_inner()) } }) };
654         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()) } }); };
655         let mut local_expiry_time_arg = if expiry_time_arg.is_some() { Some( { expiry_time_arg.take() }) } else { None };
656         Payee { inner: ObjOps::heap_alloc(nativePayee {
657                 pubkey: pubkey_arg.into_rust(),
658                 features: local_features_arg,
659                 route_hints: local_route_hints_arg,
660                 expiry_time: local_expiry_time_arg,
661         }), is_owned: true }
662 }
663 impl Clone for Payee {
664         fn clone(&self) -> Self {
665                 Self {
666                         inner: if <*mut nativePayee>::is_null(self.inner) { core::ptr::null_mut() } else {
667                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
668                         is_owned: true,
669                 }
670         }
671 }
672 #[allow(unused)]
673 /// Used only if an object of this type is returned as a trait impl by a method
674 pub(crate) extern "C" fn Payee_clone_void(this_ptr: *const c_void) -> *mut c_void {
675         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayee)).clone() })) as *mut c_void
676 }
677 #[no_mangle]
678 /// Creates a copy of the Payee
679 pub extern "C" fn Payee_clone(orig: &Payee) -> Payee {
680         orig.clone()
681 }
682 /// Checks if two Payees contain equal inner contents.
683 #[no_mangle]
684 pub extern "C" fn Payee_hash(o: &Payee) -> u64 {
685         if o.inner.is_null() { return 0; }
686         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
687         #[allow(deprecated)]
688         let mut hasher = core::hash::SipHasher::new();
689         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
690         core::hash::Hasher::finish(&hasher)
691 }
692 /// Checks if two Payees contain equal inner contents.
693 /// This ignores pointers and is_owned flags and looks at the values in fields.
694 /// Two objects with NULL inner values will be considered "equal" here.
695 #[no_mangle]
696 pub extern "C" fn Payee_eq(a: &Payee, b: &Payee) -> bool {
697         if a.inner == b.inner { return true; }
698         if a.inner.is_null() || b.inner.is_null() { return false; }
699         if a.get_native_ref() == b.get_native_ref() { true } else { false }
700 }
701 #[no_mangle]
702 /// Serialize the Payee object into a byte array which can be read by Payee_read
703 pub extern "C" fn Payee_write(obj: &Payee) -> crate::c_types::derived::CVec_u8Z {
704         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
705 }
706 #[no_mangle]
707 pub(crate) extern "C" fn Payee_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
708         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePayee) })
709 }
710 #[no_mangle]
711 /// Read a Payee from a byte array, created by Payee_write
712 pub extern "C" fn Payee_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PayeeDecodeErrorZ {
713         let res: Result<lightning::routing::router::Payee, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
714         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Payee { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
715         local_res
716 }
717 /// Creates a payee with the node id of the given `pubkey`.
718 #[must_use]
719 #[no_mangle]
720 pub extern "C" fn Payee_from_node_id(mut pubkey: crate::c_types::PublicKey) -> Payee {
721         let mut ret = lightning::routing::router::Payee::from_node_id(pubkey.into_rust());
722         Payee { inner: ObjOps::heap_alloc(ret), is_owned: true }
723 }
724
725 /// Creates a payee with the node id of the given `pubkey` to use for keysend payments.
726 #[must_use]
727 #[no_mangle]
728 pub extern "C" fn Payee_for_keysend(mut pubkey: crate::c_types::PublicKey) -> Payee {
729         let mut ret = lightning::routing::router::Payee::for_keysend(pubkey.into_rust());
730         Payee { inner: ObjOps::heap_alloc(ret), is_owned: true }
731 }
732
733
734 use lightning::routing::router::RouteHint as nativeRouteHintImport;
735 pub(crate) type nativeRouteHint = nativeRouteHintImport;
736
737 /// A list of hops along a payment path terminating with a channel to the recipient.
738 #[must_use]
739 #[repr(C)]
740 pub struct RouteHint {
741         /// A pointer to the opaque Rust object.
742
743         /// Nearly everywhere, inner must be non-null, however in places where
744         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
745         pub inner: *mut nativeRouteHint,
746         /// Indicates that this is the only struct which contains the same pointer.
747
748         /// Rust functions which take ownership of an object provided via an argument require
749         /// this to be true and invalidate the object pointed to by inner.
750         pub is_owned: bool,
751 }
752
753 impl Drop for RouteHint {
754         fn drop(&mut self) {
755                 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
756                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
757                 }
758         }
759 }
760 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
761 #[no_mangle]
762 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
763 #[allow(unused)]
764 /// Used only if an object of this type is returned as a trait impl by a method
765 pub(crate) extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
766         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHint); }
767 }
768 #[allow(unused)]
769 impl RouteHint {
770         pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHint {
771                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
772         }
773         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHint {
774                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
775         }
776         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
777         pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
778                 assert!(self.is_owned);
779                 let ret = ObjOps::untweak_ptr(self.inner);
780                 self.inner = core::ptr::null_mut();
781                 ret
782         }
783 }
784 #[no_mangle]
785 pub extern "C" fn RouteHint_get_a(this_ptr: &RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ {
786         let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
787         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 } }); };
788         local_inner_val.into()
789 }
790 #[no_mangle]
791 pub extern "C" fn RouteHint_set_a(this_ptr: &mut RouteHint, mut val: crate::c_types::derived::CVec_RouteHintHopZ) {
792         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
793         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = local_val;
794 }
795 /// Constructs a new RouteHint given each field
796 #[must_use]
797 #[no_mangle]
798 pub extern "C" fn RouteHint_new(mut a_arg: crate::c_types::derived::CVec_RouteHintHopZ) -> RouteHint {
799         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()) } }); };
800         RouteHint { inner: ObjOps::heap_alloc(lightning::routing::router::RouteHint (
801                 local_a_arg,
802         )), is_owned: true }
803 }
804 impl Clone for RouteHint {
805         fn clone(&self) -> Self {
806                 Self {
807                         inner: if <*mut nativeRouteHint>::is_null(self.inner) { core::ptr::null_mut() } else {
808                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
809                         is_owned: true,
810                 }
811         }
812 }
813 #[allow(unused)]
814 /// Used only if an object of this type is returned as a trait impl by a method
815 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
816         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void
817 }
818 #[no_mangle]
819 /// Creates a copy of the RouteHint
820 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
821         orig.clone()
822 }
823 /// Checks if two RouteHints contain equal inner contents.
824 #[no_mangle]
825 pub extern "C" fn RouteHint_hash(o: &RouteHint) -> u64 {
826         if o.inner.is_null() { return 0; }
827         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
828         #[allow(deprecated)]
829         let mut hasher = core::hash::SipHasher::new();
830         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
831         core::hash::Hasher::finish(&hasher)
832 }
833 /// Checks if two RouteHints contain equal inner contents.
834 /// This ignores pointers and is_owned flags and looks at the values in fields.
835 /// Two objects with NULL inner values will be considered "equal" here.
836 #[no_mangle]
837 pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool {
838         if a.inner == b.inner { return true; }
839         if a.inner.is_null() || b.inner.is_null() { return false; }
840         if a.get_native_ref() == b.get_native_ref() { true } else { false }
841 }
842 #[no_mangle]
843 /// Serialize the RouteHint object into a byte array which can be read by RouteHint_read
844 pub extern "C" fn RouteHint_write(obj: &RouteHint) -> crate::c_types::derived::CVec_u8Z {
845         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
846 }
847 #[no_mangle]
848 pub(crate) extern "C" fn RouteHint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
849         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHint) })
850 }
851 #[no_mangle]
852 /// Read a RouteHint from a byte array, created by RouteHint_write
853 pub extern "C" fn RouteHint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintDecodeErrorZ {
854         let res: Result<lightning::routing::router::RouteHint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
855         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
856         local_res
857 }
858
859 use lightning::routing::router::RouteHintHop as nativeRouteHintHopImport;
860 pub(crate) type nativeRouteHintHop = nativeRouteHintHopImport;
861
862 /// A channel descriptor for a hop along a payment path.
863 #[must_use]
864 #[repr(C)]
865 pub struct RouteHintHop {
866         /// A pointer to the opaque Rust object.
867
868         /// Nearly everywhere, inner must be non-null, however in places where
869         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
870         pub inner: *mut nativeRouteHintHop,
871         /// Indicates that this is the only struct which contains the same pointer.
872
873         /// Rust functions which take ownership of an object provided via an argument require
874         /// this to be true and invalidate the object pointed to by inner.
875         pub is_owned: bool,
876 }
877
878 impl Drop for RouteHintHop {
879         fn drop(&mut self) {
880                 if self.is_owned && !<*mut nativeRouteHintHop>::is_null(self.inner) {
881                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
882                 }
883         }
884 }
885 /// Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL.
886 #[no_mangle]
887 pub extern "C" fn RouteHintHop_free(this_obj: RouteHintHop) { }
888 #[allow(unused)]
889 /// Used only if an object of this type is returned as a trait impl by a method
890 pub(crate) extern "C" fn RouteHintHop_free_void(this_ptr: *mut c_void) {
891         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHintHop); }
892 }
893 #[allow(unused)]
894 impl RouteHintHop {
895         pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHintHop {
896                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
897         }
898         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHintHop {
899                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
900         }
901         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
902         pub(crate) fn take_inner(mut self) -> *mut nativeRouteHintHop {
903                 assert!(self.is_owned);
904                 let ret = ObjOps::untweak_ptr(self.inner);
905                 self.inner = core::ptr::null_mut();
906                 ret
907         }
908 }
909 /// The node_id of the non-target end of the route
910 #[no_mangle]
911 pub extern "C" fn RouteHintHop_get_src_node_id(this_ptr: &RouteHintHop) -> crate::c_types::PublicKey {
912         let mut inner_val = &mut this_ptr.get_native_mut_ref().src_node_id;
913         crate::c_types::PublicKey::from_rust(&inner_val)
914 }
915 /// The node_id of the non-target end of the route
916 #[no_mangle]
917 pub extern "C" fn RouteHintHop_set_src_node_id(this_ptr: &mut RouteHintHop, mut val: crate::c_types::PublicKey) {
918         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.src_node_id = val.into_rust();
919 }
920 /// The short_channel_id of this channel
921 #[no_mangle]
922 pub extern "C" fn RouteHintHop_get_short_channel_id(this_ptr: &RouteHintHop) -> u64 {
923         let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
924         *inner_val
925 }
926 /// The short_channel_id of this channel
927 #[no_mangle]
928 pub extern "C" fn RouteHintHop_set_short_channel_id(this_ptr: &mut RouteHintHop, mut val: u64) {
929         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
930 }
931 /// The fees which must be paid to use this channel
932 #[no_mangle]
933 pub extern "C" fn RouteHintHop_get_fees(this_ptr: &RouteHintHop) -> crate::lightning::routing::network_graph::RoutingFees {
934         let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
935         crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::network_graph::RoutingFees<>) as *mut _) }, is_owned: false }
936 }
937 /// The fees which must be paid to use this channel
938 #[no_mangle]
939 pub extern "C" fn RouteHintHop_set_fees(this_ptr: &mut RouteHintHop, mut val: crate::lightning::routing::network_graph::RoutingFees) {
940         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
941 }
942 /// The difference in CLTV values between this node and the next node.
943 #[no_mangle]
944 pub extern "C" fn RouteHintHop_get_cltv_expiry_delta(this_ptr: &RouteHintHop) -> u16 {
945         let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
946         *inner_val
947 }
948 /// The difference in CLTV values between this node and the next node.
949 #[no_mangle]
950 pub extern "C" fn RouteHintHop_set_cltv_expiry_delta(this_ptr: &mut RouteHintHop, mut val: u16) {
951         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
952 }
953 /// The minimum value, in msat, which must be relayed to the next hop.
954 #[no_mangle]
955 pub extern "C" fn RouteHintHop_get_htlc_minimum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
956         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
957         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() }) };
958         local_inner_val
959 }
960 /// The minimum value, in msat, which must be relayed to the next hop.
961 #[no_mangle]
962 pub extern "C" fn RouteHintHop_set_htlc_minimum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
963         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
964         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = local_val;
965 }
966 /// The maximum value in msat available for routing with a single HTLC.
967 #[no_mangle]
968 pub extern "C" fn RouteHintHop_get_htlc_maximum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
969         let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
970         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() }) };
971         local_inner_val
972 }
973 /// The maximum value in msat available for routing with a single HTLC.
974 #[no_mangle]
975 pub extern "C" fn RouteHintHop_set_htlc_maximum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
976         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
977         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
978 }
979 /// Constructs a new RouteHintHop given each field
980 #[must_use]
981 #[no_mangle]
982 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::network_graph::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 {
983         let mut local_htlc_minimum_msat_arg = if htlc_minimum_msat_arg.is_some() { Some( { htlc_minimum_msat_arg.take() }) } else { None };
984         let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
985         RouteHintHop { inner: ObjOps::heap_alloc(nativeRouteHintHop {
986                 src_node_id: src_node_id_arg.into_rust(),
987                 short_channel_id: short_channel_id_arg,
988                 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
989                 cltv_expiry_delta: cltv_expiry_delta_arg,
990                 htlc_minimum_msat: local_htlc_minimum_msat_arg,
991                 htlc_maximum_msat: local_htlc_maximum_msat_arg,
992         }), is_owned: true }
993 }
994 impl Clone for RouteHintHop {
995         fn clone(&self) -> Self {
996                 Self {
997                         inner: if <*mut nativeRouteHintHop>::is_null(self.inner) { core::ptr::null_mut() } else {
998                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
999                         is_owned: true,
1000                 }
1001         }
1002 }
1003 #[allow(unused)]
1004 /// Used only if an object of this type is returned as a trait impl by a method
1005 pub(crate) extern "C" fn RouteHintHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
1006         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHintHop)).clone() })) as *mut c_void
1007 }
1008 #[no_mangle]
1009 /// Creates a copy of the RouteHintHop
1010 pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop {
1011         orig.clone()
1012 }
1013 /// Checks if two RouteHintHops contain equal inner contents.
1014 #[no_mangle]
1015 pub extern "C" fn RouteHintHop_hash(o: &RouteHintHop) -> u64 {
1016         if o.inner.is_null() { return 0; }
1017         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1018         #[allow(deprecated)]
1019         let mut hasher = core::hash::SipHasher::new();
1020         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1021         core::hash::Hasher::finish(&hasher)
1022 }
1023 /// Checks if two RouteHintHops contain equal inner contents.
1024 /// This ignores pointers and is_owned flags and looks at the values in fields.
1025 /// Two objects with NULL inner values will be considered "equal" here.
1026 #[no_mangle]
1027 pub extern "C" fn RouteHintHop_eq(a: &RouteHintHop, b: &RouteHintHop) -> bool {
1028         if a.inner == b.inner { return true; }
1029         if a.inner.is_null() || b.inner.is_null() { return false; }
1030         if a.get_native_ref() == b.get_native_ref() { true } else { false }
1031 }
1032 #[no_mangle]
1033 /// Serialize the RouteHintHop object into a byte array which can be read by RouteHintHop_read
1034 pub extern "C" fn RouteHintHop_write(obj: &RouteHintHop) -> crate::c_types::derived::CVec_u8Z {
1035         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1036 }
1037 #[no_mangle]
1038 pub(crate) extern "C" fn RouteHintHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1039         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHintHop) })
1040 }
1041 #[no_mangle]
1042 /// Read a RouteHintHop from a byte array, created by RouteHintHop_write
1043 pub extern "C" fn RouteHintHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintHopDecodeErrorZ {
1044         let res: Result<lightning::routing::router::RouteHintHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1045         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 { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1046         local_res
1047 }
1048 /// Finds a route from us (payer) to the given target node (payee).
1049 ///
1050 /// If the payee provided features in their invoice, they should be provided via `params.payee`.
1051 /// Without this, MPP will only be used if the payee's features are available in the network graph.
1052 ///
1053 /// Private routing paths between a public node and the target may be included in `params.payee`.
1054 ///
1055 /// If some channels aren't announced, it may be useful to fill in `first_hops` with the results
1056 /// from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of our local
1057 /// channels from [`NetworkGraph`] will be ignored, and only those in `first_hops` will be used.
1058 ///
1059 /// The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
1060 /// However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
1061 /// `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
1062 ///
1063 /// # Note
1064 ///
1065 /// May be used to re-compute a [`Route`] when handling a [`Event::PaymentPathFailed`]. Any
1066 /// adjustments to the [`NetworkGraph`] and channel scores should be made prior to calling this
1067 /// function.
1068 ///
1069 /// # Panics
1070 ///
1071 /// Panics if first_hops contains channels without short_channel_ids;
1072 /// [`ChannelManager::list_usable_channels`] will never include such channels.
1073 ///
1074 /// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
1075 /// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
1076 ///
1077 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
1078 #[no_mangle]
1079 pub extern "C" fn find_route(mut our_node_pubkey: crate::c_types::PublicKey, params: &crate::lightning::routing::router::RouteParameters, network: &crate::lightning::routing::network_graph::NetworkGraph, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut logger: crate::lightning::util::logger::Logger, scorer: &crate::lightning::routing::scoring::Score) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
1080         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[..]);
1081         let mut ret = lightning::routing::router::find_route(&our_node_pubkey.into_rust(), params.get_native_ref(), network.get_native_ref(), local_first_hops, logger, scorer);
1082         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() };
1083         local_ret
1084 }
1085