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 everyhwere, 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 everyhwere, 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::chaininterface::ChainWatchInterface, 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 everyhwere, 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(mut chain_monitor: crate::chain::chaininterface::ChainWatchInterface, mut logger: crate::util::logger::Logger) -> NetGraphMsgHandler {
135 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(chain_monitor, logger);
136 NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
139 /// Creates a new tracker of the actual state of the network of channels and nodes,
140 /// assuming an existing Network Graph.
143 pub extern "C" fn NetGraphMsgHandler_from_net_graph(mut chain_monitor: crate::chain::chaininterface::ChainWatchInterface, mut logger: crate::util::logger::Logger, mut network_graph: crate::routing::network_graph::NetworkGraph) -> NetGraphMsgHandler {
144 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::from_net_graph(chain_monitor, logger, *unsafe { Box::from_raw(network_graph.take_ptr()) });
145 NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
148 /// Take a read lock on the network_graph and return it in the C-bindings
149 /// newtype helper. This is likely only useful when called via the C
150 /// bindings as you can call `self.network_graph.read().unwrap()` in Rust
154 pub extern "C" fn NetGraphMsgHandler_read_locked_graph(this_arg: &NetGraphMsgHandler) -> crate::routing::network_graph::LockedNetworkGraph {
155 let mut ret = unsafe { &*this_arg.inner }.read_locked_graph();
156 crate::routing::network_graph::LockedNetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
159 /// Get a reference to the NetworkGraph which this read-lock contains.
162 pub extern "C" fn LockedNetworkGraph_graph(this_arg: &LockedNetworkGraph) -> crate::routing::network_graph::NetworkGraph {
163 let mut ret = unsafe { &*this_arg.inner }.graph();
164 crate::routing::network_graph::NetworkGraph { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
168 pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: *const NetGraphMsgHandler) -> crate::ln::msgs::RoutingMessageHandler {
169 crate::ln::msgs::RoutingMessageHandler {
170 this_arg: unsafe { (*this_arg).inner as *mut c_void },
172 handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement,
173 handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement,
174 handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update,
175 handle_htlc_fail_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update,
176 get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements,
177 get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements,
178 should_request_full_sync: NetGraphMsgHandler_RoutingMessageHandler_should_request_full_sync,
181 use lightning::ln::msgs::RoutingMessageHandler as RoutingMessageHandlerTraitImport;
183 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
184 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_node_announcement(unsafe { &*msg.inner });
185 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 } }) };
189 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
190 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_channel_announcement(unsafe { &*msg.inner });
191 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 } }) };
194 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, update: &crate::ln::msgs::HTLCFailChannelUpdate) {
195 unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_htlc_fail_channel_update(&update.to_native())
198 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
199 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_channel_update(unsafe { &*msg.inner });
200 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 } }) };
204 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 {
205 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.get_next_channel_announcements(starting_point, batch_amount);
206 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 }); };
210 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 {
211 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();
212 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.get_next_node_announcements(local_starting_point, batch_amount);
213 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 } }); };
217 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_should_request_full_sync(this_arg: *const c_void, _node_id: crate::c_types::PublicKey) -> bool {
218 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.should_request_full_sync(&_node_id.into_rust());
223 use lightning::routing::network_graph::DirectionalChannelInfo as nativeDirectionalChannelInfoImport;
224 type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport;
226 /// Details about one direction of a channel. Received
227 /// within a channel update.
230 pub struct DirectionalChannelInfo {
231 /// Nearly everyhwere, inner must be non-null, however in places where
232 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
233 pub inner: *mut nativeDirectionalChannelInfo,
237 impl Drop for DirectionalChannelInfo {
239 if self.is_owned && !self.inner.is_null() {
240 let _ = unsafe { Box::from_raw(self.inner) };
245 pub extern "C" fn DirectionalChannelInfo_free(this_ptr: DirectionalChannelInfo) { }
247 /// Used only if an object of this type is returned as a trait impl by a method
248 extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) {
249 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectionalChannelInfo); }
252 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
253 impl DirectionalChannelInfo {
254 pub(crate) fn take_ptr(mut self) -> *mut nativeDirectionalChannelInfo {
255 assert!(self.is_owned);
256 let ret = self.inner;
257 self.inner = std::ptr::null_mut();
261 /// When the last update to the channel direction was issued.
262 /// Value is opaque, as set in the announcement.
264 pub extern "C" fn DirectionalChannelInfo_get_last_update(this_ptr: &DirectionalChannelInfo) -> u32 {
265 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
268 /// When the last update to the channel direction was issued.
269 /// Value is opaque, as set in the announcement.
271 pub extern "C" fn DirectionalChannelInfo_set_last_update(this_ptr: &mut DirectionalChannelInfo, mut val: u32) {
272 unsafe { &mut *this_ptr.inner }.last_update = val;
274 /// Whether the channel can be currently used for payments (in this one direction).
276 pub extern "C" fn DirectionalChannelInfo_get_enabled(this_ptr: &DirectionalChannelInfo) -> bool {
277 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.enabled;
280 /// Whether the channel can be currently used for payments (in this one direction).
282 pub extern "C" fn DirectionalChannelInfo_set_enabled(this_ptr: &mut DirectionalChannelInfo, mut val: bool) {
283 unsafe { &mut *this_ptr.inner }.enabled = val;
285 /// The difference in CLTV values that you must have when routing through this channel.
287 pub extern "C" fn DirectionalChannelInfo_get_cltv_expiry_delta(this_ptr: &DirectionalChannelInfo) -> u16 {
288 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta;
291 /// The difference in CLTV values that you must have when routing through this channel.
293 pub extern "C" fn DirectionalChannelInfo_set_cltv_expiry_delta(this_ptr: &mut DirectionalChannelInfo, mut val: u16) {
294 unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val;
296 /// The minimum value, which must be relayed to the next hop via the channel
298 pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &DirectionalChannelInfo) -> u64 {
299 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat;
302 /// The minimum value, which must be relayed to the next hop via the channel
304 pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) {
305 unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val;
307 /// Most recent update for the channel received from the network
308 /// Mostly redundant with the data we store in fields explicitly.
309 /// Everything else is useful only for sending out for initial routing sync.
310 /// Not stored if contains excess data to prevent DoS.
312 pub extern "C" fn DirectionalChannelInfo_get_last_update_message(this_ptr: &DirectionalChannelInfo) -> crate::ln::msgs::ChannelUpdate {
313 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update_message;
314 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 };
317 /// Most recent update for the channel received from the network
318 /// Mostly redundant with the data we store in fields explicitly.
319 /// Everything else is useful only for sending out for initial routing sync.
320 /// Not stored if contains excess data to prevent DoS.
322 pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut DirectionalChannelInfo, mut val: crate::ln::msgs::ChannelUpdate) {
323 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
324 unsafe { &mut *this_ptr.inner }.last_update_message = local_val;
327 pub extern "C" fn DirectionalChannelInfo_write(obj: *const DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z {
328 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
331 pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> DirectionalChannelInfo {
332 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
333 DirectionalChannelInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
335 DirectionalChannelInfo { inner: std::ptr::null_mut(), is_owned: true }
339 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
340 type nativeChannelInfo = nativeChannelInfoImport;
342 /// Details about a channel (both directions).
343 /// Received within a channel announcement.
346 pub struct ChannelInfo {
347 /// Nearly everyhwere, inner must be non-null, however in places where
348 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
349 pub inner: *mut nativeChannelInfo,
353 impl Drop for ChannelInfo {
355 if self.is_owned && !self.inner.is_null() {
356 let _ = unsafe { Box::from_raw(self.inner) };
361 pub extern "C" fn ChannelInfo_free(this_ptr: ChannelInfo) { }
363 /// Used only if an object of this type is returned as a trait impl by a method
364 extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
365 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
368 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
370 pub(crate) fn take_ptr(mut self) -> *mut nativeChannelInfo {
371 assert!(self.is_owned);
372 let ret = self.inner;
373 self.inner = std::ptr::null_mut();
377 /// Source node of the first direction of a channel
379 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
380 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_one;
381 crate::c_types::PublicKey::from_rust(&(*inner_val))
383 /// Source node of the first direction of a channel
385 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
386 unsafe { &mut *this_ptr.inner }.node_one = val.into_rust();
388 /// Details about the first direction of a channel
390 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
391 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.one_to_two;
392 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 };
395 /// Details about the first direction of a channel
397 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) {
398 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
399 unsafe { &mut *this_ptr.inner }.one_to_two = local_val;
401 /// Source node of the second direction of a channel
403 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
404 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_two;
405 crate::c_types::PublicKey::from_rust(&(*inner_val))
407 /// Source node of the second direction of a channel
409 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
410 unsafe { &mut *this_ptr.inner }.node_two = val.into_rust();
412 /// Details about the second direction of a channel
414 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
415 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.two_to_one;
416 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 };
419 /// Details about the second direction of a channel
421 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) {
422 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
423 unsafe { &mut *this_ptr.inner }.two_to_one = local_val;
425 /// An initial announcement of the channel
426 /// Mostly redundant with the data we store in fields explicitly.
427 /// Everything else is useful only for sending out for initial routing sync.
428 /// Not stored if contains excess data to prevent DoS.
430 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::ln::msgs::ChannelAnnouncement {
431 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
432 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 };
435 /// An initial announcement of the channel
436 /// Mostly redundant with the data we store in fields explicitly.
437 /// Everything else is useful only for sending out for initial routing sync.
438 /// Not stored if contains excess data to prevent DoS.
440 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::ln::msgs::ChannelAnnouncement) {
441 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
442 unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
445 pub extern "C" fn ChannelInfo_write(obj: *const ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
446 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
449 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> ChannelInfo {
450 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
451 ChannelInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
453 ChannelInfo { inner: std::ptr::null_mut(), is_owned: true }
457 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
458 type nativeRoutingFees = nativeRoutingFeesImport;
460 /// Fees for routing via a given channel or a node
463 pub struct RoutingFees {
464 /// Nearly everyhwere, inner must be non-null, however in places where
465 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
466 pub inner: *mut nativeRoutingFees,
470 impl Drop for RoutingFees {
472 if self.is_owned && !self.inner.is_null() {
473 let _ = unsafe { Box::from_raw(self.inner) };
478 pub extern "C" fn RoutingFees_free(this_ptr: RoutingFees) { }
480 /// Used only if an object of this type is returned as a trait impl by a method
481 extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
482 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
485 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
487 pub(crate) fn take_ptr(mut self) -> *mut nativeRoutingFees {
488 assert!(self.is_owned);
489 let ret = self.inner;
490 self.inner = std::ptr::null_mut();
494 impl Clone for RoutingFees {
495 fn clone(&self) -> Self {
497 inner: Box::into_raw(Box::new(unsafe { &*self.inner }.clone())),
503 /// Used only if an object of this type is returned as a trait impl by a method
504 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
505 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
507 /// Flat routing fee in satoshis
509 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
510 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.base_msat;
513 /// Flat routing fee in satoshis
515 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
516 unsafe { &mut *this_ptr.inner }.base_msat = val;
518 /// Liquidity-based routing fee in millionths of a routed amount.
519 /// In other words, 10000 is 1%.
521 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
522 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.proportional_millionths;
525 /// Liquidity-based routing fee in millionths of a routed amount.
526 /// In other words, 10000 is 1%.
528 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
529 unsafe { &mut *this_ptr.inner }.proportional_millionths = val;
533 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
534 RoutingFees { inner: Box::into_raw(Box::new(nativeRoutingFees {
535 base_msat: base_msat_arg,
536 proportional_millionths: proportional_millionths_arg,
537 })), is_owned: true }
540 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> RoutingFees {
541 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
542 RoutingFees { inner: Box::into_raw(Box::new(res)), is_owned: true }
544 RoutingFees { inner: std::ptr::null_mut(), is_owned: true }
548 pub extern "C" fn RoutingFees_write(obj: *const RoutingFees) -> crate::c_types::derived::CVec_u8Z {
549 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
552 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
553 type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
555 /// Information received in the latest node_announcement from this node.
558 pub struct NodeAnnouncementInfo {
559 /// Nearly everyhwere, inner must be non-null, however in places where
560 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
561 pub inner: *mut nativeNodeAnnouncementInfo,
565 impl Drop for NodeAnnouncementInfo {
567 if self.is_owned && !self.inner.is_null() {
568 let _ = unsafe { Box::from_raw(self.inner) };
573 pub extern "C" fn NodeAnnouncementInfo_free(this_ptr: NodeAnnouncementInfo) { }
575 /// Used only if an object of this type is returned as a trait impl by a method
576 extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
577 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
580 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
581 impl NodeAnnouncementInfo {
582 pub(crate) fn take_ptr(mut self) -> *mut nativeNodeAnnouncementInfo {
583 assert!(self.is_owned);
584 let ret = self.inner;
585 self.inner = std::ptr::null_mut();
589 /// When the last known update to the node state was issued.
590 /// Value is opaque, as set in the announcement.
592 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
593 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
596 /// When the last known update to the node state was issued.
597 /// Value is opaque, as set in the announcement.
599 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
600 unsafe { &mut *this_ptr.inner }.last_update = val;
602 /// Color assigned to the node
604 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
605 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.rgb;
608 /// Color assigned to the node
610 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
611 unsafe { &mut *this_ptr.inner }.rgb = val.data;
613 /// Moniker assigned to the node.
614 /// May be invalid or malicious (eg control chars),
615 /// should not be exposed to the user.
617 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
618 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.alias;
621 /// Moniker assigned to the node.
622 /// May be invalid or malicious (eg control chars),
623 /// should not be exposed to the user.
625 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
626 unsafe { &mut *this_ptr.inner }.alias = val.data;
628 /// Internet-level addresses via which one can connect to the node
630 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
631 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
632 unsafe { &mut *this_ptr.inner }.addresses = local_val;
634 /// An initial announcement of the node
635 /// Mostly redundant with the data we store in fields explicitly.
636 /// Everything else is useful only for sending out for initial routing sync.
637 /// Not stored if contains excess data to prevent DoS.
639 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::ln::msgs::NodeAnnouncement {
640 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
641 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 };
644 /// An initial announcement of the node
645 /// Mostly redundant with the data we store in fields explicitly.
646 /// Everything else is useful only for sending out for initial routing sync.
647 /// Not stored if contains excess data to prevent DoS.
649 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::msgs::NodeAnnouncement) {
650 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
651 unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
654 pub extern "C" fn NodeAnnouncementInfo_write(obj: *const NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
655 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
658 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> NodeAnnouncementInfo {
659 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
660 NodeAnnouncementInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
662 NodeAnnouncementInfo { inner: std::ptr::null_mut(), is_owned: true }
666 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
667 type nativeNodeInfo = nativeNodeInfoImport;
669 /// Details about a node in the network, known from the network announcement.
672 pub struct NodeInfo {
673 /// Nearly everyhwere, inner must be non-null, however in places where
674 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
675 pub inner: *mut nativeNodeInfo,
679 impl Drop for NodeInfo {
681 if self.is_owned && !self.inner.is_null() {
682 let _ = unsafe { Box::from_raw(self.inner) };
687 pub extern "C" fn NodeInfo_free(this_ptr: NodeInfo) { }
689 /// Used only if an object of this type is returned as a trait impl by a method
690 extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
691 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
694 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
696 pub(crate) fn take_ptr(mut self) -> *mut nativeNodeInfo {
697 assert!(self.is_owned);
698 let ret = self.inner;
699 self.inner = std::ptr::null_mut();
703 /// All valid channels a node has announced
705 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
706 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
707 unsafe { &mut *this_ptr.inner }.channels = local_val;
709 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
710 /// The two fields (flat and proportional fee) are independent,
711 /// meaning they don't have to refer to the same channel.
713 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::routing::network_graph::RoutingFees {
714 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees;
715 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 };
718 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
719 /// The two fields (flat and proportional fee) are independent,
720 /// meaning they don't have to refer to the same channel.
722 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::RoutingFees) {
723 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
724 unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees = local_val;
726 /// More information about a node from node_announcement.
727 /// Optional because we store a Node entry after learning about it from
728 /// a channel announcement, but before receiving a node announcement.
730 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::routing::network_graph::NodeAnnouncementInfo {
731 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_info;
732 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 };
735 /// More information about a node from node_announcement.
736 /// Optional because we store a Node entry after learning about it from
737 /// a channel announcement, but before receiving a node announcement.
739 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::NodeAnnouncementInfo) {
740 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_ptr()) } }) };
741 unsafe { &mut *this_ptr.inner }.announcement_info = local_val;
745 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 {
746 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
747 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()) } }) };
748 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()) } }) };
749 NodeInfo { inner: Box::into_raw(Box::new(nativeNodeInfo {
750 channels: local_channels_arg,
751 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
752 announcement_info: local_announcement_info_arg,
753 })), is_owned: true }
756 pub extern "C" fn NodeInfo_write(obj: *const NodeInfo) -> crate::c_types::derived::CVec_u8Z {
757 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
760 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> NodeInfo {
761 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
762 NodeInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
764 NodeInfo { inner: std::ptr::null_mut(), is_owned: true }
768 pub extern "C" fn NetworkGraph_write(obj: *const NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
769 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
772 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> NetworkGraph {
773 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
774 NetworkGraph { inner: Box::into_raw(Box::new(res)), is_owned: true }
776 NetworkGraph { inner: std::ptr::null_mut(), is_owned: true }
779 /// Creates a new, empty, network graph.
782 pub extern "C" fn NetworkGraph_new() -> crate::routing::network_graph::NetworkGraph {
783 let mut ret = lightning::routing::network_graph::NetworkGraph::new();
784 crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
787 /// Close a channel if a corresponding HTLC fail was sent.
788 /// If permanent, removes a channel from the local storage.
789 /// May cause the removal of nodes too, if this was their last channel.
790 /// If not permanent, makes channels unavailable for routing.
792 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
793 unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.close_channel_from_update(short_channel_id, is_permanent)