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 alloc::str::FromStr;
12 use core::ffi::c_void;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
16 #[cfg(feature="no-std")]
17 use alloc::{vec::Vec, boxed::Box};
20 use lightning::routing::network_graph::NodeId as nativeNodeIdImport;
21 pub(crate) type nativeNodeId = nativeNodeIdImport;
23 /// Represents the compressed public key of a node
27 /// A pointer to the opaque Rust object.
29 /// Nearly everywhere, inner must be non-null, however in places where
30 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
31 pub inner: *mut nativeNodeId,
32 /// Indicates that this is the only struct which contains the same pointer.
34 /// Rust functions which take ownership of an object provided via an argument require
35 /// this to be true and invalidate the object pointed to by inner.
39 impl Drop for NodeId {
41 if self.is_owned && !<*mut nativeNodeId>::is_null(self.inner) {
42 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
46 /// Frees any resources used by the NodeId, if is_owned is set and inner is non-NULL.
48 pub extern "C" fn NodeId_free(this_obj: NodeId) { }
50 /// Used only if an object of this type is returned as a trait impl by a method
51 pub(crate) extern "C" fn NodeId_free_void(this_ptr: *mut c_void) {
52 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeId); }
56 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeId {
57 unsafe { &*ObjOps::untweak_ptr(self.inner) }
59 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeId {
60 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
62 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
63 pub(crate) fn take_inner(mut self) -> *mut nativeNodeId {
64 assert!(self.is_owned);
65 let ret = ObjOps::untweak_ptr(self.inner);
66 self.inner = core::ptr::null_mut();
70 impl Clone for NodeId {
71 fn clone(&self) -> Self {
73 inner: if <*mut nativeNodeId>::is_null(self.inner) { core::ptr::null_mut() } else {
74 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
80 /// Used only if an object of this type is returned as a trait impl by a method
81 pub(crate) extern "C" fn NodeId_clone_void(this_ptr: *const c_void) -> *mut c_void {
82 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeId)).clone() })) as *mut c_void
85 /// Creates a copy of the NodeId
86 pub extern "C" fn NodeId_clone(orig: &NodeId) -> NodeId {
89 /// Create a new NodeId from a public key
92 pub extern "C" fn NodeId_from_pubkey(mut pubkey: crate::c_types::PublicKey) -> NodeId {
93 let mut ret = lightning::routing::network_graph::NodeId::from_pubkey(&pubkey.into_rust());
94 NodeId { inner: ObjOps::heap_alloc(ret), is_owned: true }
97 /// Get the public key slice from this NodeId
100 pub extern "C" fn NodeId_as_slice(this_arg: &NodeId) -> crate::c_types::u8slice {
101 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_slice();
102 let mut local_ret = crate::c_types::u8slice::from_slice(ret);
106 /// Checks if two NodeIds contain equal inner contents.
108 pub extern "C" fn NodeId_hash(o: &NodeId) -> u64 {
109 if o.inner.is_null() { return 0; }
110 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
112 let mut hasher = core::hash::SipHasher::new();
113 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
114 core::hash::Hasher::finish(&hasher)
117 /// Serialize the NodeId object into a byte array which can be read by NodeId_read
118 pub extern "C" fn NodeId_write(obj: &NodeId) -> crate::c_types::derived::CVec_u8Z {
119 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
122 pub(crate) extern "C" fn NodeId_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
123 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeId) })
126 /// Read a NodeId from a byte array, created by NodeId_write
127 pub extern "C" fn NodeId_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeIdDecodeErrorZ {
128 let res: Result<lightning::routing::network_graph::NodeId, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
129 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NodeId { 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() };
133 use lightning::routing::network_graph::NetworkGraph as nativeNetworkGraphImport;
134 pub(crate) type nativeNetworkGraph = nativeNetworkGraphImport;
136 /// Represents the network as nodes and channels between them
139 pub struct NetworkGraph {
140 /// A pointer to the opaque Rust object.
142 /// Nearly everywhere, inner must be non-null, however in places where
143 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
144 pub inner: *mut nativeNetworkGraph,
145 /// Indicates that this is the only struct which contains the same pointer.
147 /// Rust functions which take ownership of an object provided via an argument require
148 /// this to be true and invalidate the object pointed to by inner.
152 impl Drop for NetworkGraph {
154 if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) {
155 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
159 /// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL.
161 pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { }
163 /// Used only if an object of this type is returned as a trait impl by a method
164 pub(crate) extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
165 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetworkGraph); }
169 pub(crate) fn get_native_ref(&self) -> &'static nativeNetworkGraph {
170 unsafe { &*ObjOps::untweak_ptr(self.inner) }
172 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetworkGraph {
173 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
175 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
176 pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
177 assert!(self.is_owned);
178 let ret = ObjOps::untweak_ptr(self.inner);
179 self.inner = core::ptr::null_mut();
183 impl Clone for NetworkGraph {
184 fn clone(&self) -> Self {
186 inner: if <*mut nativeNetworkGraph>::is_null(self.inner) { core::ptr::null_mut() } else {
187 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
193 /// Used only if an object of this type is returned as a trait impl by a method
194 pub(crate) extern "C" fn NetworkGraph_clone_void(this_ptr: *const c_void) -> *mut c_void {
195 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNetworkGraph)).clone() })) as *mut c_void
198 /// Creates a copy of the NetworkGraph
199 pub extern "C" fn NetworkGraph_clone(orig: &NetworkGraph) -> NetworkGraph {
203 use lightning::routing::network_graph::ReadOnlyNetworkGraph as nativeReadOnlyNetworkGraphImport;
204 pub(crate) type nativeReadOnlyNetworkGraph = nativeReadOnlyNetworkGraphImport<'static>;
206 /// A read-only view of [`NetworkGraph`].
209 pub struct ReadOnlyNetworkGraph {
210 /// A pointer to the opaque Rust object.
212 /// Nearly everywhere, inner must be non-null, however in places where
213 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
214 pub inner: *mut nativeReadOnlyNetworkGraph,
215 /// Indicates that this is the only struct which contains the same pointer.
217 /// Rust functions which take ownership of an object provided via an argument require
218 /// this to be true and invalidate the object pointed to by inner.
222 impl Drop for ReadOnlyNetworkGraph {
224 if self.is_owned && !<*mut nativeReadOnlyNetworkGraph>::is_null(self.inner) {
225 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
229 /// Frees any resources used by the ReadOnlyNetworkGraph, if is_owned is set and inner is non-NULL.
231 pub extern "C" fn ReadOnlyNetworkGraph_free(this_obj: ReadOnlyNetworkGraph) { }
233 /// Used only if an object of this type is returned as a trait impl by a method
234 pub(crate) extern "C" fn ReadOnlyNetworkGraph_free_void(this_ptr: *mut c_void) {
235 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeReadOnlyNetworkGraph); }
238 impl ReadOnlyNetworkGraph {
239 pub(crate) fn get_native_ref(&self) -> &'static nativeReadOnlyNetworkGraph {
240 unsafe { &*ObjOps::untweak_ptr(self.inner) }
242 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReadOnlyNetworkGraph {
243 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
245 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
246 pub(crate) fn take_inner(mut self) -> *mut nativeReadOnlyNetworkGraph {
247 assert!(self.is_owned);
248 let ret = ObjOps::untweak_ptr(self.inner);
249 self.inner = core::ptr::null_mut();
253 /// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
254 /// return packet by a node along the route. See [BOLT #4] for details.
256 /// [BOLT #4]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md
260 pub enum NetworkUpdate {
261 /// An error indicating a `channel_update` messages should be applied via
262 /// [`NetworkGraph::update_channel`].
263 ChannelUpdateMessage {
264 /// The update to apply via [`NetworkGraph::update_channel`].
265 msg: crate::lightning::ln::msgs::ChannelUpdate,
267 /// An error indicating only that a channel has been closed, which should be applied via
268 /// [`NetworkGraph::close_channel_from_update`].
270 /// The short channel id of the closed channel.
271 short_channel_id: u64,
272 /// Whether the channel should be permanently removed or temporarily disabled until a new
273 /// `channel_update` message is received.
276 /// An error indicating only that a node has failed, which should be applied via
277 /// [`NetworkGraph::fail_node`].
279 /// The node id of the failed node.
280 node_id: crate::c_types::PublicKey,
281 /// Whether the node should be permanently removed from consideration or can be restored
282 /// when a new `channel_update` message is received.
286 use lightning::routing::network_graph::NetworkUpdate as nativeNetworkUpdate;
289 pub(crate) fn to_native(&self) -> nativeNetworkUpdate {
291 NetworkUpdate::ChannelUpdateMessage {ref msg, } => {
292 let mut msg_nonref = (*msg).clone();
293 nativeNetworkUpdate::ChannelUpdateMessage {
294 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
297 NetworkUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => {
298 let mut short_channel_id_nonref = (*short_channel_id).clone();
299 let mut is_permanent_nonref = (*is_permanent).clone();
300 nativeNetworkUpdate::ChannelClosed {
301 short_channel_id: short_channel_id_nonref,
302 is_permanent: is_permanent_nonref,
305 NetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
306 let mut node_id_nonref = (*node_id).clone();
307 let mut is_permanent_nonref = (*is_permanent).clone();
308 nativeNetworkUpdate::NodeFailure {
309 node_id: node_id_nonref.into_rust(),
310 is_permanent: is_permanent_nonref,
316 pub(crate) fn into_native(self) -> nativeNetworkUpdate {
318 NetworkUpdate::ChannelUpdateMessage {mut msg, } => {
319 nativeNetworkUpdate::ChannelUpdateMessage {
320 msg: *unsafe { Box::from_raw(msg.take_inner()) },
323 NetworkUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => {
324 nativeNetworkUpdate::ChannelClosed {
325 short_channel_id: short_channel_id,
326 is_permanent: is_permanent,
329 NetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
330 nativeNetworkUpdate::NodeFailure {
331 node_id: node_id.into_rust(),
332 is_permanent: is_permanent,
338 pub(crate) fn from_native(native: &nativeNetworkUpdate) -> Self {
340 nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => {
341 let mut msg_nonref = (*msg).clone();
342 NetworkUpdate::ChannelUpdateMessage {
343 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
346 nativeNetworkUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => {
347 let mut short_channel_id_nonref = (*short_channel_id).clone();
348 let mut is_permanent_nonref = (*is_permanent).clone();
349 NetworkUpdate::ChannelClosed {
350 short_channel_id: short_channel_id_nonref,
351 is_permanent: is_permanent_nonref,
354 nativeNetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
355 let mut node_id_nonref = (*node_id).clone();
356 let mut is_permanent_nonref = (*is_permanent).clone();
357 NetworkUpdate::NodeFailure {
358 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
359 is_permanent: is_permanent_nonref,
365 pub(crate) fn native_into(native: nativeNetworkUpdate) -> Self {
367 nativeNetworkUpdate::ChannelUpdateMessage {mut msg, } => {
368 NetworkUpdate::ChannelUpdateMessage {
369 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
372 nativeNetworkUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => {
373 NetworkUpdate::ChannelClosed {
374 short_channel_id: short_channel_id,
375 is_permanent: is_permanent,
378 nativeNetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
379 NetworkUpdate::NodeFailure {
380 node_id: crate::c_types::PublicKey::from_rust(&node_id),
381 is_permanent: is_permanent,
387 /// Frees any resources used by the NetworkUpdate
389 pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { }
390 /// Creates a copy of the NetworkUpdate
392 pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate {
396 /// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
397 pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate {
398 NetworkUpdate::ChannelUpdateMessage {
403 /// Utility method to constructs a new ChannelClosed-variant NetworkUpdate
404 pub extern "C" fn NetworkUpdate_channel_closed(short_channel_id: u64, is_permanent: bool) -> NetworkUpdate {
405 NetworkUpdate::ChannelClosed {
411 /// Utility method to constructs a new NodeFailure-variant NetworkUpdate
412 pub extern "C" fn NetworkUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent: bool) -> NetworkUpdate {
413 NetworkUpdate::NodeFailure {
419 /// Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
420 pub extern "C" fn NetworkUpdate_write(obj: &NetworkUpdate) -> crate::c_types::derived::CVec_u8Z {
421 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
424 /// Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
425 pub extern "C" fn NetworkUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_NetworkUpdateZDecodeErrorZ {
426 let res: Result<Option<lightning::routing::network_graph::NetworkUpdate>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
427 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_NetworkUpdateZ::None } else { crate::c_types::derived::COption_NetworkUpdateZ::Some( { crate::lightning::routing::network_graph::NetworkUpdate::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() };
430 impl From<nativeNetGraphMsgHandler> for crate::lightning::util::events::EventHandler {
431 fn from(obj: nativeNetGraphMsgHandler) -> Self {
432 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
433 let mut ret = NetGraphMsgHandler_as_EventHandler(&rust_obj);
434 // 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
435 rust_obj.inner = core::ptr::null_mut();
436 ret.free = Some(NetGraphMsgHandler_free_void);
440 /// Constructs a new EventHandler which calls the relevant methods on this_arg.
441 /// This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is
443 pub extern "C" fn NetGraphMsgHandler_as_EventHandler(this_arg: &NetGraphMsgHandler) -> crate::lightning::util::events::EventHandler {
444 crate::lightning::util::events::EventHandler {
445 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
447 handle_event: NetGraphMsgHandler_EventHandler_handle_event,
451 extern "C" fn NetGraphMsgHandler_EventHandler_handle_event(this_arg: *const c_void, event: &crate::lightning::util::events::Event) {
452 <nativeNetGraphMsgHandler as lightning::util::events::EventHandler<>>::handle_event(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &event.to_native())
456 use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport;
457 pub(crate) type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport<&'static lightning::routing::network_graph::NetworkGraph, crate::lightning::chain::Access, crate::lightning::util::logger::Logger>;
459 /// Receives and validates network updates from peers,
460 /// stores authentic and relevant data as a network graph.
461 /// This network graph is then used for routing payments.
462 /// Provides interface to help with initial routing sync by
463 /// serving historical announcements.
465 /// Serves as an [`EventHandler`] for applying updates from [`Event::PaymentPathFailed`] to the
466 /// [`NetworkGraph`].
469 pub struct NetGraphMsgHandler {
470 /// A pointer to the opaque Rust object.
472 /// Nearly everywhere, inner must be non-null, however in places where
473 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
474 pub inner: *mut nativeNetGraphMsgHandler,
475 /// Indicates that this is the only struct which contains the same pointer.
477 /// Rust functions which take ownership of an object provided via an argument require
478 /// this to be true and invalidate the object pointed to by inner.
482 impl Drop for NetGraphMsgHandler {
484 if self.is_owned && !<*mut nativeNetGraphMsgHandler>::is_null(self.inner) {
485 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
489 /// Frees any resources used by the NetGraphMsgHandler, if is_owned is set and inner is non-NULL.
491 pub extern "C" fn NetGraphMsgHandler_free(this_obj: NetGraphMsgHandler) { }
493 /// Used only if an object of this type is returned as a trait impl by a method
494 pub(crate) extern "C" fn NetGraphMsgHandler_free_void(this_ptr: *mut c_void) {
495 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetGraphMsgHandler); }
498 impl NetGraphMsgHandler {
499 pub(crate) fn get_native_ref(&self) -> &'static nativeNetGraphMsgHandler {
500 unsafe { &*ObjOps::untweak_ptr(self.inner) }
502 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetGraphMsgHandler {
503 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
505 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
506 pub(crate) fn take_inner(mut self) -> *mut nativeNetGraphMsgHandler {
507 assert!(self.is_owned);
508 let ret = ObjOps::untweak_ptr(self.inner);
509 self.inner = core::ptr::null_mut();
513 /// Creates a new tracker of the actual state of the network of channels and nodes,
514 /// assuming an existing Network Graph.
515 /// Chain monitor is used to make sure announced channels exist on-chain,
516 /// channel data is correct, and that the announcement is signed with
517 /// channel owners' keys.
520 pub extern "C" fn NetGraphMsgHandler_new(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 {
521 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() }) } };
522 let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(network_graph.get_native_ref(), local_chain_access, logger);
523 NetGraphMsgHandler { inner: ObjOps::heap_alloc(ret), is_owned: true }
526 /// Adds a provider used to check new announcements. Does not affect
527 /// existing announcements unless they are updated.
528 /// Add, update or remove the provider would replace the current one.
530 pub extern "C" fn NetGraphMsgHandler_add_chain_access(this_arg: &mut NetGraphMsgHandler, mut chain_access: crate::c_types::derived::COption_AccessZ) {
531 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() }) } };
532 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut nativeNetGraphMsgHandler)) }.add_chain_access(local_chain_access)
535 impl From<nativeNetGraphMsgHandler> for crate::lightning::ln::msgs::RoutingMessageHandler {
536 fn from(obj: nativeNetGraphMsgHandler) -> Self {
537 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
538 let mut ret = NetGraphMsgHandler_as_RoutingMessageHandler(&rust_obj);
539 // 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
540 rust_obj.inner = core::ptr::null_mut();
541 ret.free = Some(NetGraphMsgHandler_free_void);
545 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
546 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
548 pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: &NetGraphMsgHandler) -> crate::lightning::ln::msgs::RoutingMessageHandler {
549 crate::lightning::ln::msgs::RoutingMessageHandler {
550 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
552 handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement,
553 handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement,
554 handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update,
555 get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements,
556 get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements,
557 sync_routing_table: NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table,
558 handle_reply_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range,
559 handle_reply_short_channel_ids_end: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
560 handle_query_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range,
561 handle_query_short_channel_ids: NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids,
562 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
563 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
565 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
571 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 {
572 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
573 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() };
577 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 {
578 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
579 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() };
583 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 {
584 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, msg.get_native_ref());
585 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() };
589 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 {
590 let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, starting_point, batch_amount);
591 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() { core::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() { core::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 }); };
595 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 {
596 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();
597 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);
598 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 } }); };
601 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) {
602 <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())
605 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 {
606 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()) });
607 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() };
611 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 {
612 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()) });
613 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() };
617 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 {
618 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()) });
619 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() };
623 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 {
624 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()) });
625 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() };
629 impl From<nativeNetGraphMsgHandler> for crate::lightning::util::events::MessageSendEventsProvider {
630 fn from(obj: nativeNetGraphMsgHandler) -> Self {
631 let mut rust_obj = NetGraphMsgHandler { inner: ObjOps::heap_alloc(obj), is_owned: true };
632 let mut ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&rust_obj);
633 // 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
634 rust_obj.inner = core::ptr::null_mut();
635 ret.free = Some(NetGraphMsgHandler_free_void);
639 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
640 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
642 pub extern "C" fn NetGraphMsgHandler_as_MessageSendEventsProvider(this_arg: &NetGraphMsgHandler) -> crate::lightning::util::events::MessageSendEventsProvider {
643 crate::lightning::util::events::MessageSendEventsProvider {
644 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
646 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
651 extern "C" fn NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
652 let mut ret = <nativeNetGraphMsgHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, );
653 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
658 use lightning::routing::network_graph::ChannelUpdateInfo as nativeChannelUpdateInfoImport;
659 pub(crate) type nativeChannelUpdateInfo = nativeChannelUpdateInfoImport;
661 /// Details about one direction of a channel as received within a [`ChannelUpdate`].
664 pub struct ChannelUpdateInfo {
665 /// A pointer to the opaque Rust object.
667 /// Nearly everywhere, inner must be non-null, however in places where
668 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
669 pub inner: *mut nativeChannelUpdateInfo,
670 /// Indicates that this is the only struct which contains the same pointer.
672 /// Rust functions which take ownership of an object provided via an argument require
673 /// this to be true and invalidate the object pointed to by inner.
677 impl Drop for ChannelUpdateInfo {
679 if self.is_owned && !<*mut nativeChannelUpdateInfo>::is_null(self.inner) {
680 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
684 /// Frees any resources used by the ChannelUpdateInfo, if is_owned is set and inner is non-NULL.
686 pub extern "C" fn ChannelUpdateInfo_free(this_obj: ChannelUpdateInfo) { }
688 /// Used only if an object of this type is returned as a trait impl by a method
689 pub(crate) extern "C" fn ChannelUpdateInfo_free_void(this_ptr: *mut c_void) {
690 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelUpdateInfo); }
693 impl ChannelUpdateInfo {
694 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUpdateInfo {
695 unsafe { &*ObjOps::untweak_ptr(self.inner) }
697 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUpdateInfo {
698 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
700 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
701 pub(crate) fn take_inner(mut self) -> *mut nativeChannelUpdateInfo {
702 assert!(self.is_owned);
703 let ret = ObjOps::untweak_ptr(self.inner);
704 self.inner = core::ptr::null_mut();
708 /// When the last update to the channel direction was issued.
709 /// Value is opaque, as set in the announcement.
711 pub extern "C" fn ChannelUpdateInfo_get_last_update(this_ptr: &ChannelUpdateInfo) -> u32 {
712 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
715 /// When the last update to the channel direction was issued.
716 /// Value is opaque, as set in the announcement.
718 pub extern "C" fn ChannelUpdateInfo_set_last_update(this_ptr: &mut ChannelUpdateInfo, mut val: u32) {
719 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
721 /// Whether the channel can be currently used for payments (in this one direction).
723 pub extern "C" fn ChannelUpdateInfo_get_enabled(this_ptr: &ChannelUpdateInfo) -> bool {
724 let mut inner_val = &mut this_ptr.get_native_mut_ref().enabled;
727 /// Whether the channel can be currently used for payments (in this one direction).
729 pub extern "C" fn ChannelUpdateInfo_set_enabled(this_ptr: &mut ChannelUpdateInfo, mut val: bool) {
730 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.enabled = val;
732 /// The difference in CLTV values that you must have when routing through this channel.
734 pub extern "C" fn ChannelUpdateInfo_get_cltv_expiry_delta(this_ptr: &ChannelUpdateInfo) -> u16 {
735 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
738 /// The difference in CLTV values that you must have when routing through this channel.
740 pub extern "C" fn ChannelUpdateInfo_set_cltv_expiry_delta(this_ptr: &mut ChannelUpdateInfo, mut val: u16) {
741 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
743 /// The minimum value, which must be relayed to the next hop via the channel
745 pub extern "C" fn ChannelUpdateInfo_get_htlc_minimum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
746 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
749 /// The minimum value, which must be relayed to the next hop via the channel
751 pub extern "C" fn ChannelUpdateInfo_set_htlc_minimum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
752 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
754 /// The maximum value which may be relayed to the next hop via the channel.
756 pub extern "C" fn ChannelUpdateInfo_get_htlc_maximum_msat(this_ptr: &ChannelUpdateInfo) -> crate::c_types::derived::COption_u64Z {
757 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
758 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() }) };
761 /// The maximum value which may be relayed to the next hop via the channel.
763 pub extern "C" fn ChannelUpdateInfo_set_htlc_maximum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: crate::c_types::derived::COption_u64Z) {
764 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
765 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val;
767 /// Fees charged when the channel is used for routing
769 pub extern "C" fn ChannelUpdateInfo_get_fees(this_ptr: &ChannelUpdateInfo) -> crate::lightning::routing::network_graph::RoutingFees {
770 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
771 crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::network_graph::RoutingFees<>) as *mut _) }, is_owned: false }
773 /// Fees charged when the channel is used for routing
775 pub extern "C" fn ChannelUpdateInfo_set_fees(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
776 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
778 /// Most recent update for the channel received from the network
779 /// Mostly redundant with the data we store in fields explicitly.
780 /// Everything else is useful only for sending out for initial routing sync.
781 /// Not stored if contains excess data to prevent DoS.
783 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
785 pub extern "C" fn ChannelUpdateInfo_get_last_update_message(this_ptr: &ChannelUpdateInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
786 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update_message;
787 let mut local_inner_val = crate::lightning::ln::msgs::ChannelUpdate { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::msgs::ChannelUpdate<>) as *mut _ }, is_owned: false };
790 /// Most recent update for the channel received from the network
791 /// Mostly redundant with the data we store in fields explicitly.
792 /// Everything else is useful only for sending out for initial routing sync.
793 /// Not stored if contains excess data to prevent DoS.
795 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
797 pub extern "C" fn ChannelUpdateInfo_set_last_update_message(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
798 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
799 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val;
801 /// Constructs a new ChannelUpdateInfo given each field
804 pub extern "C" fn ChannelUpdateInfo_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) -> ChannelUpdateInfo {
805 let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
806 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()) } }) };
807 ChannelUpdateInfo { inner: ObjOps::heap_alloc(nativeChannelUpdateInfo {
808 last_update: last_update_arg,
809 enabled: enabled_arg,
810 cltv_expiry_delta: cltv_expiry_delta_arg,
811 htlc_minimum_msat: htlc_minimum_msat_arg,
812 htlc_maximum_msat: local_htlc_maximum_msat_arg,
813 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
814 last_update_message: local_last_update_message_arg,
817 impl Clone for ChannelUpdateInfo {
818 fn clone(&self) -> Self {
820 inner: if <*mut nativeChannelUpdateInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
821 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
827 /// Used only if an object of this type is returned as a trait impl by a method
828 pub(crate) extern "C" fn ChannelUpdateInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
829 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUpdateInfo)).clone() })) as *mut c_void
832 /// Creates a copy of the ChannelUpdateInfo
833 pub extern "C" fn ChannelUpdateInfo_clone(orig: &ChannelUpdateInfo) -> ChannelUpdateInfo {
837 /// Serialize the ChannelUpdateInfo object into a byte array which can be read by ChannelUpdateInfo_read
838 pub extern "C" fn ChannelUpdateInfo_write(obj: &ChannelUpdateInfo) -> crate::c_types::derived::CVec_u8Z {
839 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
842 pub(crate) extern "C" fn ChannelUpdateInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
843 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdateInfo) })
846 /// Read a ChannelUpdateInfo from a byte array, created by ChannelUpdateInfo_write
847 pub extern "C" fn ChannelUpdateInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelUpdateInfoDecodeErrorZ {
848 let res: Result<lightning::routing::network_graph::ChannelUpdateInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
849 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::ChannelUpdateInfo { 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() };
853 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
854 pub(crate) type nativeChannelInfo = nativeChannelInfoImport;
856 /// Details about a channel (both directions).
857 /// Received within a channel announcement.
860 pub struct ChannelInfo {
861 /// A pointer to the opaque Rust object.
863 /// Nearly everywhere, inner must be non-null, however in places where
864 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
865 pub inner: *mut nativeChannelInfo,
866 /// Indicates that this is the only struct which contains the same pointer.
868 /// Rust functions which take ownership of an object provided via an argument require
869 /// this to be true and invalidate the object pointed to by inner.
873 impl Drop for ChannelInfo {
875 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
876 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
880 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
882 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
884 /// Used only if an object of this type is returned as a trait impl by a method
885 pub(crate) extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
886 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
890 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelInfo {
891 unsafe { &*ObjOps::untweak_ptr(self.inner) }
893 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelInfo {
894 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
896 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
897 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
898 assert!(self.is_owned);
899 let ret = ObjOps::untweak_ptr(self.inner);
900 self.inner = core::ptr::null_mut();
904 /// Protocol features of a channel communicated during its announcement
906 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
907 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
908 crate::lightning::ln::features::ChannelFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::ChannelFeatures<>) as *mut _) }, is_owned: false }
910 /// Protocol features of a channel communicated during its announcement
912 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
913 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
915 /// Source node of the first direction of a channel
917 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::NodeId {
918 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one;
919 crate::lightning::routing::network_graph::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::network_graph::NodeId<>) as *mut _) }, is_owned: false }
921 /// Source node of the first direction of a channel
923 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::NodeId) {
924 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = *unsafe { Box::from_raw(val.take_inner()) };
926 /// Details about the first direction of a channel
928 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
930 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::ChannelUpdateInfo {
931 let mut inner_val = &mut this_ptr.get_native_mut_ref().one_to_two;
932 let mut local_inner_val = crate::lightning::routing::network_graph::ChannelUpdateInfo { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::network_graph::ChannelUpdateInfo<>) as *mut _ }, is_owned: false };
935 /// Details about the first direction of a channel
937 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
939 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::ChannelUpdateInfo) {
940 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
941 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.one_to_two = local_val;
943 /// Source node of the second direction of a channel
945 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::NodeId {
946 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two;
947 crate::lightning::routing::network_graph::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::network_graph::NodeId<>) as *mut _) }, is_owned: false }
949 /// Source node of the second direction of a channel
951 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::NodeId) {
952 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = *unsafe { Box::from_raw(val.take_inner()) };
954 /// Details about the second direction of a channel
956 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
958 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::ChannelUpdateInfo {
959 let mut inner_val = &mut this_ptr.get_native_mut_ref().two_to_one;
960 let mut local_inner_val = crate::lightning::routing::network_graph::ChannelUpdateInfo { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::network_graph::ChannelUpdateInfo<>) as *mut _ }, is_owned: false };
963 /// Details about the second direction of a channel
965 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
967 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::ChannelUpdateInfo) {
968 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
969 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.two_to_one = local_val;
971 /// The channel capacity as seen on-chain, if chain lookup is available.
973 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
974 let mut inner_val = &mut this_ptr.get_native_mut_ref().capacity_sats;
975 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() }) };
978 /// The channel capacity as seen on-chain, if chain lookup is available.
980 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
981 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
982 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.capacity_sats = local_val;
984 /// An initial announcement of the channel
985 /// Mostly redundant with the data we store in fields explicitly.
986 /// Everything else is useful only for sending out for initial routing sync.
987 /// Not stored if contains excess data to prevent DoS.
989 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
991 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
992 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
993 let mut local_inner_val = crate::lightning::ln::msgs::ChannelAnnouncement { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::msgs::ChannelAnnouncement<>) as *mut _ }, is_owned: false };
996 /// An initial announcement of the channel
997 /// Mostly redundant with the data we store in fields explicitly.
998 /// Everything else is useful only for sending out for initial routing sync.
999 /// Not stored if contains excess data to prevent DoS.
1001 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1003 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
1004 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1005 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1007 impl Clone for ChannelInfo {
1008 fn clone(&self) -> Self {
1010 inner: if <*mut nativeChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1011 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1017 /// Used only if an object of this type is returned as a trait impl by a method
1018 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1019 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
1022 /// Creates a copy of the ChannelInfo
1023 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
1027 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
1028 pub extern "C" fn ChannelInfo_write(obj: &ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
1029 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1032 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1033 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
1036 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
1037 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
1038 let res: Result<lightning::routing::network_graph::ChannelInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1039 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() };
1043 use lightning::routing::network_graph::DirectedChannelInfo as nativeDirectedChannelInfoImport;
1044 pub(crate) type nativeDirectedChannelInfo = nativeDirectedChannelInfoImport<'static>;
1046 /// A wrapper around [`ChannelInfo`] representing information about the channel as directed from a
1047 /// source node to a target node.
1050 pub struct DirectedChannelInfo {
1051 /// A pointer to the opaque Rust object.
1053 /// Nearly everywhere, inner must be non-null, however in places where
1054 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1055 pub inner: *mut nativeDirectedChannelInfo,
1056 /// Indicates that this is the only struct which contains the same pointer.
1058 /// Rust functions which take ownership of an object provided via an argument require
1059 /// this to be true and invalidate the object pointed to by inner.
1063 impl Drop for DirectedChannelInfo {
1064 fn drop(&mut self) {
1065 if self.is_owned && !<*mut nativeDirectedChannelInfo>::is_null(self.inner) {
1066 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1070 /// Frees any resources used by the DirectedChannelInfo, if is_owned is set and inner is non-NULL.
1072 pub extern "C" fn DirectedChannelInfo_free(this_obj: DirectedChannelInfo) { }
1074 /// Used only if an object of this type is returned as a trait impl by a method
1075 pub(crate) extern "C" fn DirectedChannelInfo_free_void(this_ptr: *mut c_void) {
1076 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectedChannelInfo); }
1079 impl DirectedChannelInfo {
1080 pub(crate) fn get_native_ref(&self) -> &'static nativeDirectedChannelInfo {
1081 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1083 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectedChannelInfo {
1084 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1086 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1087 pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelInfo {
1088 assert!(self.is_owned);
1089 let ret = ObjOps::untweak_ptr(self.inner);
1090 self.inner = core::ptr::null_mut();
1094 impl Clone for DirectedChannelInfo {
1095 fn clone(&self) -> Self {
1097 inner: if <*mut nativeDirectedChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1098 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1104 /// Used only if an object of this type is returned as a trait impl by a method
1105 pub(crate) extern "C" fn DirectedChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1106 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectedChannelInfo)).clone() })) as *mut c_void
1109 /// Creates a copy of the DirectedChannelInfo
1110 pub extern "C" fn DirectedChannelInfo_clone(orig: &DirectedChannelInfo) -> DirectedChannelInfo {
1113 /// Returns information for the channel.
1116 pub extern "C" fn DirectedChannelInfo_channel(this_arg: &DirectedChannelInfo) -> crate::lightning::routing::network_graph::ChannelInfo {
1117 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel();
1118 crate::lightning::routing::network_graph::ChannelInfo { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::routing::network_graph::ChannelInfo<>) as *mut _) }, is_owned: false }
1121 /// Returns information for the direction.
1123 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1126 pub extern "C" fn DirectedChannelInfo_direction(this_arg: &DirectedChannelInfo) -> crate::lightning::routing::network_graph::ChannelUpdateInfo {
1127 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.direction();
1128 let mut local_ret = crate::lightning::routing::network_graph::ChannelUpdateInfo { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::routing::network_graph::ChannelUpdateInfo<>) as *mut _ }, is_owned: false };
1132 /// Returns the [`EffectiveCapacity`] of the channel in the direction.
1134 /// This is either the total capacity from the funding transaction, if known, or the
1135 /// `htlc_maximum_msat` for the direction as advertised by the gossip network, if known,
1136 /// whichever is smaller.
1139 pub extern "C" fn DirectedChannelInfo_effective_capacity(this_arg: &DirectedChannelInfo) -> crate::lightning::routing::network_graph::EffectiveCapacity {
1140 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.effective_capacity();
1141 crate::lightning::routing::network_graph::EffectiveCapacity::native_into(ret)
1144 /// The effective capacity of a channel for routing purposes.
1146 /// While this may be smaller than the actual channel capacity, amounts greater than
1147 /// [`Self::as_msat`] should not be routed through the channel.
1151 pub enum EffectiveCapacity {
1152 /// The available liquidity in the channel known from being a channel counterparty, and thus a
1155 /// Either the inbound or outbound liquidity depending on the direction, denominated in
1157 liquidity_msat: u64,
1159 /// The maximum HTLC amount in one direction as advertised on the gossip network.
1161 /// The maximum HTLC amount denominated in millisatoshi.
1164 /// The total capacity of the channel as determined by the funding transaction.
1166 /// The funding amount denominated in millisatoshi.
1169 /// A capacity sufficient to route any payment, typically used for private channels provided by
1172 /// A capacity that is unknown possibly because either the chain state is unavailable to know
1173 /// the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.
1176 use lightning::routing::network_graph::EffectiveCapacity as nativeEffectiveCapacity;
1177 impl EffectiveCapacity {
1179 pub(crate) fn to_native(&self) -> nativeEffectiveCapacity {
1181 EffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1182 let mut liquidity_msat_nonref = (*liquidity_msat).clone();
1183 nativeEffectiveCapacity::ExactLiquidity {
1184 liquidity_msat: liquidity_msat_nonref,
1187 EffectiveCapacity::MaximumHTLC {ref amount_msat, } => {
1188 let mut amount_msat_nonref = (*amount_msat).clone();
1189 nativeEffectiveCapacity::MaximumHTLC {
1190 amount_msat: amount_msat_nonref,
1193 EffectiveCapacity::Total {ref capacity_msat, } => {
1194 let mut capacity_msat_nonref = (*capacity_msat).clone();
1195 nativeEffectiveCapacity::Total {
1196 capacity_msat: capacity_msat_nonref,
1199 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1200 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1204 pub(crate) fn into_native(self) -> nativeEffectiveCapacity {
1206 EffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1207 nativeEffectiveCapacity::ExactLiquidity {
1208 liquidity_msat: liquidity_msat,
1211 EffectiveCapacity::MaximumHTLC {mut amount_msat, } => {
1212 nativeEffectiveCapacity::MaximumHTLC {
1213 amount_msat: amount_msat,
1216 EffectiveCapacity::Total {mut capacity_msat, } => {
1217 nativeEffectiveCapacity::Total {
1218 capacity_msat: capacity_msat,
1221 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1222 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1226 pub(crate) fn from_native(native: &nativeEffectiveCapacity) -> Self {
1228 nativeEffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1229 let mut liquidity_msat_nonref = (*liquidity_msat).clone();
1230 EffectiveCapacity::ExactLiquidity {
1231 liquidity_msat: liquidity_msat_nonref,
1234 nativeEffectiveCapacity::MaximumHTLC {ref amount_msat, } => {
1235 let mut amount_msat_nonref = (*amount_msat).clone();
1236 EffectiveCapacity::MaximumHTLC {
1237 amount_msat: amount_msat_nonref,
1240 nativeEffectiveCapacity::Total {ref capacity_msat, } => {
1241 let mut capacity_msat_nonref = (*capacity_msat).clone();
1242 EffectiveCapacity::Total {
1243 capacity_msat: capacity_msat_nonref,
1246 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1247 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1251 pub(crate) fn native_into(native: nativeEffectiveCapacity) -> Self {
1253 nativeEffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1254 EffectiveCapacity::ExactLiquidity {
1255 liquidity_msat: liquidity_msat,
1258 nativeEffectiveCapacity::MaximumHTLC {mut amount_msat, } => {
1259 EffectiveCapacity::MaximumHTLC {
1260 amount_msat: amount_msat,
1263 nativeEffectiveCapacity::Total {mut capacity_msat, } => {
1264 EffectiveCapacity::Total {
1265 capacity_msat: capacity_msat,
1268 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1269 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1273 /// Frees any resources used by the EffectiveCapacity
1275 pub extern "C" fn EffectiveCapacity_free(this_ptr: EffectiveCapacity) { }
1276 /// Creates a copy of the EffectiveCapacity
1278 pub extern "C" fn EffectiveCapacity_clone(orig: &EffectiveCapacity) -> EffectiveCapacity {
1282 /// Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity
1283 pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> EffectiveCapacity {
1284 EffectiveCapacity::ExactLiquidity {
1289 /// Utility method to constructs a new MaximumHTLC-variant EffectiveCapacity
1290 pub extern "C" fn EffectiveCapacity_maximum_htlc(amount_msat: u64) -> EffectiveCapacity {
1291 EffectiveCapacity::MaximumHTLC {
1296 /// Utility method to constructs a new Total-variant EffectiveCapacity
1297 pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64) -> EffectiveCapacity {
1298 EffectiveCapacity::Total {
1303 /// Utility method to constructs a new Infinite-variant EffectiveCapacity
1304 pub extern "C" fn EffectiveCapacity_infinite() -> EffectiveCapacity {
1305 EffectiveCapacity::Infinite}
1307 /// Utility method to constructs a new Unknown-variant EffectiveCapacity
1308 pub extern "C" fn EffectiveCapacity_unknown() -> EffectiveCapacity {
1309 EffectiveCapacity::Unknown}
1310 /// The presumed channel capacity denominated in millisatoshi for [`EffectiveCapacity::Unknown`] to
1311 /// use when making routing decisions.
1314 pub static UNKNOWN_CHANNEL_CAPACITY_MSAT: u64 = lightning::routing::network_graph::UNKNOWN_CHANNEL_CAPACITY_MSAT;
1315 /// Returns the effective capacity denominated in millisatoshi.
1318 pub extern "C" fn EffectiveCapacity_as_msat(this_arg: &EffectiveCapacity) -> u64 {
1319 let mut ret = this_arg.to_native().as_msat();
1324 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
1325 pub(crate) type nativeRoutingFees = nativeRoutingFeesImport;
1327 /// Fees for routing via a given channel or a node
1330 pub struct RoutingFees {
1331 /// A pointer to the opaque Rust object.
1333 /// Nearly everywhere, inner must be non-null, however in places where
1334 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1335 pub inner: *mut nativeRoutingFees,
1336 /// Indicates that this is the only struct which contains the same pointer.
1338 /// Rust functions which take ownership of an object provided via an argument require
1339 /// this to be true and invalidate the object pointed to by inner.
1343 impl Drop for RoutingFees {
1344 fn drop(&mut self) {
1345 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
1346 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1350 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
1352 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
1354 /// Used only if an object of this type is returned as a trait impl by a method
1355 pub(crate) extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
1356 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
1360 pub(crate) fn get_native_ref(&self) -> &'static nativeRoutingFees {
1361 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1363 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoutingFees {
1364 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1366 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1367 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
1368 assert!(self.is_owned);
1369 let ret = ObjOps::untweak_ptr(self.inner);
1370 self.inner = core::ptr::null_mut();
1374 /// Flat routing fee in satoshis
1376 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
1377 let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat;
1380 /// Flat routing fee in satoshis
1382 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
1383 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val;
1385 /// Liquidity-based routing fee in millionths of a routed amount.
1386 /// In other words, 10000 is 1%.
1388 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
1389 let mut inner_val = &mut this_ptr.get_native_mut_ref().proportional_millionths;
1392 /// Liquidity-based routing fee in millionths of a routed amount.
1393 /// In other words, 10000 is 1%.
1395 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
1396 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.proportional_millionths = val;
1398 /// Constructs a new RoutingFees given each field
1401 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
1402 RoutingFees { inner: ObjOps::heap_alloc(nativeRoutingFees {
1403 base_msat: base_msat_arg,
1404 proportional_millionths: proportional_millionths_arg,
1405 }), is_owned: true }
1407 /// Checks if two RoutingFeess contain equal inner contents.
1408 /// This ignores pointers and is_owned flags and looks at the values in fields.
1409 /// Two objects with NULL inner values will be considered "equal" here.
1411 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
1412 if a.inner == b.inner { return true; }
1413 if a.inner.is_null() || b.inner.is_null() { return false; }
1414 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1416 impl Clone for RoutingFees {
1417 fn clone(&self) -> Self {
1419 inner: if <*mut nativeRoutingFees>::is_null(self.inner) { core::ptr::null_mut() } else {
1420 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1426 /// Used only if an object of this type is returned as a trait impl by a method
1427 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
1428 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
1431 /// Creates a copy of the RoutingFees
1432 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
1435 /// Checks if two RoutingFeess contain equal inner contents.
1437 pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 {
1438 if o.inner.is_null() { return 0; }
1439 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1440 #[allow(deprecated)]
1441 let mut hasher = core::hash::SipHasher::new();
1442 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1443 core::hash::Hasher::finish(&hasher)
1446 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
1447 pub extern "C" fn RoutingFees_write(obj: &RoutingFees) -> crate::c_types::derived::CVec_u8Z {
1448 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1451 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1452 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
1455 /// Read a RoutingFees from a byte array, created by RoutingFees_write
1456 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
1457 let res: Result<lightning::routing::network_graph::RoutingFees, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1458 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() };
1462 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
1463 pub(crate) type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
1465 /// Information received in the latest node_announcement from this node.
1468 pub struct NodeAnnouncementInfo {
1469 /// A pointer to the opaque Rust object.
1471 /// Nearly everywhere, inner must be non-null, however in places where
1472 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1473 pub inner: *mut nativeNodeAnnouncementInfo,
1474 /// Indicates that this is the only struct which contains the same pointer.
1476 /// Rust functions which take ownership of an object provided via an argument require
1477 /// this to be true and invalidate the object pointed to by inner.
1481 impl Drop for NodeAnnouncementInfo {
1482 fn drop(&mut self) {
1483 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
1484 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1488 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
1490 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
1492 /// Used only if an object of this type is returned as a trait impl by a method
1493 pub(crate) extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
1494 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
1497 impl NodeAnnouncementInfo {
1498 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAnnouncementInfo {
1499 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1501 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAnnouncementInfo {
1502 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1504 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1505 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
1506 assert!(self.is_owned);
1507 let ret = ObjOps::untweak_ptr(self.inner);
1508 self.inner = core::ptr::null_mut();
1512 /// Protocol features the node announced support for
1514 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
1515 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1516 crate::lightning::ln::features::NodeFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::NodeFeatures<>) as *mut _) }, is_owned: false }
1518 /// Protocol features the node announced support for
1520 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
1521 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1523 /// When the last known update to the node state was issued.
1524 /// Value is opaque, as set in the announcement.
1526 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
1527 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
1530 /// When the last known update to the node state was issued.
1531 /// Value is opaque, as set in the announcement.
1533 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
1534 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
1536 /// Color assigned to the node
1538 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
1539 let mut inner_val = &mut this_ptr.get_native_mut_ref().rgb;
1542 /// Color assigned to the node
1544 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
1545 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data;
1547 /// Moniker assigned to the node.
1548 /// May be invalid or malicious (eg control chars),
1549 /// should not be exposed to the user.
1551 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
1552 let mut inner_val = &mut this_ptr.get_native_mut_ref().alias;
1555 /// Moniker assigned to the node.
1556 /// May be invalid or malicious (eg control chars),
1557 /// should not be exposed to the user.
1559 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
1560 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = val.data;
1562 /// Internet-level addresses via which one can connect to the node
1564 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
1565 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
1566 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.addresses = local_val;
1568 /// An initial announcement of the node
1569 /// Mostly redundant with the data we store in fields explicitly.
1570 /// Everything else is useful only for sending out for initial routing sync.
1571 /// Not stored if contains excess data to prevent DoS.
1573 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1575 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
1576 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1577 let mut local_inner_val = crate::lightning::ln::msgs::NodeAnnouncement { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::msgs::NodeAnnouncement<>) as *mut _ }, is_owned: false };
1580 /// An initial announcement of the node
1581 /// Mostly redundant with the data we store in fields explicitly.
1582 /// Everything else is useful only for sending out for initial routing sync.
1583 /// Not stored if contains excess data to prevent DoS.
1585 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1587 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
1588 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1589 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1591 /// Constructs a new NodeAnnouncementInfo given each field
1594 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 {
1595 let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
1596 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()) } }) };
1597 NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo {
1598 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1599 last_update: last_update_arg,
1601 alias: alias_arg.data,
1602 addresses: local_addresses_arg,
1603 announcement_message: local_announcement_message_arg,
1604 }), is_owned: true }
1606 impl Clone for NodeAnnouncementInfo {
1607 fn clone(&self) -> Self {
1609 inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1610 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1616 /// Used only if an object of this type is returned as a trait impl by a method
1617 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1618 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
1621 /// Creates a copy of the NodeAnnouncementInfo
1622 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1626 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1627 pub extern "C" fn NodeAnnouncementInfo_write(obj: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1628 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1631 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1632 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1635 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1636 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1637 let res: Result<lightning::routing::network_graph::NodeAnnouncementInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1638 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() };
1642 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
1643 pub(crate) type nativeNodeInfo = nativeNodeInfoImport;
1645 /// Details about a node in the network, known from the network announcement.
1648 pub struct NodeInfo {
1649 /// A pointer to the opaque Rust object.
1651 /// Nearly everywhere, inner must be non-null, however in places where
1652 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1653 pub inner: *mut nativeNodeInfo,
1654 /// Indicates that this is the only struct which contains the same pointer.
1656 /// Rust functions which take ownership of an object provided via an argument require
1657 /// this to be true and invalidate the object pointed to by inner.
1661 impl Drop for NodeInfo {
1662 fn drop(&mut self) {
1663 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1664 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1668 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1670 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1672 /// Used only if an object of this type is returned as a trait impl by a method
1673 pub(crate) extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1674 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
1678 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeInfo {
1679 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1681 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeInfo {
1682 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1684 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1685 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1686 assert!(self.is_owned);
1687 let ret = ObjOps::untweak_ptr(self.inner);
1688 self.inner = core::ptr::null_mut();
1692 /// All valid channels a node has announced
1694 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1695 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1696 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1698 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1699 /// The two fields (flat and proportional fee) are independent,
1700 /// meaning they don't have to refer to the same channel.
1702 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1704 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::RoutingFees {
1705 let mut inner_val = &mut this_ptr.get_native_mut_ref().lowest_inbound_channel_fees;
1706 let mut local_inner_val = crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::network_graph::RoutingFees<>) as *mut _ }, is_owned: false };
1709 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1710 /// The two fields (flat and proportional fee) are independent,
1711 /// meaning they don't have to refer to the same channel.
1713 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1715 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
1716 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1717 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.lowest_inbound_channel_fees = local_val;
1719 /// More information about a node from node_announcement.
1720 /// Optional because we store a Node entry after learning about it from
1721 /// a channel announcement, but before receiving a node announcement.
1723 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1725 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::NodeAnnouncementInfo {
1726 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_info;
1727 let mut local_inner_val = crate::lightning::routing::network_graph::NodeAnnouncementInfo { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::network_graph::NodeAnnouncementInfo<>) as *mut _ }, is_owned: false };
1730 /// More information about a node from node_announcement.
1731 /// Optional because we store a Node entry after learning about it from
1732 /// a channel announcement, but before receiving a node announcement.
1734 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1736 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::NodeAnnouncementInfo) {
1737 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1738 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val;
1740 /// Constructs a new NodeInfo given each field
1743 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 {
1744 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1745 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()) } }) };
1746 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()) } }) };
1747 NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo {
1748 channels: local_channels_arg,
1749 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
1750 announcement_info: local_announcement_info_arg,
1751 }), is_owned: true }
1753 impl Clone for NodeInfo {
1754 fn clone(&self) -> Self {
1756 inner: if <*mut nativeNodeInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1757 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1763 /// Used only if an object of this type is returned as a trait impl by a method
1764 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1765 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1768 /// Creates a copy of the NodeInfo
1769 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1773 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1774 pub extern "C" fn NodeInfo_write(obj: &NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1775 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1778 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1779 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1782 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1783 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1784 let res: Result<lightning::routing::network_graph::NodeInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1785 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() };
1789 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
1790 pub extern "C" fn NetworkGraph_write(obj: &NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1791 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1794 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1795 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1798 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
1799 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1800 let res: Result<lightning::routing::network_graph::NetworkGraph, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1801 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() };
1804 /// Creates a new, empty, network graph.
1807 pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::lightning::routing::network_graph::NetworkGraph {
1808 let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap());
1809 crate::lightning::routing::network_graph::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1812 /// Returns a read-only view of the network graph.
1815 pub extern "C" fn NetworkGraph_read_only(this_arg: &NetworkGraph) -> crate::lightning::routing::network_graph::ReadOnlyNetworkGraph {
1816 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_only();
1817 crate::lightning::routing::network_graph::ReadOnlyNetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1820 /// For an already known node (from channel announcements), update its stored properties from a
1821 /// given node announcement.
1823 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1824 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1825 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1828 pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1829 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_announcement(msg.get_native_ref(), secp256k1::SECP256K1);
1830 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() };
1834 /// For an already known node (from channel announcements), update its stored properties from a
1835 /// given node announcement without verifying the associated signatures. Because we aren't
1836 /// given the associated signatures here we cannot relay the node announcement to any of our
1840 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 {
1841 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_unsigned_announcement(msg.get_native_ref());
1842 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() };
1846 /// Store or update channel info from a channel announcement.
1848 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1849 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1850 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1852 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1853 /// the corresponding UTXO exists on chain and is correctly-formatted.
1856 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 {
1857 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() }) } };
1858 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_chain_access, secp256k1::SECP256K1);
1859 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() };
1863 /// Store or update channel info from a channel announcement without verifying the associated
1864 /// signatures. Because we aren't given the associated signatures here we cannot relay the
1865 /// channel announcement to any of our peers.
1867 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1868 /// the corresponding UTXO exists on chain and is correctly-formatted.
1871 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 {
1872 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() }) } };
1873 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_chain_access);
1874 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() };
1878 /// Close a channel if a corresponding HTLC fail was sent.
1879 /// If permanent, removes a channel from the local storage.
1880 /// May cause the removal of nodes too, if this was their last channel.
1881 /// If not permanent, makes channels unavailable for routing.
1883 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
1884 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.close_channel_from_update(short_channel_id, is_permanent)
1887 /// Marks a node in the graph as failed.
1889 pub extern "C" fn NetworkGraph_fail_node(this_arg: &NetworkGraph, mut _node_id: crate::c_types::PublicKey, mut is_permanent: bool) {
1890 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fail_node(&_node_id.into_rust(), is_permanent)
1893 /// Removes information about channels that we haven't heard any updates about in some time.
1894 /// This can be used regularly to prune the network graph of channels that likely no longer
1897 /// While there is no formal requirement that nodes regularly re-broadcast their channel
1898 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
1899 /// pruning occur for updates which are at least two weeks old, which we implement here.
1901 /// Note that for users of the `lightning-background-processor` crate this method may be
1902 /// automatically called regularly for you.
1904 /// This method is only available with the `std` feature. See
1905 /// [`NetworkGraph::remove_stale_channels_with_time`] for `no-std` use.
1907 pub extern "C" fn NetworkGraph_remove_stale_channels(this_arg: &NetworkGraph) {
1908 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels()
1911 /// Removes information about channels that we haven't heard any updates about in some time.
1912 /// This can be used regularly to prune the network graph of channels that likely no longer
1915 /// While there is no formal requirement that nodes regularly re-broadcast their channel
1916 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
1917 /// pruning occur for updates which are at least two weeks old, which we implement here.
1919 /// This function takes the current unix time as an argument. For users with the `std` feature
1920 /// enabled, [`NetworkGraph::remove_stale_channels`] may be preferable.
1922 pub extern "C" fn NetworkGraph_remove_stale_channels_with_time(this_arg: &NetworkGraph, mut current_time_unix: u64) {
1923 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_with_time(current_time_unix)
1926 /// For an already known (from announcement) channel, update info about one of the directions
1929 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1930 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1931 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1933 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
1934 /// materially in the future will be rejected.
1937 pub extern "C" fn NetworkGraph_update_channel(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1938 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel(msg.get_native_ref(), secp256k1::SECP256K1);
1939 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() };
1943 /// For an already known (from announcement) channel, update info about one of the directions
1944 /// of the channel without verifying the associated signatures. Because we aren't given the
1945 /// associated signatures here we cannot relay the channel update to any of our peers.
1947 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
1948 /// materially in the future will be rejected.
1951 pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1952 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_unsigned(msg.get_native_ref());
1953 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() };
1957 /// Get network addresses by node id.
1958 /// Returns None if the requested node is completely unknown,
1959 /// or if node announcement for the node was never received.
1962 pub extern "C" fn ReadOnlyNetworkGraph_get_addresses(this_arg: &ReadOnlyNetworkGraph, mut pubkey: crate::c_types::PublicKey) -> crate::c_types::derived::COption_CVec_NetAddressZZ {
1963 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_addresses(&pubkey.into_rust());
1964 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_NetAddressZZ::None } else { crate::c_types::derived::COption_CVec_NetAddressZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::lightning::ln::msgs::NetAddress::native_into(item) }); }; local_ret_0.into() }) };