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 router finds paths within a [`NetworkGraph`] for a payment.
11 use alloc::str::FromStr;
12 use alloc::string::String;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
21 use lightning::routing::router::DefaultRouter as nativeDefaultRouterImport;
22 pub(crate) type nativeDefaultRouter = nativeDefaultRouterImport<&'static lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, crate::lightning::util::logger::Logger, crate::lightning::sign::EntropySource, crate::lightning::routing::scoring::LockableScore>;
24 /// A [`Router`] implemented using [`find_route`].
27 pub struct DefaultRouter {
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 nativeDefaultRouter,
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 DefaultRouter {
42 if self.is_owned && !<*mut nativeDefaultRouter>::is_null(self.inner) {
43 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
47 /// Frees any resources used by the DefaultRouter, if is_owned is set and inner is non-NULL.
49 pub extern "C" fn DefaultRouter_free(this_obj: DefaultRouter) { }
51 /// Used only if an object of this type is returned as a trait impl by a method
52 pub(crate) extern "C" fn DefaultRouter_free_void(this_ptr: *mut c_void) {
53 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDefaultRouter) };
57 pub(crate) fn get_native_ref(&self) -> &'static nativeDefaultRouter {
58 unsafe { &*ObjOps::untweak_ptr(self.inner) }
60 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDefaultRouter {
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 nativeDefaultRouter {
65 assert!(self.is_owned);
66 let ret = ObjOps::untweak_ptr(self.inner);
67 self.inner = core::ptr::null_mut();
71 /// Creates a new router.
74 pub extern "C" fn DefaultRouter_new(network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut logger: crate::lightning::util::logger::Logger, mut entropy_source: crate::lightning::sign::EntropySource, mut scorer: crate::lightning::routing::scoring::LockableScore, mut score_params: crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> crate::lightning::routing::router::DefaultRouter {
75 let mut ret = lightning::routing::router::DefaultRouter::new(network_graph.get_native_ref(), logger, entropy_source, scorer, *unsafe { Box::from_raw(score_params.take_inner()) });
76 crate::lightning::routing::router::DefaultRouter { inner: ObjOps::heap_alloc(ret), is_owned: true }
79 impl From<nativeDefaultRouter> for crate::lightning::routing::router::Router {
80 fn from(obj: nativeDefaultRouter) -> Self {
81 let rust_obj = crate::lightning::routing::router::DefaultRouter { inner: ObjOps::heap_alloc(obj), is_owned: true };
82 let mut ret = DefaultRouter_as_Router(&rust_obj);
83 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
84 core::mem::forget(rust_obj);
85 ret.free = Some(DefaultRouter_free_void);
89 /// Constructs a new Router which calls the relevant methods on this_arg.
90 /// This copies the `inner` pointer in this_arg and thus the returned Router must be freed before this_arg is
92 pub extern "C" fn DefaultRouter_as_Router(this_arg: &DefaultRouter) -> crate::lightning::routing::router::Router {
93 crate::lightning::routing::router::Router {
94 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
96 find_route: DefaultRouter_Router_find_route,
97 find_route_with_id: DefaultRouter_Router_find_route_with_id,
98 create_blinded_payment_paths: DefaultRouter_Router_create_blinded_payment_paths,
99 MessageRouter: crate::lightning::onion_message::messenger::MessageRouter {
100 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
102 find_path: DefaultRouter_MessageRouter_find_path,
103 create_blinded_paths: DefaultRouter_MessageRouter_create_blinded_paths,
109 extern "C" fn DefaultRouter_Router_find_route(this_arg: *const c_void, mut payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
110 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[..]);
111 let mut ret = <nativeDefaultRouter as lightning::routing::router::Router<>>::find_route(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &payer.into_rust(), route_params.get_native_ref(), local_first_hops, *unsafe { Box::from_raw(inflight_htlcs.take_inner()) });
112 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() };
116 extern "C" fn DefaultRouter_Router_find_route_with_id(this_arg: *const c_void, mut payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, mut inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs, mut _payment_hash: crate::c_types::ThirtyTwoBytes, mut _payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
117 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[..]);
118 let mut ret = <nativeDefaultRouter as lightning::routing::router::Router<>>::find_route_with_id(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, &payer.into_rust(), route_params.get_native_ref(), local_first_hops, *unsafe { Box::from_raw(inflight_htlcs.take_inner()) }, ::lightning::ln::PaymentHash(_payment_hash.data), ::lightning::ln::channelmanager::PaymentId(_payment_id.data));
119 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() };
123 extern "C" fn DefaultRouter_Router_create_blinded_payment_paths(this_arg: *const c_void, mut recipient: crate::c_types::PublicKey, mut first_hops: crate::c_types::derived::CVec_ChannelDetailsZ, mut tlvs: crate::lightning::blinded_path::payment::ReceiveTlvs, mut amount_msats: u64) -> crate::c_types::derived::CResult_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ {
124 let mut local_first_hops = Vec::new(); for mut item in first_hops.into_rust().drain(..) { local_first_hops.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
125 let mut ret = <nativeDefaultRouter as lightning::routing::router::Router<>>::create_blinded_payment_paths(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, recipient.into_rust(), local_first_hops, *unsafe { Box::from_raw(tlvs.take_inner()) }, amount_msats, secp256k1::global::SECP256K1);
126 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for mut item in o.drain(..) { local_ret_0.push( { let (mut orig_ret_0_0_0, mut orig_ret_0_0_1) = item; let mut local_ret_0_0 = (crate::lightning::offers::invoice::BlindedPayInfo { inner: ObjOps::heap_alloc(orig_ret_0_0_0), is_owned: true }, crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(orig_ret_0_0_1), is_owned: true }).into(); local_ret_0_0 }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
130 impl From<nativeDefaultRouter> for crate::lightning::onion_message::messenger::MessageRouter {
131 fn from(obj: nativeDefaultRouter) -> Self {
132 let rust_obj = crate::lightning::routing::router::DefaultRouter { inner: ObjOps::heap_alloc(obj), is_owned: true };
133 let mut ret = DefaultRouter_as_MessageRouter(&rust_obj);
134 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
135 core::mem::forget(rust_obj);
136 ret.free = Some(DefaultRouter_free_void);
140 /// Constructs a new MessageRouter which calls the relevant methods on this_arg.
141 /// This copies the `inner` pointer in this_arg and thus the returned MessageRouter must be freed before this_arg is
143 pub extern "C" fn DefaultRouter_as_MessageRouter(this_arg: &DefaultRouter) -> crate::lightning::onion_message::messenger::MessageRouter {
144 crate::lightning::onion_message::messenger::MessageRouter {
145 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
147 find_path: DefaultRouter_MessageRouter_find_path,
148 create_blinded_paths: DefaultRouter_MessageRouter_create_blinded_paths,
153 extern "C" fn DefaultRouter_MessageRouter_find_path(this_arg: *const c_void, mut sender: crate::c_types::PublicKey, mut peers: crate::c_types::derived::CVec_PublicKeyZ, mut destination: crate::lightning::onion_message::messenger::Destination) -> crate::c_types::derived::CResult_OnionMessagePathNoneZ {
154 let mut local_peers = Vec::new(); for mut item in peers.into_rust().drain(..) { local_peers.push( { item.into_rust() }); };
155 let mut ret = <nativeDefaultRouter as lightning::onion_message::messenger::MessageRouter<>>::find_path(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, sender.into_rust(), local_peers, destination.into_native());
156 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::onion_message::messenger::OnionMessagePath { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
160 extern "C" fn DefaultRouter_MessageRouter_create_blinded_paths(this_arg: *const c_void, mut recipient: crate::c_types::PublicKey, mut peers: crate::c_types::derived::CVec_PublicKeyZ) -> crate::c_types::derived::CResult_CVec_BlindedPathZNoneZ {
161 let mut local_peers = Vec::new(); for mut item in peers.into_rust().drain(..) { local_peers.push( { item.into_rust() }); };
162 let mut ret = <nativeDefaultRouter as lightning::onion_message::messenger::MessageRouter<>>::create_blinded_paths(unsafe { &mut *(this_arg as *mut nativeDefaultRouter) }, recipient.into_rust(), local_peers, secp256k1::global::SECP256K1);
163 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_ret_0 = Vec::new(); for mut item in o.drain(..) { local_ret_0.push( { crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; local_ret_0.into() }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
167 /// A trait defining behavior for routing a payment.
170 /// An opaque pointer which is passed to your function implementations as an argument.
171 /// This has no meaning in the LDK, and can be NULL or any other value.
172 pub this_arg: *mut c_void,
173 /// Finds a [`Route`] for a payment between the given `payer` and a payee.
175 /// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
176 /// and [`RouteParameters::final_value_msat`], respectively.
178 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
179 pub find_route: extern "C" fn (this_arg: *const c_void, payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CResult_RouteLightningErrorZ,
180 /// Finds a [`Route`] for a payment between the given `payer` and a payee.
182 /// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]
183 /// and [`RouteParameters::final_value_msat`], respectively.
185 /// Includes a [`PaymentHash`] and a [`PaymentId`] to be able to correlate the request with a specific
188 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
189 pub find_route_with_id: extern "C" fn (this_arg: *const c_void, payer: crate::c_types::PublicKey, route_params: &crate::lightning::routing::router::RouteParameters, first_hops: *mut crate::c_types::derived::CVec_ChannelDetailsZ, inflight_htlcs: crate::lightning::routing::router::InFlightHtlcs, _payment_hash: crate::c_types::ThirtyTwoBytes, _payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_RouteLightningErrorZ,
190 /// Creates [`BlindedPath`]s for payment to the `recipient` node. The channels in `first_hops`
191 /// are assumed to be with the `recipient`'s peers. The payment secret and any constraints are
193 pub create_blinded_payment_paths: extern "C" fn (this_arg: *const c_void, recipient: crate::c_types::PublicKey, first_hops: crate::c_types::derived::CVec_ChannelDetailsZ, tlvs: crate::lightning::blinded_path::payment::ReceiveTlvs, amount_msats: u64) -> crate::c_types::derived::CResult_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ,
194 /// Implementation of MessageRouter for this object.
195 pub MessageRouter: crate::lightning::onion_message::messenger::MessageRouter,
196 /// Frees any resources associated with this object given its this_arg pointer.
197 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
198 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
200 unsafe impl Send for Router {}
201 unsafe impl Sync for Router {}
203 pub(crate) fn Router_clone_fields(orig: &Router) -> Router {
205 this_arg: orig.this_arg,
206 find_route: Clone::clone(&orig.find_route),
207 find_route_with_id: Clone::clone(&orig.find_route_with_id),
208 create_blinded_payment_paths: Clone::clone(&orig.create_blinded_payment_paths),
209 MessageRouter: crate::lightning::onion_message::messenger::MessageRouter_clone_fields(&orig.MessageRouter),
210 free: Clone::clone(&orig.free),
213 impl lightning::onion_message::messenger::MessageRouter for Router {
214 fn find_path(&self, mut sender: bitcoin::secp256k1::PublicKey, mut peers: Vec<bitcoin::secp256k1::PublicKey>, mut destination: lightning::onion_message::messenger::Destination) -> Result<lightning::onion_message::messenger::OnionMessagePath, ()> {
215 let mut local_peers = Vec::new(); for mut item in peers.drain(..) { local_peers.push( { crate::c_types::PublicKey::from_rust(&item) }); };
216 let mut ret = (self.MessageRouter.find_path)(self.MessageRouter.this_arg, crate::c_types::PublicKey::from_rust(&sender), local_peers.into(), crate::lightning::onion_message::messenger::Destination::native_into(destination));
217 let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
220 fn create_blinded_paths<T:bitcoin::secp256k1::Signing + bitcoin::secp256k1::Verification>(&self, mut recipient: bitcoin::secp256k1::PublicKey, mut peers: Vec<bitcoin::secp256k1::PublicKey>, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<Vec<lightning::blinded_path::BlindedPath>, ()> {
221 let mut local_peers = Vec::new(); for mut item in peers.drain(..) { local_peers.push( { crate::c_types::PublicKey::from_rust(&item) }); };
222 let mut ret = (self.MessageRouter.create_blinded_paths)(self.MessageRouter.this_arg, crate::c_types::PublicKey::from_rust(&recipient), local_peers.into());
223 let mut local_ret = match ret.result_ok { true => Ok( { let mut local_ret_0 = Vec::new(); for mut item in (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust().drain(..) { local_ret_0.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
228 use lightning::routing::router::Router as rustRouter;
229 impl rustRouter for Router {
230 fn find_route(&self, mut payer: &bitcoin::secp256k1::PublicKey, mut route_params: &lightning::routing::router::RouteParameters, mut first_hops: Option<&[&lightning::ln::channelmanager::ChannelDetails]>, mut inflight_htlcs: lightning::routing::router::InFlightHtlcs) -> Result<lightning::routing::router::Route, lightning::ln::msgs::LightningError> {
231 let mut local_first_hops_base = if first_hops.is_none() { SmartPtr::null() } else { SmartPtr::from_obj( { let mut local_first_hops_0 = Vec::new(); for item in (first_hops.unwrap()).iter() { local_first_hops_0.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); }; local_first_hops_0.into() }) }; let mut local_first_hops = *local_first_hops_base;
232 let mut ret = (self.find_route)(self.this_arg, crate::c_types::PublicKey::from_rust(&payer), &crate::lightning::routing::router::RouteParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((route_params as *const lightning::routing::router::RouteParameters<>) as *mut _) }, is_owned: false }, local_first_hops, crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(inflight_htlcs), is_owned: true });
233 let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
236 fn find_route_with_id(&self, mut payer: &bitcoin::secp256k1::PublicKey, mut route_params: &lightning::routing::router::RouteParameters, mut first_hops: Option<&[&lightning::ln::channelmanager::ChannelDetails]>, mut inflight_htlcs: lightning::routing::router::InFlightHtlcs, mut _payment_hash: lightning::ln::PaymentHash, mut _payment_id: lightning::ln::channelmanager::PaymentId) -> Result<lightning::routing::router::Route, lightning::ln::msgs::LightningError> {
237 let mut local_first_hops_base = if first_hops.is_none() { SmartPtr::null() } else { SmartPtr::from_obj( { let mut local_first_hops_0 = Vec::new(); for item in (first_hops.unwrap()).iter() { local_first_hops_0.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::ln::channelmanager::ChannelDetails<>) as *mut _) }, is_owned: false } }); }; local_first_hops_0.into() }) }; let mut local_first_hops = *local_first_hops_base;
238 let mut ret = (self.find_route_with_id)(self.this_arg, crate::c_types::PublicKey::from_rust(&payer), &crate::lightning::routing::router::RouteParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((route_params as *const lightning::routing::router::RouteParameters<>) as *mut _) }, is_owned: false }, local_first_hops, crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(inflight_htlcs), is_owned: true }, crate::c_types::ThirtyTwoBytes { data: _payment_hash.0 }, crate::c_types::ThirtyTwoBytes { data: _payment_id.0 });
239 let mut local_ret = match ret.result_ok { true => Ok( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).take_inner()) } }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })};
242 fn create_blinded_payment_paths<T:bitcoin::secp256k1::Signing + bitcoin::secp256k1::Verification>(&self, mut recipient: bitcoin::secp256k1::PublicKey, mut first_hops: Vec<lightning::ln::channelmanager::ChannelDetails>, mut tlvs: lightning::blinded_path::payment::ReceiveTlvs, mut amount_msats: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<T>) -> Result<Vec<(lightning::offers::invoice::BlindedPayInfo, lightning::blinded_path::BlindedPath)>, ()> {
243 let mut local_first_hops = Vec::new(); for mut item in first_hops.drain(..) { local_first_hops.push( { crate::lightning::ln::channelmanager::ChannelDetails { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
244 let mut ret = (self.create_blinded_payment_paths)(self.this_arg, crate::c_types::PublicKey::from_rust(&recipient), local_first_hops.into(), crate::lightning::blinded_path::payment::ReceiveTlvs { inner: ObjOps::heap_alloc(tlvs), is_owned: true }, amount_msats);
245 let mut local_ret = match ret.result_ok { true => Ok( { let mut local_ret_0 = Vec::new(); for mut item in (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust().drain(..) { local_ret_0.push( { let (mut orig_ret_0_0_0, mut orig_ret_0_0_1) = item.to_rust(); let mut local_ret_0_0 = (*unsafe { Box::from_raw(orig_ret_0_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_ret_0_0_1.take_inner()) }); local_ret_0_0 }); }; local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
250 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
251 // directly as a Deref trait in higher-level structs:
252 impl core::ops::Deref for Router {
254 fn deref(&self) -> &Self {
258 impl core::ops::DerefMut for Router {
259 fn deref_mut(&mut self) -> &mut Self {
263 /// Calls the free function if one is set
265 pub extern "C" fn Router_free(this_ptr: Router) { }
266 impl Drop for Router {
268 if let Some(f) = self.free {
274 use lightning::routing::router::ScorerAccountingForInFlightHtlcs as nativeScorerAccountingForInFlightHtlcsImport;
275 pub(crate) type nativeScorerAccountingForInFlightHtlcs = nativeScorerAccountingForInFlightHtlcsImport<'static, crate::lightning::routing::scoring::ScoreLookUp>;
277 /// [`ScoreLookUp`] implementation that factors in in-flight HTLC liquidity.
279 /// Useful for custom [`Router`] implementations to wrap their [`ScoreLookUp`] on-the-fly when calling
282 /// [`ScoreLookUp`]: crate::routing::scoring::ScoreLookUp
285 pub struct ScorerAccountingForInFlightHtlcs {
286 /// A pointer to the opaque Rust object.
288 /// Nearly everywhere, inner must be non-null, however in places where
289 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
290 pub inner: *mut nativeScorerAccountingForInFlightHtlcs,
291 /// Indicates that this is the only struct which contains the same pointer.
293 /// Rust functions which take ownership of an object provided via an argument require
294 /// this to be true and invalidate the object pointed to by inner.
298 impl Drop for ScorerAccountingForInFlightHtlcs {
300 if self.is_owned && !<*mut nativeScorerAccountingForInFlightHtlcs>::is_null(self.inner) {
301 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
305 /// Frees any resources used by the ScorerAccountingForInFlightHtlcs, if is_owned is set and inner is non-NULL.
307 pub extern "C" fn ScorerAccountingForInFlightHtlcs_free(this_obj: ScorerAccountingForInFlightHtlcs) { }
309 /// Used only if an object of this type is returned as a trait impl by a method
310 pub(crate) extern "C" fn ScorerAccountingForInFlightHtlcs_free_void(this_ptr: *mut c_void) {
311 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeScorerAccountingForInFlightHtlcs) };
314 impl ScorerAccountingForInFlightHtlcs {
315 pub(crate) fn get_native_ref(&self) -> &'static nativeScorerAccountingForInFlightHtlcs {
316 unsafe { &*ObjOps::untweak_ptr(self.inner) }
318 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeScorerAccountingForInFlightHtlcs {
319 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
321 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
322 pub(crate) fn take_inner(mut self) -> *mut nativeScorerAccountingForInFlightHtlcs {
323 assert!(self.is_owned);
324 let ret = ObjOps::untweak_ptr(self.inner);
325 self.inner = core::ptr::null_mut();
329 /// Initialize a new `ScorerAccountingForInFlightHtlcs`.
332 pub extern "C" fn ScorerAccountingForInFlightHtlcs_new(mut scorer: crate::lightning::routing::scoring::ScoreLookUp, inflight_htlcs: &crate::lightning::routing::router::InFlightHtlcs) -> crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs {
333 let mut ret = lightning::routing::router::ScorerAccountingForInFlightHtlcs::new(scorer, inflight_htlcs.get_native_ref());
334 crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
337 impl From<nativeScorerAccountingForInFlightHtlcs> for crate::lightning::routing::scoring::ScoreLookUp {
338 fn from(obj: nativeScorerAccountingForInFlightHtlcs) -> Self {
339 let rust_obj = crate::lightning::routing::router::ScorerAccountingForInFlightHtlcs { inner: ObjOps::heap_alloc(obj), is_owned: true };
340 let mut ret = ScorerAccountingForInFlightHtlcs_as_ScoreLookUp(&rust_obj);
341 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so forget it and set ret's free() fn
342 core::mem::forget(rust_obj);
343 ret.free = Some(ScorerAccountingForInFlightHtlcs_free_void);
347 /// Constructs a new ScoreLookUp which calls the relevant methods on this_arg.
348 /// This copies the `inner` pointer in this_arg and thus the returned ScoreLookUp must be freed before this_arg is
350 pub extern "C" fn ScorerAccountingForInFlightHtlcs_as_ScoreLookUp(this_arg: &ScorerAccountingForInFlightHtlcs) -> crate::lightning::routing::scoring::ScoreLookUp {
351 crate::lightning::routing::scoring::ScoreLookUp {
352 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
354 channel_penalty_msat: ScorerAccountingForInFlightHtlcs_ScoreLookUp_channel_penalty_msat,
359 extern "C" fn ScorerAccountingForInFlightHtlcs_ScoreLookUp_channel_penalty_msat(this_arg: *const c_void, candidate: &crate::lightning::routing::router::CandidateRouteHop, mut usage: crate::lightning::routing::scoring::ChannelUsage, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> u64 {
360 let mut ret = <nativeScorerAccountingForInFlightHtlcs as lightning::routing::scoring::ScoreLookUp<>>::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeScorerAccountingForInFlightHtlcs) }, &candidate.to_native(), *unsafe { Box::from_raw(usage.take_inner()) }, score_params.get_native_ref());
365 use lightning::routing::router::InFlightHtlcs as nativeInFlightHtlcsImport;
366 pub(crate) type nativeInFlightHtlcs = nativeInFlightHtlcsImport;
368 /// A data structure for tracking in-flight HTLCs. May be used during pathfinding to account for
369 /// in-use channel liquidity.
372 pub struct InFlightHtlcs {
373 /// A pointer to the opaque Rust object.
375 /// Nearly everywhere, inner must be non-null, however in places where
376 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
377 pub inner: *mut nativeInFlightHtlcs,
378 /// Indicates that this is the only struct which contains the same pointer.
380 /// Rust functions which take ownership of an object provided via an argument require
381 /// this to be true and invalidate the object pointed to by inner.
385 impl Drop for InFlightHtlcs {
387 if self.is_owned && !<*mut nativeInFlightHtlcs>::is_null(self.inner) {
388 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
392 /// Frees any resources used by the InFlightHtlcs, if is_owned is set and inner is non-NULL.
394 pub extern "C" fn InFlightHtlcs_free(this_obj: InFlightHtlcs) { }
396 /// Used only if an object of this type is returned as a trait impl by a method
397 pub(crate) extern "C" fn InFlightHtlcs_free_void(this_ptr: *mut c_void) {
398 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInFlightHtlcs) };
402 pub(crate) fn get_native_ref(&self) -> &'static nativeInFlightHtlcs {
403 unsafe { &*ObjOps::untweak_ptr(self.inner) }
405 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInFlightHtlcs {
406 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
408 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
409 pub(crate) fn take_inner(mut self) -> *mut nativeInFlightHtlcs {
410 assert!(self.is_owned);
411 let ret = ObjOps::untweak_ptr(self.inner);
412 self.inner = core::ptr::null_mut();
416 impl Clone for InFlightHtlcs {
417 fn clone(&self) -> Self {
419 inner: if <*mut nativeInFlightHtlcs>::is_null(self.inner) { core::ptr::null_mut() } else {
420 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
426 /// Used only if an object of this type is returned as a trait impl by a method
427 pub(crate) extern "C" fn InFlightHtlcs_clone_void(this_ptr: *const c_void) -> *mut c_void {
428 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInFlightHtlcs)).clone() })) as *mut c_void
431 /// Creates a copy of the InFlightHtlcs
432 pub extern "C" fn InFlightHtlcs_clone(orig: &InFlightHtlcs) -> InFlightHtlcs {
435 /// Constructs an empty `InFlightHtlcs`.
438 pub extern "C" fn InFlightHtlcs_new() -> crate::lightning::routing::router::InFlightHtlcs {
439 let mut ret = lightning::routing::router::InFlightHtlcs::new();
440 crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(ret), is_owned: true }
443 /// Takes in a path with payer's node id and adds the path's details to `InFlightHtlcs`.
445 pub extern "C" fn InFlightHtlcs_process_path(this_arg: &mut crate::lightning::routing::router::InFlightHtlcs, path: &crate::lightning::routing::router::Path, mut payer_node_id: crate::c_types::PublicKey) {
446 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::router::nativeInFlightHtlcs)) }.process_path(path.get_native_ref(), payer_node_id.into_rust())
449 /// Adds a known HTLC given the public key of the HTLC source, target, and short channel
452 pub extern "C" fn InFlightHtlcs_add_inflight_htlc(this_arg: &mut crate::lightning::routing::router::InFlightHtlcs, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut channel_scid: u64, mut used_msat: u64) {
453 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::router::nativeInFlightHtlcs)) }.add_inflight_htlc(source.get_native_ref(), target.get_native_ref(), channel_scid, used_msat)
456 /// Returns liquidity in msat given the public key of the HTLC source, target, and short channel
460 pub extern "C" fn InFlightHtlcs_used_liquidity_msat(this_arg: &crate::lightning::routing::router::InFlightHtlcs, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut channel_scid: u64) -> crate::c_types::derived::COption_u64Z {
461 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.used_liquidity_msat(source.get_native_ref(), target.get_native_ref(), channel_scid);
462 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap() }) };
467 /// Serialize the InFlightHtlcs object into a byte array which can be read by InFlightHtlcs_read
468 pub extern "C" fn InFlightHtlcs_write(obj: &crate::lightning::routing::router::InFlightHtlcs) -> crate::c_types::derived::CVec_u8Z {
469 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
472 pub(crate) extern "C" fn InFlightHtlcs_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
473 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInFlightHtlcs) })
476 /// Read a InFlightHtlcs from a byte array, created by InFlightHtlcs_write
477 pub extern "C" fn InFlightHtlcs_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InFlightHtlcsDecodeErrorZ {
478 let res: Result<lightning::routing::router::InFlightHtlcs, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
479 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::InFlightHtlcs { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
483 use lightning::routing::router::RouteHop as nativeRouteHopImport;
484 pub(crate) type nativeRouteHop = nativeRouteHopImport;
486 /// A hop in a route, and additional metadata about it. \"Hop\" is defined as a node and the channel
487 /// that leads to it.
490 pub struct RouteHop {
491 /// A pointer to the opaque Rust object.
493 /// Nearly everywhere, inner must be non-null, however in places where
494 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
495 pub inner: *mut nativeRouteHop,
496 /// Indicates that this is the only struct which contains the same pointer.
498 /// Rust functions which take ownership of an object provided via an argument require
499 /// this to be true and invalidate the object pointed to by inner.
503 impl Drop for RouteHop {
505 if self.is_owned && !<*mut nativeRouteHop>::is_null(self.inner) {
506 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
510 /// Frees any resources used by the RouteHop, if is_owned is set and inner is non-NULL.
512 pub extern "C" fn RouteHop_free(this_obj: RouteHop) { }
514 /// Used only if an object of this type is returned as a trait impl by a method
515 pub(crate) extern "C" fn RouteHop_free_void(this_ptr: *mut c_void) {
516 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHop) };
520 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHop {
521 unsafe { &*ObjOps::untweak_ptr(self.inner) }
523 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHop {
524 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
526 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
527 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHop {
528 assert!(self.is_owned);
529 let ret = ObjOps::untweak_ptr(self.inner);
530 self.inner = core::ptr::null_mut();
534 /// The node_id of the node at this hop.
536 pub extern "C" fn RouteHop_get_pubkey(this_ptr: &RouteHop) -> crate::c_types::PublicKey {
537 let mut inner_val = &mut this_ptr.get_native_mut_ref().pubkey;
538 crate::c_types::PublicKey::from_rust(&inner_val)
540 /// The node_id of the node at this hop.
542 pub extern "C" fn RouteHop_set_pubkey(this_ptr: &mut RouteHop, mut val: crate::c_types::PublicKey) {
543 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.pubkey = val.into_rust();
545 /// The node_announcement features of the node at this hop. For the last hop, these may be
546 /// amended to match the features present in the invoice this node generated.
548 pub extern "C" fn RouteHop_get_node_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::NodeFeatures {
549 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_features;
550 crate::lightning::ln::features::NodeFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::NodeFeatures<>) as *mut _) }, is_owned: false }
552 /// The node_announcement features of the node at this hop. For the last hop, these may be
553 /// amended to match the features present in the invoice this node generated.
555 pub extern "C" fn RouteHop_set_node_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::NodeFeatures) {
556 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_features = *unsafe { Box::from_raw(val.take_inner()) };
558 /// The channel that should be used from the previous hop to reach this node.
560 pub extern "C" fn RouteHop_get_short_channel_id(this_ptr: &RouteHop) -> u64 {
561 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
564 /// The channel that should be used from the previous hop to reach this node.
566 pub extern "C" fn RouteHop_set_short_channel_id(this_ptr: &mut RouteHop, mut val: u64) {
567 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
569 /// The channel_announcement features of the channel that should be used from the previous hop
570 /// to reach this node.
572 pub extern "C" fn RouteHop_get_channel_features(this_ptr: &RouteHop) -> crate::lightning::ln::features::ChannelFeatures {
573 let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_features;
574 crate::lightning::ln::features::ChannelFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::ChannelFeatures<>) as *mut _) }, is_owned: false }
576 /// The channel_announcement features of the channel that should be used from the previous hop
577 /// to reach this node.
579 pub extern "C" fn RouteHop_set_channel_features(this_ptr: &mut RouteHop, mut val: crate::lightning::ln::features::ChannelFeatures) {
580 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_features = *unsafe { Box::from_raw(val.take_inner()) };
582 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
583 /// If this is the last hop in [`Path::hops`]:
584 /// * if we're sending to a [`BlindedPath`], this is the fee paid for use of the entire blinded path
585 /// * otherwise, this is the full value of this [`Path`]'s part of the payment
587 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
589 pub extern "C" fn RouteHop_get_fee_msat(this_ptr: &RouteHop) -> u64 {
590 let mut inner_val = &mut this_ptr.get_native_mut_ref().fee_msat;
593 /// The fee taken on this hop (for paying for the use of the *next* channel in the path).
594 /// If this is the last hop in [`Path::hops`]:
595 /// * if we're sending to a [`BlindedPath`], this is the fee paid for use of the entire blinded path
596 /// * otherwise, this is the full value of this [`Path`]'s part of the payment
598 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
600 pub extern "C" fn RouteHop_set_fee_msat(this_ptr: &mut RouteHop, mut val: u64) {
601 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_msat = val;
603 /// The CLTV delta added for this hop.
604 /// If this is the last hop in [`Path::hops`]:
605 /// * if we're sending to a [`BlindedPath`], this is the CLTV delta for the entire blinded path
606 /// * otherwise, this is the CLTV delta expected at the destination
608 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
610 pub extern "C" fn RouteHop_get_cltv_expiry_delta(this_ptr: &RouteHop) -> u32 {
611 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
614 /// The CLTV delta added for this hop.
615 /// If this is the last hop in [`Path::hops`]:
616 /// * if we're sending to a [`BlindedPath`], this is the CLTV delta for the entire blinded path
617 /// * otherwise, this is the CLTV delta expected at the destination
619 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
621 pub extern "C" fn RouteHop_set_cltv_expiry_delta(this_ptr: &mut RouteHop, mut val: u32) {
622 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
624 /// Indicates whether this hop is possibly announced in the public network graph.
626 /// Will be `true` if there is a possibility that the channel is publicly known, i.e., if we
627 /// either know for sure it's announced in the public graph, or if any public channels exist
628 /// for which the given `short_channel_id` could be an alias for. Will be `false` if we believe
629 /// the channel to be unannounced.
631 /// Will be `true` for objects serialized with LDK version 0.0.116 and before.
633 pub extern "C" fn RouteHop_get_maybe_announced_channel(this_ptr: &RouteHop) -> bool {
634 let mut inner_val = &mut this_ptr.get_native_mut_ref().maybe_announced_channel;
637 /// Indicates whether this hop is possibly announced in the public network graph.
639 /// Will be `true` if there is a possibility that the channel is publicly known, i.e., if we
640 /// either know for sure it's announced in the public graph, or if any public channels exist
641 /// for which the given `short_channel_id` could be an alias for. Will be `false` if we believe
642 /// the channel to be unannounced.
644 /// Will be `true` for objects serialized with LDK version 0.0.116 and before.
646 pub extern "C" fn RouteHop_set_maybe_announced_channel(this_ptr: &mut RouteHop, mut val: bool) {
647 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.maybe_announced_channel = val;
649 /// Constructs a new RouteHop given each field
652 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, mut maybe_announced_channel_arg: bool) -> RouteHop {
653 RouteHop { inner: ObjOps::heap_alloc(nativeRouteHop {
654 pubkey: pubkey_arg.into_rust(),
655 node_features: *unsafe { Box::from_raw(node_features_arg.take_inner()) },
656 short_channel_id: short_channel_id_arg,
657 channel_features: *unsafe { Box::from_raw(channel_features_arg.take_inner()) },
658 fee_msat: fee_msat_arg,
659 cltv_expiry_delta: cltv_expiry_delta_arg,
660 maybe_announced_channel: maybe_announced_channel_arg,
663 impl Clone for RouteHop {
664 fn clone(&self) -> Self {
666 inner: if <*mut nativeRouteHop>::is_null(self.inner) { core::ptr::null_mut() } else {
667 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
673 /// Used only if an object of this type is returned as a trait impl by a method
674 pub(crate) extern "C" fn RouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
675 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRouteHop)).clone() })) as *mut c_void
678 /// Creates a copy of the RouteHop
679 pub extern "C" fn RouteHop_clone(orig: &RouteHop) -> RouteHop {
682 /// Get a string which allows debug introspection of a RouteHop object
683 pub extern "C" fn RouteHop_debug_str_void(o: *const c_void) -> Str {
684 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::RouteHop }).into()}
685 /// Generates a non-cryptographic 64-bit hash of the RouteHop.
687 pub extern "C" fn RouteHop_hash(o: &RouteHop) -> u64 {
688 if o.inner.is_null() { return 0; }
689 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
691 let mut hasher = core::hash::SipHasher::new();
692 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
693 core::hash::Hasher::finish(&hasher)
695 /// Checks if two RouteHops contain equal inner contents.
696 /// This ignores pointers and is_owned flags and looks at the values in fields.
697 /// Two objects with NULL inner values will be considered "equal" here.
699 pub extern "C" fn RouteHop_eq(a: &RouteHop, b: &RouteHop) -> bool {
700 if a.inner == b.inner { return true; }
701 if a.inner.is_null() || b.inner.is_null() { return false; }
702 if a.get_native_ref() == b.get_native_ref() { true } else { false }
705 /// Serialize the RouteHop object into a byte array which can be read by RouteHop_read
706 pub extern "C" fn RouteHop_write(obj: &crate::lightning::routing::router::RouteHop) -> crate::c_types::derived::CVec_u8Z {
707 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
710 pub(crate) extern "C" fn RouteHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
711 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHop) })
714 /// Read a RouteHop from a byte array, created by RouteHop_write
715 pub extern "C" fn RouteHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHopDecodeErrorZ {
716 let res: Result<lightning::routing::router::RouteHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
717 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::native_into(e) }).into() };
721 use lightning::routing::router::BlindedTail as nativeBlindedTailImport;
722 pub(crate) type nativeBlindedTail = nativeBlindedTailImport;
724 /// The blinded portion of a [`Path`], if we're routing to a recipient who provided blinded paths in
725 /// their [`Bolt12Invoice`].
727 /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
730 pub struct BlindedTail {
731 /// A pointer to the opaque Rust object.
733 /// Nearly everywhere, inner must be non-null, however in places where
734 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
735 pub inner: *mut nativeBlindedTail,
736 /// Indicates that this is the only struct which contains the same pointer.
738 /// Rust functions which take ownership of an object provided via an argument require
739 /// this to be true and invalidate the object pointed to by inner.
743 impl Drop for BlindedTail {
745 if self.is_owned && !<*mut nativeBlindedTail>::is_null(self.inner) {
746 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
750 /// Frees any resources used by the BlindedTail, if is_owned is set and inner is non-NULL.
752 pub extern "C" fn BlindedTail_free(this_obj: BlindedTail) { }
754 /// Used only if an object of this type is returned as a trait impl by a method
755 pub(crate) extern "C" fn BlindedTail_free_void(this_ptr: *mut c_void) {
756 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedTail) };
760 pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedTail {
761 unsafe { &*ObjOps::untweak_ptr(self.inner) }
763 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedTail {
764 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
766 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
767 pub(crate) fn take_inner(mut self) -> *mut nativeBlindedTail {
768 assert!(self.is_owned);
769 let ret = ObjOps::untweak_ptr(self.inner);
770 self.inner = core::ptr::null_mut();
774 /// The hops of the [`BlindedPath`] provided by the recipient.
776 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
778 pub extern "C" fn BlindedTail_get_hops(this_ptr: &BlindedTail) -> crate::c_types::derived::CVec_BlindedHopZ {
779 let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
780 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::blinded_path::BlindedHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::blinded_path::BlindedHop<>) as *mut _) }, is_owned: false } }); };
781 local_inner_val.into()
783 /// The hops of the [`BlindedPath`] provided by the recipient.
785 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
787 pub extern "C" fn BlindedTail_set_hops(this_ptr: &mut BlindedTail, mut val: crate::c_types::derived::CVec_BlindedHopZ) {
788 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
789 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
791 /// The blinding point of the [`BlindedPath`] provided by the recipient.
793 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
795 pub extern "C" fn BlindedTail_get_blinding_point(this_ptr: &BlindedTail) -> crate::c_types::PublicKey {
796 let mut inner_val = &mut this_ptr.get_native_mut_ref().blinding_point;
797 crate::c_types::PublicKey::from_rust(&inner_val)
799 /// The blinding point of the [`BlindedPath`] provided by the recipient.
801 /// [`BlindedPath`]: crate::blinded_path::BlindedPath
803 pub extern "C" fn BlindedTail_set_blinding_point(this_ptr: &mut BlindedTail, mut val: crate::c_types::PublicKey) {
804 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinding_point = val.into_rust();
806 /// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
807 /// inferring the destination. May be 0.
809 pub extern "C" fn BlindedTail_get_excess_final_cltv_expiry_delta(this_ptr: &BlindedTail) -> u32 {
810 let mut inner_val = &mut this_ptr.get_native_mut_ref().excess_final_cltv_expiry_delta;
813 /// Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
814 /// inferring the destination. May be 0.
816 pub extern "C" fn BlindedTail_set_excess_final_cltv_expiry_delta(this_ptr: &mut BlindedTail, mut val: u32) {
817 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.excess_final_cltv_expiry_delta = val;
819 /// The total amount paid on this [`Path`], excluding the fees.
821 pub extern "C" fn BlindedTail_get_final_value_msat(this_ptr: &BlindedTail) -> u64 {
822 let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
825 /// The total amount paid on this [`Path`], excluding the fees.
827 pub extern "C" fn BlindedTail_set_final_value_msat(this_ptr: &mut BlindedTail, mut val: u64) {
828 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
830 /// Constructs a new BlindedTail given each field
833 pub extern "C" fn BlindedTail_new(mut hops_arg: crate::c_types::derived::CVec_BlindedHopZ, mut blinding_point_arg: crate::c_types::PublicKey, mut excess_final_cltv_expiry_delta_arg: u32, mut final_value_msat_arg: u64) -> BlindedTail {
834 let mut local_hops_arg = Vec::new(); for mut item in hops_arg.into_rust().drain(..) { local_hops_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
835 BlindedTail { inner: ObjOps::heap_alloc(nativeBlindedTail {
836 hops: local_hops_arg,
837 blinding_point: blinding_point_arg.into_rust(),
838 excess_final_cltv_expiry_delta: excess_final_cltv_expiry_delta_arg,
839 final_value_msat: final_value_msat_arg,
842 impl Clone for BlindedTail {
843 fn clone(&self) -> Self {
845 inner: if <*mut nativeBlindedTail>::is_null(self.inner) { core::ptr::null_mut() } else {
846 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
852 /// Used only if an object of this type is returned as a trait impl by a method
853 pub(crate) extern "C" fn BlindedTail_clone_void(this_ptr: *const c_void) -> *mut c_void {
854 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedTail)).clone() })) as *mut c_void
857 /// Creates a copy of the BlindedTail
858 pub extern "C" fn BlindedTail_clone(orig: &BlindedTail) -> BlindedTail {
861 /// Get a string which allows debug introspection of a BlindedTail object
862 pub extern "C" fn BlindedTail_debug_str_void(o: *const c_void) -> Str {
863 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::BlindedTail }).into()}
864 /// Generates a non-cryptographic 64-bit hash of the BlindedTail.
866 pub extern "C" fn BlindedTail_hash(o: &BlindedTail) -> u64 {
867 if o.inner.is_null() { return 0; }
868 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
870 let mut hasher = core::hash::SipHasher::new();
871 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
872 core::hash::Hasher::finish(&hasher)
874 /// Checks if two BlindedTails contain equal inner contents.
875 /// This ignores pointers and is_owned flags and looks at the values in fields.
876 /// Two objects with NULL inner values will be considered "equal" here.
878 pub extern "C" fn BlindedTail_eq(a: &BlindedTail, b: &BlindedTail) -> bool {
879 if a.inner == b.inner { return true; }
880 if a.inner.is_null() || b.inner.is_null() { return false; }
881 if a.get_native_ref() == b.get_native_ref() { true } else { false }
884 /// Serialize the BlindedTail object into a byte array which can be read by BlindedTail_read
885 pub extern "C" fn BlindedTail_write(obj: &crate::lightning::routing::router::BlindedTail) -> crate::c_types::derived::CVec_u8Z {
886 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
889 pub(crate) extern "C" fn BlindedTail_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
890 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeBlindedTail) })
893 /// Read a BlindedTail from a byte array, created by BlindedTail_write
894 pub extern "C" fn BlindedTail_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_BlindedTailDecodeErrorZ {
895 let res: Result<lightning::routing::router::BlindedTail, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
896 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::BlindedTail { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
900 use lightning::routing::router::Path as nativePathImport;
901 pub(crate) type nativePath = nativePathImport;
903 /// A path in a [`Route`] to the payment recipient. Must always be at least length one.
904 /// If no [`Path::blinded_tail`] is present, then [`Path::hops`] length may be up to 19.
908 /// A pointer to the opaque Rust object.
910 /// Nearly everywhere, inner must be non-null, however in places where
911 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
912 pub inner: *mut nativePath,
913 /// Indicates that this is the only struct which contains the same pointer.
915 /// Rust functions which take ownership of an object provided via an argument require
916 /// this to be true and invalidate the object pointed to by inner.
922 if self.is_owned && !<*mut nativePath>::is_null(self.inner) {
923 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
927 /// Frees any resources used by the Path, if is_owned is set and inner is non-NULL.
929 pub extern "C" fn Path_free(this_obj: Path) { }
931 /// Used only if an object of this type is returned as a trait impl by a method
932 pub(crate) extern "C" fn Path_free_void(this_ptr: *mut c_void) {
933 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePath) };
937 pub(crate) fn get_native_ref(&self) -> &'static nativePath {
938 unsafe { &*ObjOps::untweak_ptr(self.inner) }
940 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePath {
941 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
943 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
944 pub(crate) fn take_inner(mut self) -> *mut nativePath {
945 assert!(self.is_owned);
946 let ret = ObjOps::untweak_ptr(self.inner);
947 self.inner = core::ptr::null_mut();
951 /// The list of unblinded hops in this [`Path`]. Must be at least length one.
953 pub extern "C" fn Path_get_hops(this_ptr: &Path) -> crate::c_types::derived::CVec_RouteHopZ {
954 let mut inner_val = &mut this_ptr.get_native_mut_ref().hops;
955 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); };
956 local_inner_val.into()
958 /// The list of unblinded hops in this [`Path`]. Must be at least length one.
960 pub extern "C" fn Path_set_hops(this_ptr: &mut Path, mut val: crate::c_types::derived::CVec_RouteHopZ) {
961 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
962 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hops = local_val;
964 /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
966 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
968 pub extern "C" fn Path_get_blinded_tail(this_ptr: &Path) -> crate::lightning::routing::router::BlindedTail {
969 let mut inner_val = &mut this_ptr.get_native_mut_ref().blinded_tail;
970 let mut local_inner_val = crate::lightning::routing::router::BlindedTail { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::router::BlindedTail<>) as *mut _ }, is_owned: false };
973 /// The blinded path at which this path terminates, if we're sending to one, and its metadata.
975 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
977 pub extern "C" fn Path_set_blinded_tail(this_ptr: &mut Path, mut val: crate::lightning::routing::router::BlindedTail) {
978 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
979 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinded_tail = local_val;
981 /// Constructs a new Path given each field
983 /// Note that blinded_tail_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
986 pub extern "C" fn Path_new(mut hops_arg: crate::c_types::derived::CVec_RouteHopZ, mut blinded_tail_arg: crate::lightning::routing::router::BlindedTail) -> Path {
987 let mut local_hops_arg = Vec::new(); for mut item in hops_arg.into_rust().drain(..) { local_hops_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
988 let mut local_blinded_tail_arg = if blinded_tail_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(blinded_tail_arg.take_inner()) } }) };
989 Path { inner: ObjOps::heap_alloc(nativePath {
990 hops: local_hops_arg,
991 blinded_tail: local_blinded_tail_arg,
994 impl Clone for Path {
995 fn clone(&self) -> Self {
997 inner: if <*mut nativePath>::is_null(self.inner) { core::ptr::null_mut() } else {
998 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1004 /// Used only if an object of this type is returned as a trait impl by a method
1005 pub(crate) extern "C" fn Path_clone_void(this_ptr: *const c_void) -> *mut c_void {
1006 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePath)).clone() })) as *mut c_void
1009 /// Creates a copy of the Path
1010 pub extern "C" fn Path_clone(orig: &Path) -> Path {
1013 /// Get a string which allows debug introspection of a Path object
1014 pub extern "C" fn Path_debug_str_void(o: *const c_void) -> Str {
1015 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::Path }).into()}
1016 /// Generates a non-cryptographic 64-bit hash of the Path.
1018 pub extern "C" fn Path_hash(o: &Path) -> u64 {
1019 if o.inner.is_null() { return 0; }
1020 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1021 #[allow(deprecated)]
1022 let mut hasher = core::hash::SipHasher::new();
1023 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1024 core::hash::Hasher::finish(&hasher)
1026 /// Checks if two Paths contain equal inner contents.
1027 /// This ignores pointers and is_owned flags and looks at the values in fields.
1028 /// Two objects with NULL inner values will be considered "equal" here.
1030 pub extern "C" fn Path_eq(a: &Path, b: &Path) -> bool {
1031 if a.inner == b.inner { return true; }
1032 if a.inner.is_null() || b.inner.is_null() { return false; }
1033 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1035 /// Gets the fees for a given path, excluding any excess paid to the recipient.
1038 pub extern "C" fn Path_fee_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
1039 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fee_msat();
1043 /// Gets the total amount paid on this [`Path`], excluding the fees.
1046 pub extern "C" fn Path_final_value_msat(this_arg: &crate::lightning::routing::router::Path) -> u64 {
1047 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_value_msat();
1051 /// Gets the final hop's CLTV expiry delta.
1054 pub extern "C" fn Path_final_cltv_expiry_delta(this_arg: &crate::lightning::routing::router::Path) -> crate::c_types::derived::COption_u32Z {
1055 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.final_cltv_expiry_delta();
1056 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { ret.unwrap() }) };
1061 use lightning::routing::router::Route as nativeRouteImport;
1062 pub(crate) type nativeRoute = nativeRouteImport;
1064 /// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
1065 /// it can take multiple paths. Each path is composed of one or more hops through the network.
1069 /// A pointer to the opaque Rust object.
1071 /// Nearly everywhere, inner must be non-null, however in places where
1072 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1073 pub inner: *mut nativeRoute,
1074 /// Indicates that this is the only struct which contains the same pointer.
1076 /// Rust functions which take ownership of an object provided via an argument require
1077 /// this to be true and invalidate the object pointed to by inner.
1081 impl Drop for Route {
1082 fn drop(&mut self) {
1083 if self.is_owned && !<*mut nativeRoute>::is_null(self.inner) {
1084 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1088 /// Frees any resources used by the Route, if is_owned is set and inner is non-NULL.
1090 pub extern "C" fn Route_free(this_obj: Route) { }
1092 /// Used only if an object of this type is returned as a trait impl by a method
1093 pub(crate) extern "C" fn Route_free_void(this_ptr: *mut c_void) {
1094 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoute) };
1098 pub(crate) fn get_native_ref(&self) -> &'static nativeRoute {
1099 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1101 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoute {
1102 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1104 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1105 pub(crate) fn take_inner(mut self) -> *mut nativeRoute {
1106 assert!(self.is_owned);
1107 let ret = ObjOps::untweak_ptr(self.inner);
1108 self.inner = core::ptr::null_mut();
1112 /// The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
1113 /// [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
1116 pub extern "C" fn Route_get_paths(this_ptr: &Route) -> crate::c_types::derived::CVec_PathZ {
1117 let mut inner_val = &mut this_ptr.get_native_mut_ref().paths;
1118 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::Path { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::Path<>) as *mut _) }, is_owned: false } }); };
1119 local_inner_val.into()
1121 /// The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
1122 /// [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
1125 pub extern "C" fn Route_set_paths(this_ptr: &mut Route, mut val: crate::c_types::derived::CVec_PathZ) {
1126 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1127 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.paths = local_val;
1129 /// The `route_params` parameter passed to [`find_route`].
1131 /// This is used by `ChannelManager` to track information which may be required for retries.
1133 /// Will be `None` for objects serialized with LDK versions prior to 0.0.117.
1135 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1137 pub extern "C" fn Route_get_route_params(this_ptr: &Route) -> crate::lightning::routing::router::RouteParameters {
1138 let mut inner_val = &mut this_ptr.get_native_mut_ref().route_params;
1139 let mut local_inner_val = crate::lightning::routing::router::RouteParameters { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::router::RouteParameters<>) as *mut _ }, is_owned: false };
1142 /// The `route_params` parameter passed to [`find_route`].
1144 /// This is used by `ChannelManager` to track information which may be required for retries.
1146 /// Will be `None` for objects serialized with LDK versions prior to 0.0.117.
1148 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1150 pub extern "C" fn Route_set_route_params(this_ptr: &mut Route, mut val: crate::lightning::routing::router::RouteParameters) {
1151 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1152 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.route_params = local_val;
1154 /// Constructs a new Route given each field
1156 /// Note that route_params_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
1159 pub extern "C" fn Route_new(mut paths_arg: crate::c_types::derived::CVec_PathZ, mut route_params_arg: crate::lightning::routing::router::RouteParameters) -> Route {
1160 let mut local_paths_arg = Vec::new(); for mut item in paths_arg.into_rust().drain(..) { local_paths_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1161 let mut local_route_params_arg = if route_params_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(route_params_arg.take_inner()) } }) };
1162 Route { inner: ObjOps::heap_alloc(nativeRoute {
1163 paths: local_paths_arg,
1164 route_params: local_route_params_arg,
1165 }), is_owned: true }
1167 impl Clone for Route {
1168 fn clone(&self) -> Self {
1170 inner: if <*mut nativeRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
1171 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1177 /// Used only if an object of this type is returned as a trait impl by a method
1178 pub(crate) extern "C" fn Route_clone_void(this_ptr: *const c_void) -> *mut c_void {
1179 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRoute)).clone() })) as *mut c_void
1182 /// Creates a copy of the Route
1183 pub extern "C" fn Route_clone(orig: &Route) -> Route {
1186 /// Get a string which allows debug introspection of a Route object
1187 pub extern "C" fn Route_debug_str_void(o: *const c_void) -> Str {
1188 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::Route }).into()}
1189 /// Generates a non-cryptographic 64-bit hash of the Route.
1191 pub extern "C" fn Route_hash(o: &Route) -> u64 {
1192 if o.inner.is_null() { return 0; }
1193 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1194 #[allow(deprecated)]
1195 let mut hasher = core::hash::SipHasher::new();
1196 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1197 core::hash::Hasher::finish(&hasher)
1199 /// Checks if two Routes contain equal inner contents.
1200 /// This ignores pointers and is_owned flags and looks at the values in fields.
1201 /// Two objects with NULL inner values will be considered "equal" here.
1203 pub extern "C" fn Route_eq(a: &Route, b: &Route) -> bool {
1204 if a.inner == b.inner { return true; }
1205 if a.inner.is_null() || b.inner.is_null() { return false; }
1206 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1208 /// Returns the total amount of fees paid on this [`Route`].
1210 /// For objects serialized with LDK 0.0.117 and after, this includes any extra payment made to
1211 /// the recipient, which can happen in excess of the amount passed to [`find_route`] via
1212 /// [`RouteParameters::final_value_msat`], if we had to reach the [`htlc_minimum_msat`] limits.
1214 /// [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
1217 pub extern "C" fn Route_get_total_fees(this_arg: &crate::lightning::routing::router::Route) -> u64 {
1218 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_fees();
1222 /// Returns the total amount paid on this [`Route`], excluding the fees.
1224 /// Might be more than requested as part of the given [`RouteParameters::final_value_msat`] if
1225 /// we had to reach the [`htlc_minimum_msat`] limits.
1227 /// [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
1230 pub extern "C" fn Route_get_total_amount(this_arg: &crate::lightning::routing::router::Route) -> u64 {
1231 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_total_amount();
1236 /// Serialize the Route object into a byte array which can be read by Route_read
1237 pub extern "C" fn Route_write(obj: &crate::lightning::routing::router::Route) -> crate::c_types::derived::CVec_u8Z {
1238 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1241 pub(crate) extern "C" fn Route_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1242 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoute) })
1245 /// Read a Route from a byte array, created by Route_write
1246 pub extern "C" fn Route_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteDecodeErrorZ {
1247 let res: Result<lightning::routing::router::Route, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1248 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::native_into(e) }).into() };
1252 use lightning::routing::router::RouteParameters as nativeRouteParametersImport;
1253 pub(crate) type nativeRouteParameters = nativeRouteParametersImport;
1255 /// Parameters needed to find a [`Route`].
1257 /// Passed to [`find_route`] and [`build_route_from_hops`].
1260 pub struct RouteParameters {
1261 /// A pointer to the opaque Rust object.
1263 /// Nearly everywhere, inner must be non-null, however in places where
1264 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1265 pub inner: *mut nativeRouteParameters,
1266 /// Indicates that this is the only struct which contains the same pointer.
1268 /// Rust functions which take ownership of an object provided via an argument require
1269 /// this to be true and invalidate the object pointed to by inner.
1273 impl Drop for RouteParameters {
1274 fn drop(&mut self) {
1275 if self.is_owned && !<*mut nativeRouteParameters>::is_null(self.inner) {
1276 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1280 /// Frees any resources used by the RouteParameters, if is_owned is set and inner is non-NULL.
1282 pub extern "C" fn RouteParameters_free(this_obj: RouteParameters) { }
1284 /// Used only if an object of this type is returned as a trait impl by a method
1285 pub(crate) extern "C" fn RouteParameters_free_void(this_ptr: *mut c_void) {
1286 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteParameters) };
1289 impl RouteParameters {
1290 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteParameters {
1291 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1293 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteParameters {
1294 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1296 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1297 pub(crate) fn take_inner(mut self) -> *mut nativeRouteParameters {
1298 assert!(self.is_owned);
1299 let ret = ObjOps::untweak_ptr(self.inner);
1300 self.inner = core::ptr::null_mut();
1304 /// The parameters of the failed payment path.
1306 pub extern "C" fn RouteParameters_get_payment_params(this_ptr: &RouteParameters) -> crate::lightning::routing::router::PaymentParameters {
1307 let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_params;
1308 crate::lightning::routing::router::PaymentParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::router::PaymentParameters<>) as *mut _) }, is_owned: false }
1310 /// The parameters of the failed payment path.
1312 pub extern "C" fn RouteParameters_set_payment_params(this_ptr: &mut RouteParameters, mut val: crate::lightning::routing::router::PaymentParameters) {
1313 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_params = *unsafe { Box::from_raw(val.take_inner()) };
1315 /// The amount in msats sent on the failed payment path.
1317 pub extern "C" fn RouteParameters_get_final_value_msat(this_ptr: &RouteParameters) -> u64 {
1318 let mut inner_val = &mut this_ptr.get_native_mut_ref().final_value_msat;
1321 /// The amount in msats sent on the failed payment path.
1323 pub extern "C" fn RouteParameters_set_final_value_msat(this_ptr: &mut RouteParameters, mut val: u64) {
1324 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.final_value_msat = val;
1326 /// The maximum total fees, in millisatoshi, that may accrue during route finding.
1328 /// This limit also applies to the total fees that may arise while retrying failed payment
1331 /// Note that values below a few sats may result in some paths being spuriously ignored.
1333 pub extern "C" fn RouteParameters_get_max_total_routing_fee_msat(this_ptr: &RouteParameters) -> crate::c_types::derived::COption_u64Z {
1334 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_routing_fee_msat;
1335 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() }) };
1338 /// The maximum total fees, in millisatoshi, that may accrue during route finding.
1340 /// This limit also applies to the total fees that may arise while retrying failed payment
1343 /// Note that values below a few sats may result in some paths being spuriously ignored.
1345 pub extern "C" fn RouteParameters_set_max_total_routing_fee_msat(this_ptr: &mut RouteParameters, mut val: crate::c_types::derived::COption_u64Z) {
1346 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1347 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_routing_fee_msat = local_val;
1349 /// Constructs a new RouteParameters given each field
1352 pub extern "C" fn RouteParameters_new(mut payment_params_arg: crate::lightning::routing::router::PaymentParameters, mut final_value_msat_arg: u64, mut max_total_routing_fee_msat_arg: crate::c_types::derived::COption_u64Z) -> RouteParameters {
1353 let mut local_max_total_routing_fee_msat_arg = if max_total_routing_fee_msat_arg.is_some() { Some( { max_total_routing_fee_msat_arg.take() }) } else { None };
1354 RouteParameters { inner: ObjOps::heap_alloc(nativeRouteParameters {
1355 payment_params: *unsafe { Box::from_raw(payment_params_arg.take_inner()) },
1356 final_value_msat: final_value_msat_arg,
1357 max_total_routing_fee_msat: local_max_total_routing_fee_msat_arg,
1358 }), is_owned: true }
1360 impl Clone for RouteParameters {
1361 fn clone(&self) -> Self {
1363 inner: if <*mut nativeRouteParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1364 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1370 /// Used only if an object of this type is returned as a trait impl by a method
1371 pub(crate) extern "C" fn RouteParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1372 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRouteParameters)).clone() })) as *mut c_void
1375 /// Creates a copy of the RouteParameters
1376 pub extern "C" fn RouteParameters_clone(orig: &RouteParameters) -> RouteParameters {
1379 /// Get a string which allows debug introspection of a RouteParameters object
1380 pub extern "C" fn RouteParameters_debug_str_void(o: *const c_void) -> Str {
1381 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::RouteParameters }).into()}
1382 /// Generates a non-cryptographic 64-bit hash of the RouteParameters.
1384 pub extern "C" fn RouteParameters_hash(o: &RouteParameters) -> u64 {
1385 if o.inner.is_null() { return 0; }
1386 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1387 #[allow(deprecated)]
1388 let mut hasher = core::hash::SipHasher::new();
1389 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1390 core::hash::Hasher::finish(&hasher)
1392 /// Checks if two RouteParameterss contain equal inner contents.
1393 /// This ignores pointers and is_owned flags and looks at the values in fields.
1394 /// Two objects with NULL inner values will be considered "equal" here.
1396 pub extern "C" fn RouteParameters_eq(a: &RouteParameters, b: &RouteParameters) -> bool {
1397 if a.inner == b.inner { return true; }
1398 if a.inner.is_null() || b.inner.is_null() { return false; }
1399 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1401 /// Constructs [`RouteParameters`] from the given [`PaymentParameters`] and a payment amount.
1403 /// [`Self::max_total_routing_fee_msat`] defaults to 1% of the payment amount + 50 sats
1406 pub extern "C" fn RouteParameters_from_payment_params_and_value(mut payment_params: crate::lightning::routing::router::PaymentParameters, mut final_value_msat: u64) -> crate::lightning::routing::router::RouteParameters {
1407 let mut ret = lightning::routing::router::RouteParameters::from_payment_params_and_value(*unsafe { Box::from_raw(payment_params.take_inner()) }, final_value_msat);
1408 crate::lightning::routing::router::RouteParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1412 /// Serialize the RouteParameters object into a byte array which can be read by RouteParameters_read
1413 pub extern "C" fn RouteParameters_write(obj: &crate::lightning::routing::router::RouteParameters) -> crate::c_types::derived::CVec_u8Z {
1414 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1417 pub(crate) extern "C" fn RouteParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1418 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteParameters) })
1421 /// Read a RouteParameters from a byte array, created by RouteParameters_write
1422 pub extern "C" fn RouteParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteParametersDecodeErrorZ {
1423 let res: Result<lightning::routing::router::RouteParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1424 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::RouteParameters { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1427 /// Maximum total CTLV difference we allow for a full payment path.
1430 pub static DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = lightning::routing::router::DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA;
1431 /// Maximum number of paths we allow an (MPP) payment to have.
1434 pub static DEFAULT_MAX_PATH_COUNT: u8 = lightning::routing::router::DEFAULT_MAX_PATH_COUNT;
1436 use lightning::routing::router::PaymentParameters as nativePaymentParametersImport;
1437 pub(crate) type nativePaymentParameters = nativePaymentParametersImport;
1439 /// Information used to route a payment.
1442 pub struct PaymentParameters {
1443 /// A pointer to the opaque Rust object.
1445 /// Nearly everywhere, inner must be non-null, however in places where
1446 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1447 pub inner: *mut nativePaymentParameters,
1448 /// Indicates that this is the only struct which contains the same pointer.
1450 /// Rust functions which take ownership of an object provided via an argument require
1451 /// this to be true and invalidate the object pointed to by inner.
1455 impl Drop for PaymentParameters {
1456 fn drop(&mut self) {
1457 if self.is_owned && !<*mut nativePaymentParameters>::is_null(self.inner) {
1458 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1462 /// Frees any resources used by the PaymentParameters, if is_owned is set and inner is non-NULL.
1464 pub extern "C" fn PaymentParameters_free(this_obj: PaymentParameters) { }
1466 /// Used only if an object of this type is returned as a trait impl by a method
1467 pub(crate) extern "C" fn PaymentParameters_free_void(this_ptr: *mut c_void) {
1468 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePaymentParameters) };
1471 impl PaymentParameters {
1472 pub(crate) fn get_native_ref(&self) -> &'static nativePaymentParameters {
1473 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1475 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePaymentParameters {
1476 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1478 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1479 pub(crate) fn take_inner(mut self) -> *mut nativePaymentParameters {
1480 assert!(self.is_owned);
1481 let ret = ObjOps::untweak_ptr(self.inner);
1482 self.inner = core::ptr::null_mut();
1486 /// Information about the payee, such as their features and route hints for their channels.
1488 pub extern "C" fn PaymentParameters_get_payee(this_ptr: &PaymentParameters) -> crate::lightning::routing::router::Payee {
1489 let mut inner_val = &mut this_ptr.get_native_mut_ref().payee;
1490 crate::lightning::routing::router::Payee::from_native(inner_val)
1492 /// Information about the payee, such as their features and route hints for their channels.
1494 pub extern "C" fn PaymentParameters_set_payee(this_ptr: &mut PaymentParameters, mut val: crate::lightning::routing::router::Payee) {
1495 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payee = val.into_native();
1497 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1499 pub extern "C" fn PaymentParameters_get_expiry_time(this_ptr: &PaymentParameters) -> crate::c_types::derived::COption_u64Z {
1500 let mut inner_val = &mut this_ptr.get_native_mut_ref().expiry_time;
1501 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() }) };
1504 /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1506 pub extern "C" fn PaymentParameters_set_expiry_time(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::COption_u64Z) {
1507 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
1508 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.expiry_time = local_val;
1510 /// The maximum total CLTV delta we accept for the route.
1511 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1513 pub extern "C" fn PaymentParameters_get_max_total_cltv_expiry_delta(this_ptr: &PaymentParameters) -> u32 {
1514 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_total_cltv_expiry_delta;
1517 /// The maximum total CLTV delta we accept for the route.
1518 /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1520 pub extern "C" fn PaymentParameters_set_max_total_cltv_expiry_delta(this_ptr: &mut PaymentParameters, mut val: u32) {
1521 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_cltv_expiry_delta = val;
1523 /// The maximum number of paths that may be used by (MPP) payments.
1524 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1526 pub extern "C" fn PaymentParameters_get_max_path_count(this_ptr: &PaymentParameters) -> u8 {
1527 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_path_count;
1530 /// The maximum number of paths that may be used by (MPP) payments.
1531 /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1533 pub extern "C" fn PaymentParameters_set_max_path_count(this_ptr: &mut PaymentParameters, mut val: u8) {
1534 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_path_count = val;
1536 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1537 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1538 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1539 /// increasing failure probability for those paths.
1541 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1542 /// restriction have been found. While paths which meet this criteria will be searched for, it
1543 /// is ultimately up to the scorer to select them over other paths.
1545 /// A value of 0 will allow payments up to and including a channel's total announced usable
1546 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1548 /// Default value: 2
1550 pub extern "C" fn PaymentParameters_get_max_channel_saturation_power_of_half(this_ptr: &PaymentParameters) -> u8 {
1551 let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_saturation_power_of_half;
1554 /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1555 /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1556 /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1557 /// increasing failure probability for those paths.
1559 /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1560 /// restriction have been found. While paths which meet this criteria will be searched for, it
1561 /// is ultimately up to the scorer to select them over other paths.
1563 /// A value of 0 will allow payments up to and including a channel's total announced usable
1564 /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1566 /// Default value: 2
1568 pub extern "C" fn PaymentParameters_set_max_channel_saturation_power_of_half(this_ptr: &mut PaymentParameters, mut val: u8) {
1569 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_saturation_power_of_half = val;
1571 /// A list of SCIDs which this payment was previously attempted over and which caused the
1572 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1575 /// Returns a copy of the field.
1577 pub extern "C" fn PaymentParameters_get_previously_failed_channels(this_ptr: &PaymentParameters) -> crate::c_types::derived::CVec_u64Z {
1578 let mut inner_val = this_ptr.get_native_mut_ref().previously_failed_channels.clone();
1579 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1580 local_inner_val.into()
1582 /// A list of SCIDs which this payment was previously attempted over and which caused the
1583 /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1586 pub extern "C" fn PaymentParameters_set_previously_failed_channels(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_u64Z) {
1587 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1588 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previously_failed_channels = local_val;
1590 /// A list of indices corresponding to blinded paths in [`Payee::Blinded::route_hints`] which this
1591 /// payment was previously attempted over and which caused the payment to fail. Future attempts
1592 /// for the same payment shouldn't be relayed through any of these blinded paths.
1594 /// Returns a copy of the field.
1596 pub extern "C" fn PaymentParameters_get_previously_failed_blinded_path_idxs(this_ptr: &PaymentParameters) -> crate::c_types::derived::CVec_u64Z {
1597 let mut inner_val = this_ptr.get_native_mut_ref().previously_failed_blinded_path_idxs.clone();
1598 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1599 local_inner_val.into()
1601 /// A list of indices corresponding to blinded paths in [`Payee::Blinded::route_hints`] which this
1602 /// payment was previously attempted over and which caused the payment to fail. Future attempts
1603 /// for the same payment shouldn't be relayed through any of these blinded paths.
1605 pub extern "C" fn PaymentParameters_set_previously_failed_blinded_path_idxs(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_u64Z) {
1606 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1607 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previously_failed_blinded_path_idxs = local_val;
1609 /// Constructs a new PaymentParameters given each field
1612 pub extern "C" fn PaymentParameters_new(mut payee_arg: crate::lightning::routing::router::Payee, mut expiry_time_arg: crate::c_types::derived::COption_u64Z, mut max_total_cltv_expiry_delta_arg: u32, mut max_path_count_arg: u8, mut max_channel_saturation_power_of_half_arg: u8, mut previously_failed_channels_arg: crate::c_types::derived::CVec_u64Z, mut previously_failed_blinded_path_idxs_arg: crate::c_types::derived::CVec_u64Z) -> PaymentParameters {
1613 let mut local_expiry_time_arg = if expiry_time_arg.is_some() { Some( { expiry_time_arg.take() }) } else { None };
1614 let mut local_previously_failed_channels_arg = Vec::new(); for mut item in previously_failed_channels_arg.into_rust().drain(..) { local_previously_failed_channels_arg.push( { item }); };
1615 let mut local_previously_failed_blinded_path_idxs_arg = Vec::new(); for mut item in previously_failed_blinded_path_idxs_arg.into_rust().drain(..) { local_previously_failed_blinded_path_idxs_arg.push( { item }); };
1616 PaymentParameters { inner: ObjOps::heap_alloc(nativePaymentParameters {
1617 payee: payee_arg.into_native(),
1618 expiry_time: local_expiry_time_arg,
1619 max_total_cltv_expiry_delta: max_total_cltv_expiry_delta_arg,
1620 max_path_count: max_path_count_arg,
1621 max_channel_saturation_power_of_half: max_channel_saturation_power_of_half_arg,
1622 previously_failed_channels: local_previously_failed_channels_arg,
1623 previously_failed_blinded_path_idxs: local_previously_failed_blinded_path_idxs_arg,
1624 }), is_owned: true }
1626 impl Clone for PaymentParameters {
1627 fn clone(&self) -> Self {
1629 inner: if <*mut nativePaymentParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1630 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1636 /// Used only if an object of this type is returned as a trait impl by a method
1637 pub(crate) extern "C" fn PaymentParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1638 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePaymentParameters)).clone() })) as *mut c_void
1641 /// Creates a copy of the PaymentParameters
1642 pub extern "C" fn PaymentParameters_clone(orig: &PaymentParameters) -> PaymentParameters {
1645 /// Get a string which allows debug introspection of a PaymentParameters object
1646 pub extern "C" fn PaymentParameters_debug_str_void(o: *const c_void) -> Str {
1647 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::PaymentParameters }).into()}
1648 /// Generates a non-cryptographic 64-bit hash of the PaymentParameters.
1650 pub extern "C" fn PaymentParameters_hash(o: &PaymentParameters) -> u64 {
1651 if o.inner.is_null() { return 0; }
1652 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1653 #[allow(deprecated)]
1654 let mut hasher = core::hash::SipHasher::new();
1655 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1656 core::hash::Hasher::finish(&hasher)
1658 /// Checks if two PaymentParameterss contain equal inner contents.
1659 /// This ignores pointers and is_owned flags and looks at the values in fields.
1660 /// Two objects with NULL inner values will be considered "equal" here.
1662 pub extern "C" fn PaymentParameters_eq(a: &PaymentParameters, b: &PaymentParameters) -> bool {
1663 if a.inner == b.inner { return true; }
1664 if a.inner.is_null() || b.inner.is_null() { return false; }
1665 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1668 /// Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
1669 pub extern "C" fn PaymentParameters_write(obj: &crate::lightning::routing::router::PaymentParameters) -> crate::c_types::derived::CVec_u8Z {
1670 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1673 pub(crate) extern "C" fn PaymentParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1674 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePaymentParameters) })
1677 /// Read a PaymentParameters from a byte array, created by PaymentParameters_write
1678 pub extern "C" fn PaymentParameters_read(ser: crate::c_types::u8slice, arg: u32) -> crate::c_types::derived::CResult_PaymentParametersDecodeErrorZ {
1680 let res: Result<lightning::routing::router::PaymentParameters, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1681 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1684 /// Creates a payee with the node id of the given `pubkey`.
1686 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1690 pub extern "C" fn PaymentParameters_from_node_id(mut payee_pubkey: crate::c_types::PublicKey, mut final_cltv_expiry_delta: u32) -> crate::lightning::routing::router::PaymentParameters {
1691 let mut ret = lightning::routing::router::PaymentParameters::from_node_id(payee_pubkey.into_rust(), final_cltv_expiry_delta);
1692 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1695 /// Creates a payee with the node id of the given `pubkey` to use for keysend payments.
1697 /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
1700 /// Note that MPP keysend is not widely supported yet. The `allow_mpp` lets you choose
1701 /// whether your router will be allowed to find a multi-part route for this payment. If you
1702 /// set `allow_mpp` to true, you should ensure a payment secret is set on send, likely via
1703 /// [`RecipientOnionFields::secret_only`].
1705 /// [`RecipientOnionFields::secret_only`]: crate::ln::channelmanager::RecipientOnionFields::secret_only
1708 pub extern "C" fn PaymentParameters_for_keysend(mut payee_pubkey: crate::c_types::PublicKey, mut final_cltv_expiry_delta: u32, mut allow_mpp: bool) -> crate::lightning::routing::router::PaymentParameters {
1709 let mut ret = lightning::routing::router::PaymentParameters::for_keysend(payee_pubkey.into_rust(), final_cltv_expiry_delta, allow_mpp);
1710 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1713 /// Creates parameters for paying to a blinded payee from the provided invoice. Sets
1714 /// [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and
1715 /// [`PaymentParameters::expiry_time`].
1718 pub extern "C" fn PaymentParameters_from_bolt12_invoice(invoice: &crate::lightning::offers::invoice::Bolt12Invoice) -> crate::lightning::routing::router::PaymentParameters {
1719 let mut ret = lightning::routing::router::PaymentParameters::from_bolt12_invoice(invoice.get_native_ref());
1720 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1723 /// Creates parameters for paying to a blinded payee from the provided blinded route hints.
1726 pub extern "C" fn PaymentParameters_blinded(mut blinded_route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ) -> crate::lightning::routing::router::PaymentParameters {
1727 let mut local_blinded_route_hints = Vec::new(); for mut item in blinded_route_hints.into_rust().drain(..) { local_blinded_route_hints.push( { let (mut orig_blinded_route_hints_0_0, mut orig_blinded_route_hints_0_1) = item.to_rust(); let mut local_blinded_route_hints_0 = (*unsafe { Box::from_raw(orig_blinded_route_hints_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_blinded_route_hints_0_1.take_inner()) }); local_blinded_route_hints_0 }); };
1728 let mut ret = lightning::routing::router::PaymentParameters::blinded(local_blinded_route_hints);
1729 crate::lightning::routing::router::PaymentParameters { inner: ObjOps::heap_alloc(ret), is_owned: true }
1732 /// The recipient of a payment, differing based on whether they've hidden their identity with route
1738 /// The recipient provided blinded paths and payinfo to reach them. The blinded paths themselves
1739 /// will be included in the final [`Route`].
1741 /// Aggregated routing info and blinded paths, for routing to the payee without knowing their
1743 route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ,
1744 /// Features supported by the payee.
1746 /// May be set from the payee's invoice. May be `None` if the invoice does not contain any
1749 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1750 features: crate::lightning::ln::features::Bolt12InvoiceFeatures,
1752 /// The recipient included these route hints in their BOLT11 invoice.
1754 /// The node id of the payee.
1755 node_id: crate::c_types::PublicKey,
1756 /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
1757 route_hints: crate::c_types::derived::CVec_RouteHintZ,
1758 /// Features supported by the payee.
1760 /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
1761 /// does not contain any features.
1763 /// [`for_keysend`]: PaymentParameters::for_keysend
1765 /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1766 features: crate::lightning::ln::features::Bolt11InvoiceFeatures,
1767 /// The minimum CLTV delta at the end of the route. This value must not be zero.
1768 final_cltv_expiry_delta: u32,
1771 use lightning::routing::router::Payee as PayeeImport;
1772 pub(crate) type nativePayee = PayeeImport;
1776 pub(crate) fn to_native(&self) -> nativePayee {
1778 Payee::Blinded {ref route_hints, ref features, } => {
1779 let mut route_hints_nonref = Clone::clone(route_hints);
1780 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.into_rust().drain(..) { local_route_hints_nonref.push( { let (mut orig_route_hints_nonref_0_0, mut orig_route_hints_nonref_0_1) = item.to_rust(); let mut local_route_hints_nonref_0 = (*unsafe { Box::from_raw(orig_route_hints_nonref_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_route_hints_nonref_0_1.take_inner()) }); local_route_hints_nonref_0 }); };
1781 let mut features_nonref = Clone::clone(features);
1782 let mut local_features_nonref = if features_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_nonref.take_inner()) } }) };
1783 nativePayee::Blinded {
1784 route_hints: local_route_hints_nonref,
1785 features: local_features_nonref,
1788 Payee::Clear {ref node_id, ref route_hints, ref features, ref final_cltv_expiry_delta, } => {
1789 let mut node_id_nonref = Clone::clone(node_id);
1790 let mut route_hints_nonref = Clone::clone(route_hints);
1791 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.into_rust().drain(..) { local_route_hints_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1792 let mut features_nonref = Clone::clone(features);
1793 let mut local_features_nonref = if features_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_nonref.take_inner()) } }) };
1794 let mut final_cltv_expiry_delta_nonref = Clone::clone(final_cltv_expiry_delta);
1795 nativePayee::Clear {
1796 node_id: node_id_nonref.into_rust(),
1797 route_hints: local_route_hints_nonref,
1798 features: local_features_nonref,
1799 final_cltv_expiry_delta: final_cltv_expiry_delta_nonref,
1805 pub(crate) fn into_native(self) -> nativePayee {
1807 Payee::Blinded {mut route_hints, mut features, } => {
1808 let mut local_route_hints = Vec::new(); for mut item in route_hints.into_rust().drain(..) { local_route_hints.push( { let (mut orig_route_hints_0_0, mut orig_route_hints_0_1) = item.to_rust(); let mut local_route_hints_0 = (*unsafe { Box::from_raw(orig_route_hints_0_0.take_inner()) }, *unsafe { Box::from_raw(orig_route_hints_0_1.take_inner()) }); local_route_hints_0 }); };
1809 let mut local_features = if features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features.take_inner()) } }) };
1810 nativePayee::Blinded {
1811 route_hints: local_route_hints,
1812 features: local_features,
1815 Payee::Clear {mut node_id, mut route_hints, mut features, mut final_cltv_expiry_delta, } => {
1816 let mut local_route_hints = Vec::new(); for mut item in route_hints.into_rust().drain(..) { local_route_hints.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1817 let mut local_features = if features.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features.take_inner()) } }) };
1818 nativePayee::Clear {
1819 node_id: node_id.into_rust(),
1820 route_hints: local_route_hints,
1821 features: local_features,
1822 final_cltv_expiry_delta: final_cltv_expiry_delta,
1828 pub(crate) fn from_native(native: &PayeeImport) -> Self {
1829 let native = unsafe { &*(native as *const _ as *const c_void as *const nativePayee) };
1831 nativePayee::Blinded {ref route_hints, ref features, } => {
1832 let mut route_hints_nonref = Clone::clone(route_hints);
1833 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.drain(..) { local_route_hints_nonref.push( { let (mut orig_route_hints_nonref_0_0, mut orig_route_hints_nonref_0_1) = item; let mut local_route_hints_nonref_0 = (crate::lightning::offers::invoice::BlindedPayInfo { inner: ObjOps::heap_alloc(orig_route_hints_nonref_0_0), is_owned: true }, crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(orig_route_hints_nonref_0_1), is_owned: true }).into(); local_route_hints_nonref_0 }); };
1834 let mut features_nonref = Clone::clone(features);
1835 let mut local_features_nonref = crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: if features_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features_nonref.unwrap())) } }, is_owned: true };
1837 route_hints: local_route_hints_nonref.into(),
1838 features: local_features_nonref,
1841 nativePayee::Clear {ref node_id, ref route_hints, ref features, ref final_cltv_expiry_delta, } => {
1842 let mut node_id_nonref = Clone::clone(node_id);
1843 let mut route_hints_nonref = Clone::clone(route_hints);
1844 let mut local_route_hints_nonref = Vec::new(); for mut item in route_hints_nonref.drain(..) { local_route_hints_nonref.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1845 let mut features_nonref = Clone::clone(features);
1846 let mut local_features_nonref = crate::lightning::ln::features::Bolt11InvoiceFeatures { inner: if features_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features_nonref.unwrap())) } }, is_owned: true };
1847 let mut final_cltv_expiry_delta_nonref = Clone::clone(final_cltv_expiry_delta);
1849 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
1850 route_hints: local_route_hints_nonref.into(),
1851 features: local_features_nonref,
1852 final_cltv_expiry_delta: final_cltv_expiry_delta_nonref,
1858 pub(crate) fn native_into(native: nativePayee) -> Self {
1860 nativePayee::Blinded {mut route_hints, mut features, } => {
1861 let mut local_route_hints = Vec::new(); for mut item in route_hints.drain(..) { local_route_hints.push( { let (mut orig_route_hints_0_0, mut orig_route_hints_0_1) = item; let mut local_route_hints_0 = (crate::lightning::offers::invoice::BlindedPayInfo { inner: ObjOps::heap_alloc(orig_route_hints_0_0), is_owned: true }, crate::lightning::blinded_path::BlindedPath { inner: ObjOps::heap_alloc(orig_route_hints_0_1), is_owned: true }).into(); local_route_hints_0 }); };
1862 let mut local_features = crate::lightning::ln::features::Bolt12InvoiceFeatures { inner: if features.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features.unwrap())) } }, is_owned: true };
1864 route_hints: local_route_hints.into(),
1865 features: local_features,
1868 nativePayee::Clear {mut node_id, mut route_hints, mut features, mut final_cltv_expiry_delta, } => {
1869 let mut local_route_hints = Vec::new(); for mut item in route_hints.drain(..) { local_route_hints.push( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
1870 let mut local_features = crate::lightning::ln::features::Bolt11InvoiceFeatures { inner: if features.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((features.unwrap())) } }, is_owned: true };
1872 node_id: crate::c_types::PublicKey::from_rust(&node_id),
1873 route_hints: local_route_hints.into(),
1874 features: local_features,
1875 final_cltv_expiry_delta: final_cltv_expiry_delta,
1881 /// Frees any resources used by the Payee
1883 pub extern "C" fn Payee_free(this_ptr: Payee) { }
1884 /// Creates a copy of the Payee
1886 pub extern "C" fn Payee_clone(orig: &Payee) -> Payee {
1890 /// Used only if an object of this type is returned as a trait impl by a method
1891 pub(crate) extern "C" fn Payee_clone_void(this_ptr: *const c_void) -> *mut c_void {
1892 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Payee)).clone() })) as *mut c_void
1895 /// Used only if an object of this type is returned as a trait impl by a method
1896 pub(crate) extern "C" fn Payee_free_void(this_ptr: *mut c_void) {
1897 let _ = unsafe { Box::from_raw(this_ptr as *mut Payee) };
1900 /// Utility method to constructs a new Blinded-variant Payee
1901 pub extern "C" fn Payee_blinded(route_hints: crate::c_types::derived::CVec_C2Tuple_BlindedPayInfoBlindedPathZZ, features: crate::lightning::ln::features::Bolt12InvoiceFeatures) -> Payee {
1908 /// Utility method to constructs a new Clear-variant Payee
1909 pub extern "C" fn Payee_clear(node_id: crate::c_types::PublicKey, route_hints: crate::c_types::derived::CVec_RouteHintZ, features: crate::lightning::ln::features::Bolt11InvoiceFeatures, final_cltv_expiry_delta: u32) -> Payee {
1914 final_cltv_expiry_delta,
1917 /// Get a string which allows debug introspection of a Payee object
1918 pub extern "C" fn Payee_debug_str_void(o: *const c_void) -> Str {
1919 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::Payee }).into()}
1920 /// Generates a non-cryptographic 64-bit hash of the Payee.
1922 pub extern "C" fn Payee_hash(o: &Payee) -> u64 {
1923 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1924 #[allow(deprecated)]
1925 let mut hasher = core::hash::SipHasher::new();
1926 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1927 core::hash::Hasher::finish(&hasher)
1929 /// Checks if two Payees contain equal inner contents.
1930 /// This ignores pointers and is_owned flags and looks at the values in fields.
1932 pub extern "C" fn Payee_eq(a: &Payee, b: &Payee) -> bool {
1933 if &a.to_native() == &b.to_native() { true } else { false }
1936 use lightning::routing::router::RouteHint as nativeRouteHintImport;
1937 pub(crate) type nativeRouteHint = nativeRouteHintImport;
1939 /// A list of hops along a payment path terminating with a channel to the recipient.
1942 pub struct RouteHint {
1943 /// A pointer to the opaque Rust object.
1945 /// Nearly everywhere, inner must be non-null, however in places where
1946 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1947 pub inner: *mut nativeRouteHint,
1948 /// Indicates that this is the only struct which contains the same pointer.
1950 /// Rust functions which take ownership of an object provided via an argument require
1951 /// this to be true and invalidate the object pointed to by inner.
1955 impl Drop for RouteHint {
1956 fn drop(&mut self) {
1957 if self.is_owned && !<*mut nativeRouteHint>::is_null(self.inner) {
1958 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1962 /// Frees any resources used by the RouteHint, if is_owned is set and inner is non-NULL.
1964 pub extern "C" fn RouteHint_free(this_obj: RouteHint) { }
1966 /// Used only if an object of this type is returned as a trait impl by a method
1967 pub(crate) extern "C" fn RouteHint_free_void(this_ptr: *mut c_void) {
1968 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHint) };
1972 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHint {
1973 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1975 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHint {
1976 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1978 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1979 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHint {
1980 assert!(self.is_owned);
1981 let ret = ObjOps::untweak_ptr(self.inner);
1982 self.inner = core::ptr::null_mut();
1987 pub extern "C" fn RouteHint_get_a(this_ptr: &RouteHint) -> crate::c_types::derived::CVec_RouteHintHopZ {
1988 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1989 let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::routing::router::RouteHintHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::routing::router::RouteHintHop<>) as *mut _) }, is_owned: false } }); };
1990 local_inner_val.into()
1993 pub extern "C" fn RouteHint_set_a(this_ptr: &mut RouteHint, mut val: crate::c_types::derived::CVec_RouteHintHopZ) {
1994 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
1995 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = local_val;
1997 /// Constructs a new RouteHint given each field
2000 pub extern "C" fn RouteHint_new(mut a_arg: crate::c_types::derived::CVec_RouteHintHopZ) -> RouteHint {
2001 let mut local_a_arg = Vec::new(); for mut item in a_arg.into_rust().drain(..) { local_a_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); };
2002 RouteHint { inner: ObjOps::heap_alloc(lightning::routing::router::RouteHint (
2004 )), is_owned: true }
2006 impl Clone for RouteHint {
2007 fn clone(&self) -> Self {
2009 inner: if <*mut nativeRouteHint>::is_null(self.inner) { core::ptr::null_mut() } else {
2010 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2016 /// Used only if an object of this type is returned as a trait impl by a method
2017 pub(crate) extern "C" fn RouteHint_clone_void(this_ptr: *const c_void) -> *mut c_void {
2018 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRouteHint)).clone() })) as *mut c_void
2021 /// Creates a copy of the RouteHint
2022 pub extern "C" fn RouteHint_clone(orig: &RouteHint) -> RouteHint {
2025 /// Get a string which allows debug introspection of a RouteHint object
2026 pub extern "C" fn RouteHint_debug_str_void(o: *const c_void) -> Str {
2027 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::RouteHint }).into()}
2028 /// Generates a non-cryptographic 64-bit hash of the RouteHint.
2030 pub extern "C" fn RouteHint_hash(o: &RouteHint) -> u64 {
2031 if o.inner.is_null() { return 0; }
2032 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2033 #[allow(deprecated)]
2034 let mut hasher = core::hash::SipHasher::new();
2035 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2036 core::hash::Hasher::finish(&hasher)
2038 /// Checks if two RouteHints contain equal inner contents.
2039 /// This ignores pointers and is_owned flags and looks at the values in fields.
2040 /// Two objects with NULL inner values will be considered "equal" here.
2042 pub extern "C" fn RouteHint_eq(a: &RouteHint, b: &RouteHint) -> bool {
2043 if a.inner == b.inner { return true; }
2044 if a.inner.is_null() || b.inner.is_null() { return false; }
2045 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2048 /// Serialize the RouteHint object into a byte array which can be read by RouteHint_read
2049 pub extern "C" fn RouteHint_write(obj: &crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CVec_u8Z {
2050 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2053 pub(crate) extern "C" fn RouteHint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2054 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHint) })
2057 /// Read a RouteHint from a byte array, created by RouteHint_write
2058 pub extern "C" fn RouteHint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintDecodeErrorZ {
2059 let res: Result<lightning::routing::router::RouteHint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2060 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
2064 use lightning::routing::router::RouteHintHop as nativeRouteHintHopImport;
2065 pub(crate) type nativeRouteHintHop = nativeRouteHintHopImport;
2067 /// A channel descriptor for a hop along a payment path.
2069 /// While this generally comes from BOLT 11's `r` field, this struct includes more fields than are
2070 /// available in BOLT 11. Thus, encoding and decoding this via `lightning-invoice` is lossy, as
2071 /// fields not supported in BOLT 11 will be stripped.
2074 pub struct RouteHintHop {
2075 /// A pointer to the opaque Rust object.
2077 /// Nearly everywhere, inner must be non-null, however in places where
2078 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2079 pub inner: *mut nativeRouteHintHop,
2080 /// Indicates that this is the only struct which contains the same pointer.
2082 /// Rust functions which take ownership of an object provided via an argument require
2083 /// this to be true and invalidate the object pointed to by inner.
2087 impl Drop for RouteHintHop {
2088 fn drop(&mut self) {
2089 if self.is_owned && !<*mut nativeRouteHintHop>::is_null(self.inner) {
2090 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2094 /// Frees any resources used by the RouteHintHop, if is_owned is set and inner is non-NULL.
2096 pub extern "C" fn RouteHintHop_free(this_obj: RouteHintHop) { }
2098 /// Used only if an object of this type is returned as a trait impl by a method
2099 pub(crate) extern "C" fn RouteHintHop_free_void(this_ptr: *mut c_void) {
2100 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRouteHintHop) };
2104 pub(crate) fn get_native_ref(&self) -> &'static nativeRouteHintHop {
2105 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2107 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRouteHintHop {
2108 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2110 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2111 pub(crate) fn take_inner(mut self) -> *mut nativeRouteHintHop {
2112 assert!(self.is_owned);
2113 let ret = ObjOps::untweak_ptr(self.inner);
2114 self.inner = core::ptr::null_mut();
2118 /// The node_id of the non-target end of the route
2120 pub extern "C" fn RouteHintHop_get_src_node_id(this_ptr: &RouteHintHop) -> crate::c_types::PublicKey {
2121 let mut inner_val = &mut this_ptr.get_native_mut_ref().src_node_id;
2122 crate::c_types::PublicKey::from_rust(&inner_val)
2124 /// The node_id of the non-target end of the route
2126 pub extern "C" fn RouteHintHop_set_src_node_id(this_ptr: &mut RouteHintHop, mut val: crate::c_types::PublicKey) {
2127 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.src_node_id = val.into_rust();
2129 /// The short_channel_id of this channel
2131 pub extern "C" fn RouteHintHop_get_short_channel_id(this_ptr: &RouteHintHop) -> u64 {
2132 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
2135 /// The short_channel_id of this channel
2137 pub extern "C" fn RouteHintHop_set_short_channel_id(this_ptr: &mut RouteHintHop, mut val: u64) {
2138 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
2140 /// The fees which must be paid to use this channel
2142 pub extern "C" fn RouteHintHop_get_fees(this_ptr: &RouteHintHop) -> crate::lightning::routing::gossip::RoutingFees {
2143 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
2144 crate::lightning::routing::gossip::RoutingFees { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::RoutingFees<>) as *mut _) }, is_owned: false }
2146 /// The fees which must be paid to use this channel
2148 pub extern "C" fn RouteHintHop_set_fees(this_ptr: &mut RouteHintHop, mut val: crate::lightning::routing::gossip::RoutingFees) {
2149 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
2151 /// The difference in CLTV values between this node and the next node.
2153 pub extern "C" fn RouteHintHop_get_cltv_expiry_delta(this_ptr: &RouteHintHop) -> u16 {
2154 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
2157 /// The difference in CLTV values between this node and the next node.
2159 pub extern "C" fn RouteHintHop_set_cltv_expiry_delta(this_ptr: &mut RouteHintHop, mut val: u16) {
2160 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
2162 /// The minimum value, in msat, which must be relayed to the next hop.
2164 pub extern "C" fn RouteHintHop_get_htlc_minimum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
2165 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
2166 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() }) };
2169 /// The minimum value, in msat, which must be relayed to the next hop.
2171 pub extern "C" fn RouteHintHop_set_htlc_minimum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
2172 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2173 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = local_val;
2175 /// The maximum value in msat available for routing with a single HTLC.
2177 pub extern "C" fn RouteHintHop_get_htlc_maximum_msat(this_ptr: &RouteHintHop) -> crate::c_types::derived::COption_u64Z {
2178 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
2179 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() }) };
2182 /// The maximum value in msat available for routing with a single HTLC.
2184 pub extern "C" fn RouteHintHop_set_htlc_maximum_msat(this_ptr: &mut RouteHintHop, mut val: crate::c_types::derived::COption_u64Z) {
2185 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
2186 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
2188 /// Constructs a new RouteHintHop given each field
2191 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::gossip::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 {
2192 let mut local_htlc_minimum_msat_arg = if htlc_minimum_msat_arg.is_some() { Some( { htlc_minimum_msat_arg.take() }) } else { None };
2193 let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
2194 RouteHintHop { inner: ObjOps::heap_alloc(nativeRouteHintHop {
2195 src_node_id: src_node_id_arg.into_rust(),
2196 short_channel_id: short_channel_id_arg,
2197 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
2198 cltv_expiry_delta: cltv_expiry_delta_arg,
2199 htlc_minimum_msat: local_htlc_minimum_msat_arg,
2200 htlc_maximum_msat: local_htlc_maximum_msat_arg,
2201 }), is_owned: true }
2203 impl Clone for RouteHintHop {
2204 fn clone(&self) -> Self {
2206 inner: if <*mut nativeRouteHintHop>::is_null(self.inner) { core::ptr::null_mut() } else {
2207 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2213 /// Used only if an object of this type is returned as a trait impl by a method
2214 pub(crate) extern "C" fn RouteHintHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
2215 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRouteHintHop)).clone() })) as *mut c_void
2218 /// Creates a copy of the RouteHintHop
2219 pub extern "C" fn RouteHintHop_clone(orig: &RouteHintHop) -> RouteHintHop {
2222 /// Get a string which allows debug introspection of a RouteHintHop object
2223 pub extern "C" fn RouteHintHop_debug_str_void(o: *const c_void) -> Str {
2224 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::RouteHintHop }).into()}
2225 /// Generates a non-cryptographic 64-bit hash of the RouteHintHop.
2227 pub extern "C" fn RouteHintHop_hash(o: &RouteHintHop) -> u64 {
2228 if o.inner.is_null() { return 0; }
2229 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2230 #[allow(deprecated)]
2231 let mut hasher = core::hash::SipHasher::new();
2232 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2233 core::hash::Hasher::finish(&hasher)
2235 /// Checks if two RouteHintHops contain equal inner contents.
2236 /// This ignores pointers and is_owned flags and looks at the values in fields.
2237 /// Two objects with NULL inner values will be considered "equal" here.
2239 pub extern "C" fn RouteHintHop_eq(a: &RouteHintHop, b: &RouteHintHop) -> bool {
2240 if a.inner == b.inner { return true; }
2241 if a.inner.is_null() || b.inner.is_null() { return false; }
2242 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2245 /// Serialize the RouteHintHop object into a byte array which can be read by RouteHintHop_read
2246 pub extern "C" fn RouteHintHop_write(obj: &crate::lightning::routing::router::RouteHintHop) -> crate::c_types::derived::CVec_u8Z {
2247 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
2250 pub(crate) extern "C" fn RouteHintHop_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
2251 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRouteHintHop) })
2254 /// Read a RouteHintHop from a byte array, created by RouteHintHop_write
2255 pub extern "C" fn RouteHintHop_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RouteHintHopDecodeErrorZ {
2256 let res: Result<lightning::routing::router::RouteHintHop, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
2257 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::router::RouteHintHop { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
2261 use lightning::routing::router::FirstHopCandidate as nativeFirstHopCandidateImport;
2262 pub(crate) type nativeFirstHopCandidate = nativeFirstHopCandidateImport<'static>;
2264 /// A [`CandidateRouteHop::FirstHop`] entry.
2267 pub struct FirstHopCandidate {
2268 /// A pointer to the opaque Rust object.
2270 /// Nearly everywhere, inner must be non-null, however in places where
2271 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2272 pub inner: *mut nativeFirstHopCandidate,
2273 /// Indicates that this is the only struct which contains the same pointer.
2275 /// Rust functions which take ownership of an object provided via an argument require
2276 /// this to be true and invalidate the object pointed to by inner.
2280 impl Drop for FirstHopCandidate {
2281 fn drop(&mut self) {
2282 if self.is_owned && !<*mut nativeFirstHopCandidate>::is_null(self.inner) {
2283 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2287 /// Frees any resources used by the FirstHopCandidate, if is_owned is set and inner is non-NULL.
2289 pub extern "C" fn FirstHopCandidate_free(this_obj: FirstHopCandidate) { }
2291 /// Used only if an object of this type is returned as a trait impl by a method
2292 pub(crate) extern "C" fn FirstHopCandidate_free_void(this_ptr: *mut c_void) {
2293 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeFirstHopCandidate) };
2296 impl FirstHopCandidate {
2297 pub(crate) fn get_native_ref(&self) -> &'static nativeFirstHopCandidate {
2298 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2300 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFirstHopCandidate {
2301 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2303 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2304 pub(crate) fn take_inner(mut self) -> *mut nativeFirstHopCandidate {
2305 assert!(self.is_owned);
2306 let ret = ObjOps::untweak_ptr(self.inner);
2307 self.inner = core::ptr::null_mut();
2311 impl Clone for FirstHopCandidate {
2312 fn clone(&self) -> Self {
2314 inner: if <*mut nativeFirstHopCandidate>::is_null(self.inner) { core::ptr::null_mut() } else {
2315 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2321 /// Used only if an object of this type is returned as a trait impl by a method
2322 pub(crate) extern "C" fn FirstHopCandidate_clone_void(this_ptr: *const c_void) -> *mut c_void {
2323 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeFirstHopCandidate)).clone() })) as *mut c_void
2326 /// Creates a copy of the FirstHopCandidate
2327 pub extern "C" fn FirstHopCandidate_clone(orig: &FirstHopCandidate) -> FirstHopCandidate {
2330 /// Get a string which allows debug introspection of a FirstHopCandidate object
2331 pub extern "C" fn FirstHopCandidate_debug_str_void(o: *const c_void) -> Str {
2332 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::FirstHopCandidate }).into()}
2334 use lightning::routing::router::PublicHopCandidate as nativePublicHopCandidateImport;
2335 pub(crate) type nativePublicHopCandidate = nativePublicHopCandidateImport<'static>;
2337 /// A [`CandidateRouteHop::PublicHop`] entry.
2340 pub struct PublicHopCandidate {
2341 /// A pointer to the opaque Rust object.
2343 /// Nearly everywhere, inner must be non-null, however in places where
2344 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2345 pub inner: *mut nativePublicHopCandidate,
2346 /// Indicates that this is the only struct which contains the same pointer.
2348 /// Rust functions which take ownership of an object provided via an argument require
2349 /// this to be true and invalidate the object pointed to by inner.
2353 impl Drop for PublicHopCandidate {
2354 fn drop(&mut self) {
2355 if self.is_owned && !<*mut nativePublicHopCandidate>::is_null(self.inner) {
2356 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2360 /// Frees any resources used by the PublicHopCandidate, if is_owned is set and inner is non-NULL.
2362 pub extern "C" fn PublicHopCandidate_free(this_obj: PublicHopCandidate) { }
2364 /// Used only if an object of this type is returned as a trait impl by a method
2365 pub(crate) extern "C" fn PublicHopCandidate_free_void(this_ptr: *mut c_void) {
2366 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePublicHopCandidate) };
2369 impl PublicHopCandidate {
2370 pub(crate) fn get_native_ref(&self) -> &'static nativePublicHopCandidate {
2371 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2373 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePublicHopCandidate {
2374 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2376 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2377 pub(crate) fn take_inner(mut self) -> *mut nativePublicHopCandidate {
2378 assert!(self.is_owned);
2379 let ret = ObjOps::untweak_ptr(self.inner);
2380 self.inner = core::ptr::null_mut();
2384 /// The short channel ID of the channel, i.e. the identifier by which we refer to this
2387 pub extern "C" fn PublicHopCandidate_get_short_channel_id(this_ptr: &PublicHopCandidate) -> u64 {
2388 let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id;
2391 /// The short channel ID of the channel, i.e. the identifier by which we refer to this
2394 pub extern "C" fn PublicHopCandidate_set_short_channel_id(this_ptr: &mut PublicHopCandidate, mut val: u64) {
2395 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val;
2397 impl Clone for PublicHopCandidate {
2398 fn clone(&self) -> Self {
2400 inner: if <*mut nativePublicHopCandidate>::is_null(self.inner) { core::ptr::null_mut() } else {
2401 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2407 /// Used only if an object of this type is returned as a trait impl by a method
2408 pub(crate) extern "C" fn PublicHopCandidate_clone_void(this_ptr: *const c_void) -> *mut c_void {
2409 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePublicHopCandidate)).clone() })) as *mut c_void
2412 /// Creates a copy of the PublicHopCandidate
2413 pub extern "C" fn PublicHopCandidate_clone(orig: &PublicHopCandidate) -> PublicHopCandidate {
2416 /// Get a string which allows debug introspection of a PublicHopCandidate object
2417 pub extern "C" fn PublicHopCandidate_debug_str_void(o: *const c_void) -> Str {
2418 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::PublicHopCandidate }).into()}
2420 use lightning::routing::router::PrivateHopCandidate as nativePrivateHopCandidateImport;
2421 pub(crate) type nativePrivateHopCandidate = nativePrivateHopCandidateImport<'static>;
2423 /// A [`CandidateRouteHop::PrivateHop`] entry.
2426 pub struct PrivateHopCandidate {
2427 /// A pointer to the opaque Rust object.
2429 /// Nearly everywhere, inner must be non-null, however in places where
2430 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2431 pub inner: *mut nativePrivateHopCandidate,
2432 /// Indicates that this is the only struct which contains the same pointer.
2434 /// Rust functions which take ownership of an object provided via an argument require
2435 /// this to be true and invalidate the object pointed to by inner.
2439 impl Drop for PrivateHopCandidate {
2440 fn drop(&mut self) {
2441 if self.is_owned && !<*mut nativePrivateHopCandidate>::is_null(self.inner) {
2442 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2446 /// Frees any resources used by the PrivateHopCandidate, if is_owned is set and inner is non-NULL.
2448 pub extern "C" fn PrivateHopCandidate_free(this_obj: PrivateHopCandidate) { }
2450 /// Used only if an object of this type is returned as a trait impl by a method
2451 pub(crate) extern "C" fn PrivateHopCandidate_free_void(this_ptr: *mut c_void) {
2452 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePrivateHopCandidate) };
2455 impl PrivateHopCandidate {
2456 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateHopCandidate {
2457 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2459 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateHopCandidate {
2460 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2462 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2463 pub(crate) fn take_inner(mut self) -> *mut nativePrivateHopCandidate {
2464 assert!(self.is_owned);
2465 let ret = ObjOps::untweak_ptr(self.inner);
2466 self.inner = core::ptr::null_mut();
2470 impl Clone for PrivateHopCandidate {
2471 fn clone(&self) -> Self {
2473 inner: if <*mut nativePrivateHopCandidate>::is_null(self.inner) { core::ptr::null_mut() } else {
2474 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2480 /// Used only if an object of this type is returned as a trait impl by a method
2481 pub(crate) extern "C" fn PrivateHopCandidate_clone_void(this_ptr: *const c_void) -> *mut c_void {
2482 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePrivateHopCandidate)).clone() })) as *mut c_void
2485 /// Creates a copy of the PrivateHopCandidate
2486 pub extern "C" fn PrivateHopCandidate_clone(orig: &PrivateHopCandidate) -> PrivateHopCandidate {
2489 /// Get a string which allows debug introspection of a PrivateHopCandidate object
2490 pub extern "C" fn PrivateHopCandidate_debug_str_void(o: *const c_void) -> Str {
2491 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::PrivateHopCandidate }).into()}
2493 use lightning::routing::router::BlindedPathCandidate as nativeBlindedPathCandidateImport;
2494 pub(crate) type nativeBlindedPathCandidate = nativeBlindedPathCandidateImport<'static>;
2496 /// A [`CandidateRouteHop::Blinded`] entry.
2499 pub struct BlindedPathCandidate {
2500 /// A pointer to the opaque Rust object.
2502 /// Nearly everywhere, inner must be non-null, however in places where
2503 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2504 pub inner: *mut nativeBlindedPathCandidate,
2505 /// Indicates that this is the only struct which contains the same pointer.
2507 /// Rust functions which take ownership of an object provided via an argument require
2508 /// this to be true and invalidate the object pointed to by inner.
2512 impl Drop for BlindedPathCandidate {
2513 fn drop(&mut self) {
2514 if self.is_owned && !<*mut nativeBlindedPathCandidate>::is_null(self.inner) {
2515 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2519 /// Frees any resources used by the BlindedPathCandidate, if is_owned is set and inner is non-NULL.
2521 pub extern "C" fn BlindedPathCandidate_free(this_obj: BlindedPathCandidate) { }
2523 /// Used only if an object of this type is returned as a trait impl by a method
2524 pub(crate) extern "C" fn BlindedPathCandidate_free_void(this_ptr: *mut c_void) {
2525 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBlindedPathCandidate) };
2528 impl BlindedPathCandidate {
2529 pub(crate) fn get_native_ref(&self) -> &'static nativeBlindedPathCandidate {
2530 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2532 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBlindedPathCandidate {
2533 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2535 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2536 pub(crate) fn take_inner(mut self) -> *mut nativeBlindedPathCandidate {
2537 assert!(self.is_owned);
2538 let ret = ObjOps::untweak_ptr(self.inner);
2539 self.inner = core::ptr::null_mut();
2543 impl Clone for BlindedPathCandidate {
2544 fn clone(&self) -> Self {
2546 inner: if <*mut nativeBlindedPathCandidate>::is_null(self.inner) { core::ptr::null_mut() } else {
2547 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2553 /// Used only if an object of this type is returned as a trait impl by a method
2554 pub(crate) extern "C" fn BlindedPathCandidate_clone_void(this_ptr: *const c_void) -> *mut c_void {
2555 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBlindedPathCandidate)).clone() })) as *mut c_void
2558 /// Creates a copy of the BlindedPathCandidate
2559 pub extern "C" fn BlindedPathCandidate_clone(orig: &BlindedPathCandidate) -> BlindedPathCandidate {
2562 /// Get a string which allows debug introspection of a BlindedPathCandidate object
2563 pub extern "C" fn BlindedPathCandidate_debug_str_void(o: *const c_void) -> Str {
2564 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::BlindedPathCandidate }).into()}
2566 use lightning::routing::router::OneHopBlindedPathCandidate as nativeOneHopBlindedPathCandidateImport;
2567 pub(crate) type nativeOneHopBlindedPathCandidate = nativeOneHopBlindedPathCandidateImport<'static>;
2569 /// A [`CandidateRouteHop::OneHopBlinded`] entry.
2572 pub struct OneHopBlindedPathCandidate {
2573 /// A pointer to the opaque Rust object.
2575 /// Nearly everywhere, inner must be non-null, however in places where
2576 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2577 pub inner: *mut nativeOneHopBlindedPathCandidate,
2578 /// Indicates that this is the only struct which contains the same pointer.
2580 /// Rust functions which take ownership of an object provided via an argument require
2581 /// this to be true and invalidate the object pointed to by inner.
2585 impl Drop for OneHopBlindedPathCandidate {
2586 fn drop(&mut self) {
2587 if self.is_owned && !<*mut nativeOneHopBlindedPathCandidate>::is_null(self.inner) {
2588 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2592 /// Frees any resources used by the OneHopBlindedPathCandidate, if is_owned is set and inner is non-NULL.
2594 pub extern "C" fn OneHopBlindedPathCandidate_free(this_obj: OneHopBlindedPathCandidate) { }
2596 /// Used only if an object of this type is returned as a trait impl by a method
2597 pub(crate) extern "C" fn OneHopBlindedPathCandidate_free_void(this_ptr: *mut c_void) {
2598 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOneHopBlindedPathCandidate) };
2601 impl OneHopBlindedPathCandidate {
2602 pub(crate) fn get_native_ref(&self) -> &'static nativeOneHopBlindedPathCandidate {
2603 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2605 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOneHopBlindedPathCandidate {
2606 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2608 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2609 pub(crate) fn take_inner(mut self) -> *mut nativeOneHopBlindedPathCandidate {
2610 assert!(self.is_owned);
2611 let ret = ObjOps::untweak_ptr(self.inner);
2612 self.inner = core::ptr::null_mut();
2616 impl Clone for OneHopBlindedPathCandidate {
2617 fn clone(&self) -> Self {
2619 inner: if <*mut nativeOneHopBlindedPathCandidate>::is_null(self.inner) { core::ptr::null_mut() } else {
2620 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2626 /// Used only if an object of this type is returned as a trait impl by a method
2627 pub(crate) extern "C" fn OneHopBlindedPathCandidate_clone_void(this_ptr: *const c_void) -> *mut c_void {
2628 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOneHopBlindedPathCandidate)).clone() })) as *mut c_void
2631 /// Creates a copy of the OneHopBlindedPathCandidate
2632 pub extern "C" fn OneHopBlindedPathCandidate_clone(orig: &OneHopBlindedPathCandidate) -> OneHopBlindedPathCandidate {
2635 /// Get a string which allows debug introspection of a OneHopBlindedPathCandidate object
2636 pub extern "C" fn OneHopBlindedPathCandidate_debug_str_void(o: *const c_void) -> Str {
2637 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::OneHopBlindedPathCandidate }).into()}
2638 /// A wrapper around the various hop representations.
2640 /// Can be used to examine the properties of a hop,
2641 /// potentially to decide whether to include it in a route.
2645 pub enum CandidateRouteHop {
2646 /// A hop from the payer, where the outbound liquidity is known.
2648 crate::lightning::routing::router::FirstHopCandidate),
2649 /// A hop found in the [`ReadOnlyNetworkGraph`].
2651 crate::lightning::routing::router::PublicHopCandidate),
2652 /// A private hop communicated by the payee, generally via a BOLT 11 invoice.
2654 /// Because BOLT 11 route hints can take multiple hops to get to the destination, this may not
2655 /// terminate at the payee.
2657 crate::lightning::routing::router::PrivateHopCandidate),
2658 /// A blinded path which starts with an introduction point and ultimately terminates with the
2661 /// Because we don't know the payee's identity, [`CandidateRouteHop::target`] will return
2662 /// `None` in this state.
2664 /// Because blinded paths are \"all or nothing\", and we cannot use just one part of a blinded
2665 /// path, the full path is treated as a single [`CandidateRouteHop`].
2667 crate::lightning::routing::router::BlindedPathCandidate),
2668 /// Similar to [`Self::Blinded`], but the path here only has one hop.
2670 /// While we treat this similarly to [`CandidateRouteHop::Blinded`] in many respects (e.g.
2671 /// returning `None` from [`CandidateRouteHop::target`]), in this case we do actually know the
2672 /// payee's identity - it's the introduction point!
2674 /// [`BlindedPayInfo`] provided for 1-hop blinded paths is ignored because it is meant to apply
2675 /// to the hops *between* the introduction node and the destination.
2677 /// This primarily exists to track that we need to included a blinded path at the end of our
2678 /// [`Route`], even though it doesn't actually add an additional hop in the payment.
2680 crate::lightning::routing::router::OneHopBlindedPathCandidate),
2682 use lightning::routing::router::CandidateRouteHop as CandidateRouteHopImport;
2683 pub(crate) type nativeCandidateRouteHop = CandidateRouteHopImport<'static>;
2685 impl CandidateRouteHop {
2687 pub(crate) fn to_native(&self) -> nativeCandidateRouteHop {
2689 CandidateRouteHop::FirstHop (ref a, ) => {
2690 let mut a_nonref = Clone::clone(a);
2691 nativeCandidateRouteHop::FirstHop (
2692 *unsafe { Box::from_raw(a_nonref.take_inner()) },
2695 CandidateRouteHop::PublicHop (ref a, ) => {
2696 let mut a_nonref = Clone::clone(a);
2697 nativeCandidateRouteHop::PublicHop (
2698 *unsafe { Box::from_raw(a_nonref.take_inner()) },
2701 CandidateRouteHop::PrivateHop (ref a, ) => {
2702 let mut a_nonref = Clone::clone(a);
2703 nativeCandidateRouteHop::PrivateHop (
2704 *unsafe { Box::from_raw(a_nonref.take_inner()) },
2707 CandidateRouteHop::Blinded (ref a, ) => {
2708 let mut a_nonref = Clone::clone(a);
2709 nativeCandidateRouteHop::Blinded (
2710 *unsafe { Box::from_raw(a_nonref.take_inner()) },
2713 CandidateRouteHop::OneHopBlinded (ref a, ) => {
2714 let mut a_nonref = Clone::clone(a);
2715 nativeCandidateRouteHop::OneHopBlinded (
2716 *unsafe { Box::from_raw(a_nonref.take_inner()) },
2722 pub(crate) fn into_native(self) -> nativeCandidateRouteHop {
2724 CandidateRouteHop::FirstHop (mut a, ) => {
2725 nativeCandidateRouteHop::FirstHop (
2726 *unsafe { Box::from_raw(a.take_inner()) },
2729 CandidateRouteHop::PublicHop (mut a, ) => {
2730 nativeCandidateRouteHop::PublicHop (
2731 *unsafe { Box::from_raw(a.take_inner()) },
2734 CandidateRouteHop::PrivateHop (mut a, ) => {
2735 nativeCandidateRouteHop::PrivateHop (
2736 *unsafe { Box::from_raw(a.take_inner()) },
2739 CandidateRouteHop::Blinded (mut a, ) => {
2740 nativeCandidateRouteHop::Blinded (
2741 *unsafe { Box::from_raw(a.take_inner()) },
2744 CandidateRouteHop::OneHopBlinded (mut a, ) => {
2745 nativeCandidateRouteHop::OneHopBlinded (
2746 *unsafe { Box::from_raw(a.take_inner()) },
2752 pub(crate) fn from_native(native: &CandidateRouteHopImport<'_>) -> Self {
2753 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeCandidateRouteHop) };
2755 nativeCandidateRouteHop::FirstHop (ref a, ) => {
2756 let mut a_nonref = Clone::clone(a);
2757 CandidateRouteHop::FirstHop (
2758 crate::lightning::routing::router::FirstHopCandidate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
2761 nativeCandidateRouteHop::PublicHop (ref a, ) => {
2762 let mut a_nonref = Clone::clone(a);
2763 CandidateRouteHop::PublicHop (
2764 crate::lightning::routing::router::PublicHopCandidate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
2767 nativeCandidateRouteHop::PrivateHop (ref a, ) => {
2768 let mut a_nonref = Clone::clone(a);
2769 CandidateRouteHop::PrivateHop (
2770 crate::lightning::routing::router::PrivateHopCandidate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
2773 nativeCandidateRouteHop::Blinded (ref a, ) => {
2774 let mut a_nonref = Clone::clone(a);
2775 CandidateRouteHop::Blinded (
2776 crate::lightning::routing::router::BlindedPathCandidate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
2779 nativeCandidateRouteHop::OneHopBlinded (ref a, ) => {
2780 let mut a_nonref = Clone::clone(a);
2781 CandidateRouteHop::OneHopBlinded (
2782 crate::lightning::routing::router::OneHopBlindedPathCandidate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
2788 pub(crate) fn native_into(native: nativeCandidateRouteHop) -> Self {
2790 nativeCandidateRouteHop::FirstHop (mut a, ) => {
2791 CandidateRouteHop::FirstHop (
2792 crate::lightning::routing::router::FirstHopCandidate { inner: ObjOps::heap_alloc(a), is_owned: true },
2795 nativeCandidateRouteHop::PublicHop (mut a, ) => {
2796 CandidateRouteHop::PublicHop (
2797 crate::lightning::routing::router::PublicHopCandidate { inner: ObjOps::heap_alloc(a), is_owned: true },
2800 nativeCandidateRouteHop::PrivateHop (mut a, ) => {
2801 CandidateRouteHop::PrivateHop (
2802 crate::lightning::routing::router::PrivateHopCandidate { inner: ObjOps::heap_alloc(a), is_owned: true },
2805 nativeCandidateRouteHop::Blinded (mut a, ) => {
2806 CandidateRouteHop::Blinded (
2807 crate::lightning::routing::router::BlindedPathCandidate { inner: ObjOps::heap_alloc(a), is_owned: true },
2810 nativeCandidateRouteHop::OneHopBlinded (mut a, ) => {
2811 CandidateRouteHop::OneHopBlinded (
2812 crate::lightning::routing::router::OneHopBlindedPathCandidate { inner: ObjOps::heap_alloc(a), is_owned: true },
2818 /// Frees any resources used by the CandidateRouteHop
2820 pub extern "C" fn CandidateRouteHop_free(this_ptr: CandidateRouteHop) { }
2821 /// Creates a copy of the CandidateRouteHop
2823 pub extern "C" fn CandidateRouteHop_clone(orig: &CandidateRouteHop) -> CandidateRouteHop {
2827 /// Used only if an object of this type is returned as a trait impl by a method
2828 pub(crate) extern "C" fn CandidateRouteHop_clone_void(this_ptr: *const c_void) -> *mut c_void {
2829 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const CandidateRouteHop)).clone() })) as *mut c_void
2832 /// Used only if an object of this type is returned as a trait impl by a method
2833 pub(crate) extern "C" fn CandidateRouteHop_free_void(this_ptr: *mut c_void) {
2834 let _ = unsafe { Box::from_raw(this_ptr as *mut CandidateRouteHop) };
2837 /// Utility method to constructs a new FirstHop-variant CandidateRouteHop
2838 pub extern "C" fn CandidateRouteHop_first_hop(a: crate::lightning::routing::router::FirstHopCandidate) -> CandidateRouteHop {
2839 CandidateRouteHop::FirstHop(a, )
2842 /// Utility method to constructs a new PublicHop-variant CandidateRouteHop
2843 pub extern "C" fn CandidateRouteHop_public_hop(a: crate::lightning::routing::router::PublicHopCandidate) -> CandidateRouteHop {
2844 CandidateRouteHop::PublicHop(a, )
2847 /// Utility method to constructs a new PrivateHop-variant CandidateRouteHop
2848 pub extern "C" fn CandidateRouteHop_private_hop(a: crate::lightning::routing::router::PrivateHopCandidate) -> CandidateRouteHop {
2849 CandidateRouteHop::PrivateHop(a, )
2852 /// Utility method to constructs a new Blinded-variant CandidateRouteHop
2853 pub extern "C" fn CandidateRouteHop_blinded(a: crate::lightning::routing::router::BlindedPathCandidate) -> CandidateRouteHop {
2854 CandidateRouteHop::Blinded(a, )
2857 /// Utility method to constructs a new OneHopBlinded-variant CandidateRouteHop
2858 pub extern "C" fn CandidateRouteHop_one_hop_blinded(a: crate::lightning::routing::router::OneHopBlindedPathCandidate) -> CandidateRouteHop {
2859 CandidateRouteHop::OneHopBlinded(a, )
2861 /// Get a string which allows debug introspection of a CandidateRouteHop object
2862 pub extern "C" fn CandidateRouteHop_debug_str_void(o: *const c_void) -> Str {
2863 alloc::format!("{:?}", unsafe { o as *const crate::lightning::routing::router::CandidateRouteHop }).into()}
2864 /// Returns the globally unique short channel ID for this hop, if one is known.
2866 /// This only returns `Some` if the channel is public (either our own, or one we've learned
2867 /// from the public network graph), and thus the short channel ID we have for this channel is
2868 /// globally unique and identifies this channel in a global namespace.
2871 pub extern "C" fn CandidateRouteHop_globally_unique_short_channel_id(this_arg: &crate::lightning::routing::router::CandidateRouteHop) -> crate::c_types::derived::COption_u64Z {
2872 let mut ret = this_arg.to_native().globally_unique_short_channel_id();
2873 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { ret.unwrap() }) };
2877 /// Returns the required difference in HTLC CLTV expiry between the [`Self::source`] and the
2878 /// next-hop for an HTLC taking this hop.
2880 /// This is the time that the node(s) in this hop have to claim the HTLC on-chain if the
2881 /// next-hop goes on chain with a payment preimage.
2884 pub extern "C" fn CandidateRouteHop_cltv_expiry_delta(this_arg: &crate::lightning::routing::router::CandidateRouteHop) -> u32 {
2885 let mut ret = this_arg.to_native().cltv_expiry_delta();
2889 /// Returns the minimum amount that can be sent over this hop, in millisatoshis.
2892 pub extern "C" fn CandidateRouteHop_htlc_minimum_msat(this_arg: &crate::lightning::routing::router::CandidateRouteHop) -> u64 {
2893 let mut ret = this_arg.to_native().htlc_minimum_msat();
2897 /// Returns the fees that must be paid to route an HTLC over this channel.
2900 pub extern "C" fn CandidateRouteHop_fees(this_arg: &crate::lightning::routing::router::CandidateRouteHop) -> crate::lightning::routing::gossip::RoutingFees {
2901 let mut ret = this_arg.to_native().fees();
2902 crate::lightning::routing::gossip::RoutingFees { inner: ObjOps::heap_alloc(ret), is_owned: true }
2905 /// Returns the source node id of current hop.
2907 /// Source node id refers to the node forwarding the HTLC through this hop.
2909 /// For [`Self::FirstHop`] we return payer's node id.
2912 pub extern "C" fn CandidateRouteHop_source(this_arg: &crate::lightning::routing::router::CandidateRouteHop) -> crate::lightning::routing::gossip::NodeId {
2913 let mut ret = this_arg.to_native().source();
2914 crate::lightning::routing::gossip::NodeId { inner: ObjOps::heap_alloc(ret), is_owned: true }
2917 /// Returns the target node id of this hop, if known.
2919 /// Target node id refers to the node receiving the HTLC after this hop.
2921 /// For [`Self::Blinded`] we return `None` because the ultimate destination after the blinded
2922 /// path is unknown.
2924 /// For [`Self::OneHopBlinded`] we return `None` because the target is the same as the source,
2925 /// and such a return value would be somewhat nonsensical.
2927 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2930 pub extern "C" fn CandidateRouteHop_target(this_arg: &crate::lightning::routing::router::CandidateRouteHop) -> crate::lightning::routing::gossip::NodeId {
2931 let mut ret = this_arg.to_native().target();
2932 let mut local_ret = crate::lightning::routing::gossip::NodeId { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true };
2936 /// Finds a route from us (payer) to the given target node (payee).
2938 /// If the payee provided features in their invoice, they should be provided via the `payee` field
2939 /// in the given [`RouteParameters::payment_params`].
2940 /// Without this, MPP will only be used if the payee's features are available in the network graph.
2942 /// Private routing paths between a public node and the target may be included in the `payee` field
2943 /// of [`RouteParameters::payment_params`].
2945 /// If some channels aren't announced, it may be useful to fill in `first_hops` with the results
2946 /// from [`ChannelManager::list_usable_channels`]. If it is filled in, the view of these channels
2947 /// from `network_graph` will be ignored, and only those in `first_hops` will be used.
2949 /// The fees on channels from us to the next hop are ignored as they are assumed to all be equal.
2950 /// However, the enabled/disabled bit on such channels as well as the `htlc_minimum_msat` /
2951 /// `htlc_maximum_msat` *are* checked as they may change based on the receiving node.
2955 /// Panics if first_hops contains channels without `short_channel_id`s;
2956 /// [`ChannelManager::list_usable_channels`] will never include such channels.
2958 /// [`ChannelManager::list_usable_channels`]: crate::ln::channelmanager::ChannelManager::list_usable_channels
2959 /// [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
2960 /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
2962 /// Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
2964 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::ScoreLookUp, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters, random_seed_bytes: *const [u8; 32]) -> crate::c_types::derived::CResult_RouteLightningErrorZ {
2965 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[..]);
2966 let mut ret = lightning::routing::router::find_route::<crate::lightning::util::logger::Logger, crate::lightning::util::logger::Logger, crate::lightning::routing::scoring::ScoreLookUp>(&our_node_pubkey.into_rust(), route_params.get_native_ref(), network_graph.get_native_ref(), local_first_hops, logger, scorer, score_params.get_native_ref(), unsafe { &*random_seed_bytes});
2967 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() };
2971 /// Construct a route from us (payer) to the target node (payee) via the given hops (which should
2972 /// exclude the payer, but include the payee). This may be useful, e.g., for probing the chosen path.
2974 /// Re-uses logic from `find_route`, so the restrictions described there also apply here.
2976 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 {
2977 let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { item.into_rust() }); };
2978 let mut ret = lightning::routing::router::build_route_from_hops::<crate::lightning::util::logger::Logger, crate::lightning::util::logger::Logger>(&our_node_pubkey.into_rust(), &local_hops[..], route_params.get_native_ref(), network_graph.get_native_ref(), logger, unsafe { &*random_seed_bytes});
2979 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() };