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();
68 impl Clone for NetworkGraph {
69 fn clone(&self) -> Self {
71 inner: if <*mut nativeNetworkGraph>::is_null(self.inner) { std::ptr::null_mut() } else {
72 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
78 /// Used only if an object of this type is returned as a trait impl by a method
79 pub(crate) extern "C" fn NetworkGraph_clone_void(this_ptr: *const c_void) -> *mut c_void {
80 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNetworkGraph)).clone() })) as *mut c_void
83 /// Creates a copy of the NetworkGraph
84 pub extern "C" fn NetworkGraph_clone(orig: &NetworkGraph) -> NetworkGraph {
88 use lightning::routing::network_graph::ReadOnlyNetworkGraph as nativeReadOnlyNetworkGraphImport;
89 type nativeReadOnlyNetworkGraph = nativeReadOnlyNetworkGraphImport<'static>;
91 /// A read-only view of [`NetworkGraph`].
94 pub struct ReadOnlyNetworkGraph {
95 /// A pointer to the opaque Rust object.
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 nativeReadOnlyNetworkGraph,
100 /// Indicates that this is the only struct which contains the same pointer.
102 /// Rust functions which take ownership of an object provided via an argument require
103 /// this to be true and invalidate the object pointed to by inner.
107 impl Drop for ReadOnlyNetworkGraph {
109 if self.is_owned && !<*mut nativeReadOnlyNetworkGraph>::is_null(self.inner) {
110 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
114 /// Frees any resources used by the ReadOnlyNetworkGraph, if is_owned is set and inner is non-NULL.
116 pub extern "C" fn ReadOnlyNetworkGraph_free(this_obj: ReadOnlyNetworkGraph) { }
118 /// Used only if an object of this type is returned as a trait impl by a method
119 extern "C" fn ReadOnlyNetworkGraph_free_void(this_ptr: *mut c_void) {
120 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeReadOnlyNetworkGraph); }
123 impl ReadOnlyNetworkGraph {
124 pub(crate) fn get_native_ref(&self) -> &'static nativeReadOnlyNetworkGraph {
125 unsafe { &*ObjOps::untweak_ptr(self.inner) }
127 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReadOnlyNetworkGraph {
128 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
130 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
131 pub(crate) fn take_inner(mut self) -> *mut nativeReadOnlyNetworkGraph {
132 assert!(self.is_owned);
133 let ret = ObjOps::untweak_ptr(self.inner);
134 self.inner = std::ptr::null_mut();
138 /// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
139 /// return packet by a node along the route. See [BOLT #4] for details.
141 /// [BOLT #4]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md
145 pub enum NetworkUpdate {
146 /// An error indicating a `channel_update` messages should be applied via
147 /// [`NetworkGraph::update_channel`].
148 ChannelUpdateMessage {
149 /// The update to apply via [`NetworkGraph::update_channel`].
150 msg: crate::lightning::ln::msgs::ChannelUpdate,
152 /// An error indicating only that a channel has been closed, which should be applied via
153 /// [`NetworkGraph::close_channel_from_update`].
155 /// The short channel id of the closed channel.
156 short_channel_id: u64,
157 /// Whether the channel should be permanently removed or temporarily disabled until a new
158 /// `channel_update` message is received.
161 /// An error indicating only that a node has failed, which should be applied via
162 /// [`NetworkGraph::fail_node`].
164 /// The node id of the failed node.
165 node_id: crate::c_types::PublicKey,
166 /// Whether the node should be permanently removed from consideration or can be restored
167 /// when a new `channel_update` message is received.
171 use lightning::routing::network_graph::NetworkUpdate as nativeNetworkUpdate;
174 pub(crate) fn to_native(&self) -> nativeNetworkUpdate {
176 NetworkUpdate::ChannelUpdateMessage {ref msg, } => {
177 let mut msg_nonref = (*msg).clone();
178 nativeNetworkUpdate::ChannelUpdateMessage {
179 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
182 NetworkUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => {
183 let mut short_channel_id_nonref = (*short_channel_id).clone();
184 let mut is_permanent_nonref = (*is_permanent).clone();
185 nativeNetworkUpdate::ChannelClosed {
186 short_channel_id: short_channel_id_nonref,
187 is_permanent: is_permanent_nonref,
190 NetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
191 let mut node_id_nonref = (*node_id).clone();
192 let mut is_permanent_nonref = (*is_permanent).clone();
193 nativeNetworkUpdate::NodeFailure {
194 node_id: node_id_nonref.into_rust(),
195 is_permanent: is_permanent_nonref,
201 pub(crate) fn into_native(self) -> nativeNetworkUpdate {
203 NetworkUpdate::ChannelUpdateMessage {mut msg, } => {
204 nativeNetworkUpdate::ChannelUpdateMessage {
205 msg: *unsafe { Box::from_raw(msg.take_inner()) },
208 NetworkUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => {
209 nativeNetworkUpdate::ChannelClosed {
210 short_channel_id: short_channel_id,
211 is_permanent: is_permanent,
214 NetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
215 nativeNetworkUpdate::NodeFailure {
216 node_id: node_id.into_rust(),
217 is_permanent: is_permanent,
223 pub(crate) fn from_native(native: &nativeNetworkUpdate) -> Self {
225 nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => {
226 let mut msg_nonref = (*msg).clone();
227 NetworkUpdate::ChannelUpdateMessage {
228 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
231 nativeNetworkUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => {
232 let mut short_channel_id_nonref = (*short_channel_id).clone();
233 let mut is_permanent_nonref = (*is_permanent).clone();
234 NetworkUpdate::ChannelClosed {
235 short_channel_id: short_channel_id_nonref,
236 is_permanent: is_permanent_nonref,
239 nativeNetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
240 let mut node_id_nonref = (*node_id).clone();
241 let mut is_permanent_nonref = (*is_permanent).clone();
242 NetworkUpdate::NodeFailure {
243 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
244 is_permanent: is_permanent_nonref,
250 pub(crate) fn native_into(native: nativeNetworkUpdate) -> Self {
252 nativeNetworkUpdate::ChannelUpdateMessage {mut msg, } => {
253 NetworkUpdate::ChannelUpdateMessage {
254 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
257 nativeNetworkUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => {
258 NetworkUpdate::ChannelClosed {
259 short_channel_id: short_channel_id,
260 is_permanent: is_permanent,
263 nativeNetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
264 NetworkUpdate::NodeFailure {
265 node_id: crate::c_types::PublicKey::from_rust(&node_id),
266 is_permanent: is_permanent,
272 /// Frees any resources used by the NetworkUpdate
274 pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { }
275 /// Creates a copy of the NetworkUpdate
277 pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate {
281 /// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
282 pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate {
283 NetworkUpdate::ChannelUpdateMessage {
288 /// Utility method to constructs a new ChannelClosed-variant NetworkUpdate
289 pub extern "C" fn NetworkUpdate_channel_closed(short_channel_id: u64, is_permanent: bool) -> NetworkUpdate {
290 NetworkUpdate::ChannelClosed {
296 /// Utility method to constructs a new NodeFailure-variant NetworkUpdate
297 pub extern "C" fn NetworkUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent: bool) -> NetworkUpdate {
298 NetworkUpdate::NodeFailure {
304 /// Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
305 pub extern "C" fn NetworkUpdate_write(obj: &NetworkUpdate) -> crate::c_types::derived::CVec_u8Z {
306 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
308 impl From<nativeNetGraphMsgHandler> for crate::lightning::util::events::EventHandler {
309 fn from(obj: nativeNetGraphMsgHandler) -> Self {
310 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
311 let mut ret = NetGraphMsgHandler_as_EventHandler(&rust_obj);
312 // 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
313 rust_obj.inner = std::ptr::null_mut();
314 ret.free = Some(NetGraphMsgHandler_free_void);
318 /// Constructs a new EventHandler which calls the relevant methods on this_arg.
319 /// This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is
321 pub extern "C" fn NetGraphMsgHandler_as_EventHandler(this_arg: &NetGraphMsgHandler) -> crate::lightning::util::events::EventHandler {
322 crate::lightning::util::events::EventHandler {
323 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
325 handle_event: NetGraphMsgHandler_EventHandler_handle_event,
329 extern "C" fn NetGraphMsgHandler_EventHandler_handle_event(this_arg: *const c_void, event: &crate::lightning::util::events::Event) {
330 <nativeNetGraphMsgHandler as lightning::util::events::EventHandler<>>::handle_event(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &event.to_native())
334 use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport;
335 type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport<crate::lightning::chain::Access, crate::lightning::util::logger::Logger>;
337 /// Receives and validates network updates from peers,
338 /// stores authentic and relevant data as a network graph.
339 /// This network graph is then used for routing payments.
340 /// Provides interface to help with initial routing sync by
341 /// serving historical announcements.
343 /// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the
344 /// [`NetworkGraph`].
347 pub struct NetGraphMsgHandler {
348 /// A pointer to the opaque Rust object.
350 /// Nearly everywhere, inner must be non-null, however in places where
351 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
352 pub inner: *mut nativeNetGraphMsgHandler,
353 /// Indicates that this is the only struct which contains the same pointer.
355 /// Rust functions which take ownership of an object provided via an argument require
356 /// this to be true and invalidate the object pointed to by inner.
360 impl Drop for NetGraphMsgHandler {
362 if self.is_owned && !<*mut nativeNetGraphMsgHandler>::is_null(self.inner) {
363 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
367 /// Frees any resources used by the NetGraphMsgHandler, if is_owned is set and inner is non-NULL.
369 pub extern "C" fn NetGraphMsgHandler_free(this_obj: NetGraphMsgHandler) { }
371 /// Used only if an object of this type is returned as a trait impl by a method
372 extern "C" fn NetGraphMsgHandler_free_void(this_ptr: *mut c_void) {
373 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetGraphMsgHandler); }
376 impl NetGraphMsgHandler {
377 pub(crate) fn get_native_ref(&self) -> &'static nativeNetGraphMsgHandler {
378 unsafe { &*ObjOps::untweak_ptr(self.inner) }
380 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetGraphMsgHandler {
381 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
383 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
384 pub(crate) fn take_inner(mut self) -> *mut nativeNetGraphMsgHandler {
385 assert!(self.is_owned);
386 let ret = ObjOps::untweak_ptr(self.inner);
387 self.inner = std::ptr::null_mut();
391 /// Representation of the payment channel network
393 pub extern "C" fn NetGraphMsgHandler_get_network_graph(this_ptr: &NetGraphMsgHandler) -> crate::lightning::routing::network_graph::NetworkGraph {
394 let mut inner_val = &mut this_ptr.get_native_mut_ref().network_graph;
395 crate::lightning::routing::network_graph::NetworkGraph { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
397 /// Representation of the payment channel network
399 pub extern "C" fn NetGraphMsgHandler_set_network_graph(this_ptr: &mut NetGraphMsgHandler, mut val: crate::lightning::routing::network_graph::NetworkGraph) {
400 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.network_graph = *unsafe { Box::from_raw(val.take_inner()) };
402 /// Creates a new tracker of the actual state of the network of channels and nodes,
403 /// assuming an existing Network Graph.
404 /// Chain monitor is used to make sure announced channels exist on-chain,
405 /// channel data is correct, and that the announcement is signed with
406 /// channel owners' keys.
409 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 {
410 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() }) } };
411 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(*unsafe { Box::from_raw(network_graph.take_inner()) }, local_chain_access, logger);
412 NetGraphMsgHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
415 /// Adds a provider used to check new announcements. Does not affect
416 /// existing announcements unless they are updated.
417 /// Add, update or remove the provider would replace the current one.
419 pub extern "C" fn NetGraphMsgHandler_add_chain_access(this_arg: &mut NetGraphMsgHandler, mut chain_access: crate::c_types::derived::COption_AccessZ) {
420 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() }) } };
421 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut nativeNetGraphMsgHandler)) }.add_chain_access(local_chain_access)
424 impl From<nativeNetGraphMsgHandler> for crate::lightning::ln::msgs::RoutingMessageHandler {
425 fn from(obj: nativeNetGraphMsgHandler) -> Self {
426 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
427 let mut ret = NetGraphMsgHandler_as_RoutingMessageHandler(&rust_obj);
428 // 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
429 rust_obj.inner = std::ptr::null_mut();
430 ret.free = Some(NetGraphMsgHandler_free_void);
434 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
435 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
437 pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: &NetGraphMsgHandler) -> crate::lightning::ln::msgs::RoutingMessageHandler {
438 crate::lightning::ln::msgs::RoutingMessageHandler {
439 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
441 handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement,
442 handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement,
443 handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update,
444 get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements,
445 get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements,
446 sync_routing_table: NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table,
447 handle_reply_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range,
448 handle_reply_short_channel_ids_end: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
449 handle_query_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range,
450 handle_query_short_channel_ids: NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids,
451 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
452 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
454 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
460 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 {
461 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
462 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() };
466 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 {
467 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
468 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() };
472 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 {
473 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
474 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() };
478 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 {
479 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, starting_point, batch_amount);
480 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 }); };
484 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 {
485 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();
486 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);
487 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 } }); };
490 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) {
491 <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())
494 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 {
495 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()) });
496 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() };
500 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 {
501 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()) });
502 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() };
506 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 {
507 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()) });
508 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() };
512 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 {
513 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()) });
514 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() };
518 impl From<nativeNetGraphMsgHandler> for crate::lightning::util::events::MessageSendEventsProvider {
519 fn from(obj: nativeNetGraphMsgHandler) -> Self {
520 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
521 let mut ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&rust_obj);
522 // 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
523 rust_obj.inner = std::ptr::null_mut();
524 ret.free = Some(NetGraphMsgHandler_free_void);
528 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
529 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
531 pub extern "C" fn NetGraphMsgHandler_as_MessageSendEventsProvider(this_arg: &NetGraphMsgHandler) -> crate::lightning::util::events::MessageSendEventsProvider {
532 crate::lightning::util::events::MessageSendEventsProvider {
533 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
535 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
540 extern "C" fn NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
541 let mut ret = <nativeNetGraphMsgHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, );
542 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
547 use lightning::routing::network_graph::DirectionalChannelInfo as nativeDirectionalChannelInfoImport;
548 type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport;
550 /// Details about one direction of a channel. Received
551 /// within a channel update.
554 pub struct DirectionalChannelInfo {
555 /// A pointer to the opaque Rust object.
557 /// Nearly everywhere, inner must be non-null, however in places where
558 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
559 pub inner: *mut nativeDirectionalChannelInfo,
560 /// Indicates that this is the only struct which contains the same pointer.
562 /// Rust functions which take ownership of an object provided via an argument require
563 /// this to be true and invalidate the object pointed to by inner.
567 impl Drop for DirectionalChannelInfo {
569 if self.is_owned && !<*mut nativeDirectionalChannelInfo>::is_null(self.inner) {
570 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
574 /// Frees any resources used by the DirectionalChannelInfo, if is_owned is set and inner is non-NULL.
576 pub extern "C" fn DirectionalChannelInfo_free(this_obj: DirectionalChannelInfo) { }
578 /// Used only if an object of this type is returned as a trait impl by a method
579 extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) {
580 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectionalChannelInfo); }
583 impl DirectionalChannelInfo {
584 pub(crate) fn get_native_ref(&self) -> &'static nativeDirectionalChannelInfo {
585 unsafe { &*ObjOps::untweak_ptr(self.inner) }
587 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectionalChannelInfo {
588 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
590 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
591 pub(crate) fn take_inner(mut self) -> *mut nativeDirectionalChannelInfo {
592 assert!(self.is_owned);
593 let ret = ObjOps::untweak_ptr(self.inner);
594 self.inner = std::ptr::null_mut();
598 /// When the last update to the channel direction was issued.
599 /// Value is opaque, as set in the announcement.
601 pub extern "C" fn DirectionalChannelInfo_get_last_update(this_ptr: &DirectionalChannelInfo) -> u32 {
602 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
605 /// When the last update to the channel direction was issued.
606 /// Value is opaque, as set in the announcement.
608 pub extern "C" fn DirectionalChannelInfo_set_last_update(this_ptr: &mut DirectionalChannelInfo, mut val: u32) {
609 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
611 /// Whether the channel can be currently used for payments (in this one direction).
613 pub extern "C" fn DirectionalChannelInfo_get_enabled(this_ptr: &DirectionalChannelInfo) -> bool {
614 let mut inner_val = &mut this_ptr.get_native_mut_ref().enabled;
617 /// Whether the channel can be currently used for payments (in this one direction).
619 pub extern "C" fn DirectionalChannelInfo_set_enabled(this_ptr: &mut DirectionalChannelInfo, mut val: bool) {
620 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.enabled = val;
622 /// The difference in CLTV values that you must have when routing through this channel.
624 pub extern "C" fn DirectionalChannelInfo_get_cltv_expiry_delta(this_ptr: &DirectionalChannelInfo) -> u16 {
625 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
628 /// The difference in CLTV values that you must have when routing through this channel.
630 pub extern "C" fn DirectionalChannelInfo_set_cltv_expiry_delta(this_ptr: &mut DirectionalChannelInfo, mut val: u16) {
631 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
633 /// The minimum value, which must be relayed to the next hop via the channel
635 pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &DirectionalChannelInfo) -> u64 {
636 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
639 /// The minimum value, which must be relayed to the next hop via the channel
641 pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) {
642 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
644 /// The maximum value which may be relayed to the next hop via the channel.
646 pub extern "C" fn DirectionalChannelInfo_get_htlc_maximum_msat(this_ptr: &DirectionalChannelInfo) -> crate::c_types::derived::COption_u64Z {
647 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
648 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() }) };
651 /// The maximum value which may be relayed to the next hop via the channel.
653 pub extern "C" fn DirectionalChannelInfo_set_htlc_maximum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
654 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
655 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
657 /// Fees charged when the channel is used for routing
659 pub extern "C" fn DirectionalChannelInfo_get_fees(this_ptr: &DirectionalChannelInfo) -> crate::lightning::routing::network_graph::RoutingFees {
660 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
661 crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
663 /// Fees charged when the channel is used for routing
665 pub extern "C" fn DirectionalChannelInfo_set_fees(this_ptr: &mut DirectionalChannelInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
666 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
668 /// Most recent update for the channel received from the network
669 /// Mostly redundant with the data we store in fields explicitly.
670 /// Everything else is useful only for sending out for initial routing sync.
671 /// Not stored if contains excess data to prevent DoS.
673 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
675 pub extern "C" fn DirectionalChannelInfo_get_last_update_message(this_ptr: &DirectionalChannelInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
676 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update_message;
677 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 };
680 /// Most recent update for the channel received from the network
681 /// Mostly redundant with the data we store in fields explicitly.
682 /// Everything else is useful only for sending out for initial routing sync.
683 /// Not stored if contains excess data to prevent DoS.
685 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
687 pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut DirectionalChannelInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
688 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
689 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val;
691 /// Constructs a new DirectionalChannelInfo given each field
694 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 {
695 let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
696 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()) } }) };
697 DirectionalChannelInfo { inner: ObjOps::heap_alloc(nativeDirectionalChannelInfo {
698 last_update: last_update_arg,
699 enabled: enabled_arg,
700 cltv_expiry_delta: cltv_expiry_delta_arg,
701 htlc_minimum_msat: htlc_minimum_msat_arg,
702 htlc_maximum_msat: local_htlc_maximum_msat_arg,
703 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
704 last_update_message: local_last_update_message_arg,
707 impl Clone for DirectionalChannelInfo {
708 fn clone(&self) -> Self {
710 inner: if <*mut nativeDirectionalChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
711 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
717 /// Used only if an object of this type is returned as a trait impl by a method
718 pub(crate) extern "C" fn DirectionalChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
719 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectionalChannelInfo)).clone() })) as *mut c_void
722 /// Creates a copy of the DirectionalChannelInfo
723 pub extern "C" fn DirectionalChannelInfo_clone(orig: &DirectionalChannelInfo) -> DirectionalChannelInfo {
727 /// Serialize the DirectionalChannelInfo object into a byte array which can be read by DirectionalChannelInfo_read
728 pub extern "C" fn DirectionalChannelInfo_write(obj: &DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z {
729 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
732 pub(crate) extern "C" fn DirectionalChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
733 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDirectionalChannelInfo) })
736 /// Read a DirectionalChannelInfo from a byte array, created by DirectionalChannelInfo_write
737 pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DirectionalChannelInfoDecodeErrorZ {
738 let res = crate::c_types::deserialize_obj(ser);
739 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() };
743 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
744 type nativeChannelInfo = nativeChannelInfoImport;
746 /// Details about a channel (both directions).
747 /// Received within a channel announcement.
750 pub struct ChannelInfo {
751 /// A pointer to the opaque Rust object.
753 /// Nearly everywhere, inner must be non-null, however in places where
754 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
755 pub inner: *mut nativeChannelInfo,
756 /// Indicates that this is the only struct which contains the same pointer.
758 /// Rust functions which take ownership of an object provided via an argument require
759 /// this to be true and invalidate the object pointed to by inner.
763 impl Drop for ChannelInfo {
765 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
766 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
770 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
772 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
774 /// Used only if an object of this type is returned as a trait impl by a method
775 extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
776 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
780 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelInfo {
781 unsafe { &*ObjOps::untweak_ptr(self.inner) }
783 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelInfo {
784 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
786 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
787 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
788 assert!(self.is_owned);
789 let ret = ObjOps::untweak_ptr(self.inner);
790 self.inner = std::ptr::null_mut();
794 /// Protocol features of a channel communicated during its announcement
796 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
797 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
798 crate::lightning::ln::features::ChannelFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
800 /// Protocol features of a channel communicated during its announcement
802 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
803 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
805 /// Source node of the first direction of a channel
807 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
808 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one;
809 crate::c_types::PublicKey::from_rust(&inner_val)
811 /// Source node of the first direction of a channel
813 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
814 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = val.into_rust();
816 /// Details about the first direction of a channel
818 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
820 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::DirectionalChannelInfo {
821 let mut inner_val = &mut this_ptr.get_native_mut_ref().one_to_two;
822 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 };
825 /// Details about the first direction of a channel
827 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
829 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::DirectionalChannelInfo) {
830 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
831 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.one_to_two = local_val;
833 /// Source node of the second direction of a channel
835 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
836 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two;
837 crate::c_types::PublicKey::from_rust(&inner_val)
839 /// Source node of the second direction of a channel
841 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
842 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = val.into_rust();
844 /// Details about the second direction of a channel
846 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
848 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::DirectionalChannelInfo {
849 let mut inner_val = &mut this_ptr.get_native_mut_ref().two_to_one;
850 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 };
853 /// Details about the second direction of a channel
855 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
857 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::DirectionalChannelInfo) {
858 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
859 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.two_to_one = local_val;
861 /// The channel capacity as seen on-chain, if chain lookup is available.
863 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
864 let mut inner_val = &mut this_ptr.get_native_mut_ref().capacity_sats;
865 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() }) };
868 /// The channel capacity as seen on-chain, if chain lookup is available.
870 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
871 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
872 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.capacity_sats = local_val;
874 /// An initial announcement of the channel
875 /// Mostly redundant with the data we store in fields explicitly.
876 /// Everything else is useful only for sending out for initial routing sync.
877 /// Not stored if contains excess data to prevent DoS.
879 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
881 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
882 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
883 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 };
886 /// An initial announcement of the channel
887 /// Mostly redundant with the data we store in fields explicitly.
888 /// Everything else is useful only for sending out for initial routing sync.
889 /// Not stored if contains excess data to prevent DoS.
891 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
893 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
894 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
895 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
897 /// Constructs a new ChannelInfo given each field
900 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 {
901 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()) } }) };
902 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()) } }) };
903 let mut local_capacity_sats_arg = if capacity_sats_arg.is_some() { Some( { capacity_sats_arg.take() }) } else { None };
904 let mut local_announcement_message_arg = if announcement_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_message_arg.take_inner()) } }) };
905 ChannelInfo { inner: ObjOps::heap_alloc(nativeChannelInfo {
906 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
907 node_one: node_one_arg.into_rust(),
908 one_to_two: local_one_to_two_arg,
909 node_two: node_two_arg.into_rust(),
910 two_to_one: local_two_to_one_arg,
911 capacity_sats: local_capacity_sats_arg,
912 announcement_message: local_announcement_message_arg,
915 impl Clone for ChannelInfo {
916 fn clone(&self) -> Self {
918 inner: if <*mut nativeChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
919 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
925 /// Used only if an object of this type is returned as a trait impl by a method
926 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
927 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
930 /// Creates a copy of the ChannelInfo
931 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
935 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
936 pub extern "C" fn ChannelInfo_write(obj: &ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
937 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
940 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
941 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
944 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
945 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
946 let res = crate::c_types::deserialize_obj(ser);
947 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() };
951 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
952 type nativeRoutingFees = nativeRoutingFeesImport;
954 /// Fees for routing via a given channel or a node
957 pub struct RoutingFees {
958 /// A pointer to the opaque Rust object.
960 /// Nearly everywhere, inner must be non-null, however in places where
961 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
962 pub inner: *mut nativeRoutingFees,
963 /// Indicates that this is the only struct which contains the same pointer.
965 /// Rust functions which take ownership of an object provided via an argument require
966 /// this to be true and invalidate the object pointed to by inner.
970 impl Drop for RoutingFees {
972 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
973 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
977 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
979 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
981 /// Used only if an object of this type is returned as a trait impl by a method
982 extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
983 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
987 pub(crate) fn get_native_ref(&self) -> &'static nativeRoutingFees {
988 unsafe { &*ObjOps::untweak_ptr(self.inner) }
990 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoutingFees {
991 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
993 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
994 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
995 assert!(self.is_owned);
996 let ret = ObjOps::untweak_ptr(self.inner);
997 self.inner = std::ptr::null_mut();
1001 /// Flat routing fee in satoshis
1003 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
1004 let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat;
1007 /// Flat routing fee in satoshis
1009 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
1010 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val;
1012 /// Liquidity-based routing fee in millionths of a routed amount.
1013 /// In other words, 10000 is 1%.
1015 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
1016 let mut inner_val = &mut this_ptr.get_native_mut_ref().proportional_millionths;
1019 /// Liquidity-based routing fee in millionths of a routed amount.
1020 /// In other words, 10000 is 1%.
1022 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
1023 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.proportional_millionths = val;
1025 /// Constructs a new RoutingFees given each field
1028 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
1029 RoutingFees { inner: ObjOps::heap_alloc(nativeRoutingFees {
1030 base_msat: base_msat_arg,
1031 proportional_millionths: proportional_millionths_arg,
1032 }), is_owned: true }
1034 /// Checks if two RoutingFeess contain equal inner contents.
1035 /// This ignores pointers and is_owned flags and looks at the values in fields.
1036 /// Two objects with NULL inner values will be considered "equal" here.
1038 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
1039 if a.inner == b.inner { return true; }
1040 if a.inner.is_null() || b.inner.is_null() { return false; }
1041 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1043 impl Clone for RoutingFees {
1044 fn clone(&self) -> Self {
1046 inner: if <*mut nativeRoutingFees>::is_null(self.inner) { std::ptr::null_mut() } else {
1047 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1053 /// Used only if an object of this type is returned as a trait impl by a method
1054 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
1055 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
1058 /// Creates a copy of the RoutingFees
1059 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
1062 /// Checks if two RoutingFeess contain equal inner contents.
1064 pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 {
1065 if o.inner.is_null() { return 0; }
1066 // Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core
1067 #[allow(deprecated)]
1068 let mut hasher = core::hash::SipHasher::new();
1069 std::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1070 std::hash::Hasher::finish(&hasher)
1073 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
1074 pub extern "C" fn RoutingFees_write(obj: &RoutingFees) -> crate::c_types::derived::CVec_u8Z {
1075 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1078 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1079 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
1082 /// Read a RoutingFees from a byte array, created by RoutingFees_write
1083 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
1084 let res = crate::c_types::deserialize_obj(ser);
1085 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() };
1089 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
1090 type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
1092 /// Information received in the latest node_announcement from this node.
1095 pub struct NodeAnnouncementInfo {
1096 /// A pointer to the opaque Rust object.
1098 /// Nearly everywhere, inner must be non-null, however in places where
1099 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1100 pub inner: *mut nativeNodeAnnouncementInfo,
1101 /// Indicates that this is the only struct which contains the same pointer.
1103 /// Rust functions which take ownership of an object provided via an argument require
1104 /// this to be true and invalidate the object pointed to by inner.
1108 impl Drop for NodeAnnouncementInfo {
1109 fn drop(&mut self) {
1110 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
1111 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1115 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
1117 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
1119 /// Used only if an object of this type is returned as a trait impl by a method
1120 extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
1121 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
1124 impl NodeAnnouncementInfo {
1125 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAnnouncementInfo {
1126 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1128 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAnnouncementInfo {
1129 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1131 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1132 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
1133 assert!(self.is_owned);
1134 let ret = ObjOps::untweak_ptr(self.inner);
1135 self.inner = std::ptr::null_mut();
1139 /// Protocol features the node announced support for
1141 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
1142 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1143 crate::lightning::ln::features::NodeFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const _) as *mut _) }, is_owned: false }
1145 /// Protocol features the node announced support for
1147 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
1148 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1150 /// When the last known update to the node state was issued.
1151 /// Value is opaque, as set in the announcement.
1153 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
1154 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
1157 /// When the last known update to the node state was issued.
1158 /// Value is opaque, as set in the announcement.
1160 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
1161 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
1163 /// Color assigned to the node
1165 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
1166 let mut inner_val = &mut this_ptr.get_native_mut_ref().rgb;
1169 /// Color assigned to the node
1171 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
1172 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data;
1174 /// Moniker assigned to the node.
1175 /// May be invalid or malicious (eg control chars),
1176 /// should not be exposed to the user.
1178 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
1179 let mut inner_val = &mut this_ptr.get_native_mut_ref().alias;
1182 /// Moniker assigned to the node.
1183 /// May be invalid or malicious (eg control chars),
1184 /// should not be exposed to the user.
1186 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
1187 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = val.data;
1189 /// Internet-level addresses via which one can connect to the node
1191 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
1192 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
1193 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.addresses = local_val;
1195 /// An initial announcement of the node
1196 /// Mostly redundant with the data we store in fields explicitly.
1197 /// Everything else is useful only for sending out for initial routing sync.
1198 /// Not stored if contains excess data to prevent DoS.
1200 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1202 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
1203 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1204 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 };
1207 /// An initial announcement of the node
1208 /// Mostly redundant with the data we store in fields explicitly.
1209 /// Everything else is useful only for sending out for initial routing sync.
1210 /// Not stored if contains excess data to prevent DoS.
1212 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1214 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
1215 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1216 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1218 /// Constructs a new NodeAnnouncementInfo given each field
1221 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 {
1222 let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
1223 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()) } }) };
1224 NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo {
1225 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1226 last_update: last_update_arg,
1228 alias: alias_arg.data,
1229 addresses: local_addresses_arg,
1230 announcement_message: local_announcement_message_arg,
1231 }), is_owned: true }
1233 impl Clone for NodeAnnouncementInfo {
1234 fn clone(&self) -> Self {
1236 inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
1237 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1243 /// Used only if an object of this type is returned as a trait impl by a method
1244 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1245 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
1248 /// Creates a copy of the NodeAnnouncementInfo
1249 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1253 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1254 pub extern "C" fn NodeAnnouncementInfo_write(obj: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1255 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1258 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1259 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1262 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1263 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1264 let res = crate::c_types::deserialize_obj(ser);
1265 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() };
1269 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
1270 type nativeNodeInfo = nativeNodeInfoImport;
1272 /// Details about a node in the network, known from the network announcement.
1275 pub struct NodeInfo {
1276 /// A pointer to the opaque Rust object.
1278 /// Nearly everywhere, inner must be non-null, however in places where
1279 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1280 pub inner: *mut nativeNodeInfo,
1281 /// Indicates that this is the only struct which contains the same pointer.
1283 /// Rust functions which take ownership of an object provided via an argument require
1284 /// this to be true and invalidate the object pointed to by inner.
1288 impl Drop for NodeInfo {
1289 fn drop(&mut self) {
1290 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1291 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1295 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1297 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1299 /// Used only if an object of this type is returned as a trait impl by a method
1300 extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1301 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
1305 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeInfo {
1306 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1308 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeInfo {
1309 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1311 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1312 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1313 assert!(self.is_owned);
1314 let ret = ObjOps::untweak_ptr(self.inner);
1315 self.inner = std::ptr::null_mut();
1319 /// All valid channels a node has announced
1321 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1322 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1323 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1325 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1326 /// The two fields (flat and proportional fee) are independent,
1327 /// meaning they don't have to refer to the same channel.
1329 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1331 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::RoutingFees {
1332 let mut inner_val = &mut this_ptr.get_native_mut_ref().lowest_inbound_channel_fees;
1333 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 };
1336 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1337 /// The two fields (flat and proportional fee) are independent,
1338 /// meaning they don't have to refer to the same channel.
1340 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1342 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
1343 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1344 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.lowest_inbound_channel_fees = local_val;
1346 /// More information about a node from node_announcement.
1347 /// Optional because we store a Node entry after learning about it from
1348 /// a channel announcement, but before receiving a node announcement.
1350 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1352 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::NodeAnnouncementInfo {
1353 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_info;
1354 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 };
1357 /// More information about a node from node_announcement.
1358 /// Optional because we store a Node entry after learning about it from
1359 /// a channel announcement, but before receiving a node announcement.
1361 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1363 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::NodeAnnouncementInfo) {
1364 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1365 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val;
1367 /// Constructs a new NodeInfo given each field
1370 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 {
1371 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1372 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()) } }) };
1373 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()) } }) };
1374 NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo {
1375 channels: local_channels_arg,
1376 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
1377 announcement_info: local_announcement_info_arg,
1378 }), is_owned: true }
1380 impl Clone for NodeInfo {
1381 fn clone(&self) -> Self {
1383 inner: if <*mut nativeNodeInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
1384 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1390 /// Used only if an object of this type is returned as a trait impl by a method
1391 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1392 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1395 /// Creates a copy of the NodeInfo
1396 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1400 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1401 pub extern "C" fn NodeInfo_write(obj: &NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1402 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1405 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1406 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1409 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1410 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1411 let res = crate::c_types::deserialize_obj(ser);
1412 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() };
1416 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
1417 pub extern "C" fn NetworkGraph_write(obj: &NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1418 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1421 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1422 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1425 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
1426 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1427 let res = crate::c_types::deserialize_obj(ser);
1428 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() };
1431 /// Creates a new, empty, network graph.
1434 pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::lightning::routing::network_graph::NetworkGraph {
1435 let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap());
1436 crate::lightning::routing::network_graph::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1439 /// Returns a read-only view of the network graph.
1442 pub extern "C" fn NetworkGraph_read_only(this_arg: &NetworkGraph) -> crate::lightning::routing::network_graph::ReadOnlyNetworkGraph {
1443 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_only();
1444 crate::lightning::routing::network_graph::ReadOnlyNetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1447 /// For an already known node (from channel announcements), update its stored properties from a
1448 /// given node announcement.
1450 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1451 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1452 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1455 pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1456 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_announcement(msg.get_native_ref(), secp256k1::SECP256K1);
1457 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() };
1461 /// For an already known node (from channel announcements), update its stored properties from a
1462 /// given node announcement without verifying the associated signatures. Because we aren't
1463 /// given the associated signatures here we cannot relay the node announcement to any of our
1467 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 {
1468 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_unsigned_announcement(msg.get_native_ref());
1469 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() };
1473 /// Store or update channel info from a channel announcement.
1475 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1476 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1477 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1479 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1480 /// the corresponding UTXO exists on chain and is correctly-formatted.
1483 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 {
1484 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() }) } };
1485 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_chain_access, secp256k1::SECP256K1);
1486 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() };
1490 /// Store or update channel info from a channel announcement without verifying the associated
1491 /// signatures. Because we aren't given the associated signatures here we cannot relay the
1492 /// channel announcement to any of our peers.
1494 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1495 /// the corresponding UTXO exists on chain and is correctly-formatted.
1498 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 {
1499 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() }) } };
1500 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_chain_access);
1501 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() };
1505 /// Close a channel if a corresponding HTLC fail was sent.
1506 /// If permanent, removes a channel from the local storage.
1507 /// May cause the removal of nodes too, if this was their last channel.
1508 /// If not permanent, makes channels unavailable for routing.
1510 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
1511 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_from_update(short_channel_id, is_permanent)
1514 /// Marks a node in the graph as failed.
1516 pub extern "C" fn NetworkGraph_fail_node(this_arg: &NetworkGraph, mut _node_id: crate::c_types::PublicKey, mut is_permanent: bool) {
1517 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_node(&_node_id.into_rust(), is_permanent)
1520 /// For an already known (from announcement) channel, update info about one of the directions
1523 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1524 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1525 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1528 pub extern "C" fn NetworkGraph_update_channel(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1529 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel(msg.get_native_ref(), secp256k1::SECP256K1);
1530 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() };
1534 /// For an already known (from announcement) channel, update info about one of the directions
1535 /// of the channel without verifying the associated signatures. Because we aren't given the
1536 /// associated signatures here we cannot relay the channel update to any of our peers.
1539 pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1540 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_unsigned(msg.get_native_ref());
1541 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() };