Merge pull request #38 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 bitcoin::hashes::Hash;
17 use crate::c_types::*;
18
19
20 use lightning::routing::router::RouteHop as nativeRouteHopImport;
21 type nativeRouteHop = nativeRouteHopImport;
22
23 /// A hop in a route
24 #[must_use]
25 #[repr(C)]
26 pub struct RouteHop {
27         /// A pointer to the opaque Rust object.
28
29         /// Nearly everywhere, inner must be non-null, however in places where
30         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
31         pub inner: *mut nativeRouteHop,
32         /// Indicates that this is the only struct which contains the same pointer.
33
34         /// Rust functions which take ownership of an object provided via an argument require
35         /// this to be true and invalidate the object pointed to by inner.
36         pub is_owned: bool,
37 }
38
39 impl Drop for RouteHop {
40         fn drop(&mut self) {
41                 if self.is_owned && !<*mut nativeRouteHop>::is_null(self.inner) {
42                         let _ = unsafe { Box::from_raw(self.inner) };
43                 }
44         }
45 }
46 /// Frees any resources used by the RouteHop, if is_owned is set and inner is non-NULL.
47 #[no_mangle]
48 pub extern "C" fn RouteHop_free(this_obj: RouteHop) { }
49 #[allow(unused)]
50 /// Used only if an object of this type is returned as a trait impl by a method
51 extern "C" fn RouteHop_free_void(this_ptr: *mut c_void) {
52         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHop); }
53 }
54 #[allow(unused)]
55 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
56 impl RouteHop {
57         pub(crate) fn take_inner(mut self) -> *mut nativeRouteHop {
58                 assert!(self.is_owned);
59                 let ret = self.inner;
60                 self.inner = std::ptr::null_mut();
61                 ret
62         }
63 }
64 /// The node_id of the node at this hop.
65 #[no_mangle]
66 pub extern "C" fn RouteHop_get_pubkey(this_ptr: &RouteHop) -> crate::c_types::PublicKey {
67         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.pubkey;
68         crate::c_types::PublicKey::from_rust(&inner_val)
69 }
70 /// The node_id of the node at this hop.
71 #[no_mangle]
72 pub extern "C" fn RouteHop_set_pubkey(this_ptr: &mut RouteHop, mut val: crate::c_types::PublicKey) {
73         unsafe { &mut *this_ptr.inner }.pubkey = val.into_rust();
74 }
75 /// The node_announcement features of the node at this hop. For the last hop, these may be
76 /// amended to match the features present in the invoice this node generated.
77 #[no_mangle]
78 pub extern "C" fn RouteHop_get_node_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::NodeFeatures {
79         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_features;
80         crate::lightning::ln::features::NodeFeatures { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
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_set_node_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::NodeFeatures) {
86         unsafe { &mut *this_ptr.inner }.node_features = *unsafe { Box::from_raw(val.take_inner()) };
87 }
88 /// The channel that should be used from the previous hop to reach this node.
89 #[no_mangle]
90 pub extern "C" fn RouteHop_get_short_channel_id(this_ptr: &RouteHop) -> u64 {
91         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.short_channel_id;
92         *inner_val
93 }
94 /// The channel that should be used from the previous hop to reach this node.
95 #[no_mangle]
96 pub extern "C" fn RouteHop_set_short_channel_id(this_ptr: &mut RouteHop, mut val: u64) {
97         unsafe { &mut *this_ptr.inner }.short_channel_id = val;
98 }
99 /// The channel_announcement features of the channel that should be used from the previous hop
100 /// to reach this node.
101 #[no_mangle]
102 pub extern "C" fn RouteHop_get_channel_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::ChannelFeatures {
103         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.channel_features;
104         crate::lightning::ln::features::ChannelFeatures { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
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_set_channel_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::ChannelFeatures) {
110         unsafe { &mut *this_ptr.inner }.channel_features = *unsafe { Box::from_raw(val.take_inner()) };
111 }
112 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
113 /// For the last hop, this should be the full value of the payment (might be more than
114 /// requested if we had to match htlc_minimum_msat).
115 #[no_mangle]
116 pub extern "C" fn RouteHop_get_fee_msat(this_ptr: &RouteHop) -> u64 {
117         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fee_msat;
118         *inner_val
119 }
120 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
121 /// For the last hop, this should be the full value of the payment (might be more than
122 /// requested if we had to match htlc_minimum_msat).
123 #[no_mangle]
124 pub extern "C" fn RouteHop_set_fee_msat(this_ptr: &mut RouteHop, mut val: u64) {
125         unsafe { &mut *this_ptr.inner }.fee_msat = val;
126 }
127 /// The CLTV delta added for this hop. For the last hop, this should be the full CLTV value
128 /// expected at the destination, in excess of the current block height.
129 #[no_mangle]
130 pub extern "C" fn RouteHop_get_cltv_expiry_delta(this_ptr: &RouteHop) -> u32 {
131         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta;
132         *inner_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_set_cltv_expiry_delta(this_ptr: &mut RouteHop, mut val: u32) {
138         unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val;
139 }
140 /// Constructs a new RouteHop given each field
141 #[must_use]
142 #[no_mangle]
143 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 {
144         RouteHop { inner: Box::into_raw(Box::new(nativeRouteHop {
145                 pubkey: pubkey_arg.into_rust(),
146                 node_features: *unsafe { Box::from_raw(node_features_arg.take_inner()) },
147                 short_channel_id: short_channel_id_arg,
148                 channel_features: *unsafe { Box::from_raw(channel_features_arg.take_inner()) },
149                 fee_msat: fee_msat_arg,
150                 cltv_expiry_delta: cltv_expiry_delta_arg,
151         })), is_owned: true }
152 }
153 impl Clone for RouteHop {
154         fn clone(&self) -> Self {
155                 Self {
156                         inner: if <*mut nativeRouteHop>::is_null(self.inner) { std::ptr::null_mut() } else {
157                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
158                         is_owned: true,
159                 }
160         }
161 }
162 #[allow(unused)]
163 /// Used only if an object of this type is returned as a trait impl by a method
164 pub(crate) extern "C" fn RouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
165         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHop)).clone() })) as *mut c_void
166 }
167 #[no_mangle]
168 /// Creates a copy of the RouteHop
169 pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop {
170         orig.clone()
171 }
172 #[no_mangle]
173 /// Serialize the RouteHop object into a byte array which can be read by RouteHop_read
174 pub extern "C" fn RouteHop_write(obj: &RouteHop) -> crate::c_types::derived::CVec_u8Z {
175         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
176 }
177 #[no_mangle]
178 pub(crate) extern "C" fn RouteHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
179         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHop) })
180 }
181 #[no_mangle]
182 /// Read a RouteHop from a byte array, created by RouteHop_write
183 pub extern "C" fn RouteHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHopDecodeErrorZ {
184         let res = crate::c_types::deserialize_obj(ser);
185         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::RouteHop { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
186         local_res
187 }
188
189 use lightning::routing::router::Route as nativeRouteImport;
190 type nativeRoute = nativeRouteImport;
191
192 /// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
193 /// it can take multiple paths. Each path is composed of one or more hops through the network.
194 #[must_use]
195 #[repr(C)]
196 pub struct Route {
197         /// A pointer to the opaque Rust object.
198
199         /// Nearly everywhere, inner must be non-null, however in places where
200         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
201         pub inner: *mut nativeRoute,
202         /// Indicates that this is the only struct which contains the same pointer.
203
204         /// Rust functions which take ownership of an object provided via an argument require
205         /// this to be true and invalidate the object pointed to by inner.
206         pub is_owned: bool,
207 }
208
209 impl Drop for Route {
210         fn drop(&mut self) {
211                 if self.is_owned && !<*mut nativeRoute>::is_null(self.inner) {
212                         let _ = unsafe { Box::from_raw(self.inner) };
213                 }
214         }
215 }
216 /// Frees any resources used by the Route, if is_owned is set and inner is non-NULL.
217 #[no_mangle]
218 pub extern "C" fn Route_free(this_obj: Route) { }
219 #[allow(unused)]
220 /// Used only if an object of this type is returned as a trait impl by a method
221 extern "C" fn Route_free_void(this_ptr: *mut c_void) {
222         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoute); }
223 }
224 #[allow(unused)]
225 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
226 impl Route {
227         pub(crate) fn take_inner(mut self) -> *mut nativeRoute {
228                 assert!(self.is_owned);
229                 let ret = self.inner;
230                 self.inner = std::ptr::null_mut();
231                 ret
232         }
233 }
234 /// The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
235 /// last RouteHop in each path must be the same.
236 /// Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the
237 /// destination. Thus, this must always be at least length one. While the maximum length of any
238 /// given path is variable, keeping the length of any path to less than 20 should currently
239 /// ensure it is viable.
240 #[no_mangle]
241 pub extern "C" fn Route_set_paths(this_ptr: &mut Route, mut val: crate::c_types::derived::CVec_CVec_RouteHopZZ) {
242         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 }); };
243         unsafe { &mut *this_ptr.inner }.paths = local_val;
244 }
245 /// Constructs a new Route given each field
246 #[must_use]
247 #[no_mangle]
248 pub extern "C" fn Route_new(mut paths_arg: crate::c_types::derived::CVec_CVec_RouteHopZZ) -> Route {
249         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 }); };
250         Route { inner: Box::into_raw(Box::new(nativeRoute {
251                 paths: local_paths_arg,
252         })), is_owned: true }
253 }
254 impl Clone for Route {
255         fn clone(&self) -> Self {
256                 Self {
257                         inner: if <*mut nativeRoute>::is_null(self.inner) { std::ptr::null_mut() } else {
258                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
259                         is_owned: true,
260                 }
261         }
262 }
263 #[allow(unused)]
264 /// Used only if an object of this type is returned as a trait impl by a method
265 pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_void {
266         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoute)).clone() })) as *mut c_void
267 }
268 #[no_mangle]
269 /// Creates a copy of the Route
270 pub extern "C" fn Route_clone(orig: &Route) -> Route {
271         orig.clone()
272 }
273 #[no_mangle]
274 /// Serialize the Route object into a byte array which can be read by Route_read
275 pub extern "C" fn Route_write(obj: &Route) -> crate::c_types::derived::CVec_u8Z {
276         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
277 }
278 #[no_mangle]
279 pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
280         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) })
281 }
282 #[no_mangle]
283 /// Read a Route from a byte array, created by Route_write
284 pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ {
285         let res = crate::c_types::deserialize_obj(ser);
286         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
287         local_res
288 }
289
290 use lightning::routing::router::RouteHint as nativeRouteHintImport;
291 type nativeRouteHint = nativeRouteHintImport;
292
293 /// A list of hops along a payment path terminating with a channel to the recipient.
294 #[must_use]
295 #[repr(C)]
296 pub struct RouteHint {
297         /// A pointer to the opaque Rust object.
298
299         /// Nearly everywhere, inner must be non-null, however in places where
300         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
301         pub inner: *mut nativeRouteHint,
302         /// Indicates that this is the only struct which contains the same pointer.
303
304         /// Rust functions which take ownership of an object provided via an argument require
305         /// this to be true and invalidate the object pointed to by inner.
306         pub is_owned: bool,
307 }
308
309 impl Drop for RouteHint {
310         fn drop(&mut self) {
311                 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
312                         let _ = unsafe { Box::from_raw(self.inner) };
313                 }
314         }
315 }
316 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
317 #[no_mangle]
318 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
319 #[allow(unused)]
320 /// Used only if an object of this type is returned as a trait impl by a method
321 extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
322         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHint); }
323 }
324 #[allow(unused)]
325 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
326 impl RouteHint {
327         pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
328                 assert!(self.is_owned);
329                 let ret = self.inner;
330                 self.inner = std::ptr::null_mut();
331                 ret
332         }
333 }
334 /// Checks if two RouteHints contain equal inner contents.
335 /// This ignores pointers and is_owned flags and looks at the values in fields.
336 /// Two objects with NULL inner values will be considered "equal" here.
337 #[no_mangle]
338 pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool {
339         if a.inner == b.inner { return true; }
340         if a.inner.is_null() || b.inner.is_null() { return false; }
341         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
342 }
343 impl Clone for RouteHint {
344         fn clone(&self) -> Self {
345                 Self {
346                         inner: if <*mut nativeRouteHint>::is_null(self.inner) { std::ptr::null_mut() } else {
347                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
348                         is_owned: true,
349                 }
350         }
351 }
352 #[allow(unused)]
353 /// Used only if an object of this type is returned as a trait impl by a method
354 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
355         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void
356 }
357 #[no_mangle]
358 /// Creates a copy of the RouteHint
359 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
360         orig.clone()
361 }
362
363 use lightning::routing::router::RouteHintHop as nativeRouteHintHopImport;
364 type nativeRouteHintHop = nativeRouteHintHopImport;
365
366 /// A channel descriptor for a hop along a payment path.
367 #[must_use]
368 #[repr(C)]
369 pub struct RouteHintHop {
370         /// A pointer to the opaque Rust object.
371
372         /// Nearly everywhere, inner must be non-null, however in places where
373         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
374         pub inner: *mut nativeRouteHintHop,
375         /// Indicates that this is the only struct which contains the same pointer.
376
377         /// Rust functions which take ownership of an object provided via an argument require
378         /// this to be true and invalidate the object pointed to by inner.
379         pub is_owned: bool,
380 }
381
382 impl Drop for RouteHintHop {
383         fn drop(&mut self) {
384                 if self.is_owned && !<*mut nativeRouteHintHop>::is_null(self.inner) {
385                         let _ = unsafe { Box::from_raw(self.inner) };
386                 }
387         }
388 }
389 /// Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL.
390 #[no_mangle]
391 pub extern "C" fn RouteHintHop_free(this_obj: RouteHintHop) { }
392 #[allow(unused)]
393 /// Used only if an object of this type is returned as a trait impl by a method
394 extern "C" fn RouteHintHop_free_void(this_ptr: *mut c_void) {
395         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHintHop); }
396 }
397 #[allow(unused)]
398 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
399 impl RouteHintHop {
400         pub(crate) fn take_inner(mut self) -> *mut nativeRouteHintHop {
401                 assert!(self.is_owned);
402                 let ret = self.inner;
403                 self.inner = std::ptr::null_mut();
404                 ret
405         }
406 }
407 /// The node_id of the non-target end of the route
408 #[no_mangle]
409 pub extern "C" fn RouteHintHop_get_src_node_id(this_ptr: &RouteHintHop) -> crate::c_types::PublicKey {
410         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.src_node_id;
411         crate::c_types::PublicKey::from_rust(&inner_val)
412 }
413 /// The node_id of the non-target end of the route
414 #[no_mangle]
415 pub extern "C" fn RouteHintHop_set_src_node_id(this_ptr: &mut RouteHintHop, mut val: crate::c_types::PublicKey) {
416         unsafe { &mut *this_ptr.inner }.src_node_id = val.into_rust();
417 }
418 /// The short_channel_id of this channel
419 #[no_mangle]
420 pub extern "C" fn RouteHintHop_get_short_channel_id(this_ptr: &RouteHintHop) -> u64 {
421         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.short_channel_id;
422         *inner_val
423 }
424 /// The short_channel_id of this channel
425 #[no_mangle]
426 pub extern "C" fn RouteHintHop_set_short_channel_id(this_ptr: &mut RouteHintHop, mut val: u64) {
427         unsafe { &mut *this_ptr.inner }.short_channel_id = val;
428 }
429 /// The fees which must be paid to use this channel
430 #[no_mangle]
431 pub extern "C" fn RouteHintHop_get_fees(this_ptr: &RouteHintHop) -> crate::lightning::routing::network_graph::RoutingFees {
432         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fees;
433         crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
434 }
435 /// The fees which must be paid to use this channel
436 #[no_mangle]
437 pub extern "C" fn RouteHintHop_set_fees(this_ptr: &mut RouteHintHop, mut val: crate::lightning::routing::network_graph::RoutingFees) {
438         unsafe { &mut *this_ptr.inner }.fees = *unsafe { Box::from_raw(val.take_inner()) };
439 }
440 /// The difference in CLTV values between this node and the next node.
441 #[no_mangle]
442 pub extern "C" fn RouteHintHop_get_cltv_expiry_delta(this_ptr: &RouteHintHop) -> u16 {
443         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta;
444         *inner_val
445 }
446 /// The difference in CLTV values between this node and the next node.
447 #[no_mangle]
448 pub extern "C" fn RouteHintHop_set_cltv_expiry_delta(this_ptr: &mut RouteHintHop, mut val: u16) {
449         unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val;
450 }
451 /// The minimum value, in msat, which must be relayed to the next hop.
452 #[no_mangle]
453 pub extern "C" fn RouteHintHop_get_htlc_minimum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
454         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat;
455         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()) } };
456         local_inner_val
457 }
458 /// The minimum value, in msat, which must be relayed to the next hop.
459 #[no_mangle]
460 pub extern "C" fn RouteHintHop_set_htlc_minimum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
461         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
462         unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = local_val;
463 }
464 /// The maximum value in msat available for routing with a single HTLC.
465 #[no_mangle]
466 pub extern "C" fn RouteHintHop_get_htlc_maximum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
467         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_maximum_msat;
468         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()) } };
469         local_inner_val
470 }
471 /// The maximum value in msat available for routing with a single HTLC.
472 #[no_mangle]
473 pub extern "C" fn RouteHintHop_set_htlc_maximum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
474         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
475         unsafe { &mut *this_ptr.inner }.htlc_maximum_msat = local_val;
476 }
477 /// Constructs a new RouteHintHop given each field
478 #[must_use]
479 #[no_mangle]
480 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 {
481         let mut local_htlc_minimum_msat_arg = if htlc_minimum_msat_arg.is_some() { Some( { htlc_minimum_msat_arg.take() }) } else { None };
482         let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
483         RouteHintHop { inner: Box::into_raw(Box::new(nativeRouteHintHop {
484                 src_node_id: src_node_id_arg.into_rust(),
485                 short_channel_id: short_channel_id_arg,
486                 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
487                 cltv_expiry_delta: cltv_expiry_delta_arg,
488                 htlc_minimum_msat: local_htlc_minimum_msat_arg,
489                 htlc_maximum_msat: local_htlc_maximum_msat_arg,
490         })), is_owned: true }
491 }
492 /// Checks if two RouteHintHops contain equal inner contents.
493 /// This ignores pointers and is_owned flags and looks at the values in fields.
494 /// Two objects with NULL inner values will be considered "equal" here.
495 #[no_mangle]
496 pub extern "C" fn RouteHintHop_eq(a: &RouteHintHop, b: &RouteHintHop) -> bool {
497         if a.inner == b.inner { return true; }
498         if a.inner.is_null() || b.inner.is_null() { return false; }
499         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
500 }
501 impl Clone for RouteHintHop {
502         fn clone(&self) -> Self {
503                 Self {
504                         inner: if <*mut nativeRouteHintHop>::is_null(self.inner) { std::ptr::null_mut() } else {
505                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
506                         is_owned: true,
507                 }
508         }
509 }
510 #[allow(unused)]
511 /// Used only if an object of this type is returned as a trait impl by a method
512 pub(crate) extern "C" fn RouteHintHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
513         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHintHop)).clone() })) as *mut c_void
514 }
515 #[no_mangle]
516 /// Creates a copy of the RouteHintHop
517 pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop {
518         orig.clone()
519 }
520 /// Gets a keysend route from us (payer) to the given target node (payee). This is needed because
521 /// keysend payments do not have an invoice from which to pull the payee's supported features, which
522 /// makes it tricky to otherwise supply the `payee_features` parameter of `get_route`.
523 ///
524 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
525 #[no_mangle]
526 pub extern "C" fn get_keysend_route(mut our_node_id: crate::c_types::PublicKey, network: &crate::lightning::routing::network_graph::NetworkGraph, mut payee: crate::c_types::PublicKey, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut last_hops: crate::c_types::derived::CVec_RouteHintZ, mut final_value_msat: u64, mut final_cltv: u32, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
527         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( { unsafe { &*item.inner } }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]);
528         let mut local_last_hops = Vec::new(); for mut item in last_hops.as_slice().iter() { local_last_hops.push( { unsafe { &*item.inner } }); };
529         let mut ret = lightning::routing::router::get_keysend_route(&our_node_id.into_rust(), unsafe { &*network.inner }, &payee.into_rust(), local_first_hops, &local_last_hops[..], final_value_msat, final_cltv, logger);
530         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
531         local_ret
532 }
533
534 /// Gets a route from us (payer) to the given target node (payee).
535 ///
536 /// If the payee provided features in their invoice, they should be provided via payee_features.
537 /// Without this, MPP will only be used if the payee's features are available in the network graph.
538 ///
539 /// Private routing paths between a public node and the target may be included in `last_hops`.
540 /// Currently, only the last hop in each path is considered.
541 ///
542 /// If some channels aren't announced, it may be useful to fill in a first_hops with the
543 /// results from a local ChannelManager::list_usable_channels() call. If it is filled in, our
544 /// view of our local channels (from net_graph_msg_handler) will be ignored, and only those
545 /// in first_hops will be used.
546 ///
547 /// Panics if first_hops contains channels without short_channel_ids
548 /// (ChannelManager::list_usable_channels will never include such channels).
549 ///
550 /// The fees on channels from us to next-hops are ignored (as they are assumed to all be
551 /// equal), however the enabled/disabled bit on such channels as well as the
552 /// htlc_minimum_msat/htlc_maximum_msat *are* checked as they may change based on the receiving node.
553 ///
554 /// Note that payee_features (or a relevant inner pointer) may be NULL or all-0s to represent None
555 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
556 #[no_mangle]
557 pub extern "C" fn get_route(mut our_node_id: crate::c_types::PublicKey, network: &crate::lightning::routing::network_graph::NetworkGraph, mut payee: crate::c_types::PublicKey, mut payee_features: crate::lightning::ln::features::InvoiceFeatures, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut last_hops: crate::c_types::derived::CVec_RouteHintZ, mut final_value_msat: u64, mut final_cltv: u32, mut logger: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
558         let mut local_payee_features = if payee_features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(payee_features.take_inner()) } }) };
559         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( { unsafe { &*item.inner } }); }; local_first_hops_0 }) }; let mut local_first_hops = local_first_hops_base.as_ref().map(|a| &a[..]);
560         let mut local_last_hops = Vec::new(); for mut item in last_hops.as_slice().iter() { local_last_hops.push( { unsafe { &*item.inner } }); };
561         let mut ret = lightning::routing::router::get_route(&our_node_id.into_rust(), unsafe { &*network.inner }, &payee.into_rust(), local_payee_features, local_first_hops, &local_last_hops[..], final_value_msat, final_cltv, logger);
562         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::Route { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
563         local_ret
564 }
565