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