1 //! The top-level network map tracking logic lives here.
4 use bitcoin::hashes::Hash;
8 use lightning::routing::network_graph::NetworkGraph as nativeNetworkGraphImport;
9 type nativeNetworkGraph = nativeNetworkGraphImport;
11 /// Represents the network as nodes and channels between them
14 pub struct NetworkGraph {
15 /// Nearly everywhere, inner must be non-null, however in places where
16 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
17 pub inner: *mut nativeNetworkGraph,
21 impl Drop for NetworkGraph {
23 if self.is_owned && !self.inner.is_null() {
24 let _ = unsafe { Box::from_raw(self.inner) };
29 pub extern "C" fn NetworkGraph_free(this_ptr: NetworkGraph) { }
31 /// Used only if an object of this type is returned as a trait impl by a method
32 extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
33 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetworkGraph); }
36 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
38 pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
39 assert!(self.is_owned);
41 self.inner = std::ptr::null_mut();
46 use lightning::routing::network_graph::LockedNetworkGraph as nativeLockedNetworkGraphImport;
47 type nativeLockedNetworkGraph = nativeLockedNetworkGraphImport<'static>;
49 /// A simple newtype for RwLockReadGuard<'a, NetworkGraph>.
50 /// This exists only to make accessing a RwLock<NetworkGraph> possible from
51 /// the C bindings, as it can be done directly in Rust code.
54 pub struct LockedNetworkGraph {
55 /// Nearly everywhere, inner must be non-null, however in places where
56 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
57 pub inner: *mut nativeLockedNetworkGraph,
61 impl Drop for LockedNetworkGraph {
63 if self.is_owned && !self.inner.is_null() {
64 let _ = unsafe { Box::from_raw(self.inner) };
69 pub extern "C" fn LockedNetworkGraph_free(this_ptr: LockedNetworkGraph) { }
71 /// Used only if an object of this type is returned as a trait impl by a method
72 extern "C" fn LockedNetworkGraph_free_void(this_ptr: *mut c_void) {
73 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLockedNetworkGraph); }
76 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
77 impl LockedNetworkGraph {
78 pub(crate) fn take_inner(mut self) -> *mut nativeLockedNetworkGraph {
79 assert!(self.is_owned);
81 self.inner = std::ptr::null_mut();
86 use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport;
87 type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport<crate::chain::Access, crate::util::logger::Logger>;
89 /// Receives and validates network updates from peers,
90 /// stores authentic and relevant data as a network graph.
91 /// This network graph is then used for routing payments.
92 /// Provides interface to help with initial routing sync by
93 /// serving historical announcements.
96 pub struct NetGraphMsgHandler {
97 /// Nearly everywhere, inner must be non-null, however in places where
98 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
99 pub inner: *mut nativeNetGraphMsgHandler,
103 impl Drop for NetGraphMsgHandler {
105 if self.is_owned && !self.inner.is_null() {
106 let _ = unsafe { Box::from_raw(self.inner) };
111 pub extern "C" fn NetGraphMsgHandler_free(this_ptr: NetGraphMsgHandler) { }
113 /// Used only if an object of this type is returned as a trait impl by a method
114 extern "C" fn NetGraphMsgHandler_free_void(this_ptr: *mut c_void) {
115 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetGraphMsgHandler); }
118 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
119 impl NetGraphMsgHandler {
120 pub(crate) fn take_inner(mut self) -> *mut nativeNetGraphMsgHandler {
121 assert!(self.is_owned);
122 let ret = self.inner;
123 self.inner = std::ptr::null_mut();
127 /// Creates a new tracker of the actual state of the network of channels and nodes,
128 /// assuming a fresh network graph.
129 /// Chain monitor is used to make sure announced channels exist on-chain,
130 /// channel data is correct, and that the announcement is signed with
131 /// channel owners' keys.
134 pub extern "C" fn NetGraphMsgHandler_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes, chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger) -> NetGraphMsgHandler {
135 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
136 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap(), local_chain_access, logger);
137 NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
140 /// Creates a new tracker of the actual state of the network of channels and nodes,
141 /// assuming an existing Network Graph.
144 pub extern "C" fn NetGraphMsgHandler_from_net_graph(chain_access: *mut crate::chain::Access, mut logger: crate::util::logger::Logger, mut network_graph: crate::routing::network_graph::NetworkGraph) -> NetGraphMsgHandler {
145 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
146 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::from_net_graph(local_chain_access, logger, *unsafe { Box::from_raw(network_graph.take_inner()) });
147 NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
150 /// Take a read lock on the network_graph and return it in the C-bindings
151 /// newtype helper. This is likely only useful when called via the C
152 /// bindings as you can call `self.network_graph.read().unwrap()` in Rust
156 pub extern "C" fn NetGraphMsgHandler_read_locked_graph(this_arg: &NetGraphMsgHandler) -> crate::routing::network_graph::LockedNetworkGraph {
157 let mut ret = unsafe { &*this_arg.inner }.read_locked_graph();
158 crate::routing::network_graph::LockedNetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
161 /// Get a reference to the NetworkGraph which this read-lock contains.
164 pub extern "C" fn LockedNetworkGraph_graph(this_arg: &LockedNetworkGraph) -> crate::routing::network_graph::NetworkGraph {
165 let mut ret = unsafe { &*this_arg.inner }.graph();
166 crate::routing::network_graph::NetworkGraph { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
169 impl From<nativeNetGraphMsgHandler> for crate::ln::msgs::RoutingMessageHandler {
170 fn from(obj: nativeNetGraphMsgHandler) -> Self {
171 let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
172 let mut ret = NetGraphMsgHandler_as_RoutingMessageHandler(&rust_obj);
173 // 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
174 rust_obj.inner = std::ptr::null_mut();
175 ret.free = Some(NetGraphMsgHandler_free_void);
180 pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: &NetGraphMsgHandler) -> crate::ln::msgs::RoutingMessageHandler {
181 crate::ln::msgs::RoutingMessageHandler {
182 this_arg: unsafe { (*this_arg).inner as *mut c_void },
184 handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement,
185 handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement,
186 handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update,
187 handle_htlc_fail_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update,
188 get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements,
189 get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements,
190 sync_routing_table: NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table,
191 handle_reply_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range,
192 handle_reply_short_channel_ids_end: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
193 handle_query_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range,
194 handle_query_short_channel_ids: NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids,
195 MessageSendEventsProvider: crate::util::events::MessageSendEventsProvider {
196 this_arg: unsafe { (*this_arg).inner as *mut c_void },
198 get_and_clear_pending_msg_events: NetGraphMsgHandler_RoutingMessageHandler_get_and_clear_pending_msg_events,
202 use lightning::ln::msgs::RoutingMessageHandler as RoutingMessageHandlerTraitImport;
204 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
205 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_node_announcement(unsafe { &*msg.inner });
206 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() };
210 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
211 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_channel_announcement(unsafe { &*msg.inner });
212 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() };
215 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, update: &crate::ln::msgs::HTLCFailChannelUpdate) {
216 unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_htlc_fail_channel_update(&update.to_native())
219 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
220 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_channel_update(unsafe { &*msg.inner });
221 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() };
225 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 {
226 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.get_next_channel_announcements(starting_point, batch_amount);
227 let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_1 = crate::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { std::ptr::null_mut() } else { { Box::into_raw(Box::new((orig_ret_0_1.unwrap()))) } }, is_owned: true }; let mut local_orig_ret_0_2 = crate::ln::msgs::ChannelUpdate { inner: if orig_ret_0_2.is_none() { std::ptr::null_mut() } else { { Box::into_raw(Box::new((orig_ret_0_2.unwrap()))) } }, is_owned: true }; let mut local_ret_0 = (crate::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(orig_ret_0_0)), is_owned: true }, local_orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }); };
231 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 {
232 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();
233 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.get_next_node_announcements(local_starting_point, batch_amount);
234 let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
237 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) {
238 unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.sync_routing_table(&their_node_id.into_rust(), unsafe { &*init_msg.inner })
241 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 {
242 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_reply_channel_range(&their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
243 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() };
247 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 {
248 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_reply_short_channel_ids_end(&their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
249 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() };
253 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 {
254 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_query_channel_range(&_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) });
255 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() };
259 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 {
260 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.handle_query_short_channel_ids(&_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) });
261 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() };
264 use lightning::util::events::MessageSendEventsProvider as nativeMessageSendEventsProviderTrait;
266 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
267 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.get_and_clear_pending_msg_events();
268 let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
272 impl From<nativeNetGraphMsgHandler> for crate::util::events::MessageSendEventsProvider {
273 fn from(obj: nativeNetGraphMsgHandler) -> Self {
274 let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
275 let mut ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&rust_obj);
276 // 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
277 rust_obj.inner = std::ptr::null_mut();
278 ret.free = Some(NetGraphMsgHandler_free_void);
283 pub extern "C" fn NetGraphMsgHandler_as_MessageSendEventsProvider(this_arg: &NetGraphMsgHandler) -> crate::util::events::MessageSendEventsProvider {
284 crate::util::events::MessageSendEventsProvider {
285 this_arg: unsafe { (*this_arg).inner as *mut c_void },
287 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
290 use lightning::util::events::MessageSendEventsProvider as MessageSendEventsProviderTraitImport;
292 extern "C" fn NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
293 let mut ret = unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }.get_and_clear_pending_msg_events();
294 let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { crate::util::events::MessageSendEvent::native_into(item) }); };
299 use lightning::routing::network_graph::DirectionalChannelInfo as nativeDirectionalChannelInfoImport;
300 type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport;
302 /// Details about one direction of a channel. Received
303 /// within a channel update.
306 pub struct DirectionalChannelInfo {
307 /// Nearly everywhere, inner must be non-null, however in places where
308 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
309 pub inner: *mut nativeDirectionalChannelInfo,
313 impl Drop for DirectionalChannelInfo {
315 if self.is_owned && !self.inner.is_null() {
316 let _ = unsafe { Box::from_raw(self.inner) };
321 pub extern "C" fn DirectionalChannelInfo_free(this_ptr: DirectionalChannelInfo) { }
323 /// Used only if an object of this type is returned as a trait impl by a method
324 extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) {
325 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectionalChannelInfo); }
328 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
329 impl DirectionalChannelInfo {
330 pub(crate) fn take_inner(mut self) -> *mut nativeDirectionalChannelInfo {
331 assert!(self.is_owned);
332 let ret = self.inner;
333 self.inner = std::ptr::null_mut();
337 impl Clone for DirectionalChannelInfo {
338 fn clone(&self) -> Self {
340 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
341 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
347 /// Used only if an object of this type is returned as a trait impl by a method
348 pub(crate) extern "C" fn DirectionalChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
349 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectionalChannelInfo)).clone() })) as *mut c_void
352 pub extern "C" fn DirectionalChannelInfo_clone(orig: &DirectionalChannelInfo) -> DirectionalChannelInfo {
355 /// When the last update to the channel direction was issued.
356 /// Value is opaque, as set in the announcement.
358 pub extern "C" fn DirectionalChannelInfo_get_last_update(this_ptr: &DirectionalChannelInfo) -> u32 {
359 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
362 /// When the last update to the channel direction was issued.
363 /// Value is opaque, as set in the announcement.
365 pub extern "C" fn DirectionalChannelInfo_set_last_update(this_ptr: &mut DirectionalChannelInfo, mut val: u32) {
366 unsafe { &mut *this_ptr.inner }.last_update = val;
368 /// Whether the channel can be currently used for payments (in this one direction).
370 pub extern "C" fn DirectionalChannelInfo_get_enabled(this_ptr: &DirectionalChannelInfo) -> bool {
371 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.enabled;
374 /// Whether the channel can be currently used for payments (in this one direction).
376 pub extern "C" fn DirectionalChannelInfo_set_enabled(this_ptr: &mut DirectionalChannelInfo, mut val: bool) {
377 unsafe { &mut *this_ptr.inner }.enabled = val;
379 /// The difference in CLTV values that you must have when routing through this channel.
381 pub extern "C" fn DirectionalChannelInfo_get_cltv_expiry_delta(this_ptr: &DirectionalChannelInfo) -> u16 {
382 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta;
385 /// The difference in CLTV values that you must have when routing through this channel.
387 pub extern "C" fn DirectionalChannelInfo_set_cltv_expiry_delta(this_ptr: &mut DirectionalChannelInfo, mut val: u16) {
388 unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val;
390 /// The minimum value, which must be relayed to the next hop via the channel
392 pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &DirectionalChannelInfo) -> u64 {
393 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat;
396 /// The minimum value, which must be relayed to the next hop via the channel
398 pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) {
399 unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val;
401 /// Fees charged when the channel is used for routing
403 pub extern "C" fn DirectionalChannelInfo_get_fees(this_ptr: &DirectionalChannelInfo) -> crate::routing::network_graph::RoutingFees {
404 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fees;
405 crate::routing::network_graph::RoutingFees { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
407 /// Fees charged when the channel is used for routing
409 pub extern "C" fn DirectionalChannelInfo_set_fees(this_ptr: &mut DirectionalChannelInfo, mut val: crate::routing::network_graph::RoutingFees) {
410 unsafe { &mut *this_ptr.inner }.fees = *unsafe { Box::from_raw(val.take_inner()) };
412 /// Most recent update for the channel received from the network
413 /// Mostly redundant with the data we store in fields explicitly.
414 /// Everything else is useful only for sending out for initial routing sync.
415 /// Not stored if contains excess data to prevent DoS.
417 pub extern "C" fn DirectionalChannelInfo_get_last_update_message(this_ptr: &DirectionalChannelInfo) -> crate::ln::msgs::ChannelUpdate {
418 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update_message;
419 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 };
422 /// Most recent update for the channel received from the network
423 /// Mostly redundant with the data we store in fields explicitly.
424 /// Everything else is useful only for sending out for initial routing sync.
425 /// Not stored if contains excess data to prevent DoS.
427 pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut DirectionalChannelInfo, mut val: crate::ln::msgs::ChannelUpdate) {
428 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
429 unsafe { &mut *this_ptr.inner }.last_update_message = local_val;
432 pub extern "C" fn DirectionalChannelInfo_write(obj: &DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z {
433 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
436 pub(crate) extern "C" fn DirectionalChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
437 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDirectionalChannelInfo) })
440 pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> DirectionalChannelInfo {
441 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
442 DirectionalChannelInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
444 DirectionalChannelInfo { inner: std::ptr::null_mut(), is_owned: true }
448 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
449 type nativeChannelInfo = nativeChannelInfoImport;
451 /// Details about a channel (both directions).
452 /// Received within a channel announcement.
455 pub struct ChannelInfo {
456 /// Nearly everywhere, inner must be non-null, however in places where
457 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
458 pub inner: *mut nativeChannelInfo,
462 impl Drop for ChannelInfo {
464 if self.is_owned && !self.inner.is_null() {
465 let _ = unsafe { Box::from_raw(self.inner) };
470 pub extern "C" fn ChannelInfo_free(this_ptr: ChannelInfo) { }
472 /// Used only if an object of this type is returned as a trait impl by a method
473 extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
474 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
477 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
479 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
480 assert!(self.is_owned);
481 let ret = self.inner;
482 self.inner = std::ptr::null_mut();
486 /// Protocol features of a channel communicated during its announcement
488 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::ln::features::ChannelFeatures {
489 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
490 crate::ln::features::ChannelFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
492 /// Protocol features of a channel communicated during its announcement
494 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::ln::features::ChannelFeatures) {
495 unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) };
497 /// Source node of the first direction of a channel
499 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
500 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_one;
501 crate::c_types::PublicKey::from_rust(&(*inner_val))
503 /// Source node of the first direction of a channel
505 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
506 unsafe { &mut *this_ptr.inner }.node_one = val.into_rust();
508 /// Details about the first direction of a channel
510 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
511 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.one_to_two;
512 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 };
515 /// Details about the first direction of a channel
517 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::routing::network_graph::DirectionalChannelInfo) {
518 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
519 unsafe { &mut *this_ptr.inner }.one_to_two = local_val;
521 /// Source node of the second direction of a channel
523 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
524 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_two;
525 crate::c_types::PublicKey::from_rust(&(*inner_val))
527 /// Source node of the second direction of a channel
529 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
530 unsafe { &mut *this_ptr.inner }.node_two = val.into_rust();
532 /// Details about the second direction of a channel
534 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::routing::network_graph::DirectionalChannelInfo {
535 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.two_to_one;
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 second direction of a channel
541 pub extern "C" fn ChannelInfo_set_two_to_one(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 }.two_to_one = local_val;
545 /// An initial announcement of the channel
546 /// Mostly redundant with the data we store in fields explicitly.
547 /// Everything else is useful only for sending out for initial routing sync.
548 /// Not stored if contains excess data to prevent DoS.
550 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::ln::msgs::ChannelAnnouncement {
551 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
552 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 };
555 /// An initial announcement of the channel
556 /// Mostly redundant with the data we store in fields explicitly.
557 /// Everything else is useful only for sending out for initial routing sync.
558 /// Not stored if contains excess data to prevent DoS.
560 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::ln::msgs::ChannelAnnouncement) {
561 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
562 unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
565 pub extern "C" fn ChannelInfo_write(obj: &ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
566 crate::c_types::serialize_obj(unsafe { &(*(*obj).inner) })
569 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
570 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
573 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> ChannelInfo {
574 if let Ok(res) = crate::c_types::deserialize_obj(ser) {
575 ChannelInfo { inner: Box::into_raw(Box::new(res)), is_owned: true }
577 ChannelInfo { inner: std::ptr::null_mut(), is_owned: true }
581 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
582 type nativeRoutingFees = nativeRoutingFeesImport;
584 /// Fees for routing via a given channel or a node
587 pub struct RoutingFees {
588 /// Nearly everywhere, inner must be non-null, however in places where
589 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
590 pub inner: *mut nativeRoutingFees,
594 impl Drop for RoutingFees {
596 if self.is_owned && !self.inner.is_null() {
597 let _ = unsafe { Box::from_raw(self.inner) };
602 pub extern "C" fn RoutingFees_free(this_ptr: RoutingFees) { }
604 /// Used only if an object of this type is returned as a trait impl by a method
605 extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
606 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
609 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
611 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
612 assert!(self.is_owned);
613 let ret = self.inner;
614 self.inner = std::ptr::null_mut();
618 impl Clone for RoutingFees {
619 fn clone(&self) -> Self {
621 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
622 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
628 /// Used only if an object of this type is returned as a trait impl by a method
629 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
630 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
633 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
636 /// Flat routing fee in satoshis
638 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
639 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.base_msat;
642 /// Flat routing fee in satoshis
644 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
645 unsafe { &mut *this_ptr.inner }.base_msat = val;
647 /// Liquidity-based routing fee in millionths of a routed amount.
648 /// In other words, 10000 is 1%.
650 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
651 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.proportional_millionths;
654 /// Liquidity-based routing fee in millionths of a routed amount.
655 /// In other words, 10000 is 1%.
657 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
658 unsafe { &mut *this_ptr.inner }.proportional_millionths = val;
662 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
663 RoutingFees { inner: Box::into_raw(Box::new(nativeRoutingFees {
664 base_msat: base_msat_arg,
665 proportional_millionths: proportional_millionths_arg,
666 })), is_owned: true }
669 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
670 let res = crate::c_types::deserialize_obj(ser);
671 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() };
675 pub extern "C" fn RoutingFees_write(obj: &RoutingFees) -> crate::c_types::derived::CVec_u8Z {
676 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
679 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
680 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
683 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
684 type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
686 /// Information received in the latest node_announcement from this node.
689 pub struct NodeAnnouncementInfo {
690 /// Nearly everywhere, inner must be non-null, however in places where
691 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
692 pub inner: *mut nativeNodeAnnouncementInfo,
696 impl Drop for NodeAnnouncementInfo {
698 if self.is_owned && !self.inner.is_null() {
699 let _ = unsafe { Box::from_raw(self.inner) };
704 pub extern "C" fn NodeAnnouncementInfo_free(this_ptr: NodeAnnouncementInfo) { }
706 /// Used only if an object of this type is returned as a trait impl by a method
707 extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
708 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
711 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
712 impl NodeAnnouncementInfo {
713 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
714 assert!(self.is_owned);
715 let ret = self.inner;
716 self.inner = std::ptr::null_mut();
720 impl Clone for NodeAnnouncementInfo {
721 fn clone(&self) -> Self {
723 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
724 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
730 /// Used only if an object of this type is returned as a trait impl by a method
731 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
732 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
735 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
738 /// Protocol features the node announced support for
740 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::ln::features::NodeFeatures {
741 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
742 crate::ln::features::NodeFeatures { inner: unsafe { ( (&((*inner_val)) as *const _) as *mut _) }, is_owned: false }
744 /// Protocol features the node announced support for
746 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::features::NodeFeatures) {
747 unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) };
749 /// When the last known update to the node state was issued.
750 /// Value is opaque, as set in the announcement.
752 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
753 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
756 /// When the last known update to the node state was issued.
757 /// Value is opaque, as set in the announcement.
759 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
760 unsafe { &mut *this_ptr.inner }.last_update = val;
762 /// Color assigned to the node
764 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
765 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.rgb;
768 /// Color assigned to the node
770 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
771 unsafe { &mut *this_ptr.inner }.rgb = val.data;
773 /// Moniker assigned to the node.
774 /// May be invalid or malicious (eg control chars),
775 /// should not be exposed to the user.
777 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
778 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.alias;
781 /// Moniker assigned to the node.
782 /// May be invalid or malicious (eg control chars),
783 /// should not be exposed to the user.
785 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
786 unsafe { &mut *this_ptr.inner }.alias = val.data;
788 /// Internet-level addresses via which one can connect to the node
790 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
791 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
792 unsafe { &mut *this_ptr.inner }.addresses = local_val;
794 /// An initial announcement of the node
795 /// Mostly redundant with the data we store in fields explicitly.
796 /// Everything else is useful only for sending out for initial routing sync.
797 /// Not stored if contains excess data to prevent DoS.
799 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::ln::msgs::NodeAnnouncement {
800 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
801 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 };
804 /// An initial announcement of the node
805 /// Mostly redundant with the data we store in fields explicitly.
806 /// Everything else is useful only for sending out for initial routing sync.
807 /// Not stored if contains excess data to prevent DoS.
809 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::ln::msgs::NodeAnnouncement) {
810 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
811 unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
815 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 {
816 let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
817 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()) } }) };
818 NodeAnnouncementInfo { inner: Box::into_raw(Box::new(nativeNodeAnnouncementInfo {
819 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
820 last_update: last_update_arg,
822 alias: alias_arg.data,
823 addresses: local_addresses_arg,
824 announcement_message: local_announcement_message_arg,
825 })), is_owned: true }
828 pub extern "C" fn NodeAnnouncementInfo_write(obj: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
829 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
832 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
833 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
836 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
837 let res = crate::c_types::deserialize_obj(ser);
838 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() };
842 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
843 type nativeNodeInfo = nativeNodeInfoImport;
845 /// Details about a node in the network, known from the network announcement.
848 pub struct NodeInfo {
849 /// Nearly everywhere, inner must be non-null, however in places where
850 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
851 pub inner: *mut nativeNodeInfo,
855 impl Drop for NodeInfo {
857 if self.is_owned && !self.inner.is_null() {
858 let _ = unsafe { Box::from_raw(self.inner) };
863 pub extern "C" fn NodeInfo_free(this_ptr: NodeInfo) { }
865 /// Used only if an object of this type is returned as a trait impl by a method
866 extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
867 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
870 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
872 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
873 assert!(self.is_owned);
874 let ret = self.inner;
875 self.inner = std::ptr::null_mut();
879 impl Clone for NodeInfo {
880 fn clone(&self) -> Self {
882 inner: if self.inner.is_null() { std::ptr::null_mut() } else {
883 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
889 /// Used only if an object of this type is returned as a trait impl by a method
890 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
891 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
894 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
897 /// All valid channels a node has announced
899 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
900 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
901 unsafe { &mut *this_ptr.inner }.channels = local_val;
903 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
904 /// The two fields (flat and proportional fee) are independent,
905 /// meaning they don't have to refer to the same channel.
907 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::routing::network_graph::RoutingFees {
908 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees;
909 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 };
912 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
913 /// The two fields (flat and proportional fee) are independent,
914 /// meaning they don't have to refer to the same channel.
916 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::RoutingFees) {
917 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
918 unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees = local_val;
920 /// More information about a node from node_announcement.
921 /// Optional because we store a Node entry after learning about it from
922 /// a channel announcement, but before receiving a node announcement.
924 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::routing::network_graph::NodeAnnouncementInfo {
925 let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_info;
926 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 };
929 /// More information about a node from node_announcement.
930 /// Optional because we store a Node entry after learning about it from
931 /// a channel announcement, but before receiving a node announcement.
933 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::routing::network_graph::NodeAnnouncementInfo) {
934 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
935 unsafe { &mut *this_ptr.inner }.announcement_info = local_val;
939 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 {
940 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
941 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()) } }) };
942 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()) } }) };
943 NodeInfo { inner: Box::into_raw(Box::new(nativeNodeInfo {
944 channels: local_channels_arg,
945 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
946 announcement_info: local_announcement_info_arg,
947 })), is_owned: true }
950 pub extern "C" fn NodeInfo_write(obj: &NodeInfo) -> crate::c_types::derived::CVec_u8Z {
951 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
954 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
955 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
958 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
959 let res = crate::c_types::deserialize_obj(ser);
960 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() };
964 pub extern "C" fn NetworkGraph_write(obj: &NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
965 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
968 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
969 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
972 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
973 let res = crate::c_types::deserialize_obj(ser);
974 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() };
977 /// Creates a new, empty, network graph.
980 pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::routing::network_graph::NetworkGraph {
981 let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap());
982 crate::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
985 /// For an already known node (from channel announcements), update its stored properties from a
986 /// given node announcement.
988 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
989 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
990 /// routing messages from a source using a protocol other than the lightning P2P protocol.
993 pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
994 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_announcement(unsafe { &*msg.inner }, &bitcoin::secp256k1::Secp256k1::new());
995 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() };
999 /// For an already known node (from channel announcements), update its stored properties from a
1000 /// given node announcement without verifying the associated signatures. Because we aren't
1001 /// given the associated signatures here we cannot relay the node announcement to any of our
1005 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 {
1006 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_unsigned_announcement(unsafe { &*msg.inner });
1007 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() };
1011 /// Store or update channel info from a channel announcement.
1013 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1014 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1015 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1017 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1018 /// the corresponding UTXO exists on chain and is correctly-formatted.
1021 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 {
1022 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1023 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_announcement(unsafe { &*msg.inner }, &local_chain_access, &bitcoin::secp256k1::Secp256k1::new());
1024 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() };
1028 /// Store or update channel info from a channel announcement without verifying the associated
1029 /// signatures. Because we aren't given the associated signatures here we cannot relay the
1030 /// channel announcement to any of our peers.
1032 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1033 /// the corresponding UTXO exists on chain and is correctly-formatted.
1036 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 {
1037 let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1038 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_unsigned_announcement(unsafe { &*msg.inner }, &local_chain_access);
1039 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() };
1043 /// Close a channel if a corresponding HTLC fail was sent.
1044 /// If permanent, removes a channel from the local storage.
1045 /// May cause the removal of nodes too, if this was their last channel.
1046 /// If not permanent, makes channels unavailable for routing.
1048 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
1049 unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.close_channel_from_update(short_channel_id, is_permanent)
1052 /// For an already known (from announcement) channel, update info about one of the directions
1055 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1056 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1057 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1060 pub extern "C" fn NetworkGraph_update_channel(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1061 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel(unsafe { &*msg.inner }, &bitcoin::secp256k1::Secp256k1::new());
1062 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() };
1066 /// For an already known (from announcement) channel, update info about one of the directions
1067 /// of the channel without verifying the associated signatures. Because we aren't given the
1068 /// associated signatures here we cannot relay the channel update to any of our peers.
1071 pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &mut NetworkGraph, msg: &crate::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1072 let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_unsigned(unsafe { &*msg.inner });
1073 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() };