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 bitcoin::hashes::Hash;
17 use crate::c_types::*;
20 use lightning::routing::router::RouteHop as nativeRouteHopImport;
21 type nativeRouteHop = nativeRouteHopImport;
27 /// A pointer to the opaque Rust object.
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.
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.
39 impl Drop for RouteHop {
41 if self.is_owned && !<*mut nativeRouteHop>::is_null(self.inner) {
42 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
46 /// Frees any resources used by the RouteHop, if is_owned is set and inner is non-NULL.
48 pub extern "C" fn RouteHop_free(this_obj: RouteHop) { }
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); }
56 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHop {
57 unsafe { &*ObjOps::untweak_ptr(self.inner) }
59 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHop {
60 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
70 /// The node_id of the node at this hop.
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)
76 /// The node_id of the node at this hop.
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();
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.
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 }
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.
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()) };
94 /// The channel that should be used from the previous hop to reach this node.
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;
100 /// The channel that should be used from the previous hop to reach this node.
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;
105 /// The channel_announcement features of the channel that should be used from the previous hop
106 /// to reach this node.
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 }
112 /// The channel_announcement features of the channel that should be used from the previous hop
113 /// to reach this node.
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()) };
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).
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;
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).
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;
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.
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;
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.
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;
146 /// Constructs a new RouteHop given each field
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,
159 impl Clone for RouteHop {
160 fn clone(&self) -> 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()) },
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
174 /// Creates a copy of the RouteHop
175 pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop {
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())
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) })
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() };
195 use lightning::routing::router::Route as nativeRouteImport;
196 type nativeRoute = nativeRouteImport;
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.
203 /// A pointer to the opaque Rust object.
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.
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.
215 impl Drop for Route {
217 if self.is_owned && !<*mut nativeRoute>::is_null(self.inner) {
218 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
222 /// Frees any resources used by the Route, if is_owned is set and inner is non-NULL.
224 pub extern "C" fn Route_free(this_obj: Route) { }
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); }
232 pub(crate) fn get_native_ref(&self) -> &'static nativeRoute {
233 unsafe { &*ObjOps::untweak_ptr(self.inner) }
235 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoute {
236 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
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.
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;
257 /// Constructs a new Route given each field
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,
266 impl Clone for Route {
267 fn clone(&self) -> 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()) },
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
281 /// Creates a copy of the Route
282 pub extern "C" fn Route_clone(orig: &Route) -> Route {
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())
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) })
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() };
302 use lightning::routing::router::RouteHint as nativeRouteHintImport;
303 type nativeRouteHint = nativeRouteHintImport;
305 /// A list of hops along a payment path terminating with a channel to the recipient.
308 pub struct RouteHint {
309 /// A pointer to the opaque Rust object.
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.
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.
321 impl Drop for RouteHint {
323 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
324 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
328 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
330 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
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); }
338 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHint {
339 unsafe { &*ObjOps::untweak_ptr(self.inner) }
341 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHint {
342 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
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.
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 }
361 impl Clone for RouteHint {
362 fn clone(&self) -> 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()) },
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
376 /// Creates a copy of the RouteHint
377 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
381 use lightning::routing::router::RouteHintHop as nativeRouteHintHopImport;
382 type nativeRouteHintHop = nativeRouteHintHopImport;
384 /// A channel descriptor for a hop along a payment path.
387 pub struct RouteHintHop {
388 /// A pointer to the opaque Rust object.
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.
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.
400 impl Drop for RouteHintHop {
402 if self.is_owned && !<*mut nativeRouteHintHop>::is_null(self.inner) {
403 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
407 /// Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL.
409 pub extern "C" fn RouteHintHop_free(this_obj: RouteHintHop) { }
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); }
417 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHintHop {
418 unsafe { &*ObjOps::untweak_ptr(self.inner) }
420 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHintHop {
421 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
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();
431 /// The node_id of the non-target end of the route
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)
437 /// The node_id of the non-target end of the route
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();
442 /// The short_channel_id of this channel
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;
448 /// The short_channel_id of this channel
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;
453 /// The fees which must be paid to use this channel
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 }
459 /// The fees which must be paid to use this channel
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()) };
464 /// The difference in CLTV values between this node and the next node.
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;
470 /// The difference in CLTV values between this node and the next node.
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;
475 /// The minimum value, in msat, which must be relayed to the next hop.
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()) } };
482 /// The minimum value, in msat, which must be relayed to the next hop.
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;
488 /// The maximum value in msat available for routing with a single HTLC.
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()) } };
495 /// The maximum value in msat available for routing with a single HTLC.
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;
501 /// Constructs a new RouteHintHop given each field
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,
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.
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 }
525 impl Clone for RouteHintHop {
526 fn clone(&self) -> 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()) },
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
540 /// Creates a copy of the RouteHintHop
541 pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop {
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`.
548 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
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() };
558 /// Gets a route from us (payer) to the given target node (payee).
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.
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.
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.
571 /// Panics if first_hops contains channels without short_channel_ids
572 /// (ChannelManager::list_usable_channels will never include such channels).
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.
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
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() };