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 && !<*mut nativeNetworkGraph>::is_null(self.inner) {
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_inner(mut self) -> *mut nativeNetworkGraph {
39 assert!(self.is_owned);
41 self.inner = std::ptr::null_mut();
45 impl Clone for NetworkGraph {
46 fn clone(&self) -> Self {
48 inner: if <*mut nativeNetworkGraph>::is_null(self.inner) { std::ptr::null_mut() } else {
49 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
55 /// Used only if an object of this type is returned as a trait impl by a method
56 pub(crate) extern "C" fn NetworkGraph_clone_void(this_ptr: *const c_void) -> *mut c_void {
57 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNetworkGraph)).clone() })) as *mut c_void
60 pub extern "C" fn NetworkGraph_clone(orig: &NetworkGraph) -> NetworkGraph {
64 use lightning::routing::network_graph::LockedNetworkGraph as nativeLockedNetworkGraphImport;
65 type nativeLockedNetworkGraph = nativeLockedNetworkGraphImport<'static>;
67 /// A simple newtype for RwLockReadGuard<'a, NetworkGraph>.
68 /// This exists only to make accessing a RwLock<NetworkGraph> possible from
69 /// the C bindings, as it can be done directly in Rust code.
72 pub struct LockedNetworkGraph {
73 /// Nearly everywhere, inner must be non-null, however in places where
74 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
75 pub inner: *mut nativeLockedNetworkGraph,
79 impl Drop for LockedNetworkGraph {
81 if self.is_owned && !<*mut nativeLockedNetworkGraph>::is_null(self.inner) {
82 let _ = unsafe { Box::from_raw(self.inner) };
87 pub extern "C" fn LockedNetworkGraph_free(this_ptr: LockedNetworkGraph) { }
89 /// Used only if an object of this type is returned as a trait impl by a method
90 extern "C" fn LockedNetworkGraph_free_void(this_ptr: *mut c_void) {
91 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLockedNetworkGraph); }
94 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
95 impl LockedNetworkGraph {
96 pub(crate) fn take_inner(mut self) -> *mut nativeLockedNetworkGraph {
97 assert!(self.is_owned);
99 self.inner = std::ptr::null_mut();
104 use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport;
105 type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport<crate::chain::Access, crate::util::logger::Logger>;
107 /// Receives and validates network updates from peers,
108 /// stores authentic and relevant data as a network graph.
109 /// This network graph is then used for routing payments.
110 /// Provides interface to help with initial routing sync by
111 /// serving historical announcements.
114 pub struct NetGraphMsgHandler {
115 /// Nearly everywhere, inner must be non-null, however in places where
116 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
117 pub inner: *mut nativeNetGraphMsgHandler,
121 impl Drop for NetGraphMsgHandler {
123 if self.is_owned && !<*mut nativeNetGraphMsgHandler>::is_null(self.inner) {
124 let _ = unsafe { Box::from_raw(self.inner) };
129 pub extern "C" fn NetGraphMsgHandler_free(this_ptr: NetGraphMsgHandler) { }
131 /// Used only if an object of this type is returned as a trait impl by a method
132 extern "C" fn NetGraphMsgHandler_free_void(this_ptr: *mut c_void) {
133 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetGraphMsgHandler); }
136 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
137 impl NetGraphMsgHandler {
138 pub(crate) fn take_inner(mut self) -> *mut nativeNetGraphMsgHandler {
139 assert!(self.is_owned);
140 let ret = self.inner;
141 self.inner = std::ptr::null_mut();
145 /// Creates a new tracker of the actual state of the network of channels and nodes,
146 /// assuming a fresh network graph.
147 /// Chain monitor is used to make sure announced channels exist on-chain,
148 /// channel data is correct, and that the announcement is signed with
149 /// channel owners' keys.
152 pub extern "C" fn NetGraphMsgHandler_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes, chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger) -> NetGraphMsgHandler {
153 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
154 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap(), local_chain_access, logger);
155 NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
158 /// Creates a new tracker of the actual state of the network of channels and nodes,
159 /// assuming an existing Network Graph.
162 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 {
163 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
164 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::from_net_graph(local_chain_access, logger, *unsafe { Box::from_raw(network_graph.take_inner()) });
165 NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
168 /// Adds a provider used to check new announcements. Does not affect
169 /// existing announcements unless they are updated.
170 /// Add, update or remove the provider would replace the current one.
172 pub extern "C" fn NetGraphMsgHandler_add_chain_access(this_arg: &mut NetGraphMsgHandler, chain_access: *mut crate::chain::Access) {
173 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
174 unsafe { &mut (*(this_arg.inner as *mut nativeNetGraphMsgHandler)) }.add_chain_access(local_chain_access)
177 /// Take a read lock on the network_graph and return it in the C-bindings
178 /// newtype helper. This is likely only useful when called via the C
179 /// bindings as you can call `self.network_graph.read().unwrap()` in Rust
183 pub extern "C" fn NetGraphMsgHandler_read_locked_graph(this_arg: &NetGraphMsgHandler) -> crate::routing::network_graph::LockedNetworkGraph {
184 let mut ret = unsafe { &*this_arg.inner }.read_locked_graph();
185 crate::routing::network_graph::LockedNetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
188 /// Get a reference to the NetworkGraph which this read-lock contains.
191 pub extern "C" fn LockedNetworkGraph_graph(this_arg: &LockedNetworkGraph) -> crate::routing::network_graph::NetworkGraph {
192 let mut ret = unsafe { &*this_arg.inner }.graph();
193 crate::routing::network_graph::NetworkGraph { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
196 impl From<nativeNetGraphMsgHandler> for crate::ln::msgs::RoutingMessageHandler {
197 fn from(obj: nativeNetGraphMsgHandler) -> Self {
198 let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
199 let mut ret = NetGraphMsgHandler_as_RoutingMessageHandler(&rust_obj);
200 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
201 rust_obj.inner = std::ptr::null_mut();
202 ret.free = Some(NetGraphMsgHandler_free_void);
207 pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: &NetGraphMsgHandler) -> crate::ln::msgs::RoutingMessageHandler {
208 crate::ln::msgs::RoutingMessageHandler {
209 this_arg: unsafe { (*this_arg).inner as *mut c_void },
211 handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement,
212 handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement,
213 handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update,
214 handle_htlc_fail_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update,
215 get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements,
216 get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements,
217 sync_routing_table: NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table,
218 handle_reply_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range,
219 handle_reply_short_channel_ids_end: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
220 handle_query_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range,
221 handle_query_short_channel_ids: NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids,
222 MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider {
223 this_arg: unsafe { (*this_arg).inner as *mut c_void },
225 get_and_clear_pending_msg_events: NetGraphMsgHandler_RoutingMessageHandler_get_and_clear_pending_msg_events,
231 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
232 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner });
233 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
237 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
238 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner });
239 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
242 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, update: &crate::ln::msgs::HTLCFailChannelUpdate) {
243 <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_htlc_fail_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &update.to_native())
246 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
247 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner });
248 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
252 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 {
253 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, starting_point, batch_amount);
254 let mut local_ret = Vec::new(); for mut 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 }); };
258 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 {
259 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();
260 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, local_starting_point, batch_amount);
261 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
264 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init_msg: &crate::ln::msgs::Init) {
265 <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::sync_routing_table(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), unsafe { &*init_msg.inner })
268 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
269 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_reply_channel_range(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
270 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
274 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
275 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_reply_short_channel_ids_end(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
276 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
280 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
281 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_query_channel_range(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) });
282 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
286 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
287 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_query_short_channel_ids(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) });
288 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
292 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
293 let mut ret = <nativeNetGraphMsgHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, );
294 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
298 impl From<nativeNetGraphMsgHandler> for crate::util::events::MessageSendEventsProvider {
299 fn from(obj: nativeNetGraphMsgHandler) -> Self {
300 let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
301 let mut ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&rust_obj);
302 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
303 rust_obj.inner = std::ptr::null_mut();
304 ret.free = Some(NetGraphMsgHandler_free_void);
309 pub extern "C" fn NetGraphMsgHandler_as_MessageSendEventsProvider(this_arg: &NetGraphMsgHandler) -> crate::util::events::MessageSendEventsProvider {
310 crate::util::events::MessageSendEventsProvider {
311 this_arg: unsafe { (*this_arg).inner as *mut c_void },
313 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
318 extern "C" fn NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
319 let mut ret = <nativeNetGraphMsgHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, );
320 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
325 use lightning::routing::network_graph::DirectionalChannelInfo as nativeDirectionalChannelInfoImport;
326 type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport;
328 /// Details about one direction of a channel. Received
329 /// within a channel update.
332 pub struct DirectionalChannelInfo {
333 /// Nearly everywhere, inner must be non-null, however in places where
334 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
335 pub inner: *mut nativeDirectionalChannelInfo,
339 impl Drop for DirectionalChannelInfo {
341 if self.is_owned && !<*mut nativeDirectionalChannelInfo>::is_null(self.inner) {
342 let _ = unsafe { Box::from_raw(self.inner) };
347 pub extern "C" fn DirectionalChannelInfo_free(this_ptr: DirectionalChannelInfo) { }
349 /// Used only if an object of this type is returned as a trait impl by a method
350 extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) {
351 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectionalChannelInfo); }
354 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
355 impl DirectionalChannelInfo {
356 pub(crate) fn take_inner(mut self) -> *mut nativeDirectionalChannelInfo {
357 assert!(self.is_owned);
358 let ret = self.inner;
359 self.inner = std::ptr::null_mut();
363 /// When the last update to the channel direction was issued.
364 /// Value is opaque, as set in the announcement.
366 pub extern "C" fn DirectionalChannelInfo_get_last_update(this_ptr: &DirectionalChannelInfo) -> u32 {
367 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
370 /// When the last update to the channel direction was issued.
371 /// Value is opaque, as set in the announcement.
373 pub extern "C" fn DirectionalChannelInfo_set_last_update(this_ptr: &mut DirectionalChannelInfo, mut val: u32) {
374 unsafe { &mut *this_ptr.inner }.last_update = val;
376 /// Whether the channel can be currently used for payments (in this one direction).
378 pub extern "C" fn DirectionalChannelInfo_get_enabled(this_ptr: &DirectionalChannelInfo) -> bool {
379 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.enabled;
382 /// Whether the channel can be currently used for payments (in this one direction).
384 pub extern "C" fn DirectionalChannelInfo_set_enabled(this_ptr: &mut DirectionalChannelInfo, mut val: bool) {
385 unsafe { &mut *this_ptr.inner }.enabled = val;
387 /// The difference in CLTV values that you must have when routing through this channel.
389 pub extern "C" fn DirectionalChannelInfo_get_cltv_expiry_delta(this_ptr: &DirectionalChannelInfo) -> u16 {
390 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta;
393 /// The difference in CLTV values that you must have when routing through this channel.
395 pub extern "C" fn DirectionalChannelInfo_set_cltv_expiry_delta(this_ptr: &mut DirectionalChannelInfo, mut val: u16) {
396 unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val;
398 /// The minimum value, which must be relayed to the next hop via the channel
400 pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &DirectionalChannelInfo) -> u64 {
401 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat;
404 /// The minimum value, which must be relayed to the next hop via the channel
406 pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) {
407 unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val;
409 /// Fees charged when the channel is used for routing
411 pub extern "C" fn DirectionalChannelInfo_get_fees(this_ptr: &DirectionalChannelInfo) -> crate::routing::network_graph::RoutingFees {
412 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fees;
413 crate::routing::network_graph::RoutingFees { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
415 /// Fees charged when the channel is used for routing
417 pub extern "C" fn DirectionalChannelInfo_set_fees(this_ptr: &mut DirectionalChannelInfo, mut val: crate::routing::network_graph::RoutingFees) {
418 unsafe { &mut *this_ptr.inner }.fees = *unsafe { Box::from_raw(val.take_inner()) };
420 /// Most recent update for the channel received from the network
421 /// Mostly redundant with the data we store in fields explicitly.
422 /// Everything else is useful only for sending out for initial routing sync.
423 /// Not stored if contains excess data to prevent DoS.
425 pub extern "C" fn DirectionalChannelInfo_get_last_update_message(this_ptr: &DirectionalChannelInfo) -> crate::ln::msgs::ChannelUpdate {
426 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update_message;
427 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 };
430 /// Most recent update for the channel received from the network
431 /// Mostly redundant with the data we store in fields explicitly.
432 /// Everything else is useful only for sending out for initial routing sync.
433 /// Not stored if contains excess data to prevent DoS.
435 pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut DirectionalChannelInfo, mut val: crate::ln::msgs::ChannelUpdate) {
436 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
437 unsafe { &mut *this_ptr.inner }.last_update_message = local_val;
439 impl Clone for DirectionalChannelInfo {
440 fn clone(&self) -> Self {
442 inner: if <*mut nativeDirectionalChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
443 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
449 /// Used only if an object of this type is returned as a trait impl by a method
450 pub(crate) extern "C" fn DirectionalChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
451 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectionalChannelInfo)).clone() })) as *mut c_void
454 pub extern "C" fn DirectionalChannelInfo_clone(orig: &DirectionalChannelInfo) -> DirectionalChannelInfo {
458 pub extern "C" fn DirectionalChannelInfo_write(obj: &DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z {
459 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
462 pub(crate) extern "C" fn DirectionalChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
463 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDirectionalChannelInfo) })
466 pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DirectionalChannelInfoDecodeErrorZ {
467 let res = crate::c_types::deserialize_obj(ser);
468 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::DirectionalChannelInfo { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
472 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
473 type nativeChannelInfo = nativeChannelInfoImport;
475 /// Details about a channel (both directions).
476 /// Received within a channel announcement.
479 pub struct ChannelInfo {
480 /// Nearly everywhere, inner must be non-null, however in places where
481 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
482 pub inner: *mut nativeChannelInfo,
486 impl Drop for ChannelInfo {
488 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
489 let _ = unsafe { Box::from_raw(self.inner) };
494 pub extern "C" fn ChannelInfo_free(this_ptr: ChannelInfo) { }
496 /// Used only if an object of this type is returned as a trait impl by a method
497 extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
498 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
501 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
503 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
504 assert!(self.is_owned);
505 let ret = self.inner;
506 self.inner = std::ptr::null_mut();
510 /// Protocol features of a channel communicated during its announcement
512 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::ln::features::ChannelFeatures {
513 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
514 crate::ln::features::ChannelFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
516 /// Protocol features of a channel communicated during its announcement
518 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::ln::features::ChannelFeatures) {
519 unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) };
521 /// Source node of the first direction of a channel
523 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
524 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_one;
525 crate::c_types::PublicKey::from_rust(&(*inner_val))
527 /// Source node of the first direction of a channel
529 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
530 unsafe { &mut *this_ptr.inner }.node_one = val.into_rust();
532 /// Details about the first direction of a channel
534 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
535 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.one_to_two;
536 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 };
539 /// Details about the first direction of a channel
541 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) {
542 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
543 unsafe { &mut *this_ptr.inner }.one_to_two = local_val;
545 /// Source node of the second direction of a channel
547 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
548 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_two;
549 crate::c_types::PublicKey::from_rust(&(*inner_val))
551 /// Source node of the second direction of a channel
553 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
554 unsafe { &mut *this_ptr.inner }.node_two = val.into_rust();
556 /// Details about the second direction of a channel
558 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
559 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.two_to_one;
560 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 };
563 /// Details about the second direction of a channel
565 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) {
566 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
567 unsafe { &mut *this_ptr.inner }.two_to_one = local_val;
569 /// An initial announcement of the channel
570 /// Mostly redundant with the data we store in fields explicitly.
571 /// Everything else is useful only for sending out for initial routing sync.
572 /// Not stored if contains excess data to prevent DoS.
574 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::ln::msgs::ChannelAnnouncement {
575 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
576 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 };
579 /// An initial announcement of the channel
580 /// Mostly redundant with the data we store in fields explicitly.
581 /// Everything else is useful only for sending out for initial routing sync.
582 /// Not stored if contains excess data to prevent DoS.
584 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::ln::msgs::ChannelAnnouncement) {
585 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
586 unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
588 impl Clone for ChannelInfo {
589 fn clone(&self) -> Self {
591 inner: if <*mut nativeChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
592 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
598 /// Used only if an object of this type is returned as a trait impl by a method
599 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
600 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
603 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
607 pub extern "C" fn ChannelInfo_write(obj: &ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
608 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
611 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
612 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
615 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
616 let res = crate::c_types::deserialize_obj(ser);
617 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::ChannelInfo { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
621 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
622 type nativeRoutingFees = nativeRoutingFeesImport;
624 /// Fees for routing via a given channel or a node
627 pub struct RoutingFees {
628 /// Nearly everywhere, inner must be non-null, however in places where
629 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
630 pub inner: *mut nativeRoutingFees,
634 impl Drop for RoutingFees {
636 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
637 let _ = unsafe { Box::from_raw(self.inner) };
642 pub extern "C" fn RoutingFees_free(this_ptr: RoutingFees) { }
644 /// Used only if an object of this type is returned as a trait impl by a method
645 extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
646 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
649 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
651 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
652 assert!(self.is_owned);
653 let ret = self.inner;
654 self.inner = std::ptr::null_mut();
658 /// Flat routing fee in satoshis
660 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
661 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.base_msat;
664 /// Flat routing fee in satoshis
666 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
667 unsafe { &mut *this_ptr.inner }.base_msat = val;
669 /// Liquidity-based routing fee in millionths of a routed amount.
670 /// In other words, 10000 is 1%.
672 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
673 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.proportional_millionths;
676 /// Liquidity-based routing fee in millionths of a routed amount.
677 /// In other words, 10000 is 1%.
679 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
680 unsafe { &mut *this_ptr.inner }.proportional_millionths = val;
684 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
685 RoutingFees { inner: Box::into_raw(Box::new(nativeRoutingFees {
686 base_msat: base_msat_arg,
687 proportional_millionths: proportional_millionths_arg,
688 })), is_owned: true }
690 impl Clone for RoutingFees {
691 fn clone(&self) -> Self {
693 inner: if <*mut nativeRoutingFees>::is_null(self.inner) { std::ptr::null_mut() } else {
694 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
700 /// Used only if an object of this type is returned as a trait impl by a method
701 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
702 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
705 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
709 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
710 let res = crate::c_types::deserialize_obj(ser);
711 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::RoutingFees { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
715 pub extern "C" fn RoutingFees_write(obj: &RoutingFees) -> crate::c_types::derived::CVec_u8Z {
716 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
719 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
720 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
723 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
724 type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
726 /// Information received in the latest node_announcement from this node.
729 pub struct NodeAnnouncementInfo {
730 /// Nearly everywhere, inner must be non-null, however in places where
731 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
732 pub inner: *mut nativeNodeAnnouncementInfo,
736 impl Drop for NodeAnnouncementInfo {
738 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
739 let _ = unsafe { Box::from_raw(self.inner) };
744 pub extern "C" fn NodeAnnouncementInfo_free(this_ptr: NodeAnnouncementInfo) { }
746 /// Used only if an object of this type is returned as a trait impl by a method
747 extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
748 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
751 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
752 impl NodeAnnouncementInfo {
753 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
754 assert!(self.is_owned);
755 let ret = self.inner;
756 self.inner = std::ptr::null_mut();
760 /// Protocol features the node announced support for
762 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::ln::features::NodeFeatures {
763 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
764 crate::ln::features::NodeFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
766 /// Protocol features the node announced support for
768 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::features::NodeFeatures) {
769 unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) };
771 /// When the last known update to the node state was issued.
772 /// Value is opaque, as set in the announcement.
774 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
775 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
778 /// When the last known update to the node state was issued.
779 /// Value is opaque, as set in the announcement.
781 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
782 unsafe { &mut *this_ptr.inner }.last_update = val;
784 /// Color assigned to the node
786 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
787 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.rgb;
790 /// Color assigned to the node
792 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
793 unsafe { &mut *this_ptr.inner }.rgb = val.data;
795 /// Moniker assigned to the node.
796 /// May be invalid or malicious (eg control chars),
797 /// should not be exposed to the user.
799 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
800 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.alias;
803 /// Moniker assigned to the node.
804 /// May be invalid or malicious (eg control chars),
805 /// should not be exposed to the user.
807 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
808 unsafe { &mut *this_ptr.inner }.alias = val.data;
810 /// Internet-level addresses via which one can connect to the node
812 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
813 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
814 unsafe { &mut *this_ptr.inner }.addresses = local_val;
816 /// An initial announcement of the node
817 /// Mostly redundant with the data we store in fields explicitly.
818 /// Everything else is useful only for sending out for initial routing sync.
819 /// Not stored if contains excess data to prevent DoS.
821 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::ln::msgs::NodeAnnouncement {
822 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
823 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 };
826 /// An initial announcement of the node
827 /// Mostly redundant with the data we store in fields explicitly.
828 /// Everything else is useful only for sending out for initial routing sync.
829 /// Not stored if contains excess data to prevent DoS.
831 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::msgs::NodeAnnouncement) {
832 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
833 unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
837 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 {
838 let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
839 let mut local_announcement_message_arg = if announcement_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_message_arg.take_inner()) } }) };
840 NodeAnnouncementInfo { inner: Box::into_raw(Box::new(nativeNodeAnnouncementInfo {
841 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
842 last_update: last_update_arg,
844 alias: alias_arg.data,
845 addresses: local_addresses_arg,
846 announcement_message: local_announcement_message_arg,
847 })), is_owned: true }
849 impl Clone for NodeAnnouncementInfo {
850 fn clone(&self) -> Self {
852 inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
853 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
859 /// Used only if an object of this type is returned as a trait impl by a method
860 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
861 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
864 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
868 pub extern "C" fn NodeAnnouncementInfo_write(obj: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
869 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
872 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
873 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
876 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
877 let res = crate::c_types::deserialize_obj(ser);
878 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::NodeAnnouncementInfo { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
882 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
883 type nativeNodeInfo = nativeNodeInfoImport;
885 /// Details about a node in the network, known from the network announcement.
888 pub struct NodeInfo {
889 /// Nearly everywhere, inner must be non-null, however in places where
890 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
891 pub inner: *mut nativeNodeInfo,
895 impl Drop for NodeInfo {
897 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
898 let _ = unsafe { Box::from_raw(self.inner) };
903 pub extern "C" fn NodeInfo_free(this_ptr: NodeInfo) { }
905 /// Used only if an object of this type is returned as a trait impl by a method
906 extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
907 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
910 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
912 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
913 assert!(self.is_owned);
914 let ret = self.inner;
915 self.inner = std::ptr::null_mut();
919 /// All valid channels a node has announced
921 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
922 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
923 unsafe { &mut *this_ptr.inner }.channels = local_val;
925 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
926 /// The two fields (flat and proportional fee) are independent,
927 /// meaning they don't have to refer to the same channel.
929 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::routing::network_graph::RoutingFees {
930 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees;
931 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 };
934 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
935 /// The two fields (flat and proportional fee) are independent,
936 /// meaning they don't have to refer to the same channel.
938 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::RoutingFees) {
939 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
940 unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees = local_val;
942 /// More information about a node from node_announcement.
943 /// Optional because we store a Node entry after learning about it from
944 /// a channel announcement, but before receiving a node announcement.
946 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::routing::network_graph::NodeAnnouncementInfo {
947 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_info;
948 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 };
951 /// More information about a node from node_announcement.
952 /// Optional because we store a Node entry after learning about it from
953 /// a channel announcement, but before receiving a node announcement.
955 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::NodeAnnouncementInfo) {
956 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
957 unsafe { &mut *this_ptr.inner }.announcement_info = local_val;
961 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 {
962 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
963 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_inner()) } }) };
964 let mut local_announcement_info_arg = if announcement_info_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_info_arg.take_inner()) } }) };
965 NodeInfo { inner: Box::into_raw(Box::new(nativeNodeInfo {
966 channels: local_channels_arg,
967 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
968 announcement_info: local_announcement_info_arg,
969 })), is_owned: true }
971 impl Clone for NodeInfo {
972 fn clone(&self) -> Self {
974 inner: if <*mut nativeNodeInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
975 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
981 /// Used only if an object of this type is returned as a trait impl by a method
982 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
983 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
986 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
990 pub extern "C" fn NodeInfo_write(obj: &NodeInfo) -> crate::c_types::derived::CVec_u8Z {
991 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
994 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
995 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
998 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
999 let res = crate::c_types::deserialize_obj(ser);
1000 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::NodeInfo { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1004 pub extern "C" fn NetworkGraph_write(obj: &NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1005 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1008 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1009 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1012 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1013 let res = crate::c_types::deserialize_obj(ser);
1014 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1017 /// Creates a new, empty, network graph.
1020 pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::routing::network_graph::NetworkGraph {
1021 let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap());
1022 crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1025 /// For an already known node (from channel announcements), update its stored properties from a
1026 /// given node announcement.
1028 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1029 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1030 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1033 pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1034 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_announcement(unsafe { &*msg.inner }, secp256k1::SECP256K1);
1035 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1039 /// For an already known node (from channel announcements), update its stored properties from a
1040 /// given node announcement without verifying the associated signatures. Because we aren't
1041 /// given the associated signatures here we cannot relay the node announcement to any of our
1045 pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedNodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1046 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_unsigned_announcement(unsafe { &*msg.inner });
1047 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1051 /// Store or update channel info from a channel announcement.
1053 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1054 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1055 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1057 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1058 /// the corresponding UTXO exists on chain and is correctly-formatted.
1061 pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::ChannelAnnouncement, chain_access: *mut crate::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1062 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1063 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_announcement(unsafe { &*msg.inner }, &local_chain_access, secp256k1::SECP256K1);
1064 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1068 /// Store or update channel info from a channel announcement without verifying the associated
1069 /// signatures. Because we aren't given the associated signatures here we cannot relay the
1070 /// channel announcement to any of our peers.
1072 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1073 /// the corresponding UTXO exists on chain and is correctly-formatted.
1076 pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedChannelAnnouncement, chain_access: *mut crate::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1077 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1078 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_unsigned_announcement(unsafe { &*msg.inner }, &local_chain_access);
1079 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1083 /// Close a channel if a corresponding HTLC fail was sent.
1084 /// If permanent, removes a channel from the local storage.
1085 /// May cause the removal of nodes too, if this was their last channel.
1086 /// If not permanent, makes channels unavailable for routing.
1088 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
1089 unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.close_channel_from_update(short_channel_id, is_permanent)
1092 /// For an already known (from announcement) channel, update info about one of the directions
1095 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1096 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1097 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1100 pub extern "C" fn NetworkGraph_update_channel(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1101 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel(unsafe { &*msg.inner }, secp256k1::SECP256K1);
1102 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1106 /// For an already known (from announcement) channel, update info about one of the directions
1107 /// of the channel without verifying the associated signatures. Because we aren't given the
1108 /// associated signatures here we cannot relay the channel update to any of our peers.
1111 pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1112 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_unsigned(unsafe { &*msg.inner });
1113 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };