1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
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.
9 //! The top-level routing/network map tracking logic lives here.
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.
14 use std::str::FromStr;
16 use core::convert::Infallible;
17 use bitcoin::hashes::Hash;
18 use crate::c_types::*;
21 use lightning::routing::router::RouteHop as nativeRouteHopImport;
22 type nativeRouteHop = nativeRouteHopImport;
28 /// A pointer to the opaque Rust object.
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.
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.
40 impl Drop for RouteHop {
42 if self.is_owned && !<*mut nativeRouteHop>::is_null(self.inner) {
43 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
47 /// Frees any resources used by the RouteHop, if is_owned is set and inner is non-NULL.
49 pub extern "C" fn RouteHop_free(this_obj: RouteHop) { }
51 /// Used only if an object of this type is returned as a trait impl by a method
52 extern "C" fn RouteHop_free_void(this_ptr: *mut c_void) {
53 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHop); }
57 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHop {
58 unsafe { &*ObjOps::untweak_ptr(self.inner) }
60 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHop {
61 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
71 /// The node_id of the node at this hop.
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)
77 /// The node_id of the node at this hop.
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();
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.
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 _) as *mut _) }, is_owned: false }
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.
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()) };
95 /// The channel that should be used from the previous hop to reach this node.
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;
101 /// The channel that should be used from the previous hop to reach this node.
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;
106 /// The channel_announcement features of the channel that should be used from the previous hop
107 /// to reach this node.
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 _) as *mut _) }, is_owned: false }
113 /// The channel_announcement features of the channel that should be used from the previous hop
114 /// to reach this node.
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()) };
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).
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;
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).
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;
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.
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;
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.
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;
147 /// Constructs a new RouteHop given each field
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,
160 impl Clone for RouteHop {
161 fn clone(&self) -> 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()) },
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
175 /// Creates a copy of the RouteHop
176 pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop {
179 /// Checks if two RouteHops contain equal inner contents.
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
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)
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.
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 }
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())
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) })
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 = 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() };
215 use lightning::routing::router::Route as nativeRouteImport;
216 type nativeRoute = nativeRouteImport;
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.
223 /// A pointer to the opaque Rust object.
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.
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.
235 impl Drop for Route {
237 if self.is_owned && !<*mut nativeRoute>::is_null(self.inner) {
238 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
242 /// Frees any resources used by the Route, if is_owned is set and inner is non-NULL.
244 pub extern "C" fn Route_free(this_obj: Route) { }
246 /// Used only if an object of this type is returned as a trait impl by a method
247 extern "C" fn Route_free_void(this_ptr: *mut c_void) {
248 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoute); }
252 pub(crate) fn get_native_ref(&self) -> &'static nativeRoute {
253 unsafe { &*ObjOps::untweak_ptr(self.inner) }
255 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoute {
256 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
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.
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 _) as *mut _) }, is_owned: false } }); }; local_inner_val_0.into() }); };
276 local_inner_val.into()
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.
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;
289 /// Constructs a new Route given each field
292 pub extern "C" fn Route_new(mut paths_arg: crate::c_types::derived::CVec_CVec_RouteHopZZ) -> Route {
293 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 }); };
294 Route { inner: ObjOps::heap_alloc(nativeRoute {
295 paths: local_paths_arg,
298 impl Clone for Route {
299 fn clone(&self) -> Self {
301 inner: if <*mut nativeRoute>::is_null(self.inner) { std::ptr::null_mut() } else {
302 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
308 /// Used only if an object of this type is returned as a trait impl by a method
309 pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_void {
310 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoute)).clone() })) as *mut c_void
313 /// Creates a copy of the Route
314 pub extern "C" fn Route_clone(orig: &Route) -> Route {
317 /// Checks if two Routes contain equal inner contents.
319 pub extern "C" fn Route_hash(o: &Route) -> u64 {
320 if o.inner.is_null() { return 0; }
321 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
323 let mut hasher = core::hash::SipHasher::new();
324 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
325 std::hash::Hasher::finish(&hasher)
327 /// Checks if two Routes contain equal inner contents.
328 /// This ignores pointers and is_owned flags and looks at the values in fields.
329 /// Two objects with NULL inner values will be considered "equal" here.
331 pub extern "C" fn Route_eq(a: &Route, b: &Route) -> bool {
332 if a.inner == b.inner { return true; }
333 if a.inner.is_null() || b.inner.is_null() { return false; }
334 if a.get_native_ref() == b.get_native_ref() { true } else { false }
336 /// Returns the total amount of fees paid on this [`Route`].
338 /// This doesn't include any extra payment made to the recipient, which can happen in excess of
339 /// the amount passed to [`get_route`]'s `final_value_msat`.
342 pub extern "C" fn Route_get_total_fees(this_arg: &Route) -> u64 {
343 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_fees();
347 /// Returns the total amount paid on this [`Route`], excluding the fees.
350 pub extern "C" fn Route_get_total_amount(this_arg: &Route) -> u64 {
351 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_amount();
356 /// Serialize the Route object into a byte array which can be read by Route_read
357 pub extern "C" fn Route_write(obj: &Route) -> crate::c_types::derived::CVec_u8Z {
358 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
361 pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
362 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) })
365 /// Read a Route from a byte array, created by Route_write
366 pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ {
367 let res = crate::c_types::deserialize_obj(ser);
368 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() };
372 use lightning::routing::router::RouteHint as nativeRouteHintImport;
373 type nativeRouteHint = nativeRouteHintImport;
375 /// A list of hops along a payment path terminating with a channel to the recipient.
378 pub struct RouteHint {
379 /// A pointer to the opaque Rust object.
381 /// Nearly everywhere, inner must be non-null, however in places where
382 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
383 pub inner: *mut nativeRouteHint,
384 /// Indicates that this is the only struct which contains the same pointer.
386 /// Rust functions which take ownership of an object provided via an argument require
387 /// this to be true and invalidate the object pointed to by inner.
391 impl Drop for RouteHint {
393 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
394 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
398 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
400 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
402 /// Used only if an object of this type is returned as a trait impl by a method
403 extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
404 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHint); }
408 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHint {
409 unsafe { &*ObjOps::untweak_ptr(self.inner) }
411 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHint {
412 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
414 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
415 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
416 assert!(self.is_owned);
417 let ret = ObjOps::untweak_ptr(self.inner);
418 self.inner = std::ptr::null_mut();
422 impl Clone for RouteHint {
423 fn clone(&self) -> Self {
425 inner: if <*mut nativeRouteHint>::is_null(self.inner) { std::ptr::null_mut() } else {
426 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
432 /// Used only if an object of this type is returned as a trait impl by a method
433 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
434 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHint)).clone() })) as *mut c_void
437 /// Creates a copy of the RouteHint
438 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
441 /// Checks if two RouteHints contain equal inner contents.
443 pub extern "C" fn RouteHint_hash(o: &RouteHint) -> u64 {
444 if o.inner.is_null() { return 0; }
445 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
447 let mut hasher = core::hash::SipHasher::new();
448 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
449 std::hash::Hasher::finish(&hasher)
451 /// Checks if two RouteHints contain equal inner contents.
452 /// This ignores pointers and is_owned flags and looks at the values in fields.
453 /// Two objects with NULL inner values will be considered "equal" here.
455 pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool {
456 if a.inner == b.inner { return true; }
457 if a.inner.is_null() || b.inner.is_null() { return false; }
458 if a.get_native_ref() == b.get_native_ref() { true } else { false }
461 use lightning::routing::router::RouteHintHop as nativeRouteHintHopImport;
462 type nativeRouteHintHop = nativeRouteHintHopImport;
464 /// A channel descriptor for a hop along a payment path.
467 pub struct RouteHintHop {
468 /// A pointer to the opaque Rust object.
470 /// Nearly everywhere, inner must be non-null, however in places where
471 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
472 pub inner: *mut nativeRouteHintHop,
473 /// Indicates that this is the only struct which contains the same pointer.
475 /// Rust functions which take ownership of an object provided via an argument require
476 /// this to be true and invalidate the object pointed to by inner.
480 impl Drop for RouteHintHop {
482 if self.is_owned && !<*mut nativeRouteHintHop>::is_null(self.inner) {
483 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
487 /// Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL.
489 pub extern "C" fn RouteHintHop_free(this_obj: RouteHintHop) { }
491 /// Used only if an object of this type is returned as a trait impl by a method
492 extern "C" fn RouteHintHop_free_void(this_ptr: *mut c_void) {
493 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRouteHintHop); }
497 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHintHop {
498 unsafe { &*ObjOps::untweak_ptr(self.inner) }
500 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHintHop {
501 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
503 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
504 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHintHop {
505 assert!(self.is_owned);
506 let ret = ObjOps::untweak_ptr(self.inner);
507 self.inner = std::ptr::null_mut();
511 /// The node_id of the non-target end of the route
513 pub extern "C" fn RouteHintHop_get_src_node_id(this_ptr: &RouteHintHop) -> crate::c_types::PublicKey {
514 let mut inner_val = &mut this_ptr.get_native_mut_ref().src_node_id;
515 crate::c_types::PublicKey::from_rust(&inner_val)
517 /// The node_id of the non-target end of the route
519 pub extern "C" fn RouteHintHop_set_src_node_id(this_ptr: &mut RouteHintHop, mut val: crate::c_types::PublicKey) {
520 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.src_node_id = val.into_rust();
522 /// The short_channel_id of this channel
524 pub extern "C" fn RouteHintHop_get_short_channel_id(this_ptr: &RouteHintHop) -> u64 {
525 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
528 /// The short_channel_id of this channel
530 pub extern "C" fn RouteHintHop_set_short_channel_id(this_ptr: &mut RouteHintHop, mut val: u64) {
531 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
533 /// The fees which must be paid to use this channel
535 pub extern "C" fn RouteHintHop_get_fees(this_ptr: &RouteHintHop) -> crate::lightning::routing::network_graph::RoutingFees {
536 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
537 crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
539 /// The fees which must be paid to use this channel
541 pub extern "C" fn RouteHintHop_set_fees(this_ptr: &mut RouteHintHop, mut val: crate::lightning::routing::network_graph::RoutingFees) {
542 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
544 /// The difference in CLTV values between this node and the next node.
546 pub extern "C" fn RouteHintHop_get_cltv_expiry_delta(this_ptr: &RouteHintHop) -> u16 {
547 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
550 /// The difference in CLTV values between this node and the next node.
552 pub extern "C" fn RouteHintHop_set_cltv_expiry_delta(this_ptr: &mut RouteHintHop, mut val: u16) {
553 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
555 /// The minimum value, in msat, which must be relayed to the next hop.
557 pub extern "C" fn RouteHintHop_get_htlc_minimum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
558 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
559 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() }) };
562 /// The minimum value, in msat, which must be relayed to the next hop.
564 pub extern "C" fn RouteHintHop_set_htlc_minimum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
565 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
566 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = local_val;
568 /// The maximum value in msat available for routing with a single HTLC.
570 pub extern "C" fn RouteHintHop_get_htlc_maximum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
571 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
572 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() }) };
575 /// The maximum value in msat available for routing with a single HTLC.
577 pub extern "C" fn RouteHintHop_set_htlc_maximum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
578 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
579 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
581 /// Constructs a new RouteHintHop given each field
584 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 {
585 let mut local_htlc_minimum_msat_arg = if htlc_minimum_msat_arg.is_some() { Some( { htlc_minimum_msat_arg.take() }) } else { None };
586 let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
587 RouteHintHop { inner: ObjOps::heap_alloc(nativeRouteHintHop {
588 src_node_id: src_node_id_arg.into_rust(),
589 short_channel_id: short_channel_id_arg,
590 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
591 cltv_expiry_delta: cltv_expiry_delta_arg,
592 htlc_minimum_msat: local_htlc_minimum_msat_arg,
593 htlc_maximum_msat: local_htlc_maximum_msat_arg,
596 impl Clone for RouteHintHop {
597 fn clone(&self) -> Self {
599 inner: if <*mut nativeRouteHintHop>::is_null(self.inner) { std::ptr::null_mut() } else {
600 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
606 /// Used only if an object of this type is returned as a trait impl by a method
607 pub(crate) extern "C" fn RouteHintHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
608 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRouteHintHop)).clone() })) as *mut c_void
611 /// Creates a copy of the RouteHintHop
612 pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop {
615 /// Checks if two RouteHintHops contain equal inner contents.
617 pub extern "C" fn RouteHintHop_hash(o: &RouteHintHop) -> u64 {
618 if o.inner.is_null() { return 0; }
619 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
621 let mut hasher = core::hash::SipHasher::new();
622 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
623 std::hash::Hasher::finish(&hasher)
625 /// Checks if two RouteHintHops contain equal inner contents.
626 /// This ignores pointers and is_owned flags and looks at the values in fields.
627 /// Two objects with NULL inner values will be considered "equal" here.
629 pub extern "C" fn RouteHintHop_eq(a: &RouteHintHop, b: &RouteHintHop) -> bool {
630 if a.inner == b.inner { return true; }
631 if a.inner.is_null() || b.inner.is_null() { return false; }
632 if a.get_native_ref() == b.get_native_ref() { true } else { false }
634 /// Gets a keysend route from us (payer) to the given target node (payee). This is needed because
635 /// keysend payments do not have an invoice from which to pull the payee's supported features, which
636 /// makes it tricky to otherwise supply the `payee_features` parameter of `get_route`.
638 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
640 pub extern "C" fn get_keysend_route(mut our_node_pubkey: 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, scorer: &crate::lightning::routing::Score) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
641 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[..]);
642 let mut local_last_hops = Vec::new(); for mut item in last_hops.as_slice().iter() { local_last_hops.push( { item.get_native_ref() }); };
643 let mut ret = lightning::routing::router::get_keysend_route(&our_node_pubkey.into_rust(), network.get_native_ref(), &payee.into_rust(), local_first_hops, &local_last_hops[..], final_value_msat, final_cltv, logger, scorer);
644 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() };
648 /// Gets a route from us (payer) to the given target node (payee).
650 /// If the payee provided features in their invoice, they should be provided via payee_features.
651 /// Without this, MPP will only be used if the payee's features are available in the network graph.
653 /// Private routing paths between a public node and the target may be included in `last_hops`.
654 /// Currently, only the last hop in each path is considered.
656 /// If some channels aren't announced, it may be useful to fill in a first_hops with the
657 /// results from a local ChannelManager::list_usable_channels() call. If it is filled in, our
658 /// view of our local channels (from net_graph_msg_handler) will be ignored, and only those
659 /// in first_hops will be used.
661 /// Panics if first_hops contains channels without short_channel_ids
662 /// (ChannelManager::list_usable_channels will never include such channels).
664 /// The fees on channels from us to next-hops are ignored (as they are assumed to all be
665 /// equal), however the enabled/disabled bit on such channels as well as the
666 /// htlc_minimum_msat/htlc_maximum_msat *are* checked as they may change based on the receiving node.
668 /// Note that payee_features (or a relevant inner pointer) may be NULL or all-0s to represent None
669 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
671 pub extern "C" fn get_route(mut our_node_pubkey: 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, scorer: &crate::lightning::routing::Score) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
672 let mut local_payee_features = if payee_features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(payee_features.take_inner()) } }) };
673 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[..]);
674 let mut local_last_hops = Vec::new(); for mut item in last_hops.as_slice().iter() { local_last_hops.push( { item.get_native_ref() }); };
675 let mut ret = lightning::routing::router::get_route(&our_node_pubkey.into_rust(), network.get_native_ref(), &payee.into_rust(), local_payee_features, local_first_hops, &local_last_hops[..], final_value_msat, final_cltv, logger, scorer);
676 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() };