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