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 /// Get the public key from this NodeId
109 pub extern "C" fn NodeId_as_pubkey(this_arg: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CResult_PublicKeyErrorZ {
110 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_pubkey();
111 let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() };
115 /// Generates a non-cryptographic 64-bit hash of the NodeId.
117 pub extern "C" fn NodeId_hash(o: &NodeId) -> u64 {
118 if o.inner.is_null() { return 0; }
119 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
121 let mut hasher = core::hash::SipHasher::new();
122 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
123 core::hash::Hasher::finish(&hasher)
126 /// Serialize the NodeId object into a byte array which can be read by NodeId_read
127 pub extern "C" fn NodeId_write(obj: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CVec_u8Z {
128 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
131 pub(crate) extern "C" fn NodeId_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
132 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeId) })
135 /// Read a NodeId from a byte array, created by NodeId_write
136 pub extern "C" fn NodeId_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeIdDecodeErrorZ {
137 let res: Result<lightning::routing::gossip::NodeId, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
138 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() };
142 use lightning::routing::gossip::NetworkGraph as nativeNetworkGraphImport;
143 pub(crate) type nativeNetworkGraph = nativeNetworkGraphImport<crate::lightning::util::logger::Logger>;
145 /// Represents the network as nodes and channels between them
148 pub struct NetworkGraph {
149 /// A pointer to the opaque Rust object.
151 /// Nearly everywhere, inner must be non-null, however in places where
152 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
153 pub inner: *mut nativeNetworkGraph,
154 /// Indicates that this is the only struct which contains the same pointer.
156 /// Rust functions which take ownership of an object provided via an argument require
157 /// this to be true and invalidate the object pointed to by inner.
161 impl Drop for NetworkGraph {
163 if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) {
164 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
168 /// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL.
170 pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { }
172 /// Used only if an object of this type is returned as a trait impl by a method
173 pub(crate) extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
174 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNetworkGraph) };
178 pub(crate) fn get_native_ref(&self) -> &'static nativeNetworkGraph {
179 unsafe { &*ObjOps::untweak_ptr(self.inner) }
181 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNetworkGraph {
182 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
184 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
185 pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
186 assert!(self.is_owned);
187 let ret = ObjOps::untweak_ptr(self.inner);
188 self.inner = core::ptr::null_mut();
193 use lightning::routing::gossip::ReadOnlyNetworkGraph as nativeReadOnlyNetworkGraphImport;
194 pub(crate) type nativeReadOnlyNetworkGraph = nativeReadOnlyNetworkGraphImport<'static>;
196 /// A read-only view of [`NetworkGraph`].
199 pub struct ReadOnlyNetworkGraph {
200 /// A pointer to the opaque Rust object.
202 /// Nearly everywhere, inner must be non-null, however in places where
203 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
204 pub inner: *mut nativeReadOnlyNetworkGraph,
205 /// Indicates that this is the only struct which contains the same pointer.
207 /// Rust functions which take ownership of an object provided via an argument require
208 /// this to be true and invalidate the object pointed to by inner.
212 impl Drop for ReadOnlyNetworkGraph {
214 if self.is_owned && !<*mut nativeReadOnlyNetworkGraph>::is_null(self.inner) {
215 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
219 /// Frees any resources used by the ReadOnlyNetworkGraph, if is_owned is set and inner is non-NULL.
221 pub extern "C" fn ReadOnlyNetworkGraph_free(this_obj: ReadOnlyNetworkGraph) { }
223 /// Used only if an object of this type is returned as a trait impl by a method
224 pub(crate) extern "C" fn ReadOnlyNetworkGraph_free_void(this_ptr: *mut c_void) {
225 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeReadOnlyNetworkGraph) };
228 impl ReadOnlyNetworkGraph {
229 pub(crate) fn get_native_ref(&self) -> &'static nativeReadOnlyNetworkGraph {
230 unsafe { &*ObjOps::untweak_ptr(self.inner) }
232 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeReadOnlyNetworkGraph {
233 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
235 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
236 pub(crate) fn take_inner(mut self) -> *mut nativeReadOnlyNetworkGraph {
237 assert!(self.is_owned);
238 let ret = ObjOps::untweak_ptr(self.inner);
239 self.inner = core::ptr::null_mut();
243 /// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
244 /// return packet by a node along the route. See [BOLT #4] for details.
246 /// [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
250 pub enum NetworkUpdate {
251 /// An error indicating a `channel_update` messages should be applied via
252 /// [`NetworkGraph::update_channel`].
253 ChannelUpdateMessage {
254 /// The update to apply via [`NetworkGraph::update_channel`].
255 msg: crate::lightning::ln::msgs::ChannelUpdate,
257 /// An error indicating that a channel failed to route a payment, which should be applied via
258 /// [`NetworkGraph::channel_failed_permanent`] if permanent.
260 /// The short channel id of the closed channel.
261 short_channel_id: u64,
262 /// Whether the channel should be permanently removed or temporarily disabled until a new
263 /// `channel_update` message is received.
266 /// An error indicating that a node failed to route a payment, which should be applied via
267 /// [`NetworkGraph::node_failed_permanent`] if permanent.
269 /// The node id of the failed node.
270 node_id: crate::c_types::PublicKey,
271 /// Whether the node should be permanently removed from consideration or can be restored
272 /// when a new `channel_update` message is received.
276 use lightning::routing::gossip::NetworkUpdate as NetworkUpdateImport;
277 pub(crate) type nativeNetworkUpdate = NetworkUpdateImport;
281 pub(crate) fn to_native(&self) -> nativeNetworkUpdate {
283 NetworkUpdate::ChannelUpdateMessage {ref msg, } => {
284 let mut msg_nonref = Clone::clone(msg);
285 nativeNetworkUpdate::ChannelUpdateMessage {
286 msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
289 NetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
290 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
291 let mut is_permanent_nonref = Clone::clone(is_permanent);
292 nativeNetworkUpdate::ChannelFailure {
293 short_channel_id: short_channel_id_nonref,
294 is_permanent: is_permanent_nonref,
297 NetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
298 let mut node_id_nonref = Clone::clone(node_id);
299 let mut is_permanent_nonref = Clone::clone(is_permanent);
300 nativeNetworkUpdate::NodeFailure {
301 node_id: node_id_nonref.into_rust(),
302 is_permanent: is_permanent_nonref,
308 pub(crate) fn into_native(self) -> nativeNetworkUpdate {
310 NetworkUpdate::ChannelUpdateMessage {mut msg, } => {
311 nativeNetworkUpdate::ChannelUpdateMessage {
312 msg: *unsafe { Box::from_raw(msg.take_inner()) },
315 NetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
316 nativeNetworkUpdate::ChannelFailure {
317 short_channel_id: short_channel_id,
318 is_permanent: is_permanent,
321 NetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
322 nativeNetworkUpdate::NodeFailure {
323 node_id: node_id.into_rust(),
324 is_permanent: is_permanent,
330 pub(crate) fn from_native(native: &nativeNetworkUpdate) -> Self {
332 nativeNetworkUpdate::ChannelUpdateMessage {ref msg, } => {
333 let mut msg_nonref = Clone::clone(msg);
334 NetworkUpdate::ChannelUpdateMessage {
335 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true },
338 nativeNetworkUpdate::ChannelFailure {ref short_channel_id, ref is_permanent, } => {
339 let mut short_channel_id_nonref = Clone::clone(short_channel_id);
340 let mut is_permanent_nonref = Clone::clone(is_permanent);
341 NetworkUpdate::ChannelFailure {
342 short_channel_id: short_channel_id_nonref,
343 is_permanent: is_permanent_nonref,
346 nativeNetworkUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
347 let mut node_id_nonref = Clone::clone(node_id);
348 let mut is_permanent_nonref = Clone::clone(is_permanent);
349 NetworkUpdate::NodeFailure {
350 node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
351 is_permanent: is_permanent_nonref,
357 pub(crate) fn native_into(native: nativeNetworkUpdate) -> Self {
359 nativeNetworkUpdate::ChannelUpdateMessage {mut msg, } => {
360 NetworkUpdate::ChannelUpdateMessage {
361 msg: crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(msg), is_owned: true },
364 nativeNetworkUpdate::ChannelFailure {mut short_channel_id, mut is_permanent, } => {
365 NetworkUpdate::ChannelFailure {
366 short_channel_id: short_channel_id,
367 is_permanent: is_permanent,
370 nativeNetworkUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
371 NetworkUpdate::NodeFailure {
372 node_id: crate::c_types::PublicKey::from_rust(&node_id),
373 is_permanent: is_permanent,
379 /// Frees any resources used by the NetworkUpdate
381 pub extern "C" fn NetworkUpdate_free(this_ptr: NetworkUpdate) { }
382 /// Creates a copy of the NetworkUpdate
384 pub extern "C" fn NetworkUpdate_clone(orig: &NetworkUpdate) -> NetworkUpdate {
388 /// Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
389 pub extern "C" fn NetworkUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> NetworkUpdate {
390 NetworkUpdate::ChannelUpdateMessage {
395 /// Utility method to constructs a new ChannelFailure-variant NetworkUpdate
396 pub extern "C" fn NetworkUpdate_channel_failure(short_channel_id: u64, is_permanent: bool) -> NetworkUpdate {
397 NetworkUpdate::ChannelFailure {
403 /// Utility method to constructs a new NodeFailure-variant NetworkUpdate
404 pub extern "C" fn NetworkUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent: bool) -> NetworkUpdate {
405 NetworkUpdate::NodeFailure {
410 /// Checks if two NetworkUpdates contain equal inner contents.
411 /// This ignores pointers and is_owned flags and looks at the values in fields.
413 pub extern "C" fn NetworkUpdate_eq(a: &NetworkUpdate, b: &NetworkUpdate) -> bool {
414 if &a.to_native() == &b.to_native() { true } else { false }
417 /// Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
418 pub extern "C" fn NetworkUpdate_write(obj: &crate::lightning::routing::gossip::NetworkUpdate) -> crate::c_types::derived::CVec_u8Z {
419 crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
422 /// Read a NetworkUpdate from a byte array, created by NetworkUpdate_write
423 pub extern "C" fn NetworkUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_NetworkUpdateZDecodeErrorZ {
424 let res: Result<Option<lightning::routing::gossip::NetworkUpdate>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
425 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() };
429 use lightning::routing::gossip::P2PGossipSync as nativeP2PGossipSyncImport;
430 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>;
432 /// Receives and validates network updates from peers,
433 /// stores authentic and relevant data as a network graph.
434 /// This network graph is then used for routing payments.
435 /// Provides interface to help with initial routing sync by
436 /// serving historical announcements.
439 pub struct P2PGossipSync {
440 /// A pointer to the opaque Rust object.
442 /// Nearly everywhere, inner must be non-null, however in places where
443 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
444 pub inner: *mut nativeP2PGossipSync,
445 /// Indicates that this is the only struct which contains the same pointer.
447 /// Rust functions which take ownership of an object provided via an argument require
448 /// this to be true and invalidate the object pointed to by inner.
452 impl Drop for P2PGossipSync {
454 if self.is_owned && !<*mut nativeP2PGossipSync>::is_null(self.inner) {
455 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
459 /// Frees any resources used by the P2PGossipSync, if is_owned is set and inner is non-NULL.
461 pub extern "C" fn P2PGossipSync_free(this_obj: P2PGossipSync) { }
463 /// Used only if an object of this type is returned as a trait impl by a method
464 pub(crate) extern "C" fn P2PGossipSync_free_void(this_ptr: *mut c_void) {
465 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeP2PGossipSync) };
469 pub(crate) fn get_native_ref(&self) -> &'static nativeP2PGossipSync {
470 unsafe { &*ObjOps::untweak_ptr(self.inner) }
472 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeP2PGossipSync {
473 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
475 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
476 pub(crate) fn take_inner(mut self) -> *mut nativeP2PGossipSync {
477 assert!(self.is_owned);
478 let ret = ObjOps::untweak_ptr(self.inner);
479 self.inner = core::ptr::null_mut();
483 /// Creates a new tracker of the actual state of the network of channels and nodes,
484 /// assuming an existing [`NetworkGraph`].
485 /// UTXO lookup is used to make sure announced channels exist on-chain, channel data is
486 /// correct, and the announcement is signed with channel owners' keys.
489 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 {
490 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() } }})} };
491 let mut ret = lightning::routing::gossip::P2PGossipSync::new(network_graph.get_native_ref(), local_utxo_lookup, logger);
492 crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(ret), is_owned: true }
495 /// Adds a provider used to check new announcements. Does not affect
496 /// existing announcements unless they are updated.
497 /// Add, update or remove the provider would replace the current one.
499 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) {
500 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() } }})} };
501 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::gossip::nativeP2PGossipSync)) }.add_utxo_lookup(local_utxo_lookup)
504 /// Handles any network updates originating from [`Event`]s.
506 /// [`Event`]: crate::events::Event
508 pub extern "C" fn NetworkGraph_handle_network_update(this_arg: &crate::lightning::routing::gossip::NetworkGraph, network_update: &crate::lightning::routing::gossip::NetworkUpdate) {
509 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.handle_network_update(&network_update.to_native())
512 impl From<nativeP2PGossipSync> for crate::lightning::ln::msgs::RoutingMessageHandler {
513 fn from(obj: nativeP2PGossipSync) -> Self {
514 let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
515 let mut ret = P2PGossipSync_as_RoutingMessageHandler(&rust_obj);
516 // 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
517 rust_obj.inner = core::ptr::null_mut();
518 ret.free = Some(P2PGossipSync_free_void);
522 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
523 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
525 pub extern "C" fn P2PGossipSync_as_RoutingMessageHandler(this_arg: &P2PGossipSync) -> crate::lightning::ln::msgs::RoutingMessageHandler {
526 crate::lightning::ln::msgs::RoutingMessageHandler {
527 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
529 handle_node_announcement: P2PGossipSync_RoutingMessageHandler_handle_node_announcement,
530 handle_channel_announcement: P2PGossipSync_RoutingMessageHandler_handle_channel_announcement,
531 handle_channel_update: P2PGossipSync_RoutingMessageHandler_handle_channel_update,
532 get_next_channel_announcement: P2PGossipSync_RoutingMessageHandler_get_next_channel_announcement,
533 get_next_node_announcement: P2PGossipSync_RoutingMessageHandler_get_next_node_announcement,
534 peer_connected: P2PGossipSync_RoutingMessageHandler_peer_connected,
535 handle_reply_channel_range: P2PGossipSync_RoutingMessageHandler_handle_reply_channel_range,
536 handle_reply_short_channel_ids_end: P2PGossipSync_RoutingMessageHandler_handle_reply_short_channel_ids_end,
537 handle_query_channel_range: P2PGossipSync_RoutingMessageHandler_handle_query_channel_range,
538 handle_query_short_channel_ids: P2PGossipSync_RoutingMessageHandler_handle_query_short_channel_ids,
539 processing_queue_high: P2PGossipSync_RoutingMessageHandler_processing_queue_high,
540 provided_node_features: P2PGossipSync_RoutingMessageHandler_provided_node_features,
541 provided_init_features: P2PGossipSync_RoutingMessageHandler_provided_init_features,
542 MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider {
543 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
545 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
551 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 {
552 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
553 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() };
557 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 {
558 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
559 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() };
563 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 {
564 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, msg.get_native_ref());
565 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() };
569 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 {
570 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, starting_point);
571 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 }) };
575 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 {
576 let mut local_starting_point = if starting_point.inner.is_null() { None } else { Some( { starting_point.get_native_ref() }) };
577 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, local_starting_point);
578 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 };
582 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 {
583 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);
584 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() };
588 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 {
589 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()) });
590 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() };
594 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 {
595 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()) });
596 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() };
600 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 {
601 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()) });
602 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() };
606 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 {
607 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()) });
608 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() };
612 extern "C" fn P2PGossipSync_RoutingMessageHandler_processing_queue_high(this_arg: *const c_void) -> bool {
613 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::processing_queue_high(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
617 extern "C" fn P2PGossipSync_RoutingMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures {
618 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::provided_node_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
619 crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
622 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 {
623 let mut ret = <nativeP2PGossipSync as lightning::ln::msgs::RoutingMessageHandler<>>::provided_init_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust());
624 crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
627 impl From<nativeP2PGossipSync> for crate::lightning::events::MessageSendEventsProvider {
628 fn from(obj: nativeP2PGossipSync) -> Self {
629 let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true };
630 let mut ret = P2PGossipSync_as_MessageSendEventsProvider(&rust_obj);
631 // 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
632 rust_obj.inner = core::ptr::null_mut();
633 ret.free = Some(P2PGossipSync_free_void);
637 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
638 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
640 pub extern "C" fn P2PGossipSync_as_MessageSendEventsProvider(this_arg: &P2PGossipSync) -> crate::lightning::events::MessageSendEventsProvider {
641 crate::lightning::events::MessageSendEventsProvider {
642 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
644 get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events,
649 extern "C" fn P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
650 let mut ret = <nativeP2PGossipSync as lightning::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, );
651 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); };
656 use lightning::routing::gossip::ChannelUpdateInfo as nativeChannelUpdateInfoImport;
657 pub(crate) type nativeChannelUpdateInfo = nativeChannelUpdateInfoImport;
659 /// Details about one direction of a channel as received within a [`ChannelUpdate`].
662 pub struct ChannelUpdateInfo {
663 /// A pointer to the opaque Rust object.
665 /// Nearly everywhere, inner must be non-null, however in places where
666 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
667 pub inner: *mut nativeChannelUpdateInfo,
668 /// Indicates that this is the only struct which contains the same pointer.
670 /// Rust functions which take ownership of an object provided via an argument require
671 /// this to be true and invalidate the object pointed to by inner.
675 impl Drop for ChannelUpdateInfo {
677 if self.is_owned && !<*mut nativeChannelUpdateInfo>::is_null(self.inner) {
678 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
682 /// Frees any resources used by the ChannelUpdateInfo, if is_owned is set and inner is non-NULL.
684 pub extern "C" fn ChannelUpdateInfo_free(this_obj: ChannelUpdateInfo) { }
686 /// Used only if an object of this type is returned as a trait impl by a method
687 pub(crate) extern "C" fn ChannelUpdateInfo_free_void(this_ptr: *mut c_void) {
688 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelUpdateInfo) };
691 impl ChannelUpdateInfo {
692 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUpdateInfo {
693 unsafe { &*ObjOps::untweak_ptr(self.inner) }
695 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUpdateInfo {
696 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
698 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
699 pub(crate) fn take_inner(mut self) -> *mut nativeChannelUpdateInfo {
700 assert!(self.is_owned);
701 let ret = ObjOps::untweak_ptr(self.inner);
702 self.inner = core::ptr::null_mut();
706 /// When the last update to the channel direction was issued.
707 /// Value is opaque, as set in the announcement.
709 pub extern "C" fn ChannelUpdateInfo_get_last_update(this_ptr: &ChannelUpdateInfo) -> u32 {
710 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
713 /// When the last update to the channel direction was issued.
714 /// Value is opaque, as set in the announcement.
716 pub extern "C" fn ChannelUpdateInfo_set_last_update(this_ptr: &mut ChannelUpdateInfo, mut val: u32) {
717 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
719 /// Whether the channel can be currently used for payments (in this one direction).
721 pub extern "C" fn ChannelUpdateInfo_get_enabled(this_ptr: &ChannelUpdateInfo) -> bool {
722 let mut inner_val = &mut this_ptr.get_native_mut_ref().enabled;
725 /// Whether the channel can be currently used for payments (in this one direction).
727 pub extern "C" fn ChannelUpdateInfo_set_enabled(this_ptr: &mut ChannelUpdateInfo, mut val: bool) {
728 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.enabled = val;
730 /// The difference in CLTV values that you must have when routing through this channel.
732 pub extern "C" fn ChannelUpdateInfo_get_cltv_expiry_delta(this_ptr: &ChannelUpdateInfo) -> u16 {
733 let mut inner_val = &mut this_ptr.get_native_mut_ref().cltv_expiry_delta;
736 /// The difference in CLTV values that you must have when routing through this channel.
738 pub extern "C" fn ChannelUpdateInfo_set_cltv_expiry_delta(this_ptr: &mut ChannelUpdateInfo, mut val: u16) {
739 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.cltv_expiry_delta = val;
741 /// The minimum value, which must be relayed to the next hop via the channel
743 pub extern "C" fn ChannelUpdateInfo_get_htlc_minimum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
744 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat;
747 /// The minimum value, which must be relayed to the next hop via the channel
749 pub extern "C" fn ChannelUpdateInfo_set_htlc_minimum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
750 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val;
752 /// The maximum value which may be relayed to the next hop via the channel.
754 pub extern "C" fn ChannelUpdateInfo_get_htlc_maximum_msat(this_ptr: &ChannelUpdateInfo) -> u64 {
755 let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat;
758 /// The maximum value which may be relayed to the next hop via the channel.
760 pub extern "C" fn ChannelUpdateInfo_set_htlc_maximum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) {
761 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val;
763 /// Fees charged when the channel is used for routing
765 pub extern "C" fn ChannelUpdateInfo_get_fees(this_ptr: &ChannelUpdateInfo) -> crate::lightning::routing::gossip::RoutingFees {
766 let mut inner_val = &mut this_ptr.get_native_mut_ref().fees;
767 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 }
769 /// Fees charged when the channel is used for routing
771 pub extern "C" fn ChannelUpdateInfo_set_fees(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::routing::gossip::RoutingFees) {
772 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fees = *unsafe { Box::from_raw(val.take_inner()) };
774 /// Most recent update for the channel received from the network
775 /// Mostly redundant with the data we store in fields explicitly.
776 /// Everything else is useful only for sending out for initial routing sync.
777 /// Not stored if contains excess data to prevent DoS.
779 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
781 pub extern "C" fn ChannelUpdateInfo_get_last_update_message(this_ptr: &ChannelUpdateInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
782 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update_message;
783 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 };
786 /// Most recent update for the channel received from the network
787 /// Mostly redundant with the data we store in fields explicitly.
788 /// Everything else is useful only for sending out for initial routing sync.
789 /// Not stored if contains excess data to prevent DoS.
791 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
793 pub extern "C" fn ChannelUpdateInfo_set_last_update_message(this_ptr: &mut ChannelUpdateInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
794 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
795 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val;
797 /// Constructs a new ChannelUpdateInfo given each field
800 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 {
801 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()) } }) };
802 ChannelUpdateInfo { inner: ObjOps::heap_alloc(nativeChannelUpdateInfo {
803 last_update: last_update_arg,
804 enabled: enabled_arg,
805 cltv_expiry_delta: cltv_expiry_delta_arg,
806 htlc_minimum_msat: htlc_minimum_msat_arg,
807 htlc_maximum_msat: htlc_maximum_msat_arg,
808 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
809 last_update_message: local_last_update_message_arg,
812 impl Clone for ChannelUpdateInfo {
813 fn clone(&self) -> Self {
815 inner: if <*mut nativeChannelUpdateInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
816 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
822 /// Used only if an object of this type is returned as a trait impl by a method
823 pub(crate) extern "C" fn ChannelUpdateInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
824 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUpdateInfo)).clone() })) as *mut c_void
827 /// Creates a copy of the ChannelUpdateInfo
828 pub extern "C" fn ChannelUpdateInfo_clone(orig: &ChannelUpdateInfo) -> ChannelUpdateInfo {
831 /// Checks if two ChannelUpdateInfos contain equal inner contents.
832 /// This ignores pointers and is_owned flags and looks at the values in fields.
833 /// Two objects with NULL inner values will be considered "equal" here.
835 pub extern "C" fn ChannelUpdateInfo_eq(a: &ChannelUpdateInfo, b: &ChannelUpdateInfo) -> bool {
836 if a.inner == b.inner { return true; }
837 if a.inner.is_null() || b.inner.is_null() { return false; }
838 if a.get_native_ref() == b.get_native_ref() { true } else { false }
841 /// Serialize the ChannelUpdateInfo object into a byte array which can be read by ChannelUpdateInfo_read
842 pub extern "C" fn ChannelUpdateInfo_write(obj: &crate::lightning::routing::gossip::ChannelUpdateInfo) -> crate::c_types::derived::CVec_u8Z {
843 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
846 pub(crate) extern "C" fn ChannelUpdateInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
847 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdateInfo) })
850 /// Read a ChannelUpdateInfo from a byte array, created by ChannelUpdateInfo_write
851 pub extern "C" fn ChannelUpdateInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelUpdateInfoDecodeErrorZ {
852 let res: Result<lightning::routing::gossip::ChannelUpdateInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
853 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() };
857 use lightning::routing::gossip::ChannelInfo as nativeChannelInfoImport;
858 pub(crate) type nativeChannelInfo = nativeChannelInfoImport;
860 /// Details about a channel (both directions).
861 /// Received within a channel announcement.
864 pub struct ChannelInfo {
865 /// A pointer to the opaque Rust object.
867 /// Nearly everywhere, inner must be non-null, however in places where
868 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
869 pub inner: *mut nativeChannelInfo,
870 /// Indicates that this is the only struct which contains the same pointer.
872 /// Rust functions which take ownership of an object provided via an argument require
873 /// this to be true and invalidate the object pointed to by inner.
877 impl Drop for ChannelInfo {
879 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
880 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
884 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
886 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
888 /// Used only if an object of this type is returned as a trait impl by a method
889 pub(crate) extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
890 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelInfo) };
894 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelInfo {
895 unsafe { &*ObjOps::untweak_ptr(self.inner) }
897 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelInfo {
898 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
900 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
901 pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
902 assert!(self.is_owned);
903 let ret = ObjOps::untweak_ptr(self.inner);
904 self.inner = core::ptr::null_mut();
908 /// Protocol features of a channel communicated during its announcement
910 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
911 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
912 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 }
914 /// Protocol features of a channel communicated during its announcement
916 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
917 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
919 /// Source node of the first direction of a channel
921 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
922 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_one;
923 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 }
925 /// Source node of the first direction of a channel
927 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
928 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_one = *unsafe { Box::from_raw(val.take_inner()) };
930 /// Details about the first direction of a channel
932 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
934 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
935 let mut inner_val = &mut this_ptr.get_native_mut_ref().one_to_two;
936 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 };
939 /// Details about the first direction of a channel
941 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
943 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
944 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
945 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.one_to_two = local_val;
947 /// Source node of the second direction of a channel
949 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::NodeId {
950 let mut inner_val = &mut this_ptr.get_native_mut_ref().node_two;
951 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 }
953 /// Source node of the second direction of a channel
955 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::NodeId) {
956 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_two = *unsafe { Box::from_raw(val.take_inner()) };
958 /// Details about the second direction of a channel
960 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
962 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
963 let mut inner_val = &mut this_ptr.get_native_mut_ref().two_to_one;
964 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 };
967 /// Details about the second direction of a channel
969 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
971 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::gossip::ChannelUpdateInfo) {
972 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
973 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.two_to_one = local_val;
975 /// The channel capacity as seen on-chain, if chain lookup is available.
977 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
978 let mut inner_val = &mut this_ptr.get_native_mut_ref().capacity_sats;
979 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() }) };
982 /// The channel capacity as seen on-chain, if chain lookup is available.
984 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
985 let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
986 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.capacity_sats = local_val;
988 /// An initial announcement of the channel
989 /// Mostly redundant with the data we store in fields explicitly.
990 /// Everything else is useful only for sending out for initial routing sync.
991 /// Not stored if contains excess data to prevent DoS.
993 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
995 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
996 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
997 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 };
1000 /// An initial announcement of the channel
1001 /// Mostly redundant with the data we store in fields explicitly.
1002 /// Everything else is useful only for sending out for initial routing sync.
1003 /// Not stored if contains excess data to prevent DoS.
1005 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1007 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
1008 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1009 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1011 impl Clone for ChannelInfo {
1012 fn clone(&self) -> Self {
1014 inner: if <*mut nativeChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1015 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1021 /// Used only if an object of this type is returned as a trait impl by a method
1022 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1023 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
1026 /// Creates a copy of the ChannelInfo
1027 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
1030 /// Checks if two ChannelInfos contain equal inner contents.
1031 /// This ignores pointers and is_owned flags and looks at the values in fields.
1032 /// Two objects with NULL inner values will be considered "equal" here.
1034 pub extern "C" fn ChannelInfo_eq(a: &ChannelInfo, b: &ChannelInfo) -> bool {
1035 if a.inner == b.inner { return true; }
1036 if a.inner.is_null() || b.inner.is_null() { return false; }
1037 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1039 /// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
1041 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1044 pub extern "C" fn ChannelInfo_get_directional_info(this_arg: &crate::lightning::routing::gossip::ChannelInfo, mut channel_flags: u8) -> crate::lightning::routing::gossip::ChannelUpdateInfo {
1045 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_directional_info(channel_flags);
1046 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 };
1051 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
1052 pub extern "C" fn ChannelInfo_write(obj: &crate::lightning::routing::gossip::ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
1053 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1056 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1057 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
1060 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
1061 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
1062 let res: Result<lightning::routing::gossip::ChannelInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1063 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() };
1067 use lightning::routing::gossip::DirectedChannelInfo as nativeDirectedChannelInfoImport;
1068 pub(crate) type nativeDirectedChannelInfo = nativeDirectedChannelInfoImport<'static>;
1070 /// A wrapper around [`ChannelInfo`] representing information about the channel as directed from a
1071 /// source node to a target node.
1074 pub struct DirectedChannelInfo {
1075 /// A pointer to the opaque Rust object.
1077 /// Nearly everywhere, inner must be non-null, however in places where
1078 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1079 pub inner: *mut nativeDirectedChannelInfo,
1080 /// Indicates that this is the only struct which contains the same pointer.
1082 /// Rust functions which take ownership of an object provided via an argument require
1083 /// this to be true and invalidate the object pointed to by inner.
1087 impl Drop for DirectedChannelInfo {
1088 fn drop(&mut self) {
1089 if self.is_owned && !<*mut nativeDirectedChannelInfo>::is_null(self.inner) {
1090 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1094 /// Frees any resources used by the DirectedChannelInfo, if is_owned is set and inner is non-NULL.
1096 pub extern "C" fn DirectedChannelInfo_free(this_obj: DirectedChannelInfo) { }
1098 /// Used only if an object of this type is returned as a trait impl by a method
1099 pub(crate) extern "C" fn DirectedChannelInfo_free_void(this_ptr: *mut c_void) {
1100 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDirectedChannelInfo) };
1103 impl DirectedChannelInfo {
1104 pub(crate) fn get_native_ref(&self) -> &'static nativeDirectedChannelInfo {
1105 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1107 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDirectedChannelInfo {
1108 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1110 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1111 pub(crate) fn take_inner(mut self) -> *mut nativeDirectedChannelInfo {
1112 assert!(self.is_owned);
1113 let ret = ObjOps::untweak_ptr(self.inner);
1114 self.inner = core::ptr::null_mut();
1118 impl Clone for DirectedChannelInfo {
1119 fn clone(&self) -> Self {
1121 inner: if <*mut nativeDirectedChannelInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1122 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1128 /// Used only if an object of this type is returned as a trait impl by a method
1129 pub(crate) extern "C" fn DirectedChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1130 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectedChannelInfo)).clone() })) as *mut c_void
1133 /// Creates a copy of the DirectedChannelInfo
1134 pub extern "C" fn DirectedChannelInfo_clone(orig: &DirectedChannelInfo) -> DirectedChannelInfo {
1137 /// Returns information for the channel.
1140 pub extern "C" fn DirectedChannelInfo_channel(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::ChannelInfo {
1141 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel();
1142 crate::lightning::routing::gossip::ChannelInfo { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning::routing::gossip::ChannelInfo<>) as *mut _) }, is_owned: false }
1145 /// Returns the maximum HTLC amount allowed over the channel in the direction.
1148 pub extern "C" fn DirectedChannelInfo_htlc_maximum_msat(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> u64 {
1149 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.htlc_maximum_msat();
1153 /// Returns the [`EffectiveCapacity`] of the channel in the direction.
1155 /// This is either the total capacity from the funding transaction, if known, or the
1156 /// `htlc_maximum_msat` for the direction as advertised by the gossip network, if known,
1160 pub extern "C" fn DirectedChannelInfo_effective_capacity(this_arg: &crate::lightning::routing::gossip::DirectedChannelInfo) -> crate::lightning::routing::gossip::EffectiveCapacity {
1161 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.effective_capacity();
1162 crate::lightning::routing::gossip::EffectiveCapacity::native_into(ret)
1165 /// The effective capacity of a channel for routing purposes.
1167 /// While this may be smaller than the actual channel capacity, amounts greater than
1168 /// [`Self::as_msat`] should not be routed through the channel.
1172 pub enum EffectiveCapacity {
1173 /// The available liquidity in the channel known from being a channel counterparty, and thus a
1176 /// Either the inbound or outbound liquidity depending on the direction, denominated in
1178 liquidity_msat: u64,
1180 /// The maximum HTLC amount in one direction as advertised on the gossip network.
1182 /// The maximum HTLC amount denominated in millisatoshi.
1185 /// The total capacity of the channel as determined by the funding transaction.
1187 /// The funding amount denominated in millisatoshi.
1189 /// The maximum HTLC amount denominated in millisatoshi.
1190 htlc_maximum_msat: u64,
1192 /// A capacity sufficient to route any payment, typically used for private channels provided by
1195 /// A capacity that is unknown possibly because either the chain state is unavailable to know
1196 /// the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.
1199 use lightning::routing::gossip::EffectiveCapacity as EffectiveCapacityImport;
1200 pub(crate) type nativeEffectiveCapacity = EffectiveCapacityImport;
1202 impl EffectiveCapacity {
1204 pub(crate) fn to_native(&self) -> nativeEffectiveCapacity {
1206 EffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1207 let mut liquidity_msat_nonref = Clone::clone(liquidity_msat);
1208 nativeEffectiveCapacity::ExactLiquidity {
1209 liquidity_msat: liquidity_msat_nonref,
1212 EffectiveCapacity::MaximumHTLC {ref amount_msat, } => {
1213 let mut amount_msat_nonref = Clone::clone(amount_msat);
1214 nativeEffectiveCapacity::MaximumHTLC {
1215 amount_msat: amount_msat_nonref,
1218 EffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => {
1219 let mut capacity_msat_nonref = Clone::clone(capacity_msat);
1220 let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat);
1221 nativeEffectiveCapacity::Total {
1222 capacity_msat: capacity_msat_nonref,
1223 htlc_maximum_msat: htlc_maximum_msat_nonref,
1226 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1227 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1231 pub(crate) fn into_native(self) -> nativeEffectiveCapacity {
1233 EffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1234 nativeEffectiveCapacity::ExactLiquidity {
1235 liquidity_msat: liquidity_msat,
1238 EffectiveCapacity::MaximumHTLC {mut amount_msat, } => {
1239 nativeEffectiveCapacity::MaximumHTLC {
1240 amount_msat: amount_msat,
1243 EffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => {
1244 nativeEffectiveCapacity::Total {
1245 capacity_msat: capacity_msat,
1246 htlc_maximum_msat: htlc_maximum_msat,
1249 EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite,
1250 EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown,
1254 pub(crate) fn from_native(native: &nativeEffectiveCapacity) -> Self {
1256 nativeEffectiveCapacity::ExactLiquidity {ref liquidity_msat, } => {
1257 let mut liquidity_msat_nonref = Clone::clone(liquidity_msat);
1258 EffectiveCapacity::ExactLiquidity {
1259 liquidity_msat: liquidity_msat_nonref,
1262 nativeEffectiveCapacity::MaximumHTLC {ref amount_msat, } => {
1263 let mut amount_msat_nonref = Clone::clone(amount_msat);
1264 EffectiveCapacity::MaximumHTLC {
1265 amount_msat: amount_msat_nonref,
1268 nativeEffectiveCapacity::Total {ref capacity_msat, ref htlc_maximum_msat, } => {
1269 let mut capacity_msat_nonref = Clone::clone(capacity_msat);
1270 let mut htlc_maximum_msat_nonref = Clone::clone(htlc_maximum_msat);
1271 EffectiveCapacity::Total {
1272 capacity_msat: capacity_msat_nonref,
1273 htlc_maximum_msat: htlc_maximum_msat_nonref,
1276 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1277 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1281 pub(crate) fn native_into(native: nativeEffectiveCapacity) -> Self {
1283 nativeEffectiveCapacity::ExactLiquidity {mut liquidity_msat, } => {
1284 EffectiveCapacity::ExactLiquidity {
1285 liquidity_msat: liquidity_msat,
1288 nativeEffectiveCapacity::MaximumHTLC {mut amount_msat, } => {
1289 EffectiveCapacity::MaximumHTLC {
1290 amount_msat: amount_msat,
1293 nativeEffectiveCapacity::Total {mut capacity_msat, mut htlc_maximum_msat, } => {
1294 EffectiveCapacity::Total {
1295 capacity_msat: capacity_msat,
1296 htlc_maximum_msat: htlc_maximum_msat,
1299 nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite,
1300 nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown,
1304 /// Frees any resources used by the EffectiveCapacity
1306 pub extern "C" fn EffectiveCapacity_free(this_ptr: EffectiveCapacity) { }
1307 /// Creates a copy of the EffectiveCapacity
1309 pub extern "C" fn EffectiveCapacity_clone(orig: &EffectiveCapacity) -> EffectiveCapacity {
1313 /// Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity
1314 pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> EffectiveCapacity {
1315 EffectiveCapacity::ExactLiquidity {
1320 /// Utility method to constructs a new MaximumHTLC-variant EffectiveCapacity
1321 pub extern "C" fn EffectiveCapacity_maximum_htlc(amount_msat: u64) -> EffectiveCapacity {
1322 EffectiveCapacity::MaximumHTLC {
1327 /// Utility method to constructs a new Total-variant EffectiveCapacity
1328 pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64, htlc_maximum_msat: u64) -> EffectiveCapacity {
1329 EffectiveCapacity::Total {
1335 /// Utility method to constructs a new Infinite-variant EffectiveCapacity
1336 pub extern "C" fn EffectiveCapacity_infinite() -> EffectiveCapacity {
1337 EffectiveCapacity::Infinite}
1339 /// Utility method to constructs a new Unknown-variant EffectiveCapacity
1340 pub extern "C" fn EffectiveCapacity_unknown() -> EffectiveCapacity {
1341 EffectiveCapacity::Unknown}
1342 /// The presumed channel capacity denominated in millisatoshi for [`EffectiveCapacity::Unknown`] to
1343 /// use when making routing decisions.
1346 pub static UNKNOWN_CHANNEL_CAPACITY_MSAT: u64 = lightning::routing::gossip::UNKNOWN_CHANNEL_CAPACITY_MSAT;
1347 /// Returns the effective capacity denominated in millisatoshi.
1350 pub extern "C" fn EffectiveCapacity_as_msat(this_arg: &crate::lightning::routing::gossip::EffectiveCapacity) -> u64 {
1351 let mut ret = this_arg.to_native().as_msat();
1356 use lightning::routing::gossip::RoutingFees as nativeRoutingFeesImport;
1357 pub(crate) type nativeRoutingFees = nativeRoutingFeesImport;
1359 /// Fees for routing via a given channel or a node
1362 pub struct RoutingFees {
1363 /// A pointer to the opaque Rust object.
1365 /// Nearly everywhere, inner must be non-null, however in places where
1366 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1367 pub inner: *mut nativeRoutingFees,
1368 /// Indicates that this is the only struct which contains the same pointer.
1370 /// Rust functions which take ownership of an object provided via an argument require
1371 /// this to be true and invalidate the object pointed to by inner.
1375 impl Drop for RoutingFees {
1376 fn drop(&mut self) {
1377 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
1378 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1382 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
1384 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
1386 /// Used only if an object of this type is returned as a trait impl by a method
1387 pub(crate) extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
1388 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRoutingFees) };
1392 pub(crate) fn get_native_ref(&self) -> &'static nativeRoutingFees {
1393 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1395 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRoutingFees {
1396 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1398 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1399 pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
1400 assert!(self.is_owned);
1401 let ret = ObjOps::untweak_ptr(self.inner);
1402 self.inner = core::ptr::null_mut();
1406 /// Flat routing fee in millisatoshis.
1408 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
1409 let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat;
1412 /// Flat routing fee in millisatoshis.
1414 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
1415 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val;
1417 /// Liquidity-based routing fee in millionths of a routed amount.
1418 /// In other words, 10000 is 1%.
1420 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
1421 let mut inner_val = &mut this_ptr.get_native_mut_ref().proportional_millionths;
1424 /// Liquidity-based routing fee in millionths of a routed amount.
1425 /// In other words, 10000 is 1%.
1427 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
1428 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.proportional_millionths = val;
1430 /// Constructs a new RoutingFees given each field
1433 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
1434 RoutingFees { inner: ObjOps::heap_alloc(nativeRoutingFees {
1435 base_msat: base_msat_arg,
1436 proportional_millionths: proportional_millionths_arg,
1437 }), is_owned: true }
1439 /// Checks if two RoutingFeess contain equal inner contents.
1440 /// This ignores pointers and is_owned flags and looks at the values in fields.
1441 /// Two objects with NULL inner values will be considered "equal" here.
1443 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
1444 if a.inner == b.inner { return true; }
1445 if a.inner.is_null() || b.inner.is_null() { return false; }
1446 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1448 impl Clone for RoutingFees {
1449 fn clone(&self) -> Self {
1451 inner: if <*mut nativeRoutingFees>::is_null(self.inner) { core::ptr::null_mut() } else {
1452 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1458 /// Used only if an object of this type is returned as a trait impl by a method
1459 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
1460 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
1463 /// Creates a copy of the RoutingFees
1464 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
1467 /// Generates a non-cryptographic 64-bit hash of the RoutingFees.
1469 pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 {
1470 if o.inner.is_null() { return 0; }
1471 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1472 #[allow(deprecated)]
1473 let mut hasher = core::hash::SipHasher::new();
1474 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1475 core::hash::Hasher::finish(&hasher)
1478 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
1479 pub extern "C" fn RoutingFees_write(obj: &crate::lightning::routing::gossip::RoutingFees) -> crate::c_types::derived::CVec_u8Z {
1480 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1483 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1484 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
1487 /// Read a RoutingFees from a byte array, created by RoutingFees_write
1488 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
1489 let res: Result<lightning::routing::gossip::RoutingFees, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1490 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() };
1494 use lightning::routing::gossip::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
1495 pub(crate) type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
1497 /// Information received in the latest node_announcement from this node.
1500 pub struct NodeAnnouncementInfo {
1501 /// A pointer to the opaque Rust object.
1503 /// Nearly everywhere, inner must be non-null, however in places where
1504 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1505 pub inner: *mut nativeNodeAnnouncementInfo,
1506 /// Indicates that this is the only struct which contains the same pointer.
1508 /// Rust functions which take ownership of an object provided via an argument require
1509 /// this to be true and invalidate the object pointed to by inner.
1513 impl Drop for NodeAnnouncementInfo {
1514 fn drop(&mut self) {
1515 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
1516 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1520 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
1522 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
1524 /// Used only if an object of this type is returned as a trait impl by a method
1525 pub(crate) extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
1526 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo) };
1529 impl NodeAnnouncementInfo {
1530 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAnnouncementInfo {
1531 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1533 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAnnouncementInfo {
1534 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1536 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1537 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
1538 assert!(self.is_owned);
1539 let ret = ObjOps::untweak_ptr(self.inner);
1540 self.inner = core::ptr::null_mut();
1544 /// Protocol features the node announced support for
1546 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
1547 let mut inner_val = &mut this_ptr.get_native_mut_ref().features;
1548 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 }
1550 /// Protocol features the node announced support for
1552 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
1553 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) };
1555 /// When the last known update to the node state was issued.
1556 /// Value is opaque, as set in the announcement.
1558 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
1559 let mut inner_val = &mut this_ptr.get_native_mut_ref().last_update;
1562 /// When the last known update to the node state was issued.
1563 /// Value is opaque, as set in the announcement.
1565 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
1566 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update = val;
1568 /// Color assigned to the node
1570 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
1571 let mut inner_val = &mut this_ptr.get_native_mut_ref().rgb;
1574 /// Color assigned to the node
1576 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
1577 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data;
1579 /// Moniker assigned to the node.
1580 /// May be invalid or malicious (eg control chars),
1581 /// should not be exposed to the user.
1583 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::routing::gossip::NodeAlias {
1584 let mut inner_val = &mut this_ptr.get_native_mut_ref().alias;
1585 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 }
1587 /// Moniker assigned to the node.
1588 /// May be invalid or malicious (eg control chars),
1589 /// should not be exposed to the user.
1591 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::routing::gossip::NodeAlias) {
1592 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = *unsafe { Box::from_raw(val.take_inner()) };
1594 /// An initial announcement of the node
1595 /// Mostly redundant with the data we store in fields explicitly.
1596 /// Everything else is useful only for sending out for initial routing sync.
1597 /// Not stored if contains excess data to prevent DoS.
1599 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1601 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
1602 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_message;
1603 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 };
1606 /// An initial announcement of the node
1607 /// Mostly redundant with the data we store in fields explicitly.
1608 /// Everything else is useful only for sending out for initial routing sync.
1609 /// Not stored if contains excess data to prevent DoS.
1611 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1613 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
1614 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1615 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val;
1617 /// Constructs a new NodeAnnouncementInfo given each field
1620 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 announcement_message_arg: crate::lightning::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo {
1621 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()) } }) };
1622 NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo {
1623 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
1624 last_update: last_update_arg,
1626 alias: *unsafe { Box::from_raw(alias_arg.take_inner()) },
1627 announcement_message: local_announcement_message_arg,
1628 }), is_owned: true }
1630 impl Clone for NodeAnnouncementInfo {
1631 fn clone(&self) -> Self {
1633 inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1634 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1640 /// Used only if an object of this type is returned as a trait impl by a method
1641 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1642 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
1645 /// Creates a copy of the NodeAnnouncementInfo
1646 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1649 /// Checks if two NodeAnnouncementInfos contain equal inner contents.
1650 /// This ignores pointers and is_owned flags and looks at the values in fields.
1651 /// Two objects with NULL inner values will be considered "equal" here.
1653 pub extern "C" fn NodeAnnouncementInfo_eq(a: &NodeAnnouncementInfo, b: &NodeAnnouncementInfo) -> bool {
1654 if a.inner == b.inner { return true; }
1655 if a.inner.is_null() || b.inner.is_null() { return false; }
1656 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1658 /// Internet-level addresses via which one can connect to the node
1661 pub extern "C" fn NodeAnnouncementInfo_addresses(this_arg: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_NetAddressZ {
1662 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.addresses();
1663 let mut local_ret_clone = Vec::new(); local_ret_clone.extend_from_slice(ret); let mut ret = local_ret_clone; let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::msgs::NetAddress::native_into(item) }); };
1668 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1669 pub extern "C" fn NodeAnnouncementInfo_write(obj: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1670 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1673 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1674 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1677 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1678 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1679 let res: Result<lightning::routing::gossip::NodeAnnouncementInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1680 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() };
1684 use lightning::routing::gossip::NodeAlias as nativeNodeAliasImport;
1685 pub(crate) type nativeNodeAlias = nativeNodeAliasImport;
1687 /// A user-defined name for a node, which may be used when displaying the node in a graph.
1689 /// Since node aliases are provided by third parties, they are a potential avenue for injection
1690 /// attacks. Care must be taken when processing.
1693 pub struct NodeAlias {
1694 /// A pointer to the opaque Rust object.
1696 /// Nearly everywhere, inner must be non-null, however in places where
1697 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1698 pub inner: *mut nativeNodeAlias,
1699 /// Indicates that this is the only struct which contains the same pointer.
1701 /// Rust functions which take ownership of an object provided via an argument require
1702 /// this to be true and invalidate the object pointed to by inner.
1706 impl Drop for NodeAlias {
1707 fn drop(&mut self) {
1708 if self.is_owned && !<*mut nativeNodeAlias>::is_null(self.inner) {
1709 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1713 /// Frees any resources used by the NodeAlias, if is_owned is set and inner is non-NULL.
1715 pub extern "C" fn NodeAlias_free(this_obj: NodeAlias) { }
1717 /// Used only if an object of this type is returned as a trait impl by a method
1718 pub(crate) extern "C" fn NodeAlias_free_void(this_ptr: *mut c_void) {
1719 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAlias) };
1723 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeAlias {
1724 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1726 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeAlias {
1727 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1729 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1730 pub(crate) fn take_inner(mut self) -> *mut nativeNodeAlias {
1731 assert!(self.is_owned);
1732 let ret = ObjOps::untweak_ptr(self.inner);
1733 self.inner = core::ptr::null_mut();
1738 pub extern "C" fn NodeAlias_get_a(this_ptr: &NodeAlias) -> *const [u8; 32] {
1739 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1743 pub extern "C" fn NodeAlias_set_a(this_ptr: &mut NodeAlias, mut val: crate::c_types::ThirtyTwoBytes) {
1744 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.data;
1746 /// Constructs a new NodeAlias given each field
1749 pub extern "C" fn NodeAlias_new(mut a_arg: crate::c_types::ThirtyTwoBytes) -> NodeAlias {
1750 NodeAlias { inner: ObjOps::heap_alloc(lightning::routing::gossip::NodeAlias (
1752 )), is_owned: true }
1754 impl Clone for NodeAlias {
1755 fn clone(&self) -> Self {
1757 inner: if <*mut nativeNodeAlias>::is_null(self.inner) { core::ptr::null_mut() } else {
1758 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1764 /// Used only if an object of this type is returned as a trait impl by a method
1765 pub(crate) extern "C" fn NodeAlias_clone_void(this_ptr: *const c_void) -> *mut c_void {
1766 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAlias)).clone() })) as *mut c_void
1769 /// Creates a copy of the NodeAlias
1770 pub extern "C" fn NodeAlias_clone(orig: &NodeAlias) -> NodeAlias {
1773 /// Checks if two NodeAliass contain equal inner contents.
1774 /// This ignores pointers and is_owned flags and looks at the values in fields.
1775 /// Two objects with NULL inner values will be considered "equal" here.
1777 pub extern "C" fn NodeAlias_eq(a: &NodeAlias, b: &NodeAlias) -> bool {
1778 if a.inner == b.inner { return true; }
1779 if a.inner.is_null() || b.inner.is_null() { return false; }
1780 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1783 /// Serialize the NodeAlias object into a byte array which can be read by NodeAlias_read
1784 pub extern "C" fn NodeAlias_write(obj: &crate::lightning::routing::gossip::NodeAlias) -> crate::c_types::derived::CVec_u8Z {
1785 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1788 pub(crate) extern "C" fn NodeAlias_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1789 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAlias) })
1792 /// Read a NodeAlias from a byte array, created by NodeAlias_write
1793 pub extern "C" fn NodeAlias_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAliasDecodeErrorZ {
1794 let res: Result<lightning::routing::gossip::NodeAlias, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1795 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() };
1799 use lightning::routing::gossip::NodeInfo as nativeNodeInfoImport;
1800 pub(crate) type nativeNodeInfo = nativeNodeInfoImport;
1802 /// Details about a node in the network, known from the network announcement.
1805 pub struct NodeInfo {
1806 /// A pointer to the opaque Rust object.
1808 /// Nearly everywhere, inner must be non-null, however in places where
1809 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1810 pub inner: *mut nativeNodeInfo,
1811 /// Indicates that this is the only struct which contains the same pointer.
1813 /// Rust functions which take ownership of an object provided via an argument require
1814 /// this to be true and invalidate the object pointed to by inner.
1818 impl Drop for NodeInfo {
1819 fn drop(&mut self) {
1820 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1821 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1825 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1827 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1829 /// Used only if an object of this type is returned as a trait impl by a method
1830 pub(crate) extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1831 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeInfo) };
1835 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeInfo {
1836 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1838 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeInfo {
1839 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1841 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1842 pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1843 assert!(self.is_owned);
1844 let ret = ObjOps::untweak_ptr(self.inner);
1845 self.inner = core::ptr::null_mut();
1849 /// All valid channels a node has announced
1851 /// Returns a copy of the field.
1853 pub extern "C" fn NodeInfo_get_channels(this_ptr: &NodeInfo) -> crate::c_types::derived::CVec_u64Z {
1854 let mut inner_val = this_ptr.get_native_mut_ref().channels.clone();
1855 let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); };
1856 local_inner_val.into()
1858 /// All valid channels a node has announced
1860 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1861 let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1862 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channels = local_val;
1864 /// More information about a node from node_announcement.
1865 /// Optional because we store a Node entry after learning about it from
1866 /// a channel announcement, but before receiving a node announcement.
1868 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
1870 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::gossip::NodeAnnouncementInfo {
1871 let mut inner_val = &mut this_ptr.get_native_mut_ref().announcement_info;
1872 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 };
1875 /// More information about a node from node_announcement.
1876 /// Optional because we store a Node entry after learning about it from
1877 /// a channel announcement, but before receiving a node announcement.
1879 /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
1881 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::gossip::NodeAnnouncementInfo) {
1882 let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1883 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val;
1885 /// Constructs a new NodeInfo given each field
1888 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 {
1889 let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1890 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()) } }) };
1891 NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo {
1892 channels: local_channels_arg,
1893 announcement_info: local_announcement_info_arg,
1894 }), is_owned: true }
1896 impl Clone for NodeInfo {
1897 fn clone(&self) -> Self {
1899 inner: if <*mut nativeNodeInfo>::is_null(self.inner) { core::ptr::null_mut() } else {
1900 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1906 /// Used only if an object of this type is returned as a trait impl by a method
1907 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1908 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1911 /// Creates a copy of the NodeInfo
1912 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1915 /// Checks if two NodeInfos contain equal inner contents.
1916 /// This ignores pointers and is_owned flags and looks at the values in fields.
1917 /// Two objects with NULL inner values will be considered "equal" here.
1919 pub extern "C" fn NodeInfo_eq(a: &NodeInfo, b: &NodeInfo) -> bool {
1920 if a.inner == b.inner { return true; }
1921 if a.inner.is_null() || b.inner.is_null() { return false; }
1922 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1925 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1926 pub extern "C" fn NodeInfo_write(obj: &crate::lightning::routing::gossip::NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1927 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1930 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1931 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1934 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1935 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1936 let res: Result<lightning::routing::gossip::NodeInfo, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
1937 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() };
1941 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
1942 pub extern "C" fn NetworkGraph_write(obj: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1943 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1946 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1947 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1950 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
1951 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice, arg: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1953 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);
1954 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() };
1957 /// Creates a new, empty, network graph.
1960 pub extern "C" fn NetworkGraph_new(mut network: crate::bitcoin::network::Network, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::NetworkGraph {
1961 let mut ret = lightning::routing::gossip::NetworkGraph::new(network.into_bitcoin(), logger);
1962 crate::lightning::routing::gossip::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1965 /// Returns a read-only view of the network graph.
1968 pub extern "C" fn NetworkGraph_read_only(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::lightning::routing::gossip::ReadOnlyNetworkGraph {
1969 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.read_only();
1970 crate::lightning::routing::gossip::ReadOnlyNetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true }
1973 /// The unix timestamp provided by the most recent rapid gossip sync.
1974 /// It will be set by the rapid sync process after every sync completion.
1977 pub extern "C" fn NetworkGraph_get_last_rapid_gossip_sync_timestamp(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::derived::COption_u32Z {
1978 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_last_rapid_gossip_sync_timestamp();
1979 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() }) };
1983 /// Update the unix timestamp provided by the most recent rapid gossip sync.
1984 /// This should be done automatically by the rapid sync process after every sync completion.
1986 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) {
1987 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.set_last_rapid_gossip_sync_timestamp(last_rapid_gossip_sync_timestamp)
1990 /// For an already known node (from channel announcements), update its stored properties from a
1991 /// given node announcement.
1993 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
1994 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1995 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1998 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 {
1999 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_announcement(msg.get_native_ref());
2000 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() };
2004 /// For an already known node (from channel announcements), update its stored properties from a
2005 /// given node announcement without verifying the associated signatures. Because we aren't
2006 /// given the associated signatures here we cannot relay the node announcement to any of our
2010 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 {
2011 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_node_from_unsigned_announcement(msg.get_native_ref());
2012 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() };
2016 /// Store or update channel info from a channel announcement.
2018 /// You probably don't want to call this directly, instead relying on a P2PGossipSync's
2019 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
2020 /// routing messages from a source using a protocol other than the lightning P2P protocol.
2022 /// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
2023 /// the corresponding UTXO exists on chain and is correctly-formatted.
2026 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 {
2027 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() } }})} };
2028 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_utxo_lookup);
2029 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() };
2033 /// Store or update channel info from a channel announcement without verifying the associated
2034 /// signatures. Because we aren't given the associated signatures here we cannot relay the
2035 /// channel announcement to any of our peers.
2037 /// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
2038 /// the corresponding UTXO exists on chain and is correctly-formatted.
2041 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 {
2042 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() } }})} };
2043 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_utxo_lookup);
2044 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() };
2048 /// Update channel from partial announcement data received via rapid gossip sync
2050 /// `timestamp: u64`: Timestamp emulating the backdated original announcement receipt (by the
2051 /// rapid gossip sync server)
2053 /// All other parameters as used in [`msgs::UnsignedChannelAnnouncement`] fields.
2056 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 {
2057 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());
2058 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() };
2062 /// Marks a channel in the graph as failed permanently.
2064 /// The channel and any node for which this was their last channel are removed from the graph.
2066 pub extern "C" fn NetworkGraph_channel_failed_permanent(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut short_channel_id: u64) {
2067 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_failed_permanent(short_channel_id)
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() }) };