From: Matt Corallo <649246+TheBlueMatt@users.noreply.github.com> Date: Wed, 29 Jun 2022 18:35:53 +0000 (-0700) Subject: Merge pull request #82 from TheBlueMatt/main X-Git-Tag: v0.0.108.1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=76abeac7d836085772d3ec29894e9583b5889462;hp=45ad3320df3768514d968c70fc4b6a9d50028050;p=ldk-c-bindings Merge pull request #82 from TheBlueMatt/main 0.0.108.1 --- diff --git a/lightning-c-bindings/demo.cpp b/lightning-c-bindings/demo.cpp index 1d29ed6..5b9b713 100644 --- a/lightning-c-bindings/demo.cpp +++ b/lightning-c-bindings/demo.cpp @@ -444,8 +444,7 @@ struct LDKCResult_RouteLightningErrorZ custom_find_route(const void *this_arg, s const struct CustomRouteFinderParams *params = (struct CustomRouteFinderParams *)this_arg; assert(first_hops->datalen == 1); assert(ChannelDetails_get_is_usable(&first_hops->data[0])); - LDK::ReadOnlyNetworkGraph graph_lock = NetworkGraph_read_only(params->graph_ref); - return find_route(payer, route_params, &graph_lock, first_hops, *params->logger, scorer, ¶ms->random_seed_bytes.data); + return find_route(payer, route_params, params->graph_ref, first_hops, *params->logger, scorer, ¶ms->random_seed_bytes.data); } int main() { @@ -715,9 +714,8 @@ int main() { }, Invoice_route_hints(invoice->contents.result), COption_u64Z_none(), 0xffffffff), 5000, Invoice_min_final_cltv_expiry(invoice->contents.result)); random_bytes = keys_source1->get_secure_random_bytes(keys_source1->this_arg); - LDK::ReadOnlyNetworkGraph graph_lock = NetworkGraph_read_only(&net_graph2); - LDK::CResult_RouteLightningErrorZ route = find_route(ChannelManager_get_our_node_id(&cm1), &route_params, &graph_lock, &outbound_channels, logger1, &chan_scorer, &random_bytes.data); + LDK::CResult_RouteLightningErrorZ route = find_route(ChannelManager_get_our_node_id(&cm1), &route_params, &net_graph2, &outbound_channels, logger1, &chan_scorer, &random_bytes.data); assert(route->result_ok); LDK::CVec_CVec_RouteHopZZ paths = Route_get_paths(route->contents.result); diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index fb856cb..c1538b8 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -26843,7 +26843,7 @@ struct LDKCResult_RouteHintHopDecodeErrorZ RouteHintHop_read(struct LDKu8slice s * * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None */ -struct LDKCResult_RouteLightningErrorZ find_route(struct LDKPublicKey our_node_pubkey, const struct LDKRouteParameters *NONNULL_PTR route_params, const struct LDKReadOnlyNetworkGraph *NONNULL_PTR network_graph, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKLogger logger, const struct LDKScore *NONNULL_PTR scorer, const uint8_t (*random_seed_bytes)[32]); +struct LDKCResult_RouteLightningErrorZ find_route(struct LDKPublicKey our_node_pubkey, const struct LDKRouteParameters *NONNULL_PTR route_params, const struct LDKNetworkGraph *NONNULL_PTR network_graph, struct LDKCVec_ChannelDetailsZ *first_hops, struct LDKLogger logger, const struct LDKScore *NONNULL_PTR scorer, const uint8_t (*random_seed_bytes)[32]); /** * Construct a route from us (payer) to the target node (payee) via the given hops (which should @@ -26851,7 +26851,7 @@ struct LDKCResult_RouteLightningErrorZ find_route(struct LDKPublicKey our_node_p * * Re-uses logic from `find_route`, so the restrictions described there also apply here. */ -struct LDKCResult_RouteLightningErrorZ build_route_from_hops(struct LDKPublicKey our_node_pubkey, struct LDKCVec_PublicKeyZ hops, const struct LDKRouteParameters *NONNULL_PTR route_params, const struct LDKReadOnlyNetworkGraph *NONNULL_PTR network_graph, struct LDKLogger logger, const uint8_t (*random_seed_bytes)[32]); +struct LDKCResult_RouteLightningErrorZ build_route_from_hops(struct LDKPublicKey our_node_pubkey, struct LDKCVec_PublicKeyZ hops, const struct LDKRouteParameters *NONNULL_PTR route_params, const struct LDKNetworkGraph *NONNULL_PTR network_graph, struct LDKLogger logger, const uint8_t (*random_seed_bytes)[32]); /** * Calls the free function if one is set diff --git a/lightning-c-bindings/src/lightning/routing/router.rs b/lightning-c-bindings/src/lightning/routing/router.rs index 99df54a..ee8d9e0 100644 --- a/lightning-c-bindings/src/lightning/routing/router.rs +++ b/lightning-c-bindings/src/lightning/routing/router.rs @@ -1091,9 +1091,9 @@ pub extern "C" fn RouteHintHop_read(ser: crate::c_types::u8slice) -> crate::c_ty /// /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None #[no_mangle] -pub extern "C" fn find_route(mut our_node_pubkey: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, network_graph: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut logger: crate::lightning::util::logger::Logger, scorer: &crate::lightning::routing::scoring::Score, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ { +pub extern "C" fn find_route(mut our_node_pubkey: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, network_graph: &crate::lightning::routing::gossip::NetworkGraph, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut logger: crate::lightning::util::logger::Logger, scorer: &crate::lightning::routing::scoring::Score, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ { let mut local_first_hops_base = if first_hops == core::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[..]); - let mut ret = lightning::routing::router::find_route::(&our_node_pubkey.into_rust(), route_params.get_native_ref(), network_graph.get_native_ref(), local_first_hops, logger, scorer, unsafe { &*random_seed_bytes}); + let mut ret = lightning::routing::router::find_route::(&our_node_pubkey.into_rust(), route_params.get_native_ref(), network_graph.get_native_ref(), local_first_hops, logger, scorer, unsafe { &*random_seed_bytes}); 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() }; local_ret } @@ -1103,9 +1103,9 @@ pub extern "C" fn find_route(mut our_node_pubkey: crate::c_types::PublicKey, rou /// /// Re-uses logic from `find_route`, so the restrictions described there also apply here. #[no_mangle] -pub extern "C" fn build_route_from_hops(mut our_node_pubkey: crate::c_types::PublicKey, mut hops: crate::c_types::derived::CVec_PublicKeyZ, route_params: &crate::lightning::routing::router::RouteParameters, network_graph: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, mut logger: crate::lightning::util::logger::Logger, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ { +pub extern "C" fn build_route_from_hops(mut our_node_pubkey: crate::c_types::PublicKey, mut hops: crate::c_types::derived::CVec_PublicKeyZ, route_params: &crate::lightning::routing::router::RouteParameters, network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut logger: crate::lightning::util::logger::Logger, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ { let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { item.into_rust() }); }; - let mut ret = lightning::routing::router::build_route_from_hops::(&our_node_pubkey.into_rust(), &local_hops[..], route_params.get_native_ref(), network_graph.get_native_ref(), logger, unsafe { &*random_seed_bytes}); + let mut ret = lightning::routing::router::build_route_from_hops::(&our_node_pubkey.into_rust(), &local_hops[..], route_params.get_native_ref(), network_graph.get_native_ref(), logger, unsafe { &*random_seed_bytes}); 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() }; local_ret } diff --git a/lightning-c-bindings/src/lightning/routing/scoring.rs b/lightning-c-bindings/src/lightning/routing/scoring.rs index a45f706..16b8c4a 100644 --- a/lightning-c-bindings/src/lightning/routing/scoring.rs +++ b/lightning-c-bindings/src/lightning/routing/scoring.rs @@ -42,7 +42,7 @@ //! let scorer = ProbabilisticScorer::new(params, &network_graph, &logger); //! # let random_seed_bytes = [42u8; 32]; //! -//! let route = find_route(&payer, &route_params, &network_graph.read_only(), None, &logger, &scorer, &random_seed_bytes); +//! let route = find_route(&payer, &route_params, &network_graph, None, &logger, &scorer, &random_seed_bytes); //! # } //! ``` //!