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
521 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
522 RoutingFees { inner: Box::into_raw(Box::new(unsafe { &*orig.inner }.clone())), is_owned: true }
524 /// Flat routing fee in satoshis
526 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
527 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.base_msat;
530 /// Flat routing fee in satoshis
532 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
533 unsafe { &mut *this_ptr.inner }.base_msat = val;
535 /// Liquidity-based routing fee in millionths of a routed amount.
536 /// In other words, 10000 is 1%.
538 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
539 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.proportional_millionths;
542 /// Liquidity-based routing fee in millionths of a routed amount.
543 /// In other words, 10000 is 1%.
545 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
546 unsafe { &mut *this_ptr.inner }.proportional_millionths = val;
550 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
551 RoutingFees { inner: Box::into_raw(Box::new(nativeRoutingFees {
552 base_msat: base_msat_arg,
553 proportional_millionths: proportional_millionths_arg,
554 })), is_owned: true }
557 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> RoutingFees {
558 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
559 RoutingFees { inner: Box::into_raw(Box::new(res)), is_owned: true }
561 RoutingFees { inner: std::ptr::null_mut(), is_owned: true }
565 pub extern "C" fn RoutingFees_write(obj: *const RoutingFees) -> crate::c_types::derived::CVec_u8Z {
566 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
569 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
570 type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
572 /// Information received in the latest node_announcement from this node.
575 pub struct NodeAnnouncementInfo {
576 /// Nearly everywhere, inner must be non-null, however in places where
577 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
578 pub inner: *mut nativeNodeAnnouncementInfo,
582 impl Drop for NodeAnnouncementInfo {
584 if self.is_owned && !self.inner.is_null() {
585 let _ = unsafe { Box::from_raw(self.inner) };
590 pub extern "C" fn NodeAnnouncementInfo_free(this_ptr: NodeAnnouncementInfo) { }
592 /// Used only if an object of this type is returned as a trait impl by a method
593 extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
594 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
597 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
598 impl NodeAnnouncementInfo {
599 pub(crate) fn take_ptr(mut self) -> *mut nativeNodeAnnouncementInfo {
600 assert!(self.is_owned);
601 let ret = self.inner;
602 self.inner = std::ptr::null_mut();
606 /// Protocol features the node announced support for
608 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::ln::features::NodeFeatures {
609 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
610 crate::ln::features::NodeFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
612 /// Protocol features the node announced support for
614 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::features::NodeFeatures) {
615 unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_ptr()) };
617 /// When the last known update to the node state was issued.
618 /// Value is opaque, as set in the announcement.
620 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
621 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
624 /// When the last known update to the node state was issued.
625 /// Value is opaque, as set in the announcement.
627 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
628 unsafe { &mut *this_ptr.inner }.last_update = val;
630 /// Color assigned to the node
632 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
633 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.rgb;
636 /// Color assigned to the node
638 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
639 unsafe { &mut *this_ptr.inner }.rgb = val.data;
641 /// Moniker assigned to the node.
642 /// May be invalid or malicious (eg control chars),
643 /// should not be exposed to the user.
645 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
646 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.alias;
649 /// Moniker assigned to the node.
650 /// May be invalid or malicious (eg control chars),
651 /// should not be exposed to the user.
653 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
654 unsafe { &mut *this_ptr.inner }.alias = val.data;
656 /// Internet-level addresses via which one can connect to the node
658 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
659 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
660 unsafe { &mut *this_ptr.inner }.addresses = local_val;
662 /// An initial announcement of the node
663 /// Mostly redundant with the data we store in fields explicitly.
664 /// Everything else is useful only for sending out for initial routing sync.
665 /// Not stored if contains excess data to prevent DoS.
667 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::ln::msgs::NodeAnnouncement {
668 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
669 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 };
672 /// An initial announcement of the node
673 /// Mostly redundant with the data we store in fields explicitly.
674 /// Everything else is useful only for sending out for initial routing sync.
675 /// Not stored if contains excess data to prevent DoS.
677 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::msgs::NodeAnnouncement) {
678 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
679 unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
683 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 {
684 let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
685 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()) } }) };
686 NodeAnnouncementInfo { inner: Box::into_raw(Box::new(nativeNodeAnnouncementInfo {
687 features: *unsafe { Box::from_raw(features_arg.take_ptr()) },
688 last_update: last_update_arg,
690 alias: alias_arg.data,
691 addresses: local_addresses_arg,
692 announcement_message: local_announcement_message_arg,
693 })), is_owned: true }
696 pub extern "C" fn NodeAnnouncementInfo_write(obj: *const NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
697 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
700 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> NodeAnnouncementInfo {
701 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
702 NodeAnnouncementInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
704 NodeAnnouncementInfo { inner: std::ptr::null_mut(), is_owned: true }
708 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
709 type nativeNodeInfo = nativeNodeInfoImport;
711 /// Details about a node in the network, known from the network announcement.
714 pub struct NodeInfo {
715 /// Nearly everywhere, inner must be non-null, however in places where
716 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
717 pub inner: *mut nativeNodeInfo,
721 impl Drop for NodeInfo {
723 if self.is_owned && !self.inner.is_null() {
724 let _ = unsafe { Box::from_raw(self.inner) };
729 pub extern "C" fn NodeInfo_free(this_ptr: NodeInfo) { }
731 /// Used only if an object of this type is returned as a trait impl by a method
732 extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
733 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
736 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
738 pub(crate) fn take_ptr(mut self) -> *mut nativeNodeInfo {
739 assert!(self.is_owned);
740 let ret = self.inner;
741 self.inner = std::ptr::null_mut();
745 /// All valid channels a node has announced
747 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
748 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
749 unsafe { &mut *this_ptr.inner }.channels = local_val;
751 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
752 /// The two fields (flat and proportional fee) are independent,
753 /// meaning they don't have to refer to the same channel.
755 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::routing::network_graph::RoutingFees {
756 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees;
757 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 };
760 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
761 /// The two fields (flat and proportional fee) are independent,
762 /// meaning they don't have to refer to the same channel.
764 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::RoutingFees) {
765 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
766 unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees = local_val;
768 /// More information about a node from node_announcement.
769 /// Optional because we store a Node entry after learning about it from
770 /// a channel announcement, but before receiving a node announcement.
772 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::routing::network_graph::NodeAnnouncementInfo {
773 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_info;
774 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 };
777 /// More information about a node from node_announcement.
778 /// Optional because we store a Node entry after learning about it from
779 /// a channel announcement, but before receiving a node announcement.
781 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::NodeAnnouncementInfo) {
782 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
783 unsafe { &mut *this_ptr.inner }.announcement_info = local_val;
787 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 {
788 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
789 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()) } }) };
790 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()) } }) };
791 NodeInfo { inner: Box::into_raw(Box::new(nativeNodeInfo {
792 channels: local_channels_arg,
793 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
794 announcement_info: local_announcement_info_arg,
795 })), is_owned: true }
798 pub extern "C" fn NodeInfo_write(obj: *const NodeInfo) -> crate::c_types::derived::CVec_u8Z {
799 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
802 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> NodeInfo {
803 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
804 NodeInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
806 NodeInfo { inner: std::ptr::null_mut(), is_owned: true }
810 pub extern "C" fn NetworkGraph_write(obj: *const NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
811 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
814 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> NetworkGraph {
815 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
816 NetworkGraph { inner: Box::into_raw(Box::new(res)), is_owned: true }
818 NetworkGraph { inner: std::ptr::null_mut(), is_owned: true }
821 /// Creates a new, empty, network graph.
824 pub extern "C" fn NetworkGraph_new() -> crate::routing::network_graph::NetworkGraph {
825 let mut ret = lightning::routing::network_graph::NetworkGraph::new();
826 crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
829 /// Close a channel if a corresponding HTLC fail was sent.
830 /// If permanent, removes a channel from the local storage.
831 /// May cause the removal of nodes too, if this was their last channel.
832 /// If not permanent, makes channels unavailable for routing.
834 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
835 unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.close_channel_from_update(short_channel_id, is_permanent)