1 //! The top-level network map tracking logic lives here.
4 use bitcoin::hashes::Hash;
8 use lightning::routing::network_graph::NetworkGraph as nativeNetworkGraphImport;
9 type nativeNetworkGraph = nativeNetworkGraphImport;
11 /// Represents the network as nodes and channels between them
14 pub struct NetworkGraph {
15 /// Nearly everywhere, inner must be non-null, however in places where
16 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
17 pub inner: *mut nativeNetworkGraph,
21 impl Drop for NetworkGraph {
23 if self.is_owned && !self.inner.is_null() {
24 let _ = unsafe { Box::from_raw(self.inner) };
29 pub extern "C" fn NetworkGraph_free(this_ptr: NetworkGraph) { }
31 /// Used only if an object of this type is returned as a trait impl by a method
32 extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
33 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetworkGraph); }
36 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
38 pub(crate) fn take_ptr(mut self) -> *mut nativeNetworkGraph {
39 assert!(self.is_owned);
41 self.inner = std::ptr::null_mut();
46 use lightning::routing::network_graph::LockedNetworkGraph as nativeLockedNetworkGraphImport;
47 type nativeLockedNetworkGraph = nativeLockedNetworkGraphImport<'static>;
49 /// A simple newtype for RwLockReadGuard<'a, NetworkGraph>.
50 /// This exists only to make accessing a RwLock<NetworkGraph> possible from
51 /// the C bindings, as it can be done directly in Rust code.
54 pub struct LockedNetworkGraph {
55 /// Nearly everywhere, inner must be non-null, however in places where
56 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
57 pub inner: *mut nativeLockedNetworkGraph,
61 impl Drop for LockedNetworkGraph {
63 if self.is_owned && !self.inner.is_null() {
64 let _ = unsafe { Box::from_raw(self.inner) };
69 pub extern "C" fn LockedNetworkGraph_free(this_ptr: LockedNetworkGraph) { }
71 /// Used only if an object of this type is returned as a trait impl by a method
72 extern "C" fn LockedNetworkGraph_free_void(this_ptr: *mut c_void) {
73 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLockedNetworkGraph); }
76 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
77 impl LockedNetworkGraph {
78 pub(crate) fn take_ptr(mut self) -> *mut nativeLockedNetworkGraph {
79 assert!(self.is_owned);
81 self.inner = std::ptr::null_mut();
86 use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport;
87 type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport<crate::chain::Access, crate::util::logger::Logger>;
89 /// Receives and validates network updates from peers,
90 /// stores authentic and relevant data as a network graph.
91 /// This network graph is then used for routing payments.
92 /// Provides interface to help with initial routing sync by
93 /// serving historical announcements.
96 pub struct NetGraphMsgHandler {
97 /// Nearly everywhere, inner must be non-null, however in places where
98 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
99 pub inner: *mut nativeNetGraphMsgHandler,
103 impl Drop for NetGraphMsgHandler {
105 if self.is_owned && !self.inner.is_null() {
106 let _ = unsafe { Box::from_raw(self.inner) };
111 pub extern "C" fn NetGraphMsgHandler_free(this_ptr: NetGraphMsgHandler) { }
113 /// Used only if an object of this type is returned as a trait impl by a method
114 extern "C" fn NetGraphMsgHandler_free_void(this_ptr: *mut c_void) {
115 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetGraphMsgHandler); }
118 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
119 impl NetGraphMsgHandler {
120 pub(crate) fn take_ptr(mut self) -> *mut nativeNetGraphMsgHandler {
121 assert!(self.is_owned);
122 let ret = self.inner;
123 self.inner = std::ptr::null_mut();
127 /// Creates a new tracker of the actual state of the network of channels and nodes,
128 /// assuming a fresh network graph.
129 /// Chain monitor is used to make sure announced channels exist on-chain,
130 /// channel data is correct, and that the announcement is signed with
131 /// channel owners' keys.
134 pub extern "C" fn NetGraphMsgHandler_new(chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger) -> NetGraphMsgHandler {
135 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
136 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(local_chain_access, logger);
137 NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
140 /// Creates a new tracker of the actual state of the network of channels and nodes,
141 /// assuming an existing Network Graph.
144 pub extern "C" fn NetGraphMsgHandler_from_net_graph(chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger, mut network_graph: crate::routing::network_graph::NetworkGraph) -> NetGraphMsgHandler {
145 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
146 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::from_net_graph(local_chain_access, logger, *unsafe { Box::from_raw(network_graph.take_ptr()) });
147 NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
150 /// Take a read lock on the network_graph and return it in the C-bindings
151 /// newtype helper. This is likely only useful when called via the C
152 /// bindings as you can call `self.network_graph.read().unwrap()` in Rust
156 pub extern "C" fn NetGraphMsgHandler_read_locked_graph(this_arg: &NetGraphMsgHandler) -> crate::routing::network_graph::LockedNetworkGraph {
157 let mut ret = unsafe { &*this_arg.inner }.read_locked_graph();
158 crate::routing::network_graph::LockedNetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
161 /// Get a reference to the NetworkGraph which this read-lock contains.
164 pub extern "C" fn LockedNetworkGraph_graph(this_arg: &LockedNetworkGraph) -> crate::routing::network_graph::NetworkGraph {
165 let mut ret = unsafe { &*this_arg.inner }.graph();
166 crate::routing::network_graph::NetworkGraph { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
170 pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: *const NetGraphMsgHandler) -> crate::ln::msgs::RoutingMessageHandler {
171 crate::ln::msgs::RoutingMessageHandler {
172 this_arg: unsafe { (*this_arg).inner as *mut c_void },
174 handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement,
175 handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement,
176 handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update,
177 handle_htlc_fail_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update,
178 get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements,
179 get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements,
180 should_request_full_sync: NetGraphMsgHandler_RoutingMessageHandler_should_request_full_sync,
183 use lightning::ln::msgs::RoutingMessageHandler as RoutingMessageHandlerTraitImport;
185 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
186 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_node_announcement(unsafe { &*msg.inner });
187 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
191 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
192 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_channel_announcement(unsafe { &*msg.inner });
193 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
196 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, update: &crate::ln::msgs::HTLCFailChannelUpdate) {
197 unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_htlc_fail_channel_update(&update.to_native())
200 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
201 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_channel_update(unsafe { &*msg.inner });
202 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }) };
206 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements(this_arg: *const c_void, mut starting_point: u64, mut batch_amount: u8) -> crate::c_types::derived::CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ {
207 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.get_next_channel_announcements(starting_point, batch_amount);
208 let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_1 = crate::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { std::ptr::null_mut() } else { { Box::into_raw(Box::new((orig_ret_0_1.unwrap()))) } }, is_owned: true }; let mut local_orig_ret_0_2 = crate::ln::msgs::ChannelUpdate { inner: if orig_ret_0_2.is_none() { std::ptr::null_mut() } else { { Box::into_raw(Box::new((orig_ret_0_2.unwrap()))) } }, is_owned: true }; let mut local_ret_0 = (crate::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(orig_ret_0_0)), is_owned: true }, local_orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }); };
212 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements(this_arg: *const c_void, mut starting_point: crate::c_types::PublicKey, mut batch_amount: u8) -> crate::c_types::derived::CVec_NodeAnnouncementZ {
213 let mut local_starting_point_base = if starting_point.is_null() { None } else { Some( { starting_point.into_rust() }) }; let mut local_starting_point = local_starting_point_base.as_ref();
214 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.get_next_node_announcements(local_starting_point, batch_amount);
215 let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
219 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_should_request_full_sync(this_arg: *const c_void, mut _node_id: crate::c_types::PublicKey) -> bool {
220 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.should_request_full_sync(&_node_id.into_rust());
225 use lightning::routing::network_graph::DirectionalChannelInfo as nativeDirectionalChannelInfoImport;
226 type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport;
228 /// Details about one direction of a channel. Received
229 /// within a channel update.
232 pub struct DirectionalChannelInfo {
233 /// Nearly everywhere, inner must be non-null, however in places where
234 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
235 pub inner: *mut nativeDirectionalChannelInfo,
239 impl Drop for DirectionalChannelInfo {
241 if self.is_owned && !self.inner.is_null() {
242 let _ = unsafe { Box::from_raw(self.inner) };
247 pub extern "C" fn DirectionalChannelInfo_free(this_ptr: DirectionalChannelInfo) { }
249 /// Used only if an object of this type is returned as a trait impl by a method
250 extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) {
251 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectionalChannelInfo); }
254 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
255 impl DirectionalChannelInfo {
256 pub(crate) fn take_ptr(mut self) -> *mut nativeDirectionalChannelInfo {
257 assert!(self.is_owned);
258 let ret = self.inner;
259 self.inner = std::ptr::null_mut();
263 /// When the last update to the channel direction was issued.
264 /// Value is opaque, as set in the announcement.
266 pub extern "C" fn DirectionalChannelInfo_get_last_update(this_ptr: &DirectionalChannelInfo) -> u32 {
267 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
270 /// When the last update to the channel direction was issued.
271 /// Value is opaque, as set in the announcement.
273 pub extern "C" fn DirectionalChannelInfo_set_last_update(this_ptr: &mut DirectionalChannelInfo, mut val: u32) {
274 unsafe { &mut *this_ptr.inner }.last_update = val;
276 /// Whether the channel can be currently used for payments (in this one direction).
278 pub extern "C" fn DirectionalChannelInfo_get_enabled(this_ptr: &DirectionalChannelInfo) -> bool {
279 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.enabled;
282 /// Whether the channel can be currently used for payments (in this one direction).
284 pub extern "C" fn DirectionalChannelInfo_set_enabled(this_ptr: &mut DirectionalChannelInfo, mut val: bool) {
285 unsafe { &mut *this_ptr.inner }.enabled = val;
287 /// The difference in CLTV values that you must have when routing through this channel.
289 pub extern "C" fn DirectionalChannelInfo_get_cltv_expiry_delta(this_ptr: &DirectionalChannelInfo) -> u16 {
290 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta;
293 /// The difference in CLTV values that you must have when routing through this channel.
295 pub extern "C" fn DirectionalChannelInfo_set_cltv_expiry_delta(this_ptr: &mut DirectionalChannelInfo, mut val: u16) {
296 unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val;
298 /// The minimum value, which must be relayed to the next hop via the channel
300 pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &DirectionalChannelInfo) -> u64 {
301 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat;
304 /// The minimum value, which must be relayed to the next hop via the channel
306 pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) {
307 unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val;
309 /// Most recent update for the channel received from the network
310 /// Mostly redundant with the data we store in fields explicitly.
311 /// Everything else is useful only for sending out for initial routing sync.
312 /// Not stored if contains excess data to prevent DoS.
314 pub extern "C" fn DirectionalChannelInfo_get_last_update_message(this_ptr: &DirectionalChannelInfo) -> crate::ln::msgs::ChannelUpdate {
315 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update_message;
316 let mut local_inner_val = crate::ln::msgs::ChannelUpdate { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
319 /// Most recent update for the channel received from the network
320 /// Mostly redundant with the data we store in fields explicitly.
321 /// Everything else is useful only for sending out for initial routing sync.
322 /// Not stored if contains excess data to prevent DoS.
324 pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut DirectionalChannelInfo, mut val: crate::ln::msgs::ChannelUpdate) {
325 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
326 unsafe { &mut *this_ptr.inner }.last_update_message = local_val;
329 pub extern "C" fn DirectionalChannelInfo_write(obj: *const DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z {
330 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
333 pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> DirectionalChannelInfo {
334 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
335 DirectionalChannelInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
337 DirectionalChannelInfo { inner: std::ptr::null_mut(), is_owned: true }
341 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
342 type nativeChannelInfo = nativeChannelInfoImport;
344 /// Details about a channel (both directions).
345 /// Received within a channel announcement.
348 pub struct ChannelInfo {
349 /// Nearly everywhere, inner must be non-null, however in places where
350 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
351 pub inner: *mut nativeChannelInfo,
355 impl Drop for ChannelInfo {
357 if self.is_owned && !self.inner.is_null() {
358 let _ = unsafe { Box::from_raw(self.inner) };
363 pub extern "C" fn ChannelInfo_free(this_ptr: ChannelInfo) { }
365 /// Used only if an object of this type is returned as a trait impl by a method
366 extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
367 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
370 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
372 pub(crate) fn take_ptr(mut self) -> *mut nativeChannelInfo {
373 assert!(self.is_owned);
374 let ret = self.inner;
375 self.inner = std::ptr::null_mut();
379 /// Protocol features of a channel communicated during its announcement
381 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::ln::features::ChannelFeatures {
382 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
383 crate::ln::features::ChannelFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
385 /// Protocol features of a channel communicated during its announcement
387 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::ln::features::ChannelFeatures) {
388 unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_ptr()) };
390 /// Source node of the first direction of a channel
392 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
393 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_one;
394 crate::c_types::PublicKey::from_rust(&(*inner_val))
396 /// Source node of the first direction of a channel
398 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
399 unsafe { &mut *this_ptr.inner }.node_one = val.into_rust();
401 /// Details about the first direction of a channel
403 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
404 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.one_to_two;
405 let mut local_inner_val = crate::routing::network_graph::DirectionalChannelInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
408 /// Details about the first direction of a channel
410 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) {
411 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
412 unsafe { &mut *this_ptr.inner }.one_to_two = local_val;
414 /// Source node of the second direction of a channel
416 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
417 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_two;
418 crate::c_types::PublicKey::from_rust(&(*inner_val))
420 /// Source node of the second direction of a channel
422 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
423 unsafe { &mut *this_ptr.inner }.node_two = val.into_rust();
425 /// Details about the second direction of a channel
427 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
428 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.two_to_one;
429 let mut local_inner_val = crate::routing::network_graph::DirectionalChannelInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
432 /// Details about the second direction of a channel
434 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) {
435 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
436 unsafe { &mut *this_ptr.inner }.two_to_one = local_val;
438 /// An initial announcement of the channel
439 /// Mostly redundant with the data we store in fields explicitly.
440 /// Everything else is useful only for sending out for initial routing sync.
441 /// Not stored if contains excess data to prevent DoS.
443 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::ln::msgs::ChannelAnnouncement {
444 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
445 let mut local_inner_val = crate::ln::msgs::ChannelAnnouncement { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
448 /// An initial announcement of the channel
449 /// Mostly redundant with the data we store in fields explicitly.
450 /// Everything else is useful only for sending out for initial routing sync.
451 /// Not stored if contains excess data to prevent DoS.
453 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::ln::msgs::ChannelAnnouncement) {
454 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
455 unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
458 pub extern "C" fn ChannelInfo_write(obj: *const ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
459 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
462 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> ChannelInfo {
463 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
464 ChannelInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
466 ChannelInfo { inner: std::ptr::null_mut(), is_owned: true }
470 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
471 type nativeRoutingFees = nativeRoutingFeesImport;
473 /// Fees for routing via a given channel or a node
476 pub struct RoutingFees {
477 /// Nearly everywhere, inner must be non-null, however in places where
478 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
479 pub inner: *mut nativeRoutingFees,
483 impl Drop for RoutingFees {
485 if self.is_owned && !self.inner.is_null() {
486 let _ = unsafe { Box::from_raw(self.inner) };
491 pub extern "C" fn RoutingFees_free(this_ptr: RoutingFees) { }
493 /// Used only if an object of this type is returned as a trait impl by a method
494 extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
495 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
498 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
500 pub(crate) fn take_ptr(mut self) -> *mut nativeRoutingFees {
501 assert!(self.is_owned);
502 let ret = self.inner;
503 self.inner = std::ptr::null_mut();
507 impl Clone for RoutingFees {
508 fn clone(&self) -> Self {
510 inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
516 /// Used only if an object of this type is returned as a trait impl by a method
517 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
518 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
520 /// Flat routing fee in satoshis
522 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
523 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.base_msat;
526 /// Flat routing fee in satoshis
528 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
529 unsafe { &mut *this_ptr.inner }.base_msat = val;
531 /// Liquidity-based routing fee in millionths of a routed amount.
532 /// In other words, 10000 is 1%.
534 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
535 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.proportional_millionths;
538 /// Liquidity-based routing fee in millionths of a routed amount.
539 /// In other words, 10000 is 1%.
541 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
542 unsafe { &mut *this_ptr.inner }.proportional_millionths = val;
546 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
547 RoutingFees { inner: Box::into_raw(Box::new(nativeRoutingFees {
548 base_msat: base_msat_arg,
549 proportional_millionths: proportional_millionths_arg,
550 })), is_owned: true }
553 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> RoutingFees {
554 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
555 RoutingFees { inner: Box::into_raw(Box::new(res)), is_owned: true }
557 RoutingFees { inner: std::ptr::null_mut(), is_owned: true }
561 pub extern "C" fn RoutingFees_write(obj: *const RoutingFees) -> crate::c_types::derived::CVec_u8Z {
562 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
565 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
566 type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
568 /// Information received in the latest node_announcement from this node.
571 pub struct NodeAnnouncementInfo {
572 /// Nearly everywhere, inner must be non-null, however in places where
573 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
574 pub inner: *mut nativeNodeAnnouncementInfo,
578 impl Drop for NodeAnnouncementInfo {
580 if self.is_owned && !self.inner.is_null() {
581 let _ = unsafe { Box::from_raw(self.inner) };
586 pub extern "C" fn NodeAnnouncementInfo_free(this_ptr: NodeAnnouncementInfo) { }
588 /// Used only if an object of this type is returned as a trait impl by a method
589 extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
590 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
593 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
594 impl NodeAnnouncementInfo {
595 pub(crate) fn take_ptr(mut self) -> *mut nativeNodeAnnouncementInfo {
596 assert!(self.is_owned);
597 let ret = self.inner;
598 self.inner = std::ptr::null_mut();
602 /// Protocol features the node announced support for
604 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::ln::features::NodeFeatures {
605 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
606 crate::ln::features::NodeFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
608 /// Protocol features the node announced support for
610 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::features::NodeFeatures) {
611 unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_ptr()) };
613 /// When the last known update to the node state was issued.
614 /// Value is opaque, as set in the announcement.
616 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
617 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
620 /// When the last known update to the node state was issued.
621 /// Value is opaque, as set in the announcement.
623 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
624 unsafe { &mut *this_ptr.inner }.last_update = val;
626 /// Color assigned to the node
628 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
629 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.rgb;
632 /// Color assigned to the node
634 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
635 unsafe { &mut *this_ptr.inner }.rgb = val.data;
637 /// Moniker assigned to the node.
638 /// May be invalid or malicious (eg control chars),
639 /// should not be exposed to the user.
641 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
642 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.alias;
645 /// Moniker assigned to the node.
646 /// May be invalid or malicious (eg control chars),
647 /// should not be exposed to the user.
649 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
650 unsafe { &mut *this_ptr.inner }.alias = val.data;
652 /// Internet-level addresses via which one can connect to the node
654 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
655 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
656 unsafe { &mut *this_ptr.inner }.addresses = local_val;
658 /// An initial announcement of the node
659 /// Mostly redundant with the data we store in fields explicitly.
660 /// Everything else is useful only for sending out for initial routing sync.
661 /// Not stored if contains excess data to prevent DoS.
663 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::ln::msgs::NodeAnnouncement {
664 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
665 let mut local_inner_val = crate::ln::msgs::NodeAnnouncement { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
668 /// An initial announcement of the node
669 /// Mostly redundant with the data we store in fields explicitly.
670 /// Everything else is useful only for sending out for initial routing sync.
671 /// Not stored if contains excess data to prevent DoS.
673 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::msgs::NodeAnnouncement) {
674 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
675 unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
679 pub extern "C" fn NodeAnnouncementInfo_new(mut features_arg: crate::ln::features::NodeFeatures, mut last_update_arg: u32, mut rgb_arg: crate::c_types::ThreeBytes, mut alias_arg: crate::c_types::ThirtyTwoBytes, mut addresses_arg: crate::c_types::derived::CVec_NetAddressZ, mut announcement_message_arg: crate::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo {
680 let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
681 let mut local_announcement_message_arg = if announcement_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_message_arg.take_ptr()) } }) };
682 NodeAnnouncementInfo { inner: Box::into_raw(Box::new(nativeNodeAnnouncementInfo {
683 features: *unsafe { Box::from_raw(features_arg.take_ptr()) },
684 last_update: last_update_arg,
686 alias: alias_arg.data,
687 addresses: local_addresses_arg,
688 announcement_message: local_announcement_message_arg,
689 })), is_owned: true }
692 pub extern "C" fn NodeAnnouncementInfo_write(obj: *const NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
693 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
696 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> NodeAnnouncementInfo {
697 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
698 NodeAnnouncementInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
700 NodeAnnouncementInfo { inner: std::ptr::null_mut(), is_owned: true }
704 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
705 type nativeNodeInfo = nativeNodeInfoImport;
707 /// Details about a node in the network, known from the network announcement.
710 pub struct NodeInfo {
711 /// Nearly everywhere, inner must be non-null, however in places where
712 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
713 pub inner: *mut nativeNodeInfo,
717 impl Drop for NodeInfo {
719 if self.is_owned && !self.inner.is_null() {
720 let _ = unsafe { Box::from_raw(self.inner) };
725 pub extern "C" fn NodeInfo_free(this_ptr: NodeInfo) { }
727 /// Used only if an object of this type is returned as a trait impl by a method
728 extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
729 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
732 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
734 pub(crate) fn take_ptr(mut self) -> *mut nativeNodeInfo {
735 assert!(self.is_owned);
736 let ret = self.inner;
737 self.inner = std::ptr::null_mut();
741 /// All valid channels a node has announced
743 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
744 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
745 unsafe { &mut *this_ptr.inner }.channels = local_val;
747 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
748 /// The two fields (flat and proportional fee) are independent,
749 /// meaning they don't have to refer to the same channel.
751 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::routing::network_graph::RoutingFees {
752 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees;
753 let mut local_inner_val = crate::routing::network_graph::RoutingFees { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
756 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
757 /// The two fields (flat and proportional fee) are independent,
758 /// meaning they don't have to refer to the same channel.
760 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::RoutingFees) {
761 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
762 unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees = local_val;
764 /// More information about a node from node_announcement.
765 /// Optional because we store a Node entry after learning about it from
766 /// a channel announcement, but before receiving a node announcement.
768 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::routing::network_graph::NodeAnnouncementInfo {
769 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_info;
770 let mut local_inner_val = crate::routing::network_graph::NodeAnnouncementInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
773 /// More information about a node from node_announcement.
774 /// Optional because we store a Node entry after learning about it from
775 /// a channel announcement, but before receiving a node announcement.
777 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::NodeAnnouncementInfo) {
778 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
779 unsafe { &mut *this_ptr.inner }.announcement_info = local_val;
783 pub extern "C" fn NodeInfo_new(mut channels_arg: crate::c_types::derived::CVec_u64Z, mut lowest_inbound_channel_fees_arg: crate::routing::network_graph::RoutingFees, mut announcement_info_arg: crate::routing::network_graph::NodeAnnouncementInfo) -> NodeInfo {
784 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
785 let mut local_lowest_inbound_channel_fees_arg = if lowest_inbound_channel_fees_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(lowest_inbound_channel_fees_arg.take_ptr()) } }) };
786 let mut local_announcement_info_arg = if announcement_info_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_info_arg.take_ptr()) } }) };
787 NodeInfo { inner: Box::into_raw(Box::new(nativeNodeInfo {
788 channels: local_channels_arg,
789 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
790 announcement_info: local_announcement_info_arg,
791 })), is_owned: true }
794 pub extern "C" fn NodeInfo_write(obj: *const NodeInfo) -> crate::c_types::derived::CVec_u8Z {
795 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
798 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> NodeInfo {
799 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
800 NodeInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
802 NodeInfo { inner: std::ptr::null_mut(), is_owned: true }
806 pub extern "C" fn NetworkGraph_write(obj: *const NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
807 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
810 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> NetworkGraph {
811 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
812 NetworkGraph { inner: Box::into_raw(Box::new(res)), is_owned: true }
814 NetworkGraph { inner: std::ptr::null_mut(), is_owned: true }
817 /// Creates a new, empty, network graph.
820 pub extern "C" fn NetworkGraph_new() -> crate::routing::network_graph::NetworkGraph {
821 let mut ret = lightning::routing::network_graph::NetworkGraph::new();
822 crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
825 /// Close a channel if a corresponding HTLC fail was sent.
826 /// If permanent, removes a channel from the local storage.
827 /// May cause the removal of nodes too, if this was their last channel.
828 /// If not permanent, makes channels unavailable for routing.
830 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
831 unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.close_channel_from_update(short_channel_id, is_permanent)