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 /// A pointer to the opaque Rust object.
17 /// Nearly everywhere, inner must be non-null, however in places where
18 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
19 pub inner: *mut nativeNetworkGraph,
20 /// Indicates that this is the only struct which contains the same pointer.
22 /// Rust functions which take ownership of an object provided via an argument require
23 /// this to be true and invalidate the object pointed to by inner.
27 impl Drop for NetworkGraph {
29 if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) {
30 let _ = unsafe { Box::from_raw(self.inner) };
34 /// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL.
36 pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { }
38 /// Used only if an object of this type is returned as a trait impl by a method
39 extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
40 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetworkGraph); }
43 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
45 pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
46 assert!(self.is_owned);
48 self.inner = std::ptr::null_mut();
52 impl Clone for NetworkGraph {
53 fn clone(&self) -> Self {
55 inner: if <*mut nativeNetworkGraph>::is_null(self.inner) { std::ptr::null_mut() } else {
56 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
62 /// Used only if an object of this type is returned as a trait impl by a method
63 pub(crate) extern "C" fn NetworkGraph_clone_void(this_ptr: *const c_void) -> *mut c_void {
64 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNetworkGraph)).clone() })) as *mut c_void
67 /// Creates a copy of the NetworkGraph
68 pub extern "C" fn NetworkGraph_clone(orig: &NetworkGraph) -> NetworkGraph {
72 use lightning::routing::network_graph::LockedNetworkGraph as nativeLockedNetworkGraphImport;
73 type nativeLockedNetworkGraph = nativeLockedNetworkGraphImport<'static>;
75 /// A simple newtype for RwLockReadGuard<'a, NetworkGraph>.
76 /// This exists only to make accessing a RwLock<NetworkGraph> possible from
77 /// the C bindings, as it can be done directly in Rust code.
80 pub struct LockedNetworkGraph {
81 /// A pointer to the opaque Rust object.
83 /// Nearly everywhere, inner must be non-null, however in places where
84 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
85 pub inner: *mut nativeLockedNetworkGraph,
86 /// Indicates that this is the only struct which contains the same pointer.
88 /// Rust functions which take ownership of an object provided via an argument require
89 /// this to be true and invalidate the object pointed to by inner.
93 impl Drop for LockedNetworkGraph {
95 if self.is_owned && !<*mut nativeLockedNetworkGraph>::is_null(self.inner) {
96 let _ = unsafe { Box::from_raw(self.inner) };
100 /// Frees any resources used by the LockedNetworkGraph, if is_owned is set and inner is non-NULL.
102 pub extern "C" fn LockedNetworkGraph_free(this_obj: LockedNetworkGraph) { }
104 /// Used only if an object of this type is returned as a trait impl by a method
105 extern "C" fn LockedNetworkGraph_free_void(this_ptr: *mut c_void) {
106 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLockedNetworkGraph); }
109 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
110 impl LockedNetworkGraph {
111 pub(crate) fn take_inner(mut self) -> *mut nativeLockedNetworkGraph {
112 assert!(self.is_owned);
113 let ret = self.inner;
114 self.inner = std::ptr::null_mut();
119 use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport;
120 type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport<crate::chain::Access, crate::util::logger::Logger>;
122 /// Receives and validates network updates from peers,
123 /// stores authentic and relevant data as a network graph.
124 /// This network graph is then used for routing payments.
125 /// Provides interface to help with initial routing sync by
126 /// serving historical announcements.
129 pub struct NetGraphMsgHandler {
130 /// A pointer to the opaque Rust object.
132 /// Nearly everywhere, inner must be non-null, however in places where
133 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
134 pub inner: *mut nativeNetGraphMsgHandler,
135 /// Indicates that this is the only struct which contains the same pointer.
137 /// Rust functions which take ownership of an object provided via an argument require
138 /// this to be true and invalidate the object pointed to by inner.
142 impl Drop for NetGraphMsgHandler {
144 if self.is_owned && !<*mut nativeNetGraphMsgHandler>::is_null(self.inner) {
145 let _ = unsafe { Box::from_raw(self.inner) };
149 /// Frees any resources used by the NetGraphMsgHandler, if is_owned is set and inner is non-NULL.
151 pub extern "C" fn NetGraphMsgHandler_free(this_obj: NetGraphMsgHandler) { }
153 /// Used only if an object of this type is returned as a trait impl by a method
154 extern "C" fn NetGraphMsgHandler_free_void(this_ptr: *mut c_void) {
155 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetGraphMsgHandler); }
158 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
159 impl NetGraphMsgHandler {
160 pub(crate) fn take_inner(mut self) -> *mut nativeNetGraphMsgHandler {
161 assert!(self.is_owned);
162 let ret = self.inner;
163 self.inner = std::ptr::null_mut();
167 /// Creates a new tracker of the actual state of the network of channels and nodes,
168 /// assuming a fresh network graph.
169 /// Chain monitor is used to make sure announced channels exist on-chain,
170 /// channel data is correct, and that the announcement is signed with
171 /// channel owners' keys.
174 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 {
175 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
176 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap(), local_chain_access, logger);
177 NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
180 /// Creates a new tracker of the actual state of the network of channels and nodes,
181 /// assuming an existing Network Graph.
184 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 {
185 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
186 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::from_net_graph(local_chain_access, logger, *unsafe { Box::from_raw(network_graph.take_inner()) });
187 NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
190 /// Adds a provider used to check new announcements. Does not affect
191 /// existing announcements unless they are updated.
192 /// Add, update or remove the provider would replace the current one.
194 pub extern "C" fn NetGraphMsgHandler_add_chain_access(this_arg: &mut NetGraphMsgHandler, chain_access: *mut crate::chain::Access) {
195 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
196 unsafe { &mut (*(this_arg.inner as *mut nativeNetGraphMsgHandler)) }.add_chain_access(local_chain_access)
199 /// Take a read lock on the network_graph and return it in the C-bindings
200 /// newtype helper. This is likely only useful when called via the C
201 /// bindings as you can call `self.network_graph.read().unwrap()` in Rust
205 pub extern "C" fn NetGraphMsgHandler_read_locked_graph(this_arg: &NetGraphMsgHandler) -> crate::routing::network_graph::LockedNetworkGraph {
206 let mut ret = unsafe { &*this_arg.inner }.read_locked_graph();
207 crate::routing::network_graph::LockedNetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
210 /// Get a reference to the NetworkGraph which this read-lock contains.
213 pub extern "C" fn LockedNetworkGraph_graph(this_arg: &LockedNetworkGraph) -> crate::routing::network_graph::NetworkGraph {
214 let mut ret = unsafe { &*this_arg.inner }.graph();
215 crate::routing::network_graph::NetworkGraph { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
218 impl From<nativeNetGraphMsgHandler> for crate::ln::msgs::RoutingMessageHandler {
219 fn from(obj: nativeNetGraphMsgHandler) -> Self {
220 let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
221 let mut ret = NetGraphMsgHandler_as_RoutingMessageHandler(&rust_obj);
222 // 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
223 rust_obj.inner = std::ptr::null_mut();
224 ret.free = Some(NetGraphMsgHandler_free_void);
228 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
229 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
231 pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: &NetGraphMsgHandler) -> crate::ln::msgs::RoutingMessageHandler {
232 crate::ln::msgs::RoutingMessageHandler {
233 this_arg: unsafe { (*this_arg).inner as *mut c_void },
235 handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement,
236 handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement,
237 handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update,
238 handle_htlc_fail_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update,
239 get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements,
240 get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements,
241 sync_routing_table: NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table,
242 handle_reply_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range,
243 handle_reply_short_channel_ids_end: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
244 handle_query_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range,
245 handle_query_short_channel_ids: NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids,
246 MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider {
247 this_arg: unsafe { (*this_arg).inner as *mut c_void },
249 get_and_clear_pending_msg_events: NetGraphMsgHandler_RoutingMessageHandler_get_and_clear_pending_msg_events,
255 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
256 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner });
257 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() };
261 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
262 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner });
263 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() };
266 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, update: &crate::ln::msgs::HTLCFailChannelUpdate) {
267 <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_htlc_fail_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &update.to_native())
270 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
271 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner });
272 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() };
276 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 {
277 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, starting_point, batch_amount);
278 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 }); };
282 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 {
283 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();
284 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);
285 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 } }); };
288 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) {
289 <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 })
292 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 {
293 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()) });
294 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() };
298 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 {
299 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()) });
300 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() };
304 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 {
305 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()) });
306 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() };
310 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 {
311 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()) });
312 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() };
316 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
317 let mut ret = <nativeNetGraphMsgHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, );
318 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
322 impl From<nativeNetGraphMsgHandler> for crate::util::events::MessageSendEventsProvider {
323 fn from(obj: nativeNetGraphMsgHandler) -> Self {
324 let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
325 let mut ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&rust_obj);
326 // 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
327 rust_obj.inner = std::ptr::null_mut();
328 ret.free = Some(NetGraphMsgHandler_free_void);
332 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
333 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
335 pub extern "C" fn NetGraphMsgHandler_as_MessageSendEventsProvider(this_arg: &NetGraphMsgHandler) -> crate::util::events::MessageSendEventsProvider {
336 crate::util::events::MessageSendEventsProvider {
337 this_arg: unsafe { (*this_arg).inner as *mut c_void },
339 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
344 extern "C" fn NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
345 let mut ret = <nativeNetGraphMsgHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, );
346 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
351 use lightning::routing::network_graph::DirectionalChannelInfo as nativeDirectionalChannelInfoImport;
352 type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport;
354 /// Details about one direction of a channel. Received
355 /// within a channel update.
358 pub struct DirectionalChannelInfo {
359 /// A pointer to the opaque Rust object.
361 /// Nearly everywhere, inner must be non-null, however in places where
362 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
363 pub inner: *mut nativeDirectionalChannelInfo,
364 /// Indicates that this is the only struct which contains the same pointer.
366 /// Rust functions which take ownership of an object provided via an argument require
367 /// this to be true and invalidate the object pointed to by inner.
371 impl Drop for DirectionalChannelInfo {
373 if self.is_owned && !<*mut nativeDirectionalChannelInfo>::is_null(self.inner) {
374 let _ = unsafe { Box::from_raw(self.inner) };
378 /// Frees any resources used by the DirectionalChannelInfo, if is_owned is set and inner is non-NULL.
380 pub extern "C" fn DirectionalChannelInfo_free(this_obj: DirectionalChannelInfo) { }
382 /// Used only if an object of this type is returned as a trait impl by a method
383 extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) {
384 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectionalChannelInfo); }
387 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
388 impl DirectionalChannelInfo {
389 pub(crate) fn take_inner(mut self) -> *mut nativeDirectionalChannelInfo {
390 assert!(self.is_owned);
391 let ret = self.inner;
392 self.inner = std::ptr::null_mut();
396 /// When the last update to the channel direction was issued.
397 /// Value is opaque, as set in the announcement.
399 pub extern "C" fn DirectionalChannelInfo_get_last_update(this_ptr: &DirectionalChannelInfo) -> u32 {
400 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
403 /// When the last update to the channel direction was issued.
404 /// Value is opaque, as set in the announcement.
406 pub extern "C" fn DirectionalChannelInfo_set_last_update(this_ptr: &mut DirectionalChannelInfo, mut val: u32) {
407 unsafe { &mut *this_ptr.inner }.last_update = val;
409 /// Whether the channel can be currently used for payments (in this one direction).
411 pub extern "C" fn DirectionalChannelInfo_get_enabled(this_ptr: &DirectionalChannelInfo) -> bool {
412 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.enabled;
415 /// Whether the channel can be currently used for payments (in this one direction).
417 pub extern "C" fn DirectionalChannelInfo_set_enabled(this_ptr: &mut DirectionalChannelInfo, mut val: bool) {
418 unsafe { &mut *this_ptr.inner }.enabled = val;
420 /// The difference in CLTV values that you must have when routing through this channel.
422 pub extern "C" fn DirectionalChannelInfo_get_cltv_expiry_delta(this_ptr: &DirectionalChannelInfo) -> u16 {
423 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta;
426 /// The difference in CLTV values that you must have when routing through this channel.
428 pub extern "C" fn DirectionalChannelInfo_set_cltv_expiry_delta(this_ptr: &mut DirectionalChannelInfo, mut val: u16) {
429 unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val;
431 /// The minimum value, which must be relayed to the next hop via the channel
433 pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &DirectionalChannelInfo) -> u64 {
434 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat;
437 /// The minimum value, which must be relayed to the next hop via the channel
439 pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) {
440 unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val;
442 /// Fees charged when the channel is used for routing
444 pub extern "C" fn DirectionalChannelInfo_get_fees(this_ptr: &DirectionalChannelInfo) -> crate::routing::network_graph::RoutingFees {
445 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fees;
446 crate::routing::network_graph::RoutingFees { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
448 /// Fees charged when the channel is used for routing
450 pub extern "C" fn DirectionalChannelInfo_set_fees(this_ptr: &mut DirectionalChannelInfo, mut val: crate::routing::network_graph::RoutingFees) {
451 unsafe { &mut *this_ptr.inner }.fees = *unsafe { Box::from_raw(val.take_inner()) };
453 /// Most recent update for the channel received from the network
454 /// Mostly redundant with the data we store in fields explicitly.
455 /// Everything else is useful only for sending out for initial routing sync.
456 /// Not stored if contains excess data to prevent DoS.
458 pub extern "C" fn DirectionalChannelInfo_get_last_update_message(this_ptr: &DirectionalChannelInfo) -> crate::ln::msgs::ChannelUpdate {
459 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update_message;
460 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 };
463 /// Most recent update for the channel received from the network
464 /// Mostly redundant with the data we store in fields explicitly.
465 /// Everything else is useful only for sending out for initial routing sync.
466 /// Not stored if contains excess data to prevent DoS.
468 pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut DirectionalChannelInfo, mut val: crate::ln::msgs::ChannelUpdate) {
469 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
470 unsafe { &mut *this_ptr.inner }.last_update_message = local_val;
472 impl Clone for DirectionalChannelInfo {
473 fn clone(&self) -> Self {
475 inner: if <*mut nativeDirectionalChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
476 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
482 /// Used only if an object of this type is returned as a trait impl by a method
483 pub(crate) extern "C" fn DirectionalChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
484 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectionalChannelInfo)).clone() })) as *mut c_void
487 /// Creates a copy of the DirectionalChannelInfo
488 pub extern "C" fn DirectionalChannelInfo_clone(orig: &DirectionalChannelInfo) -> DirectionalChannelInfo {
492 /// Serialize the DirectionalChannelInfo object into a byte array which can be read by DirectionalChannelInfo_read
493 pub extern "C" fn DirectionalChannelInfo_write(obj: &DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z {
494 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
497 pub(crate) extern "C" fn DirectionalChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
498 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDirectionalChannelInfo) })
501 /// Read a DirectionalChannelInfo from a byte array, created by DirectionalChannelInfo_write
502 pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DirectionalChannelInfoDecodeErrorZ {
503 let res = crate::c_types::deserialize_obj(ser);
504 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() };
508 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
509 type nativeChannelInfo = nativeChannelInfoImport;
511 /// Details about a channel (both directions).
512 /// Received within a channel announcement.
515 pub struct ChannelInfo {
516 /// A pointer to the opaque Rust object.
518 /// Nearly everywhere, inner must be non-null, however in places where
519 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
520 pub inner: *mut nativeChannelInfo,
521 /// Indicates that this is the only struct which contains the same pointer.
523 /// Rust functions which take ownership of an object provided via an argument require
524 /// this to be true and invalidate the object pointed to by inner.
528 impl Drop for ChannelInfo {
530 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
531 let _ = unsafe { Box::from_raw(self.inner) };
535 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
537 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
539 /// Used only if an object of this type is returned as a trait impl by a method
540 extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
541 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
544 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
546 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
547 assert!(self.is_owned);
548 let ret = self.inner;
549 self.inner = std::ptr::null_mut();
553 /// Protocol features of a channel communicated during its announcement
555 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::ln::features::ChannelFeatures {
556 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
557 crate::ln::features::ChannelFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
559 /// Protocol features of a channel communicated during its announcement
561 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::ln::features::ChannelFeatures) {
562 unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) };
564 /// Source node of the first direction of a channel
566 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
567 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_one;
568 crate::c_types::PublicKey::from_rust(&(*inner_val))
570 /// Source node of the first direction of a channel
572 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
573 unsafe { &mut *this_ptr.inner }.node_one = val.into_rust();
575 /// Details about the first direction of a channel
577 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
578 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.one_to_two;
579 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 };
582 /// Details about the first direction of a channel
584 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) {
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 }.one_to_two = local_val;
588 /// Source node of the second direction of a channel
590 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
591 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_two;
592 crate::c_types::PublicKey::from_rust(&(*inner_val))
594 /// Source node of the second direction of a channel
596 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
597 unsafe { &mut *this_ptr.inner }.node_two = val.into_rust();
599 /// Details about the second direction of a channel
601 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
602 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.two_to_one;
603 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 };
606 /// Details about the second direction of a channel
608 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) {
609 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
610 unsafe { &mut *this_ptr.inner }.two_to_one = local_val;
612 /// An initial announcement of the channel
613 /// Mostly redundant with the data we store in fields explicitly.
614 /// Everything else is useful only for sending out for initial routing sync.
615 /// Not stored if contains excess data to prevent DoS.
617 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::ln::msgs::ChannelAnnouncement {
618 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
619 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 };
622 /// An initial announcement of the channel
623 /// Mostly redundant with the data we store in fields explicitly.
624 /// Everything else is useful only for sending out for initial routing sync.
625 /// Not stored if contains excess data to prevent DoS.
627 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::ln::msgs::ChannelAnnouncement) {
628 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
629 unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
631 impl Clone for ChannelInfo {
632 fn clone(&self) -> Self {
634 inner: if <*mut nativeChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
635 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
641 /// Used only if an object of this type is returned as a trait impl by a method
642 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
643 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
646 /// Creates a copy of the ChannelInfo
647 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
651 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
652 pub extern "C" fn ChannelInfo_write(obj: &ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
653 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
656 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
657 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
660 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
661 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
662 let res = crate::c_types::deserialize_obj(ser);
663 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() };
667 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
668 type nativeRoutingFees = nativeRoutingFeesImport;
670 /// Fees for routing via a given channel or a node
673 pub struct RoutingFees {
674 /// A pointer to the opaque Rust object.
676 /// Nearly everywhere, inner must be non-null, however in places where
677 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
678 pub inner: *mut nativeRoutingFees,
679 /// Indicates that this is the only struct which contains the same pointer.
681 /// Rust functions which take ownership of an object provided via an argument require
682 /// this to be true and invalidate the object pointed to by inner.
686 impl Drop for RoutingFees {
688 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
689 let _ = unsafe { Box::from_raw(self.inner) };
693 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
695 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
697 /// Used only if an object of this type is returned as a trait impl by a method
698 extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
699 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
702 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
704 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
705 assert!(self.is_owned);
706 let ret = self.inner;
707 self.inner = std::ptr::null_mut();
711 /// Flat routing fee in satoshis
713 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
714 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.base_msat;
717 /// Flat routing fee in satoshis
719 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
720 unsafe { &mut *this_ptr.inner }.base_msat = val;
722 /// Liquidity-based routing fee in millionths of a routed amount.
723 /// In other words, 10000 is 1%.
725 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
726 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.proportional_millionths;
729 /// Liquidity-based routing fee in millionths of a routed amount.
730 /// In other words, 10000 is 1%.
732 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
733 unsafe { &mut *this_ptr.inner }.proportional_millionths = val;
735 /// Constructs a new RoutingFees given each field
738 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
739 RoutingFees { inner: Box::into_raw(Box::new(nativeRoutingFees {
740 base_msat: base_msat_arg,
741 proportional_millionths: proportional_millionths_arg,
742 })), is_owned: true }
744 impl Clone for RoutingFees {
745 fn clone(&self) -> Self {
747 inner: if <*mut nativeRoutingFees>::is_null(self.inner) { std::ptr::null_mut() } else {
748 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
754 /// Used only if an object of this type is returned as a trait impl by a method
755 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
756 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
759 /// Creates a copy of the RoutingFees
760 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
764 /// Read a RoutingFees from a byte array, created by RoutingFees_write
765 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
766 let res = crate::c_types::deserialize_obj(ser);
767 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() };
771 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
772 pub extern "C" fn RoutingFees_write(obj: &RoutingFees) -> crate::c_types::derived::CVec_u8Z {
773 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
776 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
777 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
780 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
781 type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
783 /// Information received in the latest node_announcement from this node.
786 pub struct NodeAnnouncementInfo {
787 /// A pointer to the opaque Rust object.
789 /// Nearly everywhere, inner must be non-null, however in places where
790 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
791 pub inner: *mut nativeNodeAnnouncementInfo,
792 /// Indicates that this is the only struct which contains the same pointer.
794 /// Rust functions which take ownership of an object provided via an argument require
795 /// this to be true and invalidate the object pointed to by inner.
799 impl Drop for NodeAnnouncementInfo {
801 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
802 let _ = unsafe { Box::from_raw(self.inner) };
806 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
808 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
810 /// Used only if an object of this type is returned as a trait impl by a method
811 extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
812 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
815 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
816 impl NodeAnnouncementInfo {
817 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
818 assert!(self.is_owned);
819 let ret = self.inner;
820 self.inner = std::ptr::null_mut();
824 /// Protocol features the node announced support for
826 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::ln::features::NodeFeatures {
827 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
828 crate::ln::features::NodeFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
830 /// Protocol features the node announced support for
832 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::features::NodeFeatures) {
833 unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) };
835 /// When the last known update to the node state was issued.
836 /// Value is opaque, as set in the announcement.
838 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
839 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
842 /// When the last known update to the node state was issued.
843 /// Value is opaque, as set in the announcement.
845 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
846 unsafe { &mut *this_ptr.inner }.last_update = val;
848 /// Color assigned to the node
850 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
851 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.rgb;
854 /// Color assigned to the node
856 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
857 unsafe { &mut *this_ptr.inner }.rgb = val.data;
859 /// Moniker assigned to the node.
860 /// May be invalid or malicious (eg control chars),
861 /// should not be exposed to the user.
863 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
864 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.alias;
867 /// Moniker assigned to the node.
868 /// May be invalid or malicious (eg control chars),
869 /// should not be exposed to the user.
871 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
872 unsafe { &mut *this_ptr.inner }.alias = val.data;
874 /// Internet-level addresses via which one can connect to the node
876 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
877 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
878 unsafe { &mut *this_ptr.inner }.addresses = local_val;
880 /// An initial announcement of the node
881 /// Mostly redundant with the data we store in fields explicitly.
882 /// Everything else is useful only for sending out for initial routing sync.
883 /// Not stored if contains excess data to prevent DoS.
885 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::ln::msgs::NodeAnnouncement {
886 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
887 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 };
890 /// An initial announcement of the node
891 /// Mostly redundant with the data we store in fields explicitly.
892 /// Everything else is useful only for sending out for initial routing sync.
893 /// Not stored if contains excess data to prevent DoS.
895 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::msgs::NodeAnnouncement) {
896 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
897 unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
899 /// Constructs a new NodeAnnouncementInfo given each field
902 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 {
903 let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
904 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()) } }) };
905 NodeAnnouncementInfo { inner: Box::into_raw(Box::new(nativeNodeAnnouncementInfo {
906 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
907 last_update: last_update_arg,
909 alias: alias_arg.data,
910 addresses: local_addresses_arg,
911 announcement_message: local_announcement_message_arg,
912 })), is_owned: true }
914 impl Clone for NodeAnnouncementInfo {
915 fn clone(&self) -> Self {
917 inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
918 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
924 /// Used only if an object of this type is returned as a trait impl by a method
925 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
926 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
929 /// Creates a copy of the NodeAnnouncementInfo
930 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
934 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
935 pub extern "C" fn NodeAnnouncementInfo_write(obj: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
936 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
939 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
940 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
943 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
944 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
945 let res = crate::c_types::deserialize_obj(ser);
946 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() };
950 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
951 type nativeNodeInfo = nativeNodeInfoImport;
953 /// Details about a node in the network, known from the network announcement.
956 pub struct NodeInfo {
957 /// A pointer to the opaque Rust object.
959 /// Nearly everywhere, inner must be non-null, however in places where
960 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
961 pub inner: *mut nativeNodeInfo,
962 /// Indicates that this is the only struct which contains the same pointer.
964 /// Rust functions which take ownership of an object provided via an argument require
965 /// this to be true and invalidate the object pointed to by inner.
969 impl Drop for NodeInfo {
971 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
972 let _ = unsafe { Box::from_raw(self.inner) };
976 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
978 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
980 /// Used only if an object of this type is returned as a trait impl by a method
981 extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
982 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
985 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
987 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
988 assert!(self.is_owned);
989 let ret = self.inner;
990 self.inner = std::ptr::null_mut();
994 /// All valid channels a node has announced
996 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
997 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
998 unsafe { &mut *this_ptr.inner }.channels = local_val;
1000 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1001 /// The two fields (flat and proportional fee) are independent,
1002 /// meaning they don't have to refer to the same channel.
1004 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::routing::network_graph::RoutingFees {
1005 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees;
1006 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 };
1009 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1010 /// The two fields (flat and proportional fee) are independent,
1011 /// meaning they don't have to refer to the same channel.
1013 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::RoutingFees) {
1014 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1015 unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees = local_val;
1017 /// More information about a node from node_announcement.
1018 /// Optional because we store a Node entry after learning about it from
1019 /// a channel announcement, but before receiving a node announcement.
1021 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::routing::network_graph::NodeAnnouncementInfo {
1022 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_info;
1023 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 };
1026 /// More information about a node from node_announcement.
1027 /// Optional because we store a Node entry after learning about it from
1028 /// a channel announcement, but before receiving a node announcement.
1030 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::NodeAnnouncementInfo) {
1031 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1032 unsafe { &mut *this_ptr.inner }.announcement_info = local_val;
1034 /// Constructs a new NodeInfo given each field
1037 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 {
1038 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1039 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()) } }) };
1040 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()) } }) };
1041 NodeInfo { inner: Box::into_raw(Box::new(nativeNodeInfo {
1042 channels: local_channels_arg,
1043 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
1044 announcement_info: local_announcement_info_arg,
1045 })), is_owned: true }
1047 impl Clone for NodeInfo {
1048 fn clone(&self) -> Self {
1050 inner: if <*mut nativeNodeInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
1051 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1057 /// Used only if an object of this type is returned as a trait impl by a method
1058 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1059 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1062 /// Creates a copy of the NodeInfo
1063 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1067 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1068 pub extern "C" fn NodeInfo_write(obj: &NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1069 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1072 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1073 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1076 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1077 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1078 let res = crate::c_types::deserialize_obj(ser);
1079 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() };
1083 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
1084 pub extern "C" fn NetworkGraph_write(obj: &NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1085 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1088 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1089 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1092 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
1093 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1094 let res = crate::c_types::deserialize_obj(ser);
1095 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() };
1098 /// Creates a new, empty, network graph.
1101 pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::routing::network_graph::NetworkGraph {
1102 let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap());
1103 crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1106 /// For an already known node (from channel announcements), update its stored properties from a
1107 /// given node announcement.
1109 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1110 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1111 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1114 pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1115 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_announcement(unsafe { &*msg.inner }, secp256k1::SECP256K1);
1116 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() };
1120 /// For an already known node (from channel announcements), update its stored properties from a
1121 /// given node announcement without verifying the associated signatures. Because we aren't
1122 /// given the associated signatures here we cannot relay the node announcement to any of our
1126 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 {
1127 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_unsigned_announcement(unsafe { &*msg.inner });
1128 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() };
1132 /// Store or update channel info from a channel announcement.
1134 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1135 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1136 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1138 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1139 /// the corresponding UTXO exists on chain and is correctly-formatted.
1142 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 {
1143 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1144 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_announcement(unsafe { &*msg.inner }, &local_chain_access, secp256k1::SECP256K1);
1145 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() };
1149 /// Store or update channel info from a channel announcement without verifying the associated
1150 /// signatures. Because we aren't given the associated signatures here we cannot relay the
1151 /// channel announcement to any of our peers.
1153 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1154 /// the corresponding UTXO exists on chain and is correctly-formatted.
1157 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 {
1158 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1159 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_unsigned_announcement(unsafe { &*msg.inner }, &local_chain_access);
1160 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() };
1164 /// Close a channel if a corresponding HTLC fail was sent.
1165 /// If permanent, removes a channel from the local storage.
1166 /// May cause the removal of nodes too, if this was their last channel.
1167 /// If not permanent, makes channels unavailable for routing.
1169 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
1170 unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.close_channel_from_update(short_channel_id, is_permanent)
1173 /// For an already known (from announcement) channel, update info about one of the directions
1176 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1177 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1178 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1181 pub extern "C" fn NetworkGraph_update_channel(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1182 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel(unsafe { &*msg.inner }, secp256k1::SECP256K1);
1183 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() };
1187 /// For an already known (from announcement) channel, update info about one of the directions
1188 /// of the channel without verifying the associated signatures. Because we aren't given the
1189 /// associated signatures here we cannot relay the channel update to any of our peers.
1192 pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1193 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_unsigned(unsafe { &*msg.inner });
1194 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() };