1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! The top-level network map tracking logic lives here.
11 use std::str::FromStr;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
18 use lightning::routing::network_graph::NetworkGraph as nativeNetworkGraphImport;
19 type nativeNetworkGraph = nativeNetworkGraphImport;
21 /// Represents the network as nodes and channels between them
24 pub struct NetworkGraph {
25 /// A pointer to the opaque Rust object.
27 /// Nearly everywhere, inner must be non-null, however in places where
28 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
29 pub inner: *mut nativeNetworkGraph,
30 /// Indicates that this is the only struct which contains the same pointer.
32 /// Rust functions which take ownership of an object provided via an argument require
33 /// this to be true and invalidate the object pointed to by inner.
37 impl Drop for NetworkGraph {
39 if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) {
40 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
44 /// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL.
46 pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { }
48 /// Used only if an object of this type is returned as a trait impl by a method
49 extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
50 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetworkGraph); }
54 pub(crate) fn get_native_ref(&self) -> &'static nativeNetworkGraph {
55 unsafe { &*ObjOps::untweak_ptr(self.inner) }
57 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetworkGraph {
58 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
60 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
61 pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
62 assert!(self.is_owned);
63 let ret = ObjOps::untweak_ptr(self.inner);
64 self.inner = std::ptr::null_mut();
69 use lightning::routing::network_graph::ReadOnlyNetworkGraph as nativeReadOnlyNetworkGraphImport;
70 type nativeReadOnlyNetworkGraph = nativeReadOnlyNetworkGraphImport<'static>;
72 /// A read-only view of [`NetworkGraph`].
75 pub struct ReadOnlyNetworkGraph {
76 /// A pointer to the opaque Rust object.
78 /// Nearly everywhere, inner must be non-null, however in places where
79 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
80 pub inner: *mut nativeReadOnlyNetworkGraph,
81 /// Indicates that this is the only struct which contains the same pointer.
83 /// Rust functions which take ownership of an object provided via an argument require
84 /// this to be true and invalidate the object pointed to by inner.
88 impl Drop for ReadOnlyNetworkGraph {
90 if self.is_owned && !<*mut nativeReadOnlyNetworkGraph>::is_null(self.inner) {
91 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
95 /// Frees any resources used by the ReadOnlyNetworkGraph, if is_owned is set and inner is non-NULL.
97 pub extern "C" fn ReadOnlyNetworkGraph_free(this_obj: ReadOnlyNetworkGraph) { }
99 /// Used only if an object of this type is returned as a trait impl by a method
100 extern "C" fn ReadOnlyNetworkGraph_free_void(this_ptr: *mut c_void) {
101 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeReadOnlyNetworkGraph); }
104 impl ReadOnlyNetworkGraph {
105 pub(crate) fn get_native_ref(&self) -> &'static nativeReadOnlyNetworkGraph {
106 unsafe { &*ObjOps::untweak_ptr(self.inner) }
108 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReadOnlyNetworkGraph {
109 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
111 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
112 pub(crate) fn take_inner(mut self) -> *mut nativeReadOnlyNetworkGraph {
113 assert!(self.is_owned);
114 let ret = ObjOps::untweak_ptr(self.inner);
115 self.inner = std::ptr::null_mut();
119 /// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
120 /// return packet by a node along the route. See [BOLT #4] for details.
122 /// [BOLT #4]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md
126 pub enum NetworkUpdate {
127 /// An error indicating a `channel_update` messages should be applied via
128 /// [`NetworkGraph::update_channel`].
129 ChannelUpdateMessage {
130 /// The update to apply via [`NetworkGraph::update_channel`].
131 msg: crate::lightning::ln::msgs::ChannelUpdate,
133 /// An error indicating only that a channel has been closed, which should be applied via
134 /// [`NetworkGraph::close_channel_from_update`].
136 /// The short channel id of the closed channel.
137 short_channel_id: u64,
138 /// Whether the channel should be permanently removed or temporarily disabled until a new
139 /// `channel_update` message is received.
142 /// An error indicating only that a node has failed, which should be applied via
143 /// [`NetworkGraph::fail_node`].
145 /// The node id of the failed node.
146 node_id: crate::c_types::PublicKey,
147 /// Whether the node should be permanently removed from consideration or can be restored
148 /// when a new `channel_update` message is received.
152 use lightning::routing::network_graph::NetworkUpdate as nativeNetworkUpdate;
155 pub(crate) fn to_native(&self) -> nativeNetworkUpdate {
157 NetworkUpdate::ChannelUpdateMessage {ref msg, } => {
158 let mut msg_nonref = (*msg).clone();
159 nativeNetworkUpdate::ChannelUpdateMessage {
160 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
163 NetworkUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => {
164 let mut short_channel_id_nonref = (*short_channel_id).clone();
165 let mut is_permanent_nonref = (*is_permanent).clone();
166 nativeNetworkUpdate::ChannelClosed {
167 short_channel_id: short_channel_id_nonref,
168 is_permanent: is_permanent_nonref,
171 NetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
172 let mut node_id_nonref = (*node_id).clone();
173 let mut is_permanent_nonref = (*is_permanent).clone();
174 nativeNetworkUpdate::NodeFailure {
175 node_id: node_id_nonref.into_rust(),
176 is_permanent: is_permanent_nonref,
182 pub(crate) fn into_native(self) -> nativeNetworkUpdate {
184 NetworkUpdate::ChannelUpdateMessage {mut msg, } => {
185 nativeNetworkUpdate::ChannelUpdateMessage {
186 msg: *unsafe { Box::from_raw(msg.take_inner()) },
189 NetworkUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => {
190 nativeNetworkUpdate::ChannelClosed {
191 short_channel_id: short_channel_id,
192 is_permanent: is_permanent,
195 NetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
196 nativeNetworkUpdate::NodeFailure {
197 node_id: node_id.into_rust(),
198 is_permanent: is_permanent,
204 pub(crate) fn from_native(native: &nativeNetworkUpdate) -> Self {
206 nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => {
207 let mut msg_nonref = (*msg).clone();
208 NetworkUpdate::ChannelUpdateMessage {
209 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
212 nativeNetworkUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => {
213 let mut short_channel_id_nonref = (*short_channel_id).clone();
214 let mut is_permanent_nonref = (*is_permanent).clone();
215 NetworkUpdate::ChannelClosed {
216 short_channel_id: short_channel_id_nonref,
217 is_permanent: is_permanent_nonref,
220 nativeNetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
221 let mut node_id_nonref = (*node_id).clone();
222 let mut is_permanent_nonref = (*is_permanent).clone();
223 NetworkUpdate::NodeFailure {
224 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
225 is_permanent: is_permanent_nonref,
231 pub(crate) fn native_into(native: nativeNetworkUpdate) -> Self {
233 nativeNetworkUpdate::ChannelUpdateMessage {mut msg, } => {
234 NetworkUpdate::ChannelUpdateMessage {
235 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
238 nativeNetworkUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => {
239 NetworkUpdate::ChannelClosed {
240 short_channel_id: short_channel_id,
241 is_permanent: is_permanent,
244 nativeNetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
245 NetworkUpdate::NodeFailure {
246 node_id: crate::c_types::PublicKey::from_rust(&node_id),
247 is_permanent: is_permanent,
253 /// Frees any resources used by the NetworkUpdate
255 pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { }
256 /// Creates a copy of the NetworkUpdate
258 pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate {
262 /// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
263 pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate {
264 NetworkUpdate::ChannelUpdateMessage {
269 /// Utility method to constructs a new ChannelClosed-variant NetworkUpdate
270 pub extern "C" fn NetworkUpdate_channel_closed(short_channel_id: u64, is_permanent: bool) -> NetworkUpdate {
271 NetworkUpdate::ChannelClosed {
277 /// Utility method to constructs a new NodeFailure-variant NetworkUpdate
278 pub extern "C" fn NetworkUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent: bool) -> NetworkUpdate {
279 NetworkUpdate::NodeFailure {
285 /// Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
286 pub extern "C" fn NetworkUpdate_write(obj: &NetworkUpdate) -> crate::c_types::derived::CVec_u8Z {
287 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
289 impl From<nativeNetGraphMsgHandler> for crate::lightning::util::events::EventHandler {
290 fn from(obj: nativeNetGraphMsgHandler) -> Self {
291 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
292 let mut ret = NetGraphMsgHandler_as_EventHandler(&rust_obj);
293 // 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
294 rust_obj.inner = std::ptr::null_mut();
295 ret.free = Some(NetGraphMsgHandler_free_void);
299 /// Constructs a new EventHandler which calls the relevant methods on this_arg.
300 /// This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is
302 pub extern "C" fn NetGraphMsgHandler_as_EventHandler(this_arg: &NetGraphMsgHandler) -> crate::lightning::util::events::EventHandler {
303 crate::lightning::util::events::EventHandler {
304 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
306 handle_event: NetGraphMsgHandler_EventHandler_handle_event,
310 extern "C" fn NetGraphMsgHandler_EventHandler_handle_event(this_arg: *const c_void, event: &crate::lightning::util::events::Event) {
311 <nativeNetGraphMsgHandler as lightning::util::events::EventHandler<>>::handle_event(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &event.to_native())
315 use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport;
316 type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport<crate::lightning::chain::Access, crate::lightning::util::logger::Logger>;
318 /// Receives and validates network updates from peers,
319 /// stores authentic and relevant data as a network graph.
320 /// This network graph is then used for routing payments.
321 /// Provides interface to help with initial routing sync by
322 /// serving historical announcements.
324 /// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the
325 /// [`NetworkGraph`].
328 pub struct NetGraphMsgHandler {
329 /// A pointer to the opaque Rust object.
331 /// Nearly everywhere, inner must be non-null, however in places where
332 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
333 pub inner: *mut nativeNetGraphMsgHandler,
334 /// Indicates that this is the only struct which contains the same pointer.
336 /// Rust functions which take ownership of an object provided via an argument require
337 /// this to be true and invalidate the object pointed to by inner.
341 impl Drop for NetGraphMsgHandler {
343 if self.is_owned && !<*mut nativeNetGraphMsgHandler>::is_null(self.inner) {
344 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
348 /// Frees any resources used by the NetGraphMsgHandler, if is_owned is set and inner is non-NULL.
350 pub extern "C" fn NetGraphMsgHandler_free(this_obj: NetGraphMsgHandler) { }
352 /// Used only if an object of this type is returned as a trait impl by a method
353 extern "C" fn NetGraphMsgHandler_free_void(this_ptr: *mut c_void) {
354 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetGraphMsgHandler); }
357 impl NetGraphMsgHandler {
358 pub(crate) fn get_native_ref(&self) -> &'static nativeNetGraphMsgHandler {
359 unsafe { &*ObjOps::untweak_ptr(self.inner) }
361 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetGraphMsgHandler {
362 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
364 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
365 pub(crate) fn take_inner(mut self) -> *mut nativeNetGraphMsgHandler {
366 assert!(self.is_owned);
367 let ret = ObjOps::untweak_ptr(self.inner);
368 self.inner = std::ptr::null_mut();
372 /// Representation of the payment channel network
374 pub extern "C" fn NetGraphMsgHandler_get_network_graph(this_ptr: &NetGraphMsgHandler) -> crate::lightning::routing::network_graph::NetworkGraph {
375 let mut inner_val = &mut this_ptr.get_native_mut_ref().network_graph;
376 crate::lightning::routing::network_graph::NetworkGraph { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
378 /// Representation of the payment channel network
380 pub extern "C" fn NetGraphMsgHandler_set_network_graph(this_ptr: &mut NetGraphMsgHandler, mut val: crate::lightning::routing::network_graph::NetworkGraph) {
381 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.network_graph = *unsafe { Box::from_raw(val.take_inner()) };
383 /// Creates a new tracker of the actual state of the network of channels and nodes,
384 /// assuming an existing Network Graph.
385 /// Chain monitor is used to make sure announced channels exist on-chain,
386 /// channel data is correct, and that the announcement is signed with
387 /// channel owners' keys.
390 pub extern "C" fn NetGraphMsgHandler_new(mut network_graph: crate::lightning::routing::network_graph::NetworkGraph, mut chain_access: crate::c_types::derived::COption_AccessZ, mut logger: crate::lightning::util::logger::Logger) -> NetGraphMsgHandler {
391 let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } };
392 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(*unsafe { Box::from_raw(network_graph.take_inner()) }, local_chain_access, logger);
393 NetGraphMsgHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
396 /// Adds a provider used to check new announcements. Does not affect
397 /// existing announcements unless they are updated.
398 /// Add, update or remove the provider would replace the current one.
400 pub extern "C" fn NetGraphMsgHandler_add_chain_access(this_arg: &mut NetGraphMsgHandler, mut chain_access: crate::c_types::derived::COption_AccessZ) {
401 let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } };
402 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut nativeNetGraphMsgHandler)) }.add_chain_access(local_chain_access)
405 impl From<nativeNetGraphMsgHandler> for crate::lightning::ln::msgs::RoutingMessageHandler {
406 fn from(obj: nativeNetGraphMsgHandler) -> Self {
407 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
408 let mut ret = NetGraphMsgHandler_as_RoutingMessageHandler(&rust_obj);
409 // 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
410 rust_obj.inner = std::ptr::null_mut();
411 ret.free = Some(NetGraphMsgHandler_free_void);
415 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
416 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
418 pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: &NetGraphMsgHandler) -> crate::lightning::ln::msgs::RoutingMessageHandler {
419 crate::lightning::ln::msgs::RoutingMessageHandler {
420 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
422 handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement,
423 handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement,
424 handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update,
425 get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements,
426 get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements,
427 sync_routing_table: NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table,
428 handle_reply_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range,
429 handle_reply_short_channel_ids_end: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
430 handle_query_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range,
431 handle_query_short_channel_ids: NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids,
432 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
433 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
435 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
441 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
442 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
443 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::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
447 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
448 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
449 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::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
453 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
454 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
455 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::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
459 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 {
460 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, starting_point, batch_amount);
461 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::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { std::ptr::null_mut() } else { { ObjOps::heap_alloc((orig_ret_0_1.unwrap())) } }, is_owned: true }; let mut local_orig_ret_0_2 = crate::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_2.is_none() { std::ptr::null_mut() } else { { ObjOps::heap_alloc((orig_ret_0_2.unwrap())) } }, is_owned: true }; let mut local_ret_0 = (crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(orig_ret_0_0), is_owned: true }, local_orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }); };
465 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 {
466 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();
467 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);
468 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
471 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init_msg: &crate::lightning::ln::msgs::Init) {
472 <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::sync_routing_table(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), init_msg.get_native_ref())
475 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::lightning::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
476 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()) });
477 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::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
481 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::lightning::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
482 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()) });
483 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::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
487 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::lightning::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
488 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()) });
489 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::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
493 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::lightning::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
494 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()) });
495 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::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
499 impl From<nativeNetGraphMsgHandler> for crate::lightning::util::events::MessageSendEventsProvider {
500 fn from(obj: nativeNetGraphMsgHandler) -> Self {
501 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
502 let mut ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&rust_obj);
503 // 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
504 rust_obj.inner = std::ptr::null_mut();
505 ret.free = Some(NetGraphMsgHandler_free_void);
509 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
510 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
512 pub extern "C" fn NetGraphMsgHandler_as_MessageSendEventsProvider(this_arg: &NetGraphMsgHandler) -> crate::lightning::util::events::MessageSendEventsProvider {
513 crate::lightning::util::events::MessageSendEventsProvider {
514 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
516 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
521 extern "C" fn NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
522 let mut ret = <nativeNetGraphMsgHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, );
523 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
528 use lightning::routing::network_graph::DirectionalChannelInfo as nativeDirectionalChannelInfoImport;
529 type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport;
531 /// Details about one direction of a channel. Received
532 /// within a channel update.
535 pub struct DirectionalChannelInfo {
536 /// A pointer to the opaque Rust object.
538 /// Nearly everywhere, inner must be non-null, however in places where
539 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
540 pub inner: *mut nativeDirectionalChannelInfo,
541 /// Indicates that this is the only struct which contains the same pointer.
543 /// Rust functions which take ownership of an object provided via an argument require
544 /// this to be true and invalidate the object pointed to by inner.
548 impl Drop for DirectionalChannelInfo {
550 if self.is_owned && !<*mut nativeDirectionalChannelInfo>::is_null(self.inner) {
551 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
555 /// Frees any resources used by the DirectionalChannelInfo, if is_owned is set and inner is non-NULL.
557 pub extern "C" fn DirectionalChannelInfo_free(this_obj: DirectionalChannelInfo) { }
559 /// Used only if an object of this type is returned as a trait impl by a method
560 extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) {
561 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectionalChannelInfo); }
564 impl DirectionalChannelInfo {
565 pub(crate) fn get_native_ref(&self) -> &'static nativeDirectionalChannelInfo {
566 unsafe { &*ObjOps::untweak_ptr(self.inner) }
568 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectionalChannelInfo {
569 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
571 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
572 pub(crate) fn take_inner(mut self) -> *mut nativeDirectionalChannelInfo {
573 assert!(self.is_owned);
574 let ret = ObjOps::untweak_ptr(self.inner);
575 self.inner = std::ptr::null_mut();
579 /// When the last update to the channel direction was issued.
580 /// Value is opaque, as set in the announcement.
582 pub extern "C" fn DirectionalChannelInfo_get_last_update(this_ptr: &DirectionalChannelInfo) -> u32 {
583 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
586 /// When the last update to the channel direction was issued.
587 /// Value is opaque, as set in the announcement.
589 pub extern "C" fn DirectionalChannelInfo_set_last_update(this_ptr: &mut DirectionalChannelInfo, mut val: u32) {
590 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
592 /// Whether the channel can be currently used for payments (in this one direction).
594 pub extern "C" fn DirectionalChannelInfo_get_enabled(this_ptr: &DirectionalChannelInfo) -> bool {
595 let mut inner_val = &mut this_ptr.get_native_mut_ref().enabled;
598 /// Whether the channel can be currently used for payments (in this one direction).
600 pub extern "C" fn DirectionalChannelInfo_set_enabled(this_ptr: &mut DirectionalChannelInfo, mut val: bool) {
601 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.enabled = val;
603 /// The difference in CLTV values that you must have when routing through this channel.
605 pub extern "C" fn DirectionalChannelInfo_get_cltv_expiry_delta(this_ptr: &DirectionalChannelInfo) -> u16 {
606 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
609 /// The difference in CLTV values that you must have when routing through this channel.
611 pub extern "C" fn DirectionalChannelInfo_set_cltv_expiry_delta(this_ptr: &mut DirectionalChannelInfo, mut val: u16) {
612 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
614 /// The minimum value, which must be relayed to the next hop via the channel
616 pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &DirectionalChannelInfo) -> u64 {
617 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
620 /// The minimum value, which must be relayed to the next hop via the channel
622 pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) {
623 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
625 /// The maximum value which may be relayed to the next hop via the channel.
627 pub extern "C" fn DirectionalChannelInfo_get_htlc_maximum_msat(this_ptr: &DirectionalChannelInfo) -> crate::c_types::derived::COption_u64Z {
628 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
629 let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
632 /// The maximum value which may be relayed to the next hop via the channel.
634 pub extern "C" fn DirectionalChannelInfo_set_htlc_maximum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
635 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
636 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
638 /// Fees charged when the channel is used for routing
640 pub extern "C" fn DirectionalChannelInfo_get_fees(this_ptr: &DirectionalChannelInfo) -> crate::lightning::routing::network_graph::RoutingFees {
641 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
642 crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
644 /// Fees charged when the channel is used for routing
646 pub extern "C" fn DirectionalChannelInfo_set_fees(this_ptr: &mut DirectionalChannelInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
647 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
649 /// Most recent update for the channel received from the network
650 /// Mostly redundant with the data we store in fields explicitly.
651 /// Everything else is useful only for sending out for initial routing sync.
652 /// Not stored if contains excess data to prevent DoS.
654 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
656 pub extern "C" fn DirectionalChannelInfo_get_last_update_message(this_ptr: &DirectionalChannelInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
657 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update_message;
658 let mut local_inner_val = crate::lightning::ln::msgs::ChannelUpdate { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
661 /// Most recent update for the channel received from the network
662 /// Mostly redundant with the data we store in fields explicitly.
663 /// Everything else is useful only for sending out for initial routing sync.
664 /// Not stored if contains excess data to prevent DoS.
666 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
668 pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut DirectionalChannelInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
669 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
670 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val;
672 /// Constructs a new DirectionalChannelInfo given each field
675 pub extern "C" fn DirectionalChannelInfo_new(mut last_update_arg: u32, mut enabled_arg: bool, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z, mut fees_arg: crate::lightning::routing::network_graph::RoutingFees, mut last_update_message_arg: crate::lightning::ln::msgs::ChannelUpdate) -> DirectionalChannelInfo {
676 let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
677 let mut local_last_update_message_arg = if last_update_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(last_update_message_arg.take_inner()) } }) };
678 DirectionalChannelInfo { inner: ObjOps::heap_alloc(nativeDirectionalChannelInfo {
679 last_update: last_update_arg,
680 enabled: enabled_arg,
681 cltv_expiry_delta: cltv_expiry_delta_arg,
682 htlc_minimum_msat: htlc_minimum_msat_arg,
683 htlc_maximum_msat: local_htlc_maximum_msat_arg,
684 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
685 last_update_message: local_last_update_message_arg,
688 impl Clone for DirectionalChannelInfo {
689 fn clone(&self) -> Self {
691 inner: if <*mut nativeDirectionalChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
692 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
698 /// Used only if an object of this type is returned as a trait impl by a method
699 pub(crate) extern "C" fn DirectionalChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
700 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectionalChannelInfo)).clone() })) as *mut c_void
703 /// Creates a copy of the DirectionalChannelInfo
704 pub extern "C" fn DirectionalChannelInfo_clone(orig: &DirectionalChannelInfo) -> DirectionalChannelInfo {
708 /// Serialize the DirectionalChannelInfo object into a byte array which can be read by DirectionalChannelInfo_read
709 pub extern "C" fn DirectionalChannelInfo_write(obj: &DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z {
710 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
713 pub(crate) extern "C" fn DirectionalChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
714 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDirectionalChannelInfo) })
717 /// Read a DirectionalChannelInfo from a byte array, created by DirectionalChannelInfo_write
718 pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DirectionalChannelInfoDecodeErrorZ {
719 let res = crate::c_types::deserialize_obj(ser);
720 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::DirectionalChannelInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
724 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
725 type nativeChannelInfo = nativeChannelInfoImport;
727 /// Details about a channel (both directions).
728 /// Received within a channel announcement.
731 pub struct ChannelInfo {
732 /// A pointer to the opaque Rust object.
734 /// Nearly everywhere, inner must be non-null, however in places where
735 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
736 pub inner: *mut nativeChannelInfo,
737 /// Indicates that this is the only struct which contains the same pointer.
739 /// Rust functions which take ownership of an object provided via an argument require
740 /// this to be true and invalidate the object pointed to by inner.
744 impl Drop for ChannelInfo {
746 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
747 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
751 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
753 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
755 /// Used only if an object of this type is returned as a trait impl by a method
756 extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
757 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
761 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelInfo {
762 unsafe { &*ObjOps::untweak_ptr(self.inner) }
764 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelInfo {
765 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
767 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
768 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
769 assert!(self.is_owned);
770 let ret = ObjOps::untweak_ptr(self.inner);
771 self.inner = std::ptr::null_mut();
775 /// Protocol features of a channel communicated during its announcement
777 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
778 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
779 crate::lightning::ln::features::ChannelFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
781 /// Protocol features of a channel communicated during its announcement
783 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
784 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
786 /// Source node of the first direction of a channel
788 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
789 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one;
790 crate::c_types::PublicKey::from_rust(&inner_val)
792 /// Source node of the first direction of a channel
794 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
795 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = val.into_rust();
797 /// Details about the first direction of a channel
799 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
801 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::DirectionalChannelInfo {
802 let mut inner_val = &mut this_ptr.get_native_mut_ref().one_to_two;
803 let mut local_inner_val = crate::lightning::routing::network_graph::DirectionalChannelInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
806 /// Details about the first direction of a channel
808 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
810 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::DirectionalChannelInfo) {
811 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
812 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.one_to_two = local_val;
814 /// Source node of the second direction of a channel
816 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
817 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two;
818 crate::c_types::PublicKey::from_rust(&inner_val)
820 /// Source node of the second direction of a channel
822 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
823 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = val.into_rust();
825 /// Details about the second direction of a channel
827 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
829 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::DirectionalChannelInfo {
830 let mut inner_val = &mut this_ptr.get_native_mut_ref().two_to_one;
831 let mut local_inner_val = crate::lightning::routing::network_graph::DirectionalChannelInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
834 /// Details about the second direction of a channel
836 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
838 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::DirectionalChannelInfo) {
839 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
840 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.two_to_one = local_val;
842 /// The channel capacity as seen on-chain, if chain lookup is available.
844 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
845 let mut inner_val = &mut this_ptr.get_native_mut_ref().capacity_sats;
846 let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) };
849 /// The channel capacity as seen on-chain, if chain lookup is available.
851 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
852 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
853 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.capacity_sats = local_val;
855 /// An initial announcement of the channel
856 /// Mostly redundant with the data we store in fields explicitly.
857 /// Everything else is useful only for sending out for initial routing sync.
858 /// Not stored if contains excess data to prevent DoS.
860 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
862 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
863 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
864 let mut local_inner_val = crate::lightning::ln::msgs::ChannelAnnouncement { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
867 /// An initial announcement of the channel
868 /// Mostly redundant with the data we store in fields explicitly.
869 /// Everything else is useful only for sending out for initial routing sync.
870 /// Not stored if contains excess data to prevent DoS.
872 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
874 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
875 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
876 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
878 /// Constructs a new ChannelInfo given each field
881 pub extern "C" fn ChannelInfo_new(mut features_arg: crate::lightning::ln::features::ChannelFeatures, mut node_one_arg: crate::c_types::PublicKey, mut one_to_two_arg: crate::lightning::routing::network_graph::DirectionalChannelInfo, mut node_two_arg: crate::c_types::PublicKey, mut two_to_one_arg: crate::lightning::routing::network_graph::DirectionalChannelInfo, mut capacity_sats_arg: crate::c_types::derived::COption_u64Z, mut announcement_message_arg: crate::lightning::ln::msgs::ChannelAnnouncement) -> ChannelInfo {
882 let mut local_one_to_two_arg = if one_to_two_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(one_to_two_arg.take_inner()) } }) };
883 let mut local_two_to_one_arg = if two_to_one_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(two_to_one_arg.take_inner()) } }) };
884 let mut local_capacity_sats_arg = if capacity_sats_arg.is_some() { Some( { capacity_sats_arg.take() }) } else { None };
885 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()) } }) };
886 ChannelInfo { inner: ObjOps::heap_alloc(nativeChannelInfo {
887 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
888 node_one: node_one_arg.into_rust(),
889 one_to_two: local_one_to_two_arg,
890 node_two: node_two_arg.into_rust(),
891 two_to_one: local_two_to_one_arg,
892 capacity_sats: local_capacity_sats_arg,
893 announcement_message: local_announcement_message_arg,
896 impl Clone for ChannelInfo {
897 fn clone(&self) -> Self {
899 inner: if <*mut nativeChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
900 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
906 /// Used only if an object of this type is returned as a trait impl by a method
907 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
908 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
911 /// Creates a copy of the ChannelInfo
912 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
916 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
917 pub extern "C" fn ChannelInfo_write(obj: &ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
918 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
921 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
922 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
925 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
926 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
927 let res = crate::c_types::deserialize_obj(ser);
928 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::ChannelInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
932 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
933 type nativeRoutingFees = nativeRoutingFeesImport;
935 /// Fees for routing via a given channel or a node
938 pub struct RoutingFees {
939 /// A pointer to the opaque Rust object.
941 /// Nearly everywhere, inner must be non-null, however in places where
942 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
943 pub inner: *mut nativeRoutingFees,
944 /// Indicates that this is the only struct which contains the same pointer.
946 /// Rust functions which take ownership of an object provided via an argument require
947 /// this to be true and invalidate the object pointed to by inner.
951 impl Drop for RoutingFees {
953 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
954 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
958 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
960 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
962 /// Used only if an object of this type is returned as a trait impl by a method
963 extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
964 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
968 pub(crate) fn get_native_ref(&self) -> &'static nativeRoutingFees {
969 unsafe { &*ObjOps::untweak_ptr(self.inner) }
971 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoutingFees {
972 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
974 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
975 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
976 assert!(self.is_owned);
977 let ret = ObjOps::untweak_ptr(self.inner);
978 self.inner = std::ptr::null_mut();
982 /// Flat routing fee in satoshis
984 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
985 let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat;
988 /// Flat routing fee in satoshis
990 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
991 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val;
993 /// Liquidity-based routing fee in millionths of a routed amount.
994 /// In other words, 10000 is 1%.
996 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
997 let mut inner_val = &mut this_ptr.get_native_mut_ref().proportional_millionths;
1000 /// Liquidity-based routing fee in millionths of a routed amount.
1001 /// In other words, 10000 is 1%.
1003 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
1004 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.proportional_millionths = val;
1006 /// Constructs a new RoutingFees given each field
1009 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
1010 RoutingFees { inner: ObjOps::heap_alloc(nativeRoutingFees {
1011 base_msat: base_msat_arg,
1012 proportional_millionths: proportional_millionths_arg,
1013 }), is_owned: true }
1015 /// Checks if two RoutingFeess contain equal inner contents.
1016 /// This ignores pointers and is_owned flags and looks at the values in fields.
1017 /// Two objects with NULL inner values will be considered "equal" here.
1019 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
1020 if a.inner == b.inner { return true; }
1021 if a.inner.is_null() || b.inner.is_null() { return false; }
1022 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1024 impl Clone for RoutingFees {
1025 fn clone(&self) -> Self {
1027 inner: if <*mut nativeRoutingFees>::is_null(self.inner) { std::ptr::null_mut() } else {
1028 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1034 /// Used only if an object of this type is returned as a trait impl by a method
1035 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
1036 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
1039 /// Creates a copy of the RoutingFees
1040 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
1043 /// Checks if two RoutingFeess contain equal inner contents.
1045 pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 {
1046 if o.inner.is_null() { return 0; }
1047 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
1048 #[allow(deprecated)]
1049 let mut hasher = core::hash::SipHasher::new();
1050 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1051 std::hash::Hasher::finish(&hasher)
1054 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
1055 pub extern "C" fn RoutingFees_write(obj: &RoutingFees) -> crate::c_types::derived::CVec_u8Z {
1056 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1059 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1060 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
1063 /// Read a RoutingFees from a byte array, created by RoutingFees_write
1064 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
1065 let res = crate::c_types::deserialize_obj(ser);
1066 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::RoutingFees { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1070 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
1071 type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
1073 /// Information received in the latest node_announcement from this node.
1076 pub struct NodeAnnouncementInfo {
1077 /// A pointer to the opaque Rust object.
1079 /// Nearly everywhere, inner must be non-null, however in places where
1080 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1081 pub inner: *mut nativeNodeAnnouncementInfo,
1082 /// Indicates that this is the only struct which contains the same pointer.
1084 /// Rust functions which take ownership of an object provided via an argument require
1085 /// this to be true and invalidate the object pointed to by inner.
1089 impl Drop for NodeAnnouncementInfo {
1090 fn drop(&mut self) {
1091 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
1092 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1096 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
1098 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
1100 /// Used only if an object of this type is returned as a trait impl by a method
1101 extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
1102 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
1105 impl NodeAnnouncementInfo {
1106 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAnnouncementInfo {
1107 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1109 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAnnouncementInfo {
1110 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1112 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1113 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
1114 assert!(self.is_owned);
1115 let ret = ObjOps::untweak_ptr(self.inner);
1116 self.inner = std::ptr::null_mut();
1120 /// Protocol features the node announced support for
1122 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
1123 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1124 crate::lightning::ln::features::NodeFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
1126 /// Protocol features the node announced support for
1128 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
1129 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1131 /// When the last known update to the node state was issued.
1132 /// Value is opaque, as set in the announcement.
1134 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
1135 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
1138 /// When the last known update to the node state was issued.
1139 /// Value is opaque, as set in the announcement.
1141 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
1142 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
1144 /// Color assigned to the node
1146 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
1147 let mut inner_val = &mut this_ptr.get_native_mut_ref().rgb;
1150 /// Color assigned to the node
1152 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
1153 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data;
1155 /// Moniker assigned to the node.
1156 /// May be invalid or malicious (eg control chars),
1157 /// should not be exposed to the user.
1159 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
1160 let mut inner_val = &mut this_ptr.get_native_mut_ref().alias;
1163 /// Moniker assigned to the node.
1164 /// May be invalid or malicious (eg control chars),
1165 /// should not be exposed to the user.
1167 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
1168 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = val.data;
1170 /// Internet-level addresses via which one can connect to the node
1172 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
1173 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
1174 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.addresses = local_val;
1176 /// An initial announcement of the node
1177 /// Mostly redundant with the data we store in fields explicitly.
1178 /// Everything else is useful only for sending out for initial routing sync.
1179 /// Not stored if contains excess data to prevent DoS.
1181 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1183 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
1184 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1185 let mut local_inner_val = crate::lightning::ln::msgs::NodeAnnouncement { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1188 /// An initial announcement of the node
1189 /// Mostly redundant with the data we store in fields explicitly.
1190 /// Everything else is useful only for sending out for initial routing sync.
1191 /// Not stored if contains excess data to prevent DoS.
1193 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1195 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
1196 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1197 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1199 /// Constructs a new NodeAnnouncementInfo given each field
1202 pub extern "C" fn NodeAnnouncementInfo_new(mut features_arg: crate::lightning::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::lightning::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo {
1203 let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
1204 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()) } }) };
1205 NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo {
1206 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1207 last_update: last_update_arg,
1209 alias: alias_arg.data,
1210 addresses: local_addresses_arg,
1211 announcement_message: local_announcement_message_arg,
1212 }), is_owned: true }
1214 impl Clone for NodeAnnouncementInfo {
1215 fn clone(&self) -> Self {
1217 inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
1218 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1224 /// Used only if an object of this type is returned as a trait impl by a method
1225 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1226 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
1229 /// Creates a copy of the NodeAnnouncementInfo
1230 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1234 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1235 pub extern "C" fn NodeAnnouncementInfo_write(obj: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1236 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1239 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1240 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1243 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1244 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1245 let res = crate::c_types::deserialize_obj(ser);
1246 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NodeAnnouncementInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1250 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
1251 type nativeNodeInfo = nativeNodeInfoImport;
1253 /// Details about a node in the network, known from the network announcement.
1256 pub struct NodeInfo {
1257 /// A pointer to the opaque Rust object.
1259 /// Nearly everywhere, inner must be non-null, however in places where
1260 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1261 pub inner: *mut nativeNodeInfo,
1262 /// Indicates that this is the only struct which contains the same pointer.
1264 /// Rust functions which take ownership of an object provided via an argument require
1265 /// this to be true and invalidate the object pointed to by inner.
1269 impl Drop for NodeInfo {
1270 fn drop(&mut self) {
1271 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1272 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1276 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1278 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1280 /// Used only if an object of this type is returned as a trait impl by a method
1281 extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1282 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
1286 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeInfo {
1287 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1289 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeInfo {
1290 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1292 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1293 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1294 assert!(self.is_owned);
1295 let ret = ObjOps::untweak_ptr(self.inner);
1296 self.inner = std::ptr::null_mut();
1300 /// All valid channels a node has announced
1302 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1303 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1304 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1306 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1307 /// The two fields (flat and proportional fee) are independent,
1308 /// meaning they don't have to refer to the same channel.
1310 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1312 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::RoutingFees {
1313 let mut inner_val = &mut this_ptr.get_native_mut_ref().lowest_inbound_channel_fees;
1314 let mut local_inner_val = crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1317 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1318 /// The two fields (flat and proportional fee) are independent,
1319 /// meaning they don't have to refer to the same channel.
1321 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1323 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
1324 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1325 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.lowest_inbound_channel_fees = local_val;
1327 /// More information about a node from node_announcement.
1328 /// Optional because we store a Node entry after learning about it from
1329 /// a channel announcement, but before receiving a node announcement.
1331 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1333 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::NodeAnnouncementInfo {
1334 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_info;
1335 let mut local_inner_val = crate::lightning::routing::network_graph::NodeAnnouncementInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const _) as *mut _ }, is_owned: false };
1338 /// More information about a node from node_announcement.
1339 /// Optional because we store a Node entry after learning about it from
1340 /// a channel announcement, but before receiving a node announcement.
1342 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1344 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::NodeAnnouncementInfo) {
1345 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1346 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val;
1348 /// Constructs a new NodeInfo given each field
1351 pub extern "C" fn NodeInfo_new(mut channels_arg: crate::c_types::derived::CVec_u64Z, mut lowest_inbound_channel_fees_arg: crate::lightning::routing::network_graph::RoutingFees, mut announcement_info_arg: crate::lightning::routing::network_graph::NodeAnnouncementInfo) -> NodeInfo {
1352 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1353 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()) } }) };
1354 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()) } }) };
1355 NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo {
1356 channels: local_channels_arg,
1357 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
1358 announcement_info: local_announcement_info_arg,
1359 }), is_owned: true }
1361 impl Clone for NodeInfo {
1362 fn clone(&self) -> Self {
1364 inner: if <*mut nativeNodeInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
1365 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1371 /// Used only if an object of this type is returned as a trait impl by a method
1372 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1373 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1376 /// Creates a copy of the NodeInfo
1377 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1381 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1382 pub extern "C" fn NodeInfo_write(obj: &NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1383 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1386 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1387 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1390 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1391 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1392 let res = crate::c_types::deserialize_obj(ser);
1393 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NodeInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1397 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
1398 pub extern "C" fn NetworkGraph_write(obj: &NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1399 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1402 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1403 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1406 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
1407 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1408 let res = crate::c_types::deserialize_obj(ser);
1409 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NetworkGraph { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1412 /// Creates a new, empty, network graph.
1415 pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::lightning::routing::network_graph::NetworkGraph {
1416 let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap());
1417 crate::lightning::routing::network_graph::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1420 /// Returns a read-only view of the network graph.
1423 pub extern "C" fn NetworkGraph_read_only(this_arg: &NetworkGraph) -> crate::lightning::routing::network_graph::ReadOnlyNetworkGraph {
1424 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_only();
1425 crate::lightning::routing::network_graph::ReadOnlyNetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1428 /// For an already known node (from channel announcements), update its stored properties from a
1429 /// given node announcement.
1431 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1432 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1433 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1436 pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1437 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_announcement(msg.get_native_ref(), secp256k1::SECP256K1);
1438 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::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1442 /// For an already known node (from channel announcements), update its stored properties from a
1443 /// given node announcement without verifying the associated signatures. Because we aren't
1444 /// given the associated signatures here we cannot relay the node announcement to any of our
1448 pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedNodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1449 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_unsigned_announcement(msg.get_native_ref());
1450 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::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1454 /// Store or update channel info from a channel announcement.
1456 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1457 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1458 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1460 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1461 /// the corresponding UTXO exists on chain and is correctly-formatted.
1464 pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelAnnouncement, mut chain_access: crate::c_types::derived::COption_AccessZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1465 let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } };
1466 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_chain_access, secp256k1::SECP256K1);
1467 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::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1471 /// Store or update channel info from a channel announcement without verifying the associated
1472 /// signatures. Because we aren't given the associated signatures here we cannot relay the
1473 /// channel announcement to any of our peers.
1475 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1476 /// the corresponding UTXO exists on chain and is correctly-formatted.
1479 pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement, mut chain_access: crate::c_types::derived::COption_AccessZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1480 let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } };
1481 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_chain_access);
1482 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::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1486 /// Close a channel if a corresponding HTLC fail was sent.
1487 /// If permanent, removes a channel from the local storage.
1488 /// May cause the removal of nodes too, if this was their last channel.
1489 /// If not permanent, makes channels unavailable for routing.
1491 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
1492 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_from_update(short_channel_id, is_permanent)
1495 /// Marks a node in the graph as failed.
1497 pub extern "C" fn NetworkGraph_fail_node(this_arg: &NetworkGraph, mut _node_id: crate::c_types::PublicKey, mut is_permanent: bool) {
1498 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_node(&_node_id.into_rust(), is_permanent)
1501 /// For an already known (from announcement) channel, update info about one of the directions
1504 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1505 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1506 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1509 pub extern "C" fn NetworkGraph_update_channel(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1510 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel(msg.get_native_ref(), secp256k1::SECP256K1);
1511 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::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
1515 /// For an already known (from announcement) channel, update info about one of the directions
1516 /// of the channel without verifying the associated signatures. Because we aren't given the
1517 /// associated signatures here we cannot relay the channel update to any of our peers.
1520 pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1521 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_unsigned(msg.get_native_ref());
1522 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::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };