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 [`NetworkGraph`] stores the network gossip and [`P2PGossipSync`] fetches it from peers
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::gossip::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 let _ = unsafe { 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) -> crate::lightning::routing::gossip::NodeId {
93 let mut ret = lightning::routing::gossip::NodeId::from_pubkey(&pubkey.into_rust());
94 crate::lightning::routing::gossip::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: &crate::lightning::routing::gossip::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: &crate::lightning::routing::gossip::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::gossip::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::gossip::NodeId { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
133 use lightning::routing::gossip::NetworkGraph as nativeNetworkGraphImport;
134 pub(crate) type nativeNetworkGraph = nativeNetworkGraphImport<crate::lightning::util::logger::Logger>;
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 let _ = unsafe { 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();
184 use lightning::routing::gossip::ReadOnlyNetworkGraph as nativeReadOnlyNetworkGraphImport;
185 pub(crate) type nativeReadOnlyNetworkGraph = nativeReadOnlyNetworkGraphImport<'static>;
187 /// A read-only view of [`NetworkGraph`].
190 pub struct ReadOnlyNetworkGraph {
191 /// A pointer to the opaque Rust object.
193 /// Nearly everywhere, inner must be non-null, however in places where
194 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
195 pub inner: *mut nativeReadOnlyNetworkGraph,
196 /// Indicates that this is the only struct which contains the same pointer.
198 /// Rust functions which take ownership of an object provided via an argument require
199 /// this to be true and invalidate the object pointed to by inner.
203 impl Drop for ReadOnlyNetworkGraph {
205 if self.is_owned && !<*mut nativeReadOnlyNetworkGraph>::is_null(self.inner) {
206 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
210 /// Frees any resources used by the ReadOnlyNetworkGraph, if is_owned is set and inner is non-NULL.
212 pub extern "C" fn ReadOnlyNetworkGraph_free(this_obj: ReadOnlyNetworkGraph) { }
214 /// Used only if an object of this type is returned as a trait impl by a method
215 pub(crate) extern "C" fn ReadOnlyNetworkGraph_free_void(this_ptr: *mut c_void) {
216 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeReadOnlyNetworkGraph) };
219 impl ReadOnlyNetworkGraph {
220 pub(crate) fn get_native_ref(&self) -> &'static nativeReadOnlyNetworkGraph {
221 unsafe { &*ObjOps::untweak_ptr(self.inner) }
223 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReadOnlyNetworkGraph {
224 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
226 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
227 pub(crate) fn take_inner(mut self) -> *mut nativeReadOnlyNetworkGraph {
228 assert!(self.is_owned);
229 let ret = ObjOps::untweak_ptr(self.inner);
230 self.inner = core::ptr::null_mut();
234 /// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
235 /// return packet by a node along the route. See [BOLT #4] for details.
237 /// [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
241 pub enum NetworkUpdate {
242 /// An error indicating a `channel_update` messages should be applied via
243 /// [`NetworkGraph::update_channel`].
244 ChannelUpdateMessage {
245 /// The update to apply via [`NetworkGraph::update_channel`].
246 msg: crate::lightning::ln::msgs::ChannelUpdate,
248 /// An error indicating that a channel failed to route a payment, which should be applied via
249 /// [`NetworkGraph::channel_failed`].
251 /// The short channel id of the closed channel.
252 short_channel_id: u64,
253 /// Whether the channel should be permanently removed or temporarily disabled until a new
254 /// `channel_update` message is received.
257 /// An error indicating that a node failed to route a payment, which should be applied via
258 /// [`NetworkGraph::node_failed_permanent`] if permanent.
260 /// The node id of the failed node.
261 node_id: crate::c_types::PublicKey,
262 /// Whether the node should be permanently removed from consideration or can be restored
263 /// when a new `channel_update` message is received.
267 use lightning::routing::gossip::NetworkUpdate as NetworkUpdateImport;
268 pub(crate) type nativeNetworkUpdate = NetworkUpdateImport;
272 pub(crate) fn to_native(&self) -> nativeNetworkUpdate {
274 NetworkUpdate::ChannelUpdateMessage {ref msg, } => {
275 let mut msg_nonref = Clone::clone(msg);
276 nativeNetworkUpdate::ChannelUpdateMessage {
277 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
280 NetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
281 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
282 let mut is_permanent_nonref = Clone::clone(is_permanent);
283 nativeNetworkUpdate::ChannelFailure {
284 short_channel_id: short_channel_id_nonref,
285 is_permanent: is_permanent_nonref,
288 NetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
289 let mut node_id_nonref = Clone::clone(node_id);
290 let mut is_permanent_nonref = Clone::clone(is_permanent);
291 nativeNetworkUpdate::NodeFailure {
292 node_id: node_id_nonref.into_rust(),
293 is_permanent: is_permanent_nonref,
299 pub(crate) fn into_native(self) -> nativeNetworkUpdate {
301 NetworkUpdate::ChannelUpdateMessage {mut msg, } => {
302 nativeNetworkUpdate::ChannelUpdateMessage {
303 msg: *unsafe { Box::from_raw(msg.take_inner()) },
306 NetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
307 nativeNetworkUpdate::ChannelFailure {
308 short_channel_id: short_channel_id,
309 is_permanent: is_permanent,
312 NetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
313 nativeNetworkUpdate::NodeFailure {
314 node_id: node_id.into_rust(),
315 is_permanent: is_permanent,
321 pub(crate) fn from_native(native: &nativeNetworkUpdate) -> Self {
323 nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => {
324 let mut msg_nonref = Clone::clone(msg);
325 NetworkUpdate::ChannelUpdateMessage {
326 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
329 nativeNetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
330 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
331 let mut is_permanent_nonref = Clone::clone(is_permanent);
332 NetworkUpdate::ChannelFailure {
333 short_channel_id: short_channel_id_nonref,
334 is_permanent: is_permanent_nonref,
337 nativeNetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
338 let mut node_id_nonref = Clone::clone(node_id);
339 let mut is_permanent_nonref = Clone::clone(is_permanent);
340 NetworkUpdate::NodeFailure {
341 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
342 is_permanent: is_permanent_nonref,
348 pub(crate) fn native_into(native: nativeNetworkUpdate) -> Self {
350 nativeNetworkUpdate::ChannelUpdateMessage {mut msg, } => {
351 NetworkUpdate::ChannelUpdateMessage {
352 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
355 nativeNetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
356 NetworkUpdate::ChannelFailure {
357 short_channel_id: short_channel_id,
358 is_permanent: is_permanent,
361 nativeNetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
362 NetworkUpdate::NodeFailure {
363 node_id: crate::c_types::PublicKey::from_rust(&node_id),
364 is_permanent: is_permanent,
370 /// Frees any resources used by the NetworkUpdate
372 pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { }
373 /// Creates a copy of the NetworkUpdate
375 pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate {
379 /// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
380 pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate {
381 NetworkUpdate::ChannelUpdateMessage {
386 /// Utility method to constructs a new ChannelFailure-variant NetworkUpdate
387 pub extern "C" fn NetworkUpdate_channel_failure(short_channel_id: u64, is_permanent: bool) -> NetworkUpdate {
388 NetworkUpdate::ChannelFailure {
394 /// Utility method to constructs a new NodeFailure-variant NetworkUpdate
395 pub extern "C" fn NetworkUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent: bool) -> NetworkUpdate {
396 NetworkUpdate::NodeFailure {
401 /// Checks if two NetworkUpdates contain equal inner contents.
402 /// This ignores pointers and is_owned flags and looks at the values in fields.
404 pub extern "C" fn NetworkUpdate_eq(a: &NetworkUpdate, b: &NetworkUpdate) -> bool {
405 if &a.to_native() == &b.to_native() { true } else { false }
408 /// Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
409 pub extern "C" fn NetworkUpdate_write(obj: &crate::lightning::routing::gossip::NetworkUpdate) -> crate::c_types::derived::CVec_u8Z {
410 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
413 /// Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
414 pub extern "C" fn NetworkUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_NetworkUpdateZDecodeErrorZ {
415 let res: Result<Option<lightning::routing::gossip::NetworkUpdate>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
416 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::gossip::NetworkUpdate::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
420 use lightning::routing::gossip::P2PGossipSync as nativeP2PGossipSyncImport;
421 pub(crate) type nativeP2PGossipSync = nativeP2PGossipSyncImport<&'static lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, crate::lightning::routing::utxo::UtxoLookup, crate::lightning::util::logger::Logger>;
423 /// Receives and validates network updates from peers,
424 /// stores authentic and relevant data as a network graph.
425 /// This network graph is then used for routing payments.
426 /// Provides interface to help with initial routing sync by
427 /// serving historical announcements.
430 pub struct P2PGossipSync {
431 /// A pointer to the opaque Rust object.
433 /// Nearly everywhere, inner must be non-null, however in places where
434 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
435 pub inner: *mut nativeP2PGossipSync,
436 /// Indicates that this is the only struct which contains the same pointer.
438 /// Rust functions which take ownership of an object provided via an argument require
439 /// this to be true and invalidate the object pointed to by inner.
443 impl Drop for P2PGossipSync {
445 if self.is_owned && !<*mut nativeP2PGossipSync>::is_null(self.inner) {
446 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
450 /// Frees any resources used by the P2PGossipSync, if is_owned is set and inner is non-NULL.
452 pub extern "C" fn P2PGossipSync_free(this_obj: P2PGossipSync) { }
454 /// Used only if an object of this type is returned as a trait impl by a method
455 pub(crate) extern "C" fn P2PGossipSync_free_void(this_ptr: *mut c_void) {
456 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeP2PGossipSync) };
460 pub(crate) fn get_native_ref(&self) -> &'static nativeP2PGossipSync {
461 unsafe { &*ObjOps::untweak_ptr(self.inner) }
463 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeP2PGossipSync {
464 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
466 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
467 pub(crate) fn take_inner(mut self) -> *mut nativeP2PGossipSync {
468 assert!(self.is_owned);
469 let ret = ObjOps::untweak_ptr(self.inner);
470 self.inner = core::ptr::null_mut();
474 /// Creates a new tracker of the actual state of the network of channels and nodes,
475 /// assuming an existing Network Graph.
476 /// UTXO lookup is used to make sure announced channels exist on-chain, channel data is
477 /// correct, and the announcement is signed with channel owners' keys.
480 pub extern "C" fn P2PGossipSync_new(network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::P2PGossipSync {
481 let mut local_utxo_lookup = { /* utxo_lookup*/ let utxo_lookup_opt = utxo_lookup; { } if utxo_lookup_opt.is_none() { None } else { Some({ utxo_lookup_opt.take() }) } };
482 let mut ret = lightning::routing::gossip::P2PGossipSync::new(network_graph.get_native_ref(), local_utxo_lookup, logger);
483 crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(ret), is_owned: true }
486 /// Adds a provider used to check new announcements. Does not affect
487 /// existing announcements unless they are updated.
488 /// Add, update or remove the provider would replace the current one.
490 pub extern "C" fn P2PGossipSync_add_utxo_lookup(this_arg: &mut crate::lightning::routing::gossip::P2PGossipSync, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ) {
491 let mut local_utxo_lookup = { /* utxo_lookup*/ let utxo_lookup_opt = utxo_lookup; { } if utxo_lookup_opt.is_none() { None } else { Some({ utxo_lookup_opt.take() }) } };
492 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::gossip::nativeP2PGossipSync)) }.add_utxo_lookup(local_utxo_lookup)
495 /// Handles any network updates originating from [`Event`]s.
497 /// [`Event`]: crate::util::events::Event
499 pub extern "C" fn NetworkGraph_handle_network_update(this_arg: &crate::lightning::routing::gossip::NetworkGraph, network_update: &crate::lightning::routing::gossip::NetworkUpdate) {
500 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.handle_network_update(&network_update.to_native())
503 impl From<nativeP2PGossipSync> for crate::lightning::ln::msgs::RoutingMessageHandler {
504 fn from(obj: nativeP2PGossipSync) -> Self {
505 let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
506 let mut ret = P2PGossipSync_as_RoutingMessageHandler(&rust_obj);
507 // 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
508 rust_obj.inner = core::ptr::null_mut();
509 ret.free = Some(P2PGossipSync_free_void);
513 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
514 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
516 pub extern "C" fn P2PGossipSync_as_RoutingMessageHandler(this_arg: &P2PGossipSync) -> crate::lightning::ln::msgs::RoutingMessageHandler {
517 crate::lightning::ln::msgs::RoutingMessageHandler {
518 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
520 handle_node_announcement: P2PGossipSync_RoutingMessageHandler_handle_node_announcement,
521 handle_channel_announcement: P2PGossipSync_RoutingMessageHandler_handle_channel_announcement,
522 handle_channel_update: P2PGossipSync_RoutingMessageHandler_handle_channel_update,
523 get_next_channel_announcement: P2PGossipSync_RoutingMessageHandler_get_next_channel_announcement,
524 get_next_node_announcement: P2PGossipSync_RoutingMessageHandler_get_next_node_announcement,
525 peer_connected: P2PGossipSync_RoutingMessageHandler_peer_connected,
526 handle_reply_channel_range: P2PGossipSync_RoutingMessageHandler_handle_reply_channel_range,
527 handle_reply_short_channel_ids_end: P2PGossipSync_RoutingMessageHandler_handle_reply_short_channel_ids_end,
528 handle_query_channel_range: P2PGossipSync_RoutingMessageHandler_handle_query_channel_range,
529 handle_query_short_channel_ids: P2PGossipSync_RoutingMessageHandler_handle_query_short_channel_ids,
530 processing_queue_high: P2PGossipSync_RoutingMessageHandler_processing_queue_high,
531 provided_node_features: P2PGossipSync_RoutingMessageHandler_provided_node_features,
532 provided_init_features: P2PGossipSync_RoutingMessageHandler_provided_init_features,
533 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
534 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
536 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
542 extern "C" fn P2PGossipSync_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
543 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
544 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() };
548 extern "C" fn P2PGossipSync_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
549 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
550 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() };
554 extern "C" fn P2PGossipSync_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
555 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
556 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() };
560 extern "C" fn P2PGossipSync_RoutingMessageHandler_get_next_channel_announcement(this_arg: *const c_void, mut starting_point: u64) -> crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ {
561 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, starting_point);
562 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ::None } else { crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ::Some( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = (ret.unwrap()); 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 }) };
566 extern "C" fn P2PGossipSync_RoutingMessageHandler_get_next_node_announcement(this_arg: *const c_void, mut starting_point: crate::lightning::routing::gossip::NodeId) -> crate::lightning::ln::msgs::NodeAnnouncement {
567 let mut local_starting_point = if starting_point.inner.is_null() { None } else { Some( { starting_point.get_native_ref() }) };
568 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, local_starting_point);
569 let mut local_ret = crate::lightning::ln::msgs::NodeAnnouncement { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true };
573 extern "C" fn P2PGossipSync_RoutingMessageHandler_peer_connected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init: &crate::lightning::ln::msgs::Init, mut inbound: bool) -> crate::c_types::derived::CResult_NoneNoneZ {
574 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::peer_connected(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust(), init.get_native_ref(), inbound);
575 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
579 extern "C" fn P2PGossipSync_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 {
580 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_reply_channel_range(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
581 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() };
585 extern "C" fn P2PGossipSync_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 {
586 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_reply_short_channel_ids_end(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
587 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() };
591 extern "C" fn P2PGossipSync_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 {
592 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_query_channel_range(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
593 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() };
597 extern "C" fn P2PGossipSync_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 {
598 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_query_short_channel_ids(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
599 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() };
603 extern "C" fn P2PGossipSync_RoutingMessageHandler_processing_queue_high(this_arg: *const c_void) -> bool {
604 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::processing_queue_high(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
608 extern "C" fn P2PGossipSync_RoutingMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
609 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
610 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
613 extern "C" fn P2PGossipSync_RoutingMessageHandler_provided_init_features(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures {
614 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust());
615 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
618 impl From<nativeP2PGossipSync> for crate::lightning::util::events::MessageSendEventsProvider {
619 fn from(obj: nativeP2PGossipSync) -> Self {
620 let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
621 let mut ret = P2PGossipSync_as_MessageSendEventsProvider(&rust_obj);
622 // 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
623 rust_obj.inner = core::ptr::null_mut();
624 ret.free = Some(P2PGossipSync_free_void);
628 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
629 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
631 pub extern "C" fn P2PGossipSync_as_MessageSendEventsProvider(this_arg: &P2PGossipSync) -> crate::lightning::util::events::MessageSendEventsProvider {
632 crate::lightning::util::events::MessageSendEventsProvider {
633 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
635 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
640 extern "C" fn P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
641 let mut ret = <nativeP2PGossipSync as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
642 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
647 use lightning::routing::gossip::ChannelUpdateInfo as nativeChannelUpdateInfoImport;
648 pub(crate) type nativeChannelUpdateInfo = nativeChannelUpdateInfoImport;
650 /// Details about one direction of a channel as received within a [`ChannelUpdate`].
653 pub struct ChannelUpdateInfo {
654 /// A pointer to the opaque Rust object.
656 /// Nearly everywhere, inner must be non-null, however in places where
657 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
658 pub inner: *mut nativeChannelUpdateInfo,
659 /// Indicates that this is the only struct which contains the same pointer.
661 /// Rust functions which take ownership of an object provided via an argument require
662 /// this to be true and invalidate the object pointed to by inner.
666 impl Drop for ChannelUpdateInfo {
668 if self.is_owned && !<*mut nativeChannelUpdateInfo>::is_null(self.inner) {
669 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
673 /// Frees any resources used by the ChannelUpdateInfo, if is_owned is set and inner is non-NULL.
675 pub extern "C" fn ChannelUpdateInfo_free(this_obj: ChannelUpdateInfo) { }
677 /// Used only if an object of this type is returned as a trait impl by a method
678 pub(crate) extern "C" fn ChannelUpdateInfo_free_void(this_ptr: *mut c_void) {
679 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelUpdateInfo) };
682 impl ChannelUpdateInfo {
683 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUpdateInfo {
684 unsafe { &*ObjOps::untweak_ptr(self.inner) }
686 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUpdateInfo {
687 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
689 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
690 pub(crate) fn take_inner(mut self) -> *mut nativeChannelUpdateInfo {
691 assert!(self.is_owned);
692 let ret = ObjOps::untweak_ptr(self.inner);
693 self.inner = core::ptr::null_mut();
697 /// When the last update to the channel direction was issued.
698 /// Value is opaque, as set in the announcement.
700 pub extern "C" fn ChannelUpdateInfo_get_last_update(this_ptr: &ChannelUpdateInfo) -> u32 {
701 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
704 /// When the last update to the channel direction was issued.
705 /// Value is opaque, as set in the announcement.
707 pub extern "C" fn ChannelUpdateInfo_set_last_update(this_ptr: &mut ChannelUpdateInfo, mut val: u32) {
708 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
710 /// Whether the channel can be currently used for payments (in this one direction).
712 pub extern "C" fn ChannelUpdateInfo_get_enabled(this_ptr: &ChannelUpdateInfo) -> bool {
713 let mut inner_val = &mut this_ptr.get_native_mut_ref().enabled;
716 /// Whether the channel can be currently used for payments (in this one direction).
718 pub extern "C" fn ChannelUpdateInfo_set_enabled(this_ptr: &mut ChannelUpdateInfo, mut val: bool) {
719 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.enabled = val;
721 /// The difference in CLTV values that you must have when routing through this channel.
723 pub extern "C" fn ChannelUpdateInfo_get_cltv_expiry_delta(this_ptr: &ChannelUpdateInfo) -> u16 {
724 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
727 /// The difference in CLTV values that you must have when routing through this channel.
729 pub extern "C" fn ChannelUpdateInfo_set_cltv_expiry_delta(this_ptr: &mut ChannelUpdateInfo, mut val: u16) {
730 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
732 /// The minimum value, which must be relayed to the next hop via the channel
734 pub extern "C" fn ChannelUpdateInfo_get_htlc_minimum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
735 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
738 /// The minimum value, which must be relayed to the next hop via the channel
740 pub extern "C" fn ChannelUpdateInfo_set_htlc_minimum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
741 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
743 /// The maximum value which may be relayed to the next hop via the channel.
745 pub extern "C" fn ChannelUpdateInfo_get_htlc_maximum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
746 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
749 /// The maximum value which may be relayed to the next hop via the channel.
751 pub extern "C" fn ChannelUpdateInfo_set_htlc_maximum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
752 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val;
754 /// Fees charged when the channel is used for routing
756 pub extern "C" fn ChannelUpdateInfo_get_fees(this_ptr: &ChannelUpdateInfo) -> crate::lightning::routing::gossip::RoutingFees {
757 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
758 crate::lightning::routing::gossip::RoutingFees { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::RoutingFees<>) as *mut _) }, is_owned: false }
760 /// Fees charged when the channel is used for routing
762 pub extern "C" fn ChannelUpdateInfo_set_fees(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::routing::gossip::RoutingFees) {
763 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
765 /// Most recent update for the channel received from the network
766 /// Mostly redundant with the data we store in fields explicitly.
767 /// Everything else is useful only for sending out for initial routing sync.
768 /// Not stored if contains excess data to prevent DoS.
770 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
772 pub extern "C" fn ChannelUpdateInfo_get_last_update_message(this_ptr: &ChannelUpdateInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
773 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update_message;
774 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 };
777 /// Most recent update for the channel received from the network
778 /// Mostly redundant with the data we store in fields explicitly.
779 /// Everything else is useful only for sending out for initial routing sync.
780 /// Not stored if contains excess data to prevent DoS.
782 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
784 pub extern "C" fn ChannelUpdateInfo_set_last_update_message(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
785 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
786 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val;
788 /// Constructs a new ChannelUpdateInfo given each field
791 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: u64, mut fees_arg: crate::lightning::routing::gossip::RoutingFees, mut last_update_message_arg: crate::lightning::ln::msgs::ChannelUpdate) -> ChannelUpdateInfo {
792 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()) } }) };
793 ChannelUpdateInfo { inner: ObjOps::heap_alloc(nativeChannelUpdateInfo {
794 last_update: last_update_arg,
795 enabled: enabled_arg,
796 cltv_expiry_delta: cltv_expiry_delta_arg,
797 htlc_minimum_msat: htlc_minimum_msat_arg,
798 htlc_maximum_msat: htlc_maximum_msat_arg,
799 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
800 last_update_message: local_last_update_message_arg,
803 impl Clone for ChannelUpdateInfo {
804 fn clone(&self) -> Self {
806 inner: if <*mut nativeChannelUpdateInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
807 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
813 /// Used only if an object of this type is returned as a trait impl by a method
814 pub(crate) extern "C" fn ChannelUpdateInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
815 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUpdateInfo)).clone() })) as *mut c_void
818 /// Creates a copy of the ChannelUpdateInfo
819 pub extern "C" fn ChannelUpdateInfo_clone(orig: &ChannelUpdateInfo) -> ChannelUpdateInfo {
822 /// Checks if two ChannelUpdateInfos contain equal inner contents.
823 /// This ignores pointers and is_owned flags and looks at the values in fields.
824 /// Two objects with NULL inner values will be considered "equal" here.
826 pub extern "C" fn ChannelUpdateInfo_eq(a: &ChannelUpdateInfo, b: &ChannelUpdateInfo) -> bool {
827 if a.inner == b.inner { return true; }
828 if a.inner.is_null() || b.inner.is_null() { return false; }
829 if a.get_native_ref() == b.get_native_ref() { true } else { false }
832 /// Serialize the ChannelUpdateInfo object into a byte array which can be read by ChannelUpdateInfo_read
833 pub extern "C" fn ChannelUpdateInfo_write(obj: &crate::lightning::routing::gossip::ChannelUpdateInfo) -> crate::c_types::derived::CVec_u8Z {
834 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
837 pub(crate) extern "C" fn ChannelUpdateInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
838 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdateInfo) })
841 /// Read a ChannelUpdateInfo from a byte array, created by ChannelUpdateInfo_write
842 pub extern "C" fn ChannelUpdateInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelUpdateInfoDecodeErrorZ {
843 let res: Result<lightning::routing::gossip::ChannelUpdateInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
844 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::ChannelUpdateInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
848 use lightning::routing::gossip::ChannelInfo as nativeChannelInfoImport;
849 pub(crate) type nativeChannelInfo = nativeChannelInfoImport;
851 /// Details about a channel (both directions).
852 /// Received within a channel announcement.
855 pub struct ChannelInfo {
856 /// A pointer to the opaque Rust object.
858 /// Nearly everywhere, inner must be non-null, however in places where
859 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
860 pub inner: *mut nativeChannelInfo,
861 /// Indicates that this is the only struct which contains the same pointer.
863 /// Rust functions which take ownership of an object provided via an argument require
864 /// this to be true and invalidate the object pointed to by inner.
868 impl Drop for ChannelInfo {
870 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
871 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
875 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
877 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
879 /// Used only if an object of this type is returned as a trait impl by a method
880 pub(crate) extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
881 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelInfo) };
885 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelInfo {
886 unsafe { &*ObjOps::untweak_ptr(self.inner) }
888 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelInfo {
889 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
891 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
892 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
893 assert!(self.is_owned);
894 let ret = ObjOps::untweak_ptr(self.inner);
895 self.inner = core::ptr::null_mut();
899 /// Protocol features of a channel communicated during its announcement
901 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
902 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
903 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 }
905 /// Protocol features of a channel communicated during its announcement
907 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
908 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
910 /// Source node of the first direction of a channel
912 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
913 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one;
914 crate::lightning::routing::gossip::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::NodeId<>) as *mut _) }, is_owned: false }
916 /// Source node of the first direction of a channel
918 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
919 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = *unsafe { Box::from_raw(val.take_inner()) };
921 /// Details about the first direction of a channel
923 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
925 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
926 let mut inner_val = &mut this_ptr.get_native_mut_ref().one_to_two;
927 let mut local_inner_val = crate::lightning::routing::gossip::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::gossip::ChannelUpdateInfo<>) as *mut _ }, is_owned: false };
930 /// Details about the first direction of a channel
932 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
934 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
935 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
936 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.one_to_two = local_val;
938 /// Source node of the second direction of a channel
940 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
941 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two;
942 crate::lightning::routing::gossip::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::NodeId<>) as *mut _) }, is_owned: false }
944 /// Source node of the second direction of a channel
946 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
947 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = *unsafe { Box::from_raw(val.take_inner()) };
949 /// Details about the second direction of a channel
951 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
953 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
954 let mut inner_val = &mut this_ptr.get_native_mut_ref().two_to_one;
955 let mut local_inner_val = crate::lightning::routing::gossip::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::gossip::ChannelUpdateInfo<>) as *mut _ }, is_owned: false };
958 /// Details about the second direction of a channel
960 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
962 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
963 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
964 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.two_to_one = local_val;
966 /// The channel capacity as seen on-chain, if chain lookup is available.
968 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
969 let mut inner_val = &mut this_ptr.get_native_mut_ref().capacity_sats;
970 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() }) };
973 /// The channel capacity as seen on-chain, if chain lookup is available.
975 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
976 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
977 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.capacity_sats = local_val;
979 /// An initial announcement of the channel
980 /// Mostly redundant with the data we store in fields explicitly.
981 /// Everything else is useful only for sending out for initial routing sync.
982 /// Not stored if contains excess data to prevent DoS.
984 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
986 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
987 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
988 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 };
991 /// An initial announcement of the channel
992 /// Mostly redundant with the data we store in fields explicitly.
993 /// Everything else is useful only for sending out for initial routing sync.
994 /// Not stored if contains excess data to prevent DoS.
996 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
998 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
999 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1000 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1002 impl Clone for ChannelInfo {
1003 fn clone(&self) -> Self {
1005 inner: if <*mut nativeChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1006 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1012 /// Used only if an object of this type is returned as a trait impl by a method
1013 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1014 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
1017 /// Creates a copy of the ChannelInfo
1018 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
1021 /// Checks if two ChannelInfos contain equal inner contents.
1022 /// This ignores pointers and is_owned flags and looks at the values in fields.
1023 /// Two objects with NULL inner values will be considered "equal" here.
1025 pub extern "C" fn ChannelInfo_eq(a: &ChannelInfo, b: &ChannelInfo) -> bool {
1026 if a.inner == b.inner { return true; }
1027 if a.inner.is_null() || b.inner.is_null() { return false; }
1028 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1030 /// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
1032 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1035 pub extern "C" fn ChannelInfo_get_directional_info(this_arg: &crate::lightning::routing::gossip::ChannelInfo, mut channel_flags: u8) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
1036 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_directional_info(channel_flags);
1037 let mut local_ret = crate::lightning::routing::gossip::ChannelUpdateInfo { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::routing::gossip::ChannelUpdateInfo<>) as *mut _ }, is_owned: false };
1042 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
1043 pub extern "C" fn ChannelInfo_write(obj: &crate::lightning::routing::gossip::ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
1044 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1047 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1048 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
1051 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
1052 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
1053 let res: Result<lightning::routing::gossip::ChannelInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1054 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::ChannelInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1058 use lightning::routing::gossip::DirectedChannelInfo as nativeDirectedChannelInfoImport;
1059 pub(crate) type nativeDirectedChannelInfo = nativeDirectedChannelInfoImport<'static>;
1061 /// A wrapper around [`ChannelInfo`] representing information about the channel as directed from a
1062 /// source node to a target node.
1065 pub struct DirectedChannelInfo {
1066 /// A pointer to the opaque Rust object.
1068 /// Nearly everywhere, inner must be non-null, however in places where
1069 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1070 pub inner: *mut nativeDirectedChannelInfo,
1071 /// Indicates that this is the only struct which contains the same pointer.
1073 /// Rust functions which take ownership of an object provided via an argument require
1074 /// this to be true and invalidate the object pointed to by inner.
1078 impl Drop for DirectedChannelInfo {
1079 fn drop(&mut self) {
1080 if self.is_owned && !<*mut nativeDirectedChannelInfo>::is_null(self.inner) {
1081 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1085 /// Frees any resources used by the DirectedChannelInfo, if is_owned is set and inner is non-NULL.
1087 pub extern "C" fn DirectedChannelInfo_free(this_obj: DirectedChannelInfo) { }
1089 /// Used only if an object of this type is returned as a trait impl by a method
1090 pub(crate) extern "C" fn DirectedChannelInfo_free_void(this_ptr: *mut c_void) {
1091 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDirectedChannelInfo) };
1094 impl DirectedChannelInfo {
1095 pub(crate) fn get_native_ref(&self) -> &'static nativeDirectedChannelInfo {
1096 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1098 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectedChannelInfo {
1099 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1101 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1102 pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelInfo {
1103 assert!(self.is_owned);
1104 let ret = ObjOps::untweak_ptr(self.inner);
1105 self.inner = core::ptr::null_mut();
1109 impl Clone for DirectedChannelInfo {
1110 fn clone(&self) -> Self {
1112 inner: if <*mut nativeDirectedChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1113 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1119 /// Used only if an object of this type is returned as a trait impl by a method
1120 pub(crate) extern "C" fn DirectedChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1121 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectedChannelInfo)).clone() })) as *mut c_void
1124 /// Creates a copy of the DirectedChannelInfo
1125 pub extern "C" fn DirectedChannelInfo_clone(orig: &DirectedChannelInfo) -> DirectedChannelInfo {
1128 /// Returns information for the channel.
1131 pub extern "C" fn DirectedChannelInfo_channel(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::ChannelInfo {
1132 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel();
1133 crate::lightning::routing::gossip::ChannelInfo { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::routing::gossip::ChannelInfo<>) as *mut _) }, is_owned: false }
1136 /// Returns the maximum HTLC amount allowed over the channel in the direction.
1139 pub extern "C" fn DirectedChannelInfo_htlc_maximum_msat(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> u64 {
1140 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.htlc_maximum_msat();
1144 /// Returns the [`EffectiveCapacity`] of the channel in the direction.
1146 /// This is either the total capacity from the funding transaction, if known, or the
1147 /// `htlc_maximum_msat` for the direction as advertised by the gossip network, if known,
1151 pub extern "C" fn DirectedChannelInfo_effective_capacity(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::EffectiveCapacity {
1152 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.effective_capacity();
1153 crate::lightning::routing::gossip::EffectiveCapacity::native_into(ret)
1156 /// The effective capacity of a channel for routing purposes.
1158 /// While this may be smaller than the actual channel capacity, amounts greater than
1159 /// [`Self::as_msat`] should not be routed through the channel.
1163 pub enum EffectiveCapacity {
1164 /// The available liquidity in the channel known from being a channel counterparty, and thus a
1167 /// Either the inbound or outbound liquidity depending on the direction, denominated in
1169 liquidity_msat: u64,
1171 /// The maximum HTLC amount in one direction as advertised on the gossip network.
1173 /// The maximum HTLC amount denominated in millisatoshi.
1176 /// The total capacity of the channel as determined by the funding transaction.
1178 /// The funding amount denominated in millisatoshi.
1180 /// The maximum HTLC amount denominated in millisatoshi.
1181 htlc_maximum_msat: u64,
1183 /// A capacity sufficient to route any payment, typically used for private channels provided by
1186 /// A capacity that is unknown possibly because either the chain state is unavailable to know
1187 /// the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.
1190 use lightning::routing::gossip::EffectiveCapacity as EffectiveCapacityImport;
1191 pub(crate) type nativeEffectiveCapacity = EffectiveCapacityImport;
1193 impl EffectiveCapacity {
1195 pub(crate) fn to_native(&self) -> nativeEffectiveCapacity {
1197 EffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1198 let mut liquidity_msat_nonref = Clone::clone(liquidity_msat);
1199 nativeEffectiveCapacity::ExactLiquidity {
1200 liquidity_msat: liquidity_msat_nonref,
1203 EffectiveCapacity::MaximumHTLC {ref amount_msat, } => {
1204 let mut amount_msat_nonref = Clone::clone(amount_msat);
1205 nativeEffectiveCapacity::MaximumHTLC {
1206 amount_msat: amount_msat_nonref,
1209 EffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => {
1210 let mut capacity_msat_nonref = Clone::clone(capacity_msat);
1211 let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat);
1212 nativeEffectiveCapacity::Total {
1213 capacity_msat: capacity_msat_nonref,
1214 htlc_maximum_msat: htlc_maximum_msat_nonref,
1217 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1218 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1222 pub(crate) fn into_native(self) -> nativeEffectiveCapacity {
1224 EffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1225 nativeEffectiveCapacity::ExactLiquidity {
1226 liquidity_msat: liquidity_msat,
1229 EffectiveCapacity::MaximumHTLC {mut amount_msat, } => {
1230 nativeEffectiveCapacity::MaximumHTLC {
1231 amount_msat: amount_msat,
1234 EffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => {
1235 nativeEffectiveCapacity::Total {
1236 capacity_msat: capacity_msat,
1237 htlc_maximum_msat: htlc_maximum_msat,
1240 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1241 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1245 pub(crate) fn from_native(native: &nativeEffectiveCapacity) -> Self {
1247 nativeEffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1248 let mut liquidity_msat_nonref = Clone::clone(liquidity_msat);
1249 EffectiveCapacity::ExactLiquidity {
1250 liquidity_msat: liquidity_msat_nonref,
1253 nativeEffectiveCapacity::MaximumHTLC {ref amount_msat, } => {
1254 let mut amount_msat_nonref = Clone::clone(amount_msat);
1255 EffectiveCapacity::MaximumHTLC {
1256 amount_msat: amount_msat_nonref,
1259 nativeEffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => {
1260 let mut capacity_msat_nonref = Clone::clone(capacity_msat);
1261 let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat);
1262 EffectiveCapacity::Total {
1263 capacity_msat: capacity_msat_nonref,
1264 htlc_maximum_msat: htlc_maximum_msat_nonref,
1267 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1268 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1272 pub(crate) fn native_into(native: nativeEffectiveCapacity) -> Self {
1274 nativeEffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1275 EffectiveCapacity::ExactLiquidity {
1276 liquidity_msat: liquidity_msat,
1279 nativeEffectiveCapacity::MaximumHTLC {mut amount_msat, } => {
1280 EffectiveCapacity::MaximumHTLC {
1281 amount_msat: amount_msat,
1284 nativeEffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => {
1285 EffectiveCapacity::Total {
1286 capacity_msat: capacity_msat,
1287 htlc_maximum_msat: htlc_maximum_msat,
1290 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1291 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1295 /// Frees any resources used by the EffectiveCapacity
1297 pub extern "C" fn EffectiveCapacity_free(this_ptr: EffectiveCapacity) { }
1298 /// Creates a copy of the EffectiveCapacity
1300 pub extern "C" fn EffectiveCapacity_clone(orig: &EffectiveCapacity) -> EffectiveCapacity {
1304 /// Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity
1305 pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> EffectiveCapacity {
1306 EffectiveCapacity::ExactLiquidity {
1311 /// Utility method to constructs a new MaximumHTLC-variant EffectiveCapacity
1312 pub extern "C" fn EffectiveCapacity_maximum_htlc(amount_msat: u64) -> EffectiveCapacity {
1313 EffectiveCapacity::MaximumHTLC {
1318 /// Utility method to constructs a new Total-variant EffectiveCapacity
1319 pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64, htlc_maximum_msat: u64) -> EffectiveCapacity {
1320 EffectiveCapacity::Total {
1326 /// Utility method to constructs a new Infinite-variant EffectiveCapacity
1327 pub extern "C" fn EffectiveCapacity_infinite() -> EffectiveCapacity {
1328 EffectiveCapacity::Infinite}
1330 /// Utility method to constructs a new Unknown-variant EffectiveCapacity
1331 pub extern "C" fn EffectiveCapacity_unknown() -> EffectiveCapacity {
1332 EffectiveCapacity::Unknown}
1333 /// The presumed channel capacity denominated in millisatoshi for [`EffectiveCapacity::Unknown`] to
1334 /// use when making routing decisions.
1337 pub static UNKNOWN_CHANNEL_CAPACITY_MSAT: u64 = lightning::routing::gossip::UNKNOWN_CHANNEL_CAPACITY_MSAT;
1338 /// Returns the effective capacity denominated in millisatoshi.
1341 pub extern "C" fn EffectiveCapacity_as_msat(this_arg: &crate::lightning::routing::gossip::EffectiveCapacity) -> u64 {
1342 let mut ret = this_arg.to_native().as_msat();
1347 use lightning::routing::gossip::RoutingFees as nativeRoutingFeesImport;
1348 pub(crate) type nativeRoutingFees = nativeRoutingFeesImport;
1350 /// Fees for routing via a given channel or a node
1353 pub struct RoutingFees {
1354 /// A pointer to the opaque Rust object.
1356 /// Nearly everywhere, inner must be non-null, however in places where
1357 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1358 pub inner: *mut nativeRoutingFees,
1359 /// Indicates that this is the only struct which contains the same pointer.
1361 /// Rust functions which take ownership of an object provided via an argument require
1362 /// this to be true and invalidate the object pointed to by inner.
1366 impl Drop for RoutingFees {
1367 fn drop(&mut self) {
1368 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
1369 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1373 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
1375 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
1377 /// Used only if an object of this type is returned as a trait impl by a method
1378 pub(crate) extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
1379 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoutingFees) };
1383 pub(crate) fn get_native_ref(&self) -> &'static nativeRoutingFees {
1384 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1386 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoutingFees {
1387 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1389 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1390 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
1391 assert!(self.is_owned);
1392 let ret = ObjOps::untweak_ptr(self.inner);
1393 self.inner = core::ptr::null_mut();
1397 /// Flat routing fee in millisatoshis.
1399 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
1400 let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat;
1403 /// Flat routing fee in millisatoshis.
1405 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
1406 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val;
1408 /// Liquidity-based routing fee in millionths of a routed amount.
1409 /// In other words, 10000 is 1%.
1411 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
1412 let mut inner_val = &mut this_ptr.get_native_mut_ref().proportional_millionths;
1415 /// Liquidity-based routing fee in millionths of a routed amount.
1416 /// In other words, 10000 is 1%.
1418 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
1419 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.proportional_millionths = val;
1421 /// Constructs a new RoutingFees given each field
1424 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
1425 RoutingFees { inner: ObjOps::heap_alloc(nativeRoutingFees {
1426 base_msat: base_msat_arg,
1427 proportional_millionths: proportional_millionths_arg,
1428 }), is_owned: true }
1430 /// Checks if two RoutingFeess contain equal inner contents.
1431 /// This ignores pointers and is_owned flags and looks at the values in fields.
1432 /// Two objects with NULL inner values will be considered "equal" here.
1434 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
1435 if a.inner == b.inner { return true; }
1436 if a.inner.is_null() || b.inner.is_null() { return false; }
1437 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1439 impl Clone for RoutingFees {
1440 fn clone(&self) -> Self {
1442 inner: if <*mut nativeRoutingFees>::is_null(self.inner) { core::ptr::null_mut() } else {
1443 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1449 /// Used only if an object of this type is returned as a trait impl by a method
1450 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
1451 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
1454 /// Creates a copy of the RoutingFees
1455 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
1458 /// Checks if two RoutingFeess contain equal inner contents.
1460 pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 {
1461 if o.inner.is_null() { return 0; }
1462 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1463 #[allow(deprecated)]
1464 let mut hasher = core::hash::SipHasher::new();
1465 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1466 core::hash::Hasher::finish(&hasher)
1469 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
1470 pub extern "C" fn RoutingFees_write(obj: &crate::lightning::routing::gossip::RoutingFees) -> crate::c_types::derived::CVec_u8Z {
1471 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1474 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1475 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
1478 /// Read a RoutingFees from a byte array, created by RoutingFees_write
1479 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
1480 let res: Result<lightning::routing::gossip::RoutingFees, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1481 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::RoutingFees { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1485 use lightning::routing::gossip::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
1486 pub(crate) type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
1488 /// Information received in the latest node_announcement from this node.
1491 pub struct NodeAnnouncementInfo {
1492 /// A pointer to the opaque Rust object.
1494 /// Nearly everywhere, inner must be non-null, however in places where
1495 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1496 pub inner: *mut nativeNodeAnnouncementInfo,
1497 /// Indicates that this is the only struct which contains the same pointer.
1499 /// Rust functions which take ownership of an object provided via an argument require
1500 /// this to be true and invalidate the object pointed to by inner.
1504 impl Drop for NodeAnnouncementInfo {
1505 fn drop(&mut self) {
1506 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
1507 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1511 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
1513 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
1515 /// Used only if an object of this type is returned as a trait impl by a method
1516 pub(crate) extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
1517 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo) };
1520 impl NodeAnnouncementInfo {
1521 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAnnouncementInfo {
1522 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1524 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAnnouncementInfo {
1525 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1527 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1528 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
1529 assert!(self.is_owned);
1530 let ret = ObjOps::untweak_ptr(self.inner);
1531 self.inner = core::ptr::null_mut();
1535 /// Protocol features the node announced support for
1537 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
1538 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1539 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 }
1541 /// Protocol features the node announced support for
1543 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
1544 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1546 /// When the last known update to the node state was issued.
1547 /// Value is opaque, as set in the announcement.
1549 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
1550 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
1553 /// When the last known update to the node state was issued.
1554 /// Value is opaque, as set in the announcement.
1556 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
1557 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
1559 /// Color assigned to the node
1561 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
1562 let mut inner_val = &mut this_ptr.get_native_mut_ref().rgb;
1565 /// Color assigned to the node
1567 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
1568 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data;
1570 /// Moniker assigned to the node.
1571 /// May be invalid or malicious (eg control chars),
1572 /// should not be exposed to the user.
1574 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::routing::gossip::NodeAlias {
1575 let mut inner_val = &mut this_ptr.get_native_mut_ref().alias;
1576 crate::lightning::routing::gossip::NodeAlias { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::NodeAlias<>) as *mut _) }, is_owned: false }
1578 /// Moniker assigned to the node.
1579 /// May be invalid or malicious (eg control chars),
1580 /// should not be exposed to the user.
1582 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::routing::gossip::NodeAlias) {
1583 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = *unsafe { Box::from_raw(val.take_inner()) };
1585 /// Internet-level addresses via which one can connect to the node
1587 /// Returns a copy of the field.
1589 pub extern "C" fn NodeAnnouncementInfo_get_addresses(this_ptr: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_NetAddressZ {
1590 let mut inner_val = this_ptr.get_native_mut_ref().addresses.clone();
1591 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { crate::lightning::ln::msgs::NetAddress::native_into(item) }); };
1592 local_inner_val.into()
1594 /// Internet-level addresses via which one can connect to the node
1596 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
1597 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
1598 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.addresses = local_val;
1600 /// An initial announcement of the node
1601 /// Mostly redundant with the data we store in fields explicitly.
1602 /// Everything else is useful only for sending out for initial routing sync.
1603 /// Not stored if contains excess data to prevent DoS.
1605 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1607 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
1608 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1609 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 };
1612 /// An initial announcement of the node
1613 /// Mostly redundant with the data we store in fields explicitly.
1614 /// Everything else is useful only for sending out for initial routing sync.
1615 /// Not stored if contains excess data to prevent DoS.
1617 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1619 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
1620 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1621 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1623 /// Constructs a new NodeAnnouncementInfo given each field
1626 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::lightning::routing::gossip::NodeAlias, mut addresses_arg: crate::c_types::derived::CVec_NetAddressZ, mut announcement_message_arg: crate::lightning::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo {
1627 let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
1628 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()) } }) };
1629 NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo {
1630 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1631 last_update: last_update_arg,
1633 alias: *unsafe { Box::from_raw(alias_arg.take_inner()) },
1634 addresses: local_addresses_arg,
1635 announcement_message: local_announcement_message_arg,
1636 }), is_owned: true }
1638 impl Clone for NodeAnnouncementInfo {
1639 fn clone(&self) -> Self {
1641 inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1642 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1648 /// Used only if an object of this type is returned as a trait impl by a method
1649 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1650 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
1653 /// Creates a copy of the NodeAnnouncementInfo
1654 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1657 /// Checks if two NodeAnnouncementInfos contain equal inner contents.
1658 /// This ignores pointers and is_owned flags and looks at the values in fields.
1659 /// Two objects with NULL inner values will be considered "equal" here.
1661 pub extern "C" fn NodeAnnouncementInfo_eq(a: &NodeAnnouncementInfo, b: &NodeAnnouncementInfo) -> bool {
1662 if a.inner == b.inner { return true; }
1663 if a.inner.is_null() || b.inner.is_null() { return false; }
1664 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1667 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1668 pub extern "C" fn NodeAnnouncementInfo_write(obj: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1669 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1672 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1673 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1676 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1677 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1678 let res: Result<lightning::routing::gossip::NodeAnnouncementInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1679 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::NodeAnnouncementInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1683 use lightning::routing::gossip::NodeAlias as nativeNodeAliasImport;
1684 pub(crate) type nativeNodeAlias = nativeNodeAliasImport;
1686 /// A user-defined name for a node, which may be used when displaying the node in a graph.
1688 /// Since node aliases are provided by third parties, they are a potential avenue for injection
1689 /// attacks. Care must be taken when processing.
1692 pub struct NodeAlias {
1693 /// A pointer to the opaque Rust object.
1695 /// Nearly everywhere, inner must be non-null, however in places where
1696 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1697 pub inner: *mut nativeNodeAlias,
1698 /// Indicates that this is the only struct which contains the same pointer.
1700 /// Rust functions which take ownership of an object provided via an argument require
1701 /// this to be true and invalidate the object pointed to by inner.
1705 impl Drop for NodeAlias {
1706 fn drop(&mut self) {
1707 if self.is_owned && !<*mut nativeNodeAlias>::is_null(self.inner) {
1708 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1712 /// Frees any resources used by the NodeAlias, if is_owned is set and inner is non-NULL.
1714 pub extern "C" fn NodeAlias_free(this_obj: NodeAlias) { }
1716 /// Used only if an object of this type is returned as a trait impl by a method
1717 pub(crate) extern "C" fn NodeAlias_free_void(this_ptr: *mut c_void) {
1718 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAlias) };
1722 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAlias {
1723 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1725 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAlias {
1726 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1728 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1729 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAlias {
1730 assert!(self.is_owned);
1731 let ret = ObjOps::untweak_ptr(self.inner);
1732 self.inner = core::ptr::null_mut();
1737 pub extern "C" fn NodeAlias_get_a(this_ptr: &NodeAlias) -> *const [u8; 32] {
1738 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1742 pub extern "C" fn NodeAlias_set_a(this_ptr: &mut NodeAlias, mut val: crate::c_types::ThirtyTwoBytes) {
1743 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.data;
1745 /// Constructs a new NodeAlias given each field
1748 pub extern "C" fn NodeAlias_new(mut a_arg: crate::c_types::ThirtyTwoBytes) -> NodeAlias {
1749 NodeAlias { inner: ObjOps::heap_alloc(lightning::routing::gossip::NodeAlias (
1751 )), is_owned: true }
1753 impl Clone for NodeAlias {
1754 fn clone(&self) -> Self {
1756 inner: if <*mut nativeNodeAlias>::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 NodeAlias_clone_void(this_ptr: *const c_void) -> *mut c_void {
1765 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAlias)).clone() })) as *mut c_void
1768 /// Creates a copy of the NodeAlias
1769 pub extern "C" fn NodeAlias_clone(orig: &NodeAlias) -> NodeAlias {
1772 /// Checks if two NodeAliass contain equal inner contents.
1773 /// This ignores pointers and is_owned flags and looks at the values in fields.
1774 /// Two objects with NULL inner values will be considered "equal" here.
1776 pub extern "C" fn NodeAlias_eq(a: &NodeAlias, b: &NodeAlias) -> bool {
1777 if a.inner == b.inner { return true; }
1778 if a.inner.is_null() || b.inner.is_null() { return false; }
1779 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1782 /// Serialize the NodeAlias object into a byte array which can be read by NodeAlias_read
1783 pub extern "C" fn NodeAlias_write(obj: &crate::lightning::routing::gossip::NodeAlias) -> crate::c_types::derived::CVec_u8Z {
1784 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1787 pub(crate) extern "C" fn NodeAlias_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1788 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAlias) })
1791 /// Read a NodeAlias from a byte array, created by NodeAlias_write
1792 pub extern "C" fn NodeAlias_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAliasDecodeErrorZ {
1793 let res: Result<lightning::routing::gossip::NodeAlias, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1794 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::NodeAlias { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1798 use lightning::routing::gossip::NodeInfo as nativeNodeInfoImport;
1799 pub(crate) type nativeNodeInfo = nativeNodeInfoImport;
1801 /// Details about a node in the network, known from the network announcement.
1804 pub struct NodeInfo {
1805 /// A pointer to the opaque Rust object.
1807 /// Nearly everywhere, inner must be non-null, however in places where
1808 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1809 pub inner: *mut nativeNodeInfo,
1810 /// Indicates that this is the only struct which contains the same pointer.
1812 /// Rust functions which take ownership of an object provided via an argument require
1813 /// this to be true and invalidate the object pointed to by inner.
1817 impl Drop for NodeInfo {
1818 fn drop(&mut self) {
1819 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1820 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1824 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1826 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1828 /// Used only if an object of this type is returned as a trait impl by a method
1829 pub(crate) extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1830 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeInfo) };
1834 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeInfo {
1835 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1837 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeInfo {
1838 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1840 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1841 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1842 assert!(self.is_owned);
1843 let ret = ObjOps::untweak_ptr(self.inner);
1844 self.inner = core::ptr::null_mut();
1848 /// All valid channels a node has announced
1850 /// Returns a copy of the field.
1852 pub extern "C" fn NodeInfo_get_channels(this_ptr: &NodeInfo) -> crate::c_types::derived::CVec_u64Z {
1853 let mut inner_val = this_ptr.get_native_mut_ref().channels.clone();
1854 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1855 local_inner_val.into()
1857 /// All valid channels a node has announced
1859 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1860 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1861 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1863 /// More information about a node from node_announcement.
1864 /// Optional because we store a Node entry after learning about it from
1865 /// a channel announcement, but before receiving a node announcement.
1867 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1869 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::gossip::NodeAnnouncementInfo {
1870 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_info;
1871 let mut local_inner_val = crate::lightning::routing::gossip::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::gossip::NodeAnnouncementInfo<>) as *mut _ }, is_owned: false };
1874 /// More information about a node from node_announcement.
1875 /// Optional because we store a Node entry after learning about it from
1876 /// a channel announcement, but before receiving a node announcement.
1878 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1880 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::gossip::NodeAnnouncementInfo) {
1881 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1882 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val;
1884 /// Constructs a new NodeInfo given each field
1887 pub extern "C" fn NodeInfo_new(mut channels_arg: crate::c_types::derived::CVec_u64Z, mut announcement_info_arg: crate::lightning::routing::gossip::NodeAnnouncementInfo) -> NodeInfo {
1888 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1889 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()) } }) };
1890 NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo {
1891 channels: local_channels_arg,
1892 announcement_info: local_announcement_info_arg,
1893 }), is_owned: true }
1895 impl Clone for NodeInfo {
1896 fn clone(&self) -> Self {
1898 inner: if <*mut nativeNodeInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1899 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1905 /// Used only if an object of this type is returned as a trait impl by a method
1906 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1907 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1910 /// Creates a copy of the NodeInfo
1911 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1914 /// Checks if two NodeInfos contain equal inner contents.
1915 /// This ignores pointers and is_owned flags and looks at the values in fields.
1916 /// Two objects with NULL inner values will be considered "equal" here.
1918 pub extern "C" fn NodeInfo_eq(a: &NodeInfo, b: &NodeInfo) -> bool {
1919 if a.inner == b.inner { return true; }
1920 if a.inner.is_null() || b.inner.is_null() { return false; }
1921 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1924 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1925 pub extern "C" fn NodeInfo_write(obj: &crate::lightning::routing::gossip::NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1926 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1929 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1930 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1933 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1934 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1935 let res: Result<lightning::routing::gossip::NodeInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1936 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::NodeInfo { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1940 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
1941 pub extern "C" fn NetworkGraph_write(obj: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1942 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1945 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1946 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1949 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
1950 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice, arg: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1952 let res: Result<lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1953 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::gossip::NetworkGraph { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1956 /// Creates a new, empty, network graph.
1959 pub extern "C" fn NetworkGraph_new(mut network: crate::bitcoin::network::Network, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::NetworkGraph {
1960 let mut ret = lightning::routing::gossip::NetworkGraph::new(network.into_bitcoin(), logger);
1961 crate::lightning::routing::gossip::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1964 /// Returns a read-only view of the network graph.
1967 pub extern "C" fn NetworkGraph_read_only(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::lightning::routing::gossip::ReadOnlyNetworkGraph {
1968 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_only();
1969 crate::lightning::routing::gossip::ReadOnlyNetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1972 /// The unix timestamp provided by the most recent rapid gossip sync.
1973 /// It will be set by the rapid sync process after every sync completion.
1976 pub extern "C" fn NetworkGraph_get_last_rapid_gossip_sync_timestamp(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::COption_u32Z {
1977 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_last_rapid_gossip_sync_timestamp();
1978 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { ret.unwrap() }) };
1982 /// Update the unix timestamp provided by the most recent rapid gossip sync.
1983 /// This should be done automatically by the rapid sync process after every sync completion.
1985 pub extern "C" fn NetworkGraph_set_last_rapid_gossip_sync_timestamp(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut last_rapid_gossip_sync_timestamp: u32) {
1986 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.set_last_rapid_gossip_sync_timestamp(last_rapid_gossip_sync_timestamp)
1989 /// For an already known node (from channel announcements), update its stored properties from a
1990 /// given node announcement.
1992 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
1993 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1994 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1997 pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1998 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_announcement(msg.get_native_ref());
1999 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() };
2003 /// For an already known node (from channel announcements), update its stored properties from a
2004 /// given node announcement without verifying the associated signatures. Because we aren't
2005 /// given the associated signatures here we cannot relay the node announcement to any of our
2009 pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedNodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
2010 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_unsigned_announcement(msg.get_native_ref());
2011 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() };
2015 /// Store or update channel info from a channel announcement.
2017 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
2018 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
2019 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2021 /// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
2022 /// the corresponding UTXO exists on chain and is correctly-formatted.
2025 pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelAnnouncement, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
2026 let mut local_utxo_lookup = { /* utxo_lookup*/ let utxo_lookup_opt = utxo_lookup; { } if utxo_lookup_opt.is_none() { None } else { Some({ utxo_lookup_opt.take() }) } };
2027 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_utxo_lookup);
2028 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() };
2032 /// Store or update channel info from a channel announcement without verifying the associated
2033 /// signatures. Because we aren't given the associated signatures here we cannot relay the
2034 /// channel announcement to any of our peers.
2036 /// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
2037 /// the corresponding UTXO exists on chain and is correctly-formatted.
2040 pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
2041 let mut local_utxo_lookup = { /* utxo_lookup*/ let utxo_lookup_opt = utxo_lookup; { } if utxo_lookup_opt.is_none() { None } else { Some({ utxo_lookup_opt.take() }) } };
2042 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_utxo_lookup);
2043 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() };
2047 /// Update channel from partial announcement data received via rapid gossip sync
2049 /// `timestamp: u64`: Timestamp emulating the backdated original announcement receipt (by the
2050 /// rapid gossip sync server)
2052 /// All other parameters as used in [`msgs::UnsignedChannelAnnouncement`] fields.
2055 pub extern "C" fn NetworkGraph_add_channel_from_partial_announcement(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut short_channel_id: u64, mut timestamp: u64, mut features: crate::lightning::ln::features::ChannelFeatures, mut node_id_1: crate::c_types::PublicKey, mut node_id_2: crate::c_types::PublicKey) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
2056 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.add_channel_from_partial_announcement(short_channel_id, timestamp, *unsafe { Box::from_raw(features.take_inner()) }, node_id_1.into_rust(), node_id_2.into_rust());
2057 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() };
2061 /// Marks a channel in the graph as failed if a corresponding HTLC fail was sent.
2062 /// If permanent, removes a channel from the local storage.
2063 /// May cause the removal of nodes too, if this was their last channel.
2064 /// If not permanent, makes channels unavailable for routing.
2066 pub extern "C" fn NetworkGraph_channel_failed(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
2067 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_failed(short_channel_id, is_permanent)
2070 /// Marks a node in the graph as permanently failed, effectively removing it and its channels
2071 /// from local storage.
2073 pub extern "C" fn NetworkGraph_node_failed_permanent(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut node_id: crate::c_types::PublicKey) {
2074 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node_failed_permanent(&node_id.into_rust())
2077 /// Removes information about channels that we haven't heard any updates about in some time.
2078 /// This can be used regularly to prune the network graph of channels that likely no longer
2081 /// While there is no formal requirement that nodes regularly re-broadcast their channel
2082 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
2083 /// pruning occur for updates which are at least two weeks old, which we implement here.
2085 /// Note that for users of the `lightning-background-processor` crate this method may be
2086 /// automatically called regularly for you.
2088 /// This method will also cause us to stop tracking removed nodes and channels if they have been
2089 /// in the map for a while so that these can be resynced from gossip in the future.
2091 /// This method is only available with the `std` feature. See
2092 /// [`NetworkGraph::remove_stale_channels_and_tracking_with_time`] for `no-std` use.
2094 pub extern "C" fn NetworkGraph_remove_stale_channels_and_tracking(this_arg: &crate::lightning::routing::gossip::NetworkGraph) {
2095 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_and_tracking()
2098 /// Removes information about channels that we haven't heard any updates about in some time.
2099 /// This can be used regularly to prune the network graph of channels that likely no longer
2102 /// While there is no formal requirement that nodes regularly re-broadcast their channel
2103 /// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
2104 /// pruning occur for updates which are at least two weeks old, which we implement here.
2106 /// This method will also cause us to stop tracking removed nodes and channels if they have been
2107 /// in the map for a while so that these can be resynced from gossip in the future.
2109 /// This function takes the current unix time as an argument. For users with the `std` feature
2110 /// enabled, [`NetworkGraph::remove_stale_channels_and_tracking`] may be preferable.
2112 pub extern "C" fn NetworkGraph_remove_stale_channels_and_tracking_with_time(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut current_time_unix: u64) {
2113 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.remove_stale_channels_and_tracking_with_time(current_time_unix)
2116 /// For an already known (from announcement) channel, update info about one of the directions
2119 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
2120 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
2121 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2123 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2124 /// materially in the future will be rejected.
2127 pub extern "C" fn NetworkGraph_update_channel(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
2128 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel(msg.get_native_ref());
2129 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() };
2133 /// For an already known (from announcement) channel, update info about one of the directions
2134 /// of the channel without verifying the associated signatures. Because we aren't given the
2135 /// associated signatures here we cannot relay the channel update to any of our peers.
2137 /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
2138 /// materially in the future will be rejected.
2141 pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
2142 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_unsigned(msg.get_native_ref());
2143 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() };
2147 /// Returns information on a channel with the given id.
2149 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2152 pub extern "C" fn ReadOnlyNetworkGraph_channel(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, mut short_channel_id: u64) -> crate::lightning::routing::gossip::ChannelInfo {
2153 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel(short_channel_id);
2154 let mut local_ret = crate::lightning::routing::gossip::ChannelInfo { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::routing::gossip::ChannelInfo<>) as *mut _ }, is_owned: false };
2158 /// Returns the list of channels in the graph
2161 pub extern "C" fn ReadOnlyNetworkGraph_list_channels(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph) -> crate::c_types::derived::CVec_u64Z {
2162 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_channels();
2163 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { item }); };
2167 /// Returns information on a node with the given id.
2169 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2172 pub extern "C" fn ReadOnlyNetworkGraph_node(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, node_id: &crate::lightning::routing::gossip::NodeId) -> crate::lightning::routing::gossip::NodeInfo {
2173 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node(node_id.get_native_ref());
2174 let mut local_ret = crate::lightning::routing::gossip::NodeInfo { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::routing::gossip::NodeInfo<>) as *mut _ }, is_owned: false };
2178 /// Returns the list of nodes in the graph
2181 pub extern "C" fn ReadOnlyNetworkGraph_list_nodes(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph) -> crate::c_types::derived::CVec_NodeIdZ {
2182 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.list_nodes();
2183 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::routing::gossip::NodeId { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
2187 /// Get network addresses by node id.
2188 /// Returns None if the requested node is completely unknown,
2189 /// or if node announcement for the node was never received.
2192 pub extern "C" fn ReadOnlyNetworkGraph_get_addresses(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, mut pubkey: crate::c_types::PublicKey) -> crate::c_types::derived::COption_CVec_NetAddressZZ {
2193 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_addresses(&pubkey.into_rust());
2194 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() }) };